I’m trying to write a script to handle automation for my TRVs, so I want to iterate through a for_each loop on each one and check for specific attributes and act on that.
How would I form the for_each loop as I don’t want to hard-code the entities into the script.
I believe where - “test” is I need to create a dynamic entry towards climate. entities.
Then in the sequence I need to then ask climate.pi_heating_demand and check the value.
How would I carry this out?
psuedo-code:
Loop through all climate entities in my HA
For each entry query the climate.pi_heating_demand and if is a specific numeric/float then carry out an action
Loop through all climate entities is easily done but what is climate.pi_heating_demand? That’s the entity_id of one specific climate entity. What is its relation to all other climate entities?
Or do you mean that each one of your climate entities has an attribute named pi_heating_demand?
Copy-paste the following template into the Template Editor and confirm it lists the entity_id of all climate entities whose pi_heating_demand is greater than or equal to 7.
That likely means you have at least one climate entity that doesn’t have that attribute, you can add a selection clause to limit the rest of the template to just those that do:
Ahh! I didn’t realise one of my TRVs was a different manufacturer! Yes that’s exactly why.
Yes that modification works as expected and I get a list returned:
Yes. The for_each key will accept templates that return simple values, lists, or mappings/dictionaries.
The template already selects for the pi_heating_demand attribute’s value in selectattr('attributes.pi_heating_demand', '>=', 7)… if you wanted to check other attribute values of the entity you could add them to the template or use template conditions:
Anyways, by now you probably realize that there’s no need for a Jinja for-loop, like you originally requested, and all that’s needed is a simple template to extract a list of climate entities that meet your requirements.
For that matter, what are the exact requirements for the value of pi_heating_demand?
Thank you both, after replying i’d figured a solution that does pretty much what I want. (Thanks @123 for the info on the reply buttons, interesting and odd behaviour that! I’ve done a global reply since replying to both of you this time)
(I’m creating this as a script that I’ll call as required, it will be used to request more heat from my boiler should a TRV be requiring heat)
The pi_heating_demand comes from Danfoss TRVs via ZHA and when pi_heating_demand is set to a non-zero value then the TRV is requesting heat (There is an issue with the climate entity heat demand so I’m using this method)
If you mean the button shown in the following screenshot then that’s the one that does not send me a notification.
FWIW, I would have to subscribe to this topic in order to receive a notification for anything posted to it. I respond to hundreds of topics and if I were to subscribe to all of them I would be overwhelmed with notifications.
Does the value have to be greater than or equal to 7 or simply greater than 0?
The example I had provided used >= 7 only because that’s the value I saw in the screenshot you posted here. That’s why I had asked what was the exact requirement because my choice of using 7 as the threshold was merely for testing purposes. If it only needs to be greater than 0 then change the test to this: