MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.20.0 is available! For more information about this release, check out this topic.

    Need help with refactoring charting for a fork of a module.

    Development
    2
    16
    234
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sdetweil @jwilson5607 last edited by sdetweil

      @jwilson5607 1st… you never showed your config.js ( without the apikey) , so I don’t see your title string

      console.log()… I usually add a if(this.config.debug) in front so you can turn them on when u need it via config.js
      add a debug:false, to the beestat.js to set it to false by default.

      as for title… did u use the debugger in the dev console… you could stop right there to see if the values are what you think they should be

      ‘payload’ is just a idea name…

      its the data in the notification, ie the payload

      doesn’t matter what its called on either side… use whatever term works in your head

      payload is just generic

      in got this notification, id = 1st parm, and the data/payload of the notification is in the 2nd parm…

      you have loading cause the code does this is getdom()

              if (!this.loaded_history) {   // if data not received yet
                  outerWrapper.innerHTML = this.translate("LOADING");
                  outerWrapper.className = "dimmed light small";
                  return outerWrapper;
              }
      

      but here is where this.loaded_history is set to true

      socketNotificationReceived: function(notification, payload) {
              if (notification === "beestat_runtime") {
                  this.hist = payload;  // yay!!  we got some data from helper, save it
                  this.loaded_history = true; // indicate we  got data so getDom() will work
              }
      

      that just says hey, if I get socketnotification events, call here
      and if the id string is “beestat_runtime” then
      save the data (payload) in the variable this.hist

      on the send of result.data, you only expected the DATA on the beetstat.js,. so that is what I had sent…

      using the debugger will REALLY make this a LOT easier… cause u will see the data as u process it…

      Sam

      Create a working config
      How to add modules

      1 Reply Last reply Reply Quote 0
      • S
        sdetweil @jwilson5607 last edited by

        @jwilson5607 I don’t have my apikey yet… so only get error

        Sam

        Create a working config
        How to add modules

        1 Reply Last reply Reply Quote 0
        • S
          sdetweil @jwilson5607 last edited by sdetweil

          @jwilson5607 also, hist is set to be an array []

          but the data comes back as objects

          "data": {  //  is an object
                         "29249277": {
                              "runtime_thermostat_summary_id": 29249277,
                              "user_id": 18261,
                              "thermostat_id": XXXXXX,
                              "date": "2022-03-07",
                              "count": 124,
                              "sum_compressor_cool_1": 0,
                              "sum_compressor_cool_2": 0,
                              "sum_compressor_heat_1": 0,
                              "sum_compressor_heat_2": 0,
                              "sum_auxiliary_heat_1": 3600,
                              "sum_auxiliary_heat_2": 1335,
                              "sum_fan": 8070,
                              "sum_humidifier": 15,
                              "sum_dehumidifier": 0,
                              "sum_ventilator": 0,
                              "sum_economizer": 0,
                              "sum_degree_days": 0,
                              "avg_outdoor_temperature": 33.5,
                              "avg_outdoor_humidity": 83,
                              "min_outdoor_temperature": 31.4,
                              "max_outdoor_temperature": 36.3,
                              "avg_indoor_temperature": 68.4,
                              "avg_indoor_humidity": 38,
                              "deleted": false
                          },
                          "29249278": {
                              "runtime_thermostat_summary_id": 29249278,
                              "user_id": 18261,
                              "thermostat_id": XXXXXX,
                              "date": "2022-03-08",
                              "count": 287,
                              "sum_compressor_cool_1": 0,
                              "sum_compressor_cool_2": 0,
                              "sum_compressor_heat_1": 0,
                              "sum_compressor_heat_2": 0,
                              "sum_auxiliary_heat_1": 11250,
                              "sum_auxiliary_heat_2": 0,
                              "sum_fan": 18150,
                              "sum_humidifier": 5010,
                              "sum_dehumidifier": 0,
                              "sum_ventilator": 0,
                              "sum_economizer": 0,
                              "sum_degree_days": 0,
                              "avg_outdoor_temperature": 32,
                              "avg_outdoor_humidity": 75,
                              "min_outdoor_temperature": 27.1,
                              "max_outdoor_temperature": 36.5,
                              "avg_indoor_temperature": 68.2,
                              "avg_indoor_humidity": 36,
                              "deleted": false
                          },
          }
          

          you can’t process that with a simple for loop… as u don’t have an array, buy you could MAKE an array with the

          function Object.keys(objectname)

          is will return a list (array) of all the high level object names in the input object, in your case
          [ “29249277”, “29249278”]

          and you could use it like this

           Object.keys(this.hist).forEach(thermostat_id =>{
                       let thermostatinfo=this.hist[thermostat_id]
                           xxx=     thermostatinfo.sum_auxiliary_heat_1 / 3600
           })
          

          sent a pull request with this approach

          Sam

          Create a working config
          How to add modules

          S 1 Reply Last reply Reply Quote 0
          • S
            sdetweil @sdetweil last edited by

            @jwilson5607 finally got my beestat apikey

            one change

            in node_helper, I tested the response for the literal ‘true’, not boolean true
            change to

                         if(result.success==true){
            

            Sam

            Create a working config
            How to add modules

            J 1 Reply Last reply Reply Quote 0
            • J
              jwilson5607 @sdetweil last edited by

              @sdetweil Sorry for the delay - life got busier than normal for a while. I am extremely thankful for your help as this was beyond my current set of abilities. I’ve updated my code and verified that its working for me as expected. Thank you again, you’re amazing!

              S 1 Reply Last reply Reply Quote 1
              • S
                sdetweil @jwilson5607 last edited by

                @jwilson5607 glad u got it working…

                if I hadn’t done my own chartjs module, I would have had no clue,

                Sam

                Create a working config
                How to add modules

                1 Reply Last reply Reply Quote 0
                • 1
                • 2
                • 2 / 2
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy