A problem: I have many Hue devices in my home, all connected to HA with Z2M (I removed the Hue integration because of poor responsiveness). When Philips releases an updated, then suddenly I have long list of devices to update.
The main issues is that when Zigbee device is being updated, it (1) takes long time and more importantly (2) blocks almost all communication. If I start updating all devices at the same time, sooner than later update will stop working.
It takes few days to update all, and it is painful.
I’m looking for a way to update the Zigbee devices in some kind of automatic mode. I was thinking to have:
template sensor that would tell me number of devices waiting for an update. If we can filter by integration, then I’d filter devices on zigbee/mqtt.
template sensor that would tell me if any device is currently updating
An automation that would be activated manually (when I detect available updates)
When enabled, automation is triggered every x minutes
Automation checks template sensor if anything is available to update and if no update is currently active
automation starts an update of next device.
Questions:
Is there a better way to do such sequential update? I could turn the automation on when I leave the house or during the night, which would periodically start and update all devices
Did someone do something similar?
How to get next device for update in a nice way? By using list template sensor?
While not exactly what you want, here is how. Update multiple ESP Home devices. I don’t use zigbee, so not sure how it gets initiated, but maybe you can adapt this for your use.
#############################################################
# Automatically update ESPHome Devices
#############################################################
- id: update_esphome_devices
alias: Update ESPHome Devices
initial_state: TRUE
mode: queued
description: >-
Automatically update ESPHome Devices and notify when integration updated.
triggers:
# standard time trigger
- trigger: time
at: "01:15:00"
id: update_start
# Manual trigger
- trigger: state
entity_id: input_boolean.update_esp32
to: "on"
id: update_start
# triggerd after one device completes
- trigger: event
event_type: UPDATE_NEXT_DEVICE
id: update_next
# Group is Updated
- trigger: state
entity_id: group.esp_32
to: "off"
for: "00:00:10"
id: update_finished
#
# Timer finished - INCOMPLETE
- trigger: state
entity_id: timer.esphome_updates_timer
to: "idle"
for: "00:15:00"
id: update_restart
#
# Timer finished - ERROR
- trigger: event
event_type: timer.finished
event_data:
entity_id: timer.esphome_updates_timer
id: update_timeout
# ----------------------------------------------
conditions:
- condition: state
entity_id:
- update.d1m_gar_heat_fans_firmware
- update.bt_proxy_3_gar_sen_firmware
- update.d1m_light_sensor1_firmware
- update.d1m_srms_firmware
- update.d1m_temp_sensor1_firmware
- update.esp32_miscale_firmware
match: any
state: "on"
# ----------------------------------------------
actions:
# Start a watch-dog timer to make sure things get done. Only start one time, does not reset each loop
- if:
- "{{ states('timer.esphome_updates_timer') == 'idle' }}"
# Start timer
then:
- action: timer.start
target:
entity_id: timer.esphome_updates_timer
data:
duration:
"{{ (states.update|selectattr('state','eq','on')|map(attribute='entity_id')|select('in',integration_entities('esphome'))|list|count)*600 }}"
# Allows 10 minutes (600 sec) for each device.
- choose:
# Update Start
- conditions:
- condition: trigger
id: update_start
sequence:
- action: script.turn_on
data_template:
entity_id: script.reset_logging_esp32_status
- action: script.turn_on
data_template:
entity_id: script.update_esp32_device
# Update Next
- conditions:
- condition: trigger
id: update_next
sequence:
- action: script.turn_on
data_template:
entity_id: script.update_esp32_device
# Update Finished, ALL devices are updated!
- conditions:
- condition: trigger
id: update_finished
sequence:
- action: script.turn_on
data_template:
entity_id: script.finished_update_esp32_device
# Update Timeout - Error!
- conditions:
- condition: trigger
id: update_timeout
- condition: state
entity_id: group.esp_32
state: "on"
sequence:
- action: script.turn_on
data_template:
entity_id: script.error_update_esp32_device
# Update ReStart
- conditions:
- condition: trigger
id: update_restart
sequence:
- action: script.turn_on
data_template:
entity_id: script.reset_logging_esp32_status
- action: script.turn_on
data_template:
entity_id: script.update_esp32_device
# No conditions met
default:
sequence:
# Persistent Notification
- action: persistent_notification.create
data_template:
title: ESPHome - Default Condition
message: >-
At {{ now().strftime("%m/%d/%Y %H:%M:%S") }}.<br>
The Update ESPHome Devices automation has encountered a problem and has entered the default condition.<br>
#
If you need help creating the EVENTs just let me know and I’ll post that code as well.
My suggestion because zigbee doesn’t really like multiple devices updated at once.
Change this:
To this:
template sensor that would tell me number of devices waiting for an update. If we can filter by integration, then I’d filter devices on zigbee/mqtt.
template sensor that would tell me if the number of available updates has been reduced by 1.
automation starts an update of next device.
I’m sorry, but I’m not that well versed into templating to tell you how to do the steps above. However, I hope the above puts you (and others who might be willing to help) on the right track.
Not sure if it’s still needed, but here are the scripts for the update and event actions. You’ll see that generating the EVENT is part of the script sequence. It is then later used in the automation triggers.