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 3.8k 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.
    • A Offline
      ashishtank Module Developer @majdzik84
      last edited by ashishtank

      @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 Reply Quote 1
      • M Offline
        majdzik84 @ashishtank
        last edited by

        @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 Reply Quote 0
        • A Offline
          ashishtank Module Developer @majdzik84
          last edited by

          @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 Reply Quote 0
          • M Offline
            majdzik84 @ashishtank
            last edited by

            @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 Reply Quote 0
            • A Offline
              ashishtank Module Developer @majdzik84
              last edited by

              @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 Reply Quote 0
              • M Offline
                majdzik84 @ashishtank
                last edited by

                @ashishtank

                Yes, it works - thank you :)

                A 1 Reply Last reply Reply Quote 0
                • A Offline
                  ashishtank Module Developer @majdzik84
                  last edited by

                  @majdzik84 Good to know ! :)

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    anderios Banned
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • 1
                    • 2
                    • 1 / 2
                    • First post
                      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