#Template triggered automation

1 messages · Page 1 of 1 (latest)

pulsar vessel
#

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?

pulsar vessel
#

Bug was on my side in additional condition. Everything works. Marking as resolved.

pulsar vessel
#

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 }}

hybrid mantle
#

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

pulsar vessel
#

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'?

hybrid mantle
#

Are you still talking about the template trigger? It only triggers on the whole thing becoming true

pulsar vessel
#

Let me clarify:

hybrid mantle
#

Nothing else matters

pulsar vessel
#

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?

hybrid mantle
#

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

pulsar vessel
#

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.

pulsar vessel
hybrid mantle
#

That is the preferred approach

#

You just used |float

#

That will generate an error if the value is non-numeric

pulsar vessel
#

That way? {{ states('sensor.srednia_sensorow_ogrzewania') | float(0) < states('input_number.piec_noc') | float(0) }}

hybrid mantle
#

Yes

#

Or whatever default you want

#

That is one thing that you may see change at restart, depending on the integration

pulsar vessel
#

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?

hybrid mantle
#

That is Jinja

pulsar vessel
#

Oh, Jinja script, ok

hybrid mantle
pulsar vessel
#

Thank you for your help. 🙂

#

Restarting HA now to see if it will work or not. If not, I'll just use temperature as trigger.