I want to receive instant notification as soon as a sensor drops below a given value, and I want to be repeatedly notified but no more often than once per day.
This can’t be done with a trigger running once every x unit of time with numeric_state condition because that fails to give immediate notification. You can make the interval smaller and approach a solution, but never reach it - also it’s inelegant.
This also can’t be done with numeric_state or template trigger because from what I understand and have observed, these fail to trigger if the sensor state hasn’t changed. Even though the sensor state is being polled by HASS very frequently the value may be very stable at a single value below the threshold condition and in this case there will be no trigger ever.
Is there some other way to do this that I’m missing?
Hi Silvrr, thanks for chiming in. I’ve tried this approach, the issue is that when I turn the automation back on it doesn’t fire immediately if the sensor state is already below threshold… it waits until the sensor value changes to a new value that is also below threshold.
Trigger 1: Numeric State < threshold
Trigger 2: Time trigger at 12:00:01 (right after the automation is turned back on)
Condition 1: Numeric state < threshold
The automation would trigger anytime you go below the threshold, it would also trigger right after the automation is turned back on, however, if not below the threshold the condition would prevent the action from firing.
Interesting - a hybrid approach. As crude as it is, it’s the best option so far.
Is it possible to trigger on enabling of an automation? If so I could have Trigger 2 you described be tied to the automation coming on as opposed to a static time.
Thanks arsaboo but one requirement is for instant action and I don’t see how time trigger can give instant action - eg if the state changes in between checks. Latency can be minimized by increasing frequency but can never be made 0, plus it’s a bit inelegant.
This almost works except it doesn’t trigger after it re-enables itself, but it works the first time it’s turned on manually.
Yeah I know I’m making things difficult on myself… practically I could get away with having my 24 hours start and stop at a set time every day, but some OCD part of me wants to try and solve the challenge of making it 24 hours relative to the time of the trigger instead.
I assume you also mean to remove the turn_off and turn_on action. So if I do that the trigger will fire once on startup, because of:
- platform: state
entity_id: automation.detect_freezing_weather_test
from: 'off'
to: 'on'
…but not ever again unless the sensor value changes. Your last_trigger idea gave me a thought however. Rather than using it as a condition, I tried using it as the trigger:
- alias: Detect freezing weather test
trigger:
- platform: state
entity_id: automation.detect_freezing_weather_test
to: 'on'
- platform: template
value_template: "{{ (as_timestamp(now()) - as_timestamp(states.automation.detect_freezing_weather_test.attributes.last_triggered)) > 60 }}"
action:
- service: notify.notify
data:
message: "Freezing weather in forecast!"
title: "Weather warning"
hoping that would cause a 60s trigger loop, but alas it only fired on startup.
That is why you also need a time trigger to check periodically. BTW, "{{ (as_timestamp(now()) - as_timestamp(states.automation.detect_freezing_weather_test.attributes.last_triggered)) > 60 }}" checks if the automation was triggered in the last 60 seconds.