@jocnnor Thanks for guiding me to right direction. Code didn’t work out of the box, but it almost works now.
- id: update_zigbeedevices1
alias: OTA update Zigbee devices
trigger:
- event_data:
action: update_zigbeedevices
event_type: home_assistant_notifications_action
platform: event
action:
- variables:
# Store the list of entities here for easier lookup
entities: "{{ state_attr('group.zigbee_updates', 'entity_id') }}"
- repeat:
# Repeat for every entity in the list
count: "{{ entities | count }}"
sequence:
- choose:
conditions:
- condition: state
entity_id: "{{ entities[repeat.index] }}"
state: "on"
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/bridge/ota_update/check
payload: >
{% set entity_id = state_attr('group.zigbee_updates', 'entity_id')[repeat.index] %}
{% set parts = entity_id.split('.') -%}
{{ states[parts[0]][parts[1]].name | replace("_update_available","") }}
- delay: 5
This gives me error:
Invalid config for [automation]: Entity ID {{ entities[repeat.index] }} is an invalid entity id for dictionary value @ data['action'][1]['repeat']['sequence'][0]['choose'][0]['conditions'][0]['entity_id']. Got None.
But this automation works, so it just can’t read entities for some reason, while repeat count and entities variable is set correctly.
- id: update_zigbeedevices1
alias: OTA update Zigbee devices
trigger:
- event_data:
action: update_zigbeedevices
event_type: home_assistant_notifications_action
platform: event
action:
- variables:
# Store the list of entities here for easier lookup
entities: "{{ state_attr('group.zigbee_updates', 'entity_id') }}"
- repeat:
# Repeat for every entity in the list
count: "{{ entities | count }}"
sequence:
- choose:
conditions:
- condition: time
after: '08:00:00'
before: '21:00:00'
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/bridge/ota_update/check
payload: >
{% set entity_id = state_attr('group.zigbee_updates', 'entity_id')[repeat.index] %}
{% set parts = entity_id.split('.') -%}
{{ states[parts[0]][parts[1]].name | replace("_update_available","") }}
- delay: 5
I tried to set ‘entities’ variable so that it would be a list only for entities, with state on, but I cannot get entity_id out of it:
{{ states|selectattr('entity_id','in',state_attr('group.zigbee_updates','entity_id'))|selectattr('state','eq','on')|list }}
This returns correctly right one, but how to make a list of entity_id’s with on state?
return:
[<template TemplateState(<state binary_sensor.0x000b57fffef2c3e6_update_available=on; linkquality=78, state=OFF, update_available=True, friendly_name=0x000b57fffef2c3e6_update_available @ 2020-11-05T19:39:52.426161+02:00>)>]