The - in front of platform seem to suggest you can add multiple of them, so you can add more triggers by just adding - platform: …
trigger:
# Change in any one of the thermostat set temperatures
- platform: state
entity_id: !input thermostat_set_temperature_sensors
attribute: temperature
for:
seconds: 10 # do not trigger while value is changing
id: set_temperature_change
Reference
Yes, I know. There are a lot already; this is just an extract of what is relevant for this problem.
What are you saying?
You have reproduced the code that already works.
I do not think HA does pattern for triggers.
Node Red can do it, but you might even be able to simplify it a bit in HA.with multiple entity IDs for the same trigger. Automation Trigger - Home Assistant
I was basing my code on the documentation for template triggers, but it is not clear whether it covers my case. I need an expert who can explain in more detail when the template is evaluated and how it causes a trigger.
Topic’s title is:
How do I trigger an automation based on the change of an attribute?
Question is:
Answer: By using a State Trigger configured with the attribute
option.
You won’t have to do that if you make the following input variable a list of climate
entities instead of Template Sensors. Therefore the blueprint no longer relies on additional Template Sensors.
entity_id: !input thermostat_set_temperature_sensors
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I believe your blueprint acquires a list climate
entities in its thermostat_controls
input variable. So the State Trigger can be configured like this:
trigger:
# Change in any one of the thermostat set temperatures
- platform: state
entity_id: !input thermostat_controls
attribute: temperature
for:
seconds: 10 # do not trigger while value is changing
id: set_temperature_change
It’s the addition of the attribute
option to the State Trigger that will make it monitor the value of each climate
entity’s temperature
attribute.
attribute: temperature
With an important difference; it uses the State Trigger’s attribute
option to monitor the temperature
attribute of each climate
entity (not Template Sensor).
Are you trying to get the automation working on your system, or are you trying to write a blueprint for sharing with others?
Both. It is a new release of my blueprint “Heating X” which was first published a year ago. I will publish release 2 when it is working on my system. Why do you Ask?
Because writing a working automation to do what you want is easy. Configuring a blueprint to cope with the inputs is outside of my experience but looks a lot harder.
Sorry,I did not spot that. It does look like a simple solution for my case. I tried it and it does trigger, but for some strange reason it does not now set the trigger id, so the action that should run next doesn’t. Any idea why that should be the case??
Paste the code that is behaving as you describe.
The only way that’s possible is if the automation is tested without actually triggering any of its triggers.
How did you test it?
-
If you tested it by changing the value of the
temperature
attribute of one of theclimate
entities monitored by the State Trigger, check the trace that was produced. It will indicate the value of the trigger id. -
If you tested it by using the automation’s Run command, that only executes the automation’s actions (therefore the trigger id is undefined).
By the first method that you mention. The trace shows that the trigger fired but the action that executes based on the trigger id is skipped.
I plan to make a test automation today to reproduce the fault in isolation. If it does that I wlll log a bug report.
It was part of a large blueprint that is too large to post here, and I reverted the code anyway (to the template sensor method) so I could continue testing. I plan to make a test automation today to reproduce the fault in isolation. If it does that, I will post it and log a bug report.
Do post the automation if that happens. I’d suggest it’s much more likely your error than such an obvious bug in the very well-tested automation back end — but that’s not impossible, of course.
Post the blueprint/automation and/or the trace file (not a screenshot of the trace but the actual trace file).
The State Trigger I posted above works as described. The automation’s alleged failure to match the State Trigger’s trigger.id
would be anomalous; need to see the trace to understand why it’s happening.
Apparently this was a false test. My stand-alone demo automation worked correctly and then when I migrated it back to the blueprint it worked correctly there as well. I am grateful to all contributors for pointing out this solution.
However, for future reference, how do I get the “actual trace file”?
Spot on! And I got it in the end!
I posted instructions for another person here: