That's my template:
{{ states('sensor.srednia_sensorow_ogrzewania') | float < states('input_number.piec_noc') | float }}
sensor.srednia takes average readout from temperature sensors in rooms.
input is manually set temperature
For testing it's way above normal temperature.
In dev tools it always returns true, but when I try it as trigger for automation, adding it must stay true over 30 seconds it never triggers automation. Any ideas?
#Template triggered automation
1 messages · Page 1 of 1 (latest)
Bug was on my side in additional condition. Everything works. Marking as resolved.
Unfortunately something else is still wrong here. I have another automation with such trigfer and even with disabled conditions it didn't fired. Documentation of 'template' trigger says that state of templated entities must change - is value change of sensor counted as state change? If not, how can I make it work? I'd want to avoid scheduling it every x minute or so. I actually don't know why one of these automation finally worked, and another doesn't work at all. Not working one:
{{ states('sensor.srednia_sensorow_ogrzewania') | float < states('input_number.piec_dzien') | float }}
The value of the whole expression must change from false to true
You can use a state trigger with both of those entities listed to trigger on any change to them and then use a template condition to check whether to proceed
Oh, so they won't work till they will change for even a second to other state? And if I'd keep it like that, will they be checked on system restart? Or system will remember 'they wre true, they are true, no triggering then'?
Are you still talking about the template trigger? It only triggers on the whole thing becoming true
Let me clarify:
Nothing else matters
You said it only works (as a trigger) when it (template) changes state from false to true. It won't trigger (if I understood correctly) if it was true at moment of creation of automation (at least doesn't work for me)
So my question is, if I'll restart HA, will it re-check and potentially trigger automation on startup if template is true, or will wait for it to get to false and back to true again?
States are restored if the integration supports it, and in that case I wouldn't expect it to trigger on restart if it was already true at shutdown. You'll need to try it
Your float conversion will error out if the state becomes non-numeric, like unavailable or unknown, so it depends on the integration providing it
You should use something like float(0) to provide a default in that case
All right, so if it won't work as intended, I'll try your way (triggering with change of temperature) and then use template as condition.
I'm still new one and not quite understand what you mean by that, can you elaborate please?
That is the preferred approach
You just used |float
That will generate an error if the value is non-numeric
That way? {{ states('sensor.srednia_sensorow_ogrzewania') | float(0) < states('input_number.piec_noc') | float(0) }}
Yes
Or whatever default you want
That is one thing that you may see change at restart, depending on the integration
Ah, so bracketed value is default one. Good to know. See, from previous languages I was using brackets used that way were usually functions with values passed to them. Could you recommend some good guide for scripting in YAML in HA envirnoment?
That is Jinja
Oh, Jinja script, ok
See the topic in #1284966664357810196 for links