Automation: zigbee2mqtt device updater

Hi,

I made automation that checks updateable Zigbee devices from zigbee2mqtt bridge and asks you if you want to update them.


groups.yaml Place here all your zigbee2mqtt devices that can do OTA update
zigbee_updates:
  name: Zigbee device updates
  entities:
    - binary_sensor.0x000b57fffef2c3e6_update_available
    - binary_sensor.0x842e14fffe416ac5_update_available
    - binary_sensor.0x842e14fffefc7ffa_update_available
    - binary_sensor.0x842e14fffe415c1e_update_available
    - binary_sensor.0x842e14fffe415d7e_update_available
    - binary_sensor.0x842e14fffe43aaf8_update_available
    - binary_sensor.0x000d6ffffe54fd83_update_available
    - binary_sensor.0x000b57fffeebd210_update_available
    - binary_sensor.0x000b57fffed8366c_update_available
    - binary_sensor.0x842e14fffe41729d_update_available
    - binary_sensor.0x000d6ffffe09fda2_update_available

automations.yaml

- id: notify_if_zigbee_update
  alias: Notification- Alert That Zigbee device has updates
  initial_state: 'on'
  trigger:
  - hours: /4
    platform: time_pattern
  condition:
    condition: and
    conditions:
      # don't send notifications in night time
      - condition: template
        value_template: "{{ 8 < now().hour < 21 }}"
      - condition: template
        value_template: >
          {% set ns = namespace(found=false) -%}
          {% for entity_id in states.group.zigbee_updates.attributes.entity_id -%}
            {% set parts = entity_id.split('.') -%}
            {% if is_state(entity_id, "on") -%}
              {% set ns.found = true -%}
            {% endif -%}
          {% endfor -%}
          {{ ns.found }}
  action:
    # change here your notification service
    - service: notify.home_assistant_notifications
      data:
        message: >
          {{ "\uD83D\uDCE6" }} Zigbee device(s): 
          {%- for entity_id in states.group.zigbee_updates.attributes.entity_id -%}
            {%- set parts = entity_id.split('.') -%}
            {% if is_state(entity_id, "on") -%}
              {{ states[parts[0]][parts[1]].name | replace("_update_available","") }} {{ '\n' }}
            {%- endif -%}
          {%- endfor -%}
          has pending update(s).
        data:
          actions:
          - action: update_zigbeedevices
            title: Update
            destructive: true
          - action: ''
            title: Dismiss
- id: update_zigbeedevices
  alias: OTA update Zigbee devices
  trigger:
  - event_data:
      action: update_zigbeedevices
    # change here your notification type
    event_type: html5_notification.clicked
    platform: event
  action:
    - repeat:
        # repeat for every entity in the list
        count: "{{ expand('group.zigbee_updates') | count }}"
        sequence:
          - choose:
              conditions: "{{ expand('group.zigbee_updates')[repeat.index].state == 'on' }}"
              sequence:
                - service: mqtt.publish
                  data:
                    topic: zigbee2mqtt/bridge/ota_update/update
                    payload: "{{ expand('group.zigbee_updates')[repeat.index].entity_id.replace('binary_sensor.', '') | replace('_update_available','') }}"
                - delay: 5
6 Likes

Excelent project!
Thanks for sharing.

Interesting project. I am getting an error in - id: update_zigbeedevice

Invalid config for [automation]: Expected a dictionary @ data[‘action’][0][‘repeat’][‘sequence’][0][‘choose’][0][‘conditions’][0]. Got None. (See /config/configuration.yaml

I will work through fault finding but if you have any ideas please let me know. I am on HA Home Assistant 0.114.1

Cheers

Upgraded to Home Assistant 0.117.5 and no config error. Not fully tested updating yet, but over the first hurdle.

1 Like

@gsmckenzie I’m on HA 0.177.2 and no config error. Update also works.
If you can, you can follow upgrading process over SSH with command:

mosquitto_sub -t zigbee2mqtt/#

I’m on HA 0.117.6 (and same for 0.117.5).

{{ expand(‘group.zigbee_updates’) | count }}

This template listens for the following state changed events:

  • Kohde : binary_sensor.0x680ae2fffe97ad47_update_available
  • Kohde : binary_sensor.0x680ae2fffea7e281_update_available
  • Kohde : binary_sensor.0xec1bbdfffe2de77b_update_available
  • Kohde : binary_sensor.0xec1bbdfffe8811cb_update_available
  • Kohde : binary_sensor.0xec1bbdfffe8812d5_update_available
  • Kohde : binary_sensor.0xec1bbdfffe9ebc14_update_available
  • Kohde : group.zigbee_updates

No config error but:

2020-11-13 19:30:51 ERROR (MainThread) [homeassistant.components.automation.notification_alert_that_zigbee_device_has_updates] Notification- Alert That Zigbee device has updates: Error executing script. Service not found for call_service at pos 1: Unable to find service notify/home_assistant_notifications

2020-11-13 19:30:51 ERROR (MainThread) [homeassistant.components.automation.notification_alert_that_zigbee_device_has_updates] While executing automation automation.notification_alert_that_zigbee_device_has_updates

Traceback (most recent call last):

File “/usr/src/homeassistant/homeassistant/components/automation/init.py”, line 426, in async_trigger

await self.action_script.async_run(

File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 1010, in async_run

await asyncio.shield(run.async_run())

File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 245, in async_run

await self._async_step(log_exceptions=False)

File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 253, in _async_step

await getattr(

File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 460, in _async_call_service_step

await service_task

File “/usr/src/homeassistant/homeassistant/core.py”, line 1398, in async_call

raise ServiceNotFound(domain, service) from None

homeassistant.exceptions.ServiceNotFound: Unable to find service notify/home_assistant_notifications

@mcpaha It seems that you havent setup a notification service.

I use html5 push notifications:

There are lot of different notifier services available, like discord.