Hello all!
I need to have a certain automation for the events when entities from domain climate change state and have troubles to do so. Mainly, I have tested two equivilent approaches:
state platfor: if any entity changes state I check it’s domain in actions section. It looks like this:
trigger:
- platform: state
entity_id: all
For this piece of code I have an error: " Message malformed: Entity ID all is an invalid entity id for dictionary value @ data[‘entity_id’] " though it was copied from here: https://www.home-assistant.io/docs/automation/examples/
Another approach is the do template trigger, cheching triggers domain:
That’s the whole point of automation - not to list all entities explicitly.
What I do, is implementing most general climate controller for each room. You may have AC, humidifier, heat floors and radiators to change the climate inside single room, but they never work togather (exept last 2). In the winter you never use cooling, and never use heat floors during the summer. I have 2 temp thresholds to determine 3 seasons: summer, spring/fall, winter. And I have bool flags for what is allowed and what is not during each season - cooling, heating_ac, heating_water … Each climate entity supposed to have its own termostate in HA, but depending on the season, you should use only one, which is valid for current season, not 3 or 4 which actually are registered in each room. So you do simple automation which does the following:
Shows you valid termostate for current season only - it is easy.
Changes in state of valid termostates only are accepted.
To implement 2 I need the automation in the topic…
Templating would not only save time, but allow me not to bother when I add climate entity to the system…
Exactly this instance I’ve been experimenting with this approach. I amd doing “state_changed” event triggering, but cannot access old_state, new_state objects. Do you know what is the syntax for that? trigger.old_state.domain yelds no result…
It works, sometimes. I made it notify.persistent_notify me the entity_id if domain is climate. Not only it sent me messages for ~20% of tested events, but eat 20% of CPU as well: from 0.7% to 20%… My gues is that listening to every state_changed event using script costs rescoureces…
It depends on how that script (Automation or PyScript) is written. The key is, filter as much out in the trigger as you can, and then exit out of the script as soon as you can possibly determine you have nothing to do.
If you share your entire automation or pyscript, I’m sure we can find ways to improve performance.
I’ve achieved the result following your path, but in slightly different direction, listening to call_service events, which have the domain inside, since HVAC modes are set by means of the climate services. It works fast and reliable, atleast so far, and I do not have to list all the termostates in the automation triggers and conditions, which does save a lot of effort.