Zigbee2Mqtt - OTA "Over the Air" updates - automating the OTA one-by-one in NodeRed in Home Assistant #6543
Replies: 3 comments 2 replies
-
So first you don't need to reset Second, unless you have exactly one device of each type I'm pretty sure you're going to have race conditions. Let me explain with an example. Let's say you have 4 Philips Hue lightbulbs and an OTA update is released for that device. All 4 of those are going to have an update available at almost exactly the same time.
I have a flow similar to this but I don't do automatic updates personally. What I do is send a mobile app notification to myself when an update is available for a device. That notification will have an action which is "update" which when pressed triggers a flow that sends the MQTT message to update the device. I also have a second flow which looks to see if any sensors which match Personally I would not want automatic updates here since I'm not aware of any way to rollback a bad update. I am very cautious about updating things within my Home Automation ecosystem as I want to find out what changed and ideally know how to revert if the update didn't work well for me. I have had too many bad updates to trust automatic updates for pretty much when it comes to home automation devices and software. But if you do want that I would suggest switching from triggering on state change to polling. This way if the flow stops because an update is already in progress its ok and it will keep trying until nothing is updating. I would also use a control node like delay set to rate limit or a trigger node to ensure that only one "update is available" message can get through at one time. |
Beta Was this translation helpful? Give feedback.
-
I'm quite interested in a solution like this. @rwunsch i got like 70 zigbee devices, not all of them can be updated, but all my lights in my house are hue lights, and they get updates rather often. Right now i'm updating them manually with the Zigbee2MqttAssistant interface, which works rather well to be honest, but it's tedious and painfully slow. It takes me a couple of days to get through all my devices when an update hits. |
Beta Was this translation helpful? Give feedback.
-
hi @Dennisreneholm , I actually did not look at this issue, back after @mdegat01 's comments I added a limitation on messages (1msg/30min) - to somewhat mitigate the race-condition: I still see 2-3 devices updating simultaniously, however - but it works for me (Zigbee network might be a little slow during updates ...). For the "context stores" I had set the context-variable to "file" already, but wanted to make sure it is being reset on start-up: I did not find a way to poll for these states, as the polling -node does NOT support "regex"-based polling, and I would have to configure 70-80 nodes for polling (number of zigbee devices, actually these are 116 by now, but some are Xiaomi devices). I actually do not understand why, as the "State trigger" should only only trigger once when update is happening/state-changed, but eventually all my devices-auto-update (is this fired again on startup?). |
Beta Was this translation helpful? Give feedback.
-
Hello all,
I am very impressed by Zigbee2mqtt - and was super happy to see the build-in UI for Zigbee2mqtt in Home-Assistant - and super happy to be able to do updates of most of my devices OTA.
However, this is currently a manual process, kicking-off the update one at a time.
I tried to automate the update once the are available - and used NodeRed to do so.
Here is my approach:
The flow is here as json to be imported into node-red:
[{"id":"bb4b97fe.aa45e8","type":"tab","label":"Zigbee2mqtt update","disabled":false,"info":""},{"id":"a0d299e0.8799c8","type":"trigger-state","z":"bb4b97fe.aa45e8","name":"Update Available","server":"5a0908cf.d3bd78","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"_update_available","entityidfiltertype":"regex","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":130,"y":140,"wires":[["e82d842e.6db508"],[]]},{"id":"e82d842e.6db508","type":"switch","z":"bb4b97fe.aa45e8","name":"If \"Flow: update going on\" is FALSE","property":"zigbee_update_going_on_state","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":200,"wires":[["2b2da468.eb9c2c"]]},{"id":"8db78272.81801","type":"inject","z":"bb4b97fe.aa45e8","name":"Set \"FLOW: upgrade going on\" to FALSE on startup","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":270,"y":40,"wires":[["d98780ad.6fe93"]]},{"id":"d98780ad.6fe93","type":"change","z":"bb4b97fe.aa45e8","name":"Set \"FLOW: update goind on\" to FALSE","rules":[{"t":"set","p":"zigbee_update_going_on_state","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":40,"wires":[[]]},{"id":"72b25be3.9c9b64","type":"api-call-service","z":"bb4b97fe.aa45e8","name":"","server":"5a0908cf.d3bd78","version":1,"debugenabled":false,"service_domain":"mqtt","service":"publish","entityId":"","data":"{\"topic\":\"zigbee2mqtt/bridge/request/device/ota_update/update\",\"payload\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":430,"y":320,"wires":[["363a6d24.48f812"]]},{"id":"363a6d24.48f812","type":"change","z":"bb4b97fe.aa45e8","name":"Set \"FLOW: update going on\" to \"true\"","rules":[{"t":"set","p":"zigbee_update_going_on_state","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":400,"wires":[["5f9eb160.33258"]]},{"id":"1b324d94.b0d9d2","type":"ha-wait-until","z":"bb4b97fe.aa45e8","name":"Wait-until \"<entity>_update_available\" is OFF","server":"5a0908cf.d3bd78","outputs":2,"entityId":"","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"30","timeoutType":"num","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":630,"y":540,"wires":[["e89a0468.421658"],["e89a0468.421658"]]},{"id":"e89a0468.421658","type":"change","z":"bb4b97fe.aa45e8","name":"Set \"FLOW: update going on\" to \"false\"","rules":[{"t":"set","p":"zigbee_update_going_on_state","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":600,"wires":[[]]},{"id":"5f9eb160.33258","type":"function","z":"bb4b97fe.aa45e8","name":"add \"entity_id\" into msg.payload","func":"msg.payload = {\n entity_id: msg.data.entity_id,\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":480,"wires":[["1b324d94.b0d9d2"]]},{"id":"2b2da468.eb9c2c","type":"function","z":"bb4b97fe.aa45e8","name":"get \"friendly_name\" - remove \"udpdate_available\" - return \"friendly_name\" as payload","func":"var friendly_name = msg.data.event.new_state.attributes.friendly_name;\n//node.warn(\"friendly_name : \" + friendly_name);\nmsg.payload = friendly_name.replace(\" update available\",\"\");\n//node.warn(\"msg.payload = \" + msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":260,"wires":[["72b25be3.9c9b64"]]},{"id":"5a0908cf.d3bd78","type":"server","name":"Home Assistant","addon":true}]
This might need to be adjusted depending on your set-up - but I would expect this to be working for anyone.
I would be interested about your feedback.
Thanks and cheers
Robert
Beta Was this translation helpful? Give feedback.
All reactions