Hi, I’m just getting started with templates and would to know if there is a way to get to nested entities?
background.
I have 16 down lights in my kitchen which were not consistently reacting to commands - 16 ‘on’ commands at the same time was not reliable over ZHA. So, I created four groups and the scene now refers to the grouped zigbee lamps and is much more reliable.
But once in a while there are still bulbs that don’t react correctly, so I am writing a flow to check all the lights in a scene match the intended values - this will be triggered shortly after the scene is set.
To check if all the lights go off, I want to iterate over the entities in the scene, however when I run this template:
scene scene.kitchen_off
{% for item in state_attr('scene.kitchen_off','entity_id') %}
{{ item }} {% endfor %}
returns a mix of entities and groups:
scene scene.kitchen_off
switch.kitchen_cabinet_lights_switch_2
light.zigbee_antenna_kitchen_spots_group_1
light.zigbee_antenna_kitchen_spots_group_2
light.zigbee_antenna_kitchen_spots_group_3
light.zigbee_antenna_kitchen_spots_group_4
Is there a way for a template to expand the list to show the full list of lamps, and not one lamp and four groups?
Bonus question - can I query the lamp state definitions stored in a scene (to compare with actual)?
Are you getting error messages when the lights fail to turn off/on? If not, HA may think the change was successful, in which case I don’t think there’s any way of knowing the actual state of the light.
I am using mainly Hue lights with the ZHA integration. When a light fails to switch correctly the light’s history will usually track the incorrect state - sometimes after a few minutes.
In the following case, the lights all went out, but one came back on a few minutes later - I was in the room and can confirm they did all go out.
Forgive me, but this seems like a very complex way to not address a problem…
If the history shows the light coming on again, and (if I understand you correctly) there are no errors… doesn’t that suggest that something switched it on legitimately? Might it not be better to track down what that was?
In Home Assistant, it appears as a light entity. It doesn’t have an attribute listing the members of the Zigbee group so there’s nothing available for a template to access them.
As suggested in your other topic, you should focus on improving your Zigbee network’s reliability. Because if you are using Zigbee groups to control lights and still experience occasional failures of one or more lights then it implies there may be a problem with the network (because turning off 4 groups is just 4 broadcast messages and that’s very little traffic).
I think I understand what you are saying - there is no programmatic way I can query a ZHA group’s contents using home assistant even though the group was created through the HA UI?
If this is the case, then I’ll make a shadow scene that has all the entities directly assigned and iterate over that to validate the lights have been correctly set.