Would be great to trigger an automation if the numeric state has been above a value for a given time, like it is possible for the state-platform
For state trigger the following is valid:
automation:
trigger:
platform: state
entity_id: device_tracker.paulus, device_tracker.anne_therese
# Optional
from: 'not_home'
to: 'home'
# If given, will trigger when state has been the to state for X time.
for:
hours: 1
minutes: 10
seconds: 5
Is would be nice we could use for statement for a numeric state trigger like:
OK I found out myself. The above is working. Only it seems that the sensor gets initialised before the device it polls the attributes from is actually initialised (Vera binding)
So some messages in the log but the config is working as expected
On-topic: I voted for this feature request too. I made an automation just yesterday to turn some lights off after the luminance level (lux) was above a certain level for 5 minutes, and found out the hard way that numeric_state doesnât support for. Iâm working around it for the time being by using a template sensor so I can use state with for instead.
I donât consider adding templates the end all be all for this, all over the place they are used as workarounds for things that would be direct improvements to HA logic.
In my case I have sensor readings that bounce up and down sometimes, having the for statement would be highly useful.
Also if you are dealing with numeric sensors and personally want the uninitialized value to return 0 instead of undefined you can use the default variable.
Yeah, would be nice to reduce the number of templates and template/template binary sensors for simple things. They do add a bit to load and restart times.
I hear you there. Thatâs why I try to fully document and âindexâ my YAML by sectioning things off together and putting them in logical orders. Iâd like to move some things out of templates but theyâre so damn useful!
So I have been fighting with an automation based on power for my washer, when it turns on it spikes quite high for a moment before settling down then when running it intermittently spikes and drops all the way through the cycle.
Someone suggested using the stats plugin to smooth this out and it does work for when the unit is running however it does not work for the initial spike as essentially the states plugin has nothing to go on yet so it reads really high.
I think the for statement would greatly simplify things and provide for solutions that right now I think I can only provide by creating word sensor readings for different voltages, then doing a FOR on those states to THEN get the desired alert or output state. That would be two sets of template sensors just to show if the unit is running or in spin cycle.
I think the main problem with this is, that the last updated time changes with every value-change. If you ask if a sensor is below 50 for ten minutes, but it updates every 30 seconds with 10, 15 and some other values in that range, then it never actually has a fixed state persisting over the time of 10 minutes. It will be 10 for 30 seconds, then 12 for 30 seconds and so on. Yes, they obviously all are below 50, but from a programmers point of view thatâs not the same.
i think or the new way of thinking to make home assistant easyier for not expert users it would be important that the for statement is possible. because of this i would reopen this Feature Request