• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Force a module refresh - not the entire page

Scheduled Pinned Locked Moved Requests
11 Posts 3 Posters 2.9k Views 4 Watching
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.
  • M Offline
    majdzik84
    last edited by Dec 20, 2020, 11:09 AM

    Is there any way to command refresh one specific module?
    I found an option to refresh the entire page. I would like this way to update the HA module when the sensor changes state, not just temporarily.

    A 1 Reply Last reply Dec 20, 2020, 6:26 PM Reply Quote 0
    • A Offline
      ashishtank Module Developer @majdzik84
      last edited by Dec 20, 2020, 6:26 PM

      @majdzik84 You can call updatedom method of the target module to refresh that specific module, or if that module have notification refresh then can send notification. Check below documentation for update dom method of modules
      https://docs.magicmirror.builders/development/core-module-file.html#this-updatedom-speed

      M 1 Reply Last reply Dec 21, 2020, 10:20 AM Reply Quote 0
      • M Offline
        majdzik84 @ashishtank
        last edited by Dec 21, 2020, 10:20 AM

        @ashishtank Thank you for your answer. I am glad that there is such a possibility. Unfortunately, I don’t know where to start to get it. I will write what I mean and maybe I could count on help.

        I control the mirror through Home assistant using MMM-Remote-Control (e.g. I send command http://192.168.2.200:8080/api/module/alert/showalert?title=ZAMKNIJ ZAMEK&message=w d door%20frontowych) in the case of alerts.

        I have a module for showing sensors (https://github.com/leinich/MMM-homeassistant-sensors) that has the ability to set a time refresh.

        I would like to send a command to the mirror from Home assistant to update the module when the sensor changes its state.

        Do you know how to achieve it in a simple way for me?
        How do I send the updatedom command to this module?

        A 1 Reply Last reply Dec 21, 2020, 11:00 AM Reply Quote 0
        • A Offline
          ashishtank Module Developer @majdzik84
          last edited by ashishtank Dec 21, 2020, 11:40 AM Dec 21, 2020, 11:00 AM

          @majdzik84 If I understood you correctly, you want to send message to Magic Mirror when sensor value change in home assistant and it should refresh the MMM-HomeAssistant-Sensors module, so you see updated value of sensor over there ?

          It should be doable with MMM-Remove-control same way as you are sending alert. I have not installed the remote control module and MMM-HomeAssistant-Sensors so can’t test the code my self but you can do below.

          • Add below code in MMM-homeassistant-sensors.js
          notificationReceived: function (notification, payload, sender) {
          		if (notification === "REFRESHHOMEASSISTANT") {
          			this.getStats();
          		} 
          },
          
          • Do not forget the , after } in last line else it will break the module
          • Restart the mirror
          • From your browser open http://192.168.2.200:8080/api/module/MMM-homeassistant-sensors or http://192.168.2.200:8080/api/module/homeassistantsensors if first url does not work
          • If you see REFRESHHOMEASSISTANT in response then remote control knows new action on HA module
          • Now you can send command from HA to refresh the module using http://192.168.2.200:8080/api/module/homeassistantsensors/refreshhomeassistant (url should be in lowercase and also MMM- and - are removed in api path)

          As I can not test it and things I have suggested above are based on my code review of both the modules. you might need to adjust one or more things. but in theory it should work.

          Let me know how (or if) it works.

          M 1 Reply Last reply Dec 21, 2020, 11:43 AM Reply Quote 1
          • M Offline
            majdzik84 @ashishtank
            last edited by Dec 21, 2020, 11:43 AM

            @ashishtank
            When i try http://192.168.2.200:8080/api/module/MMM-homeassistant-sensors i dont see REFRESHHOME ASSISTANT

            {"success":true,"data":[{"index":"17","identifier":"module_17_MMM-homeassistant-sensors","name":"MMM-homeassistant-sensors","path":"modules/MMM-homeassistant-sensors/","file":"MMM-homeassistant-sensors.js","position":"bottom_left","configDeepMerge":false,"config":{"prettyName":false,"stripName":false,"title":"Home Assistant","host":"192.168.2.98","port":"8123","https":false,"token":"xxxxx","apipassword":"","updateInterval":120000,"displaySymbol":true,"debuglogging":false,"values":[{"sensor":"sensor.natalka_temperature","alertThreshold":26,"icons":[{"default":"thermometer"}]},{"sensor":"sensor.alicja_temperature","alertThreshold":26,"icons":[{"default":"thermometer"}]},{"sensor":"sensor.sypialnia_temperature","alertThreshold":26,"icons":[{"default":"thermometer"}]},{"sensor":"sensor.salon_temperatura","alertThreshold":26,"icons":[{"default":"thermometer"}]},{"sensor":"binary_sensor.zamek_front","icons":[{"state_off":"lock","state_on":"lock-open-variant"}]},{"sensor":"binary_sensor.zamek_tyl","icons":[{"state_off":"lock","state_on":"lock-open-variant"}]},{"sensor":"binary_sensor.brama_wjazdowa","icons":[{"state_off":"gate","state_on":"gate-open"}]},{"sensor":"binary_sensor.brama_lewa","icons":[{"state_off":"garage","state_on":"garage-open"}]},{"sensor":"binary_sensor.brama_prawa","icons":[{"state_off":"garage","state_on":"garage-open"}]}]},"classes":"MMM-homeassistant-sensors","hidden":false,"lockStrings":[]}]}
            

            When I try http://192.168.2.200:8080/api/module/homeassistant-sensors/refreshhomeassistant i get

            {"success":false,"message":"Module Name or Identifier Not Found!"}
            
            A 1 Reply Last reply Dec 21, 2020, 11:50 AM Reply Quote 0
            • A Offline
              ashishtank Module Developer @majdzik84
              last edited by Dec 21, 2020, 11:50 AM

              @majdzik84 said in Force a module refresh - not the entire page:

              {“success”:false,“message”:“Module Name or Identifier Not Found!”}

              • Did you added the code in MMM-homeassistant-sensors.js ?
              • Can you try http://192.168.2.200:8080/api/module/homeassistantsensors/refreshhomeassistant url ? (I have removed the - from home assistant sensors)
                for more details about module and it’s action check https://github.com/Jopyth/MMM-Remote-Control/tree/master/API
              M 1 Reply Last reply Dec 21, 2020, 12:53 PM Reply Quote 0
              • M Offline
                majdzik84 @ashishtank
                last edited by Dec 21, 2020, 12:53 PM

                @ashishtank Yes, i added the code in MMM-homeassistant-sensors.js and restart

                a6091d47-70f4-4c84-a8d5-bd13d74cdab8-image.png

                I tried different variations but refreshhomeassistant it is not visible at all.

                I try
                fff75055-7c4d-4d77-897d-0fc37ad3bb12-image.png

                A 1 Reply Last reply Dec 21, 2020, 1:01 PM Reply Quote 0
                • A Offline
                  ashishtank Module Developer @majdzik84
                  last edited by Dec 21, 2020, 1:01 PM

                  @majdzik84 Okay, not sure why it is not listing the action. can you try below once ? it will send notification to all the modules including HA module and it should refresh the module. this is based on Remote control documentation https://github.com/Jopyth/MMM-Remote-Control/blob/master/API/README.md

                  http://192.168.2.200:8080/api/notification/REFRESHHOMEASSISTANT

                  M 1 Reply Last reply Dec 21, 2020, 1:05 PM Reply Quote 0
                  • M Offline
                    majdzik84 @ashishtank
                    last edited by Dec 21, 2020, 1:05 PM

                    @ashishtank

                    Yes, it works - thank you :)

                    A 1 Reply Last reply Dec 21, 2020, 1:06 PM Reply Quote 0
                    • A Offline
                      ashishtank Module Developer @majdzik84
                      last edited by Dec 21, 2020, 1:06 PM

                      @majdzik84 Good to know ! :)

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        1/11
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy