I don’t understand why you are arguing when you have the solution in front of your face. I’ll post it one more time. Maybe you’ll try it this time instead of shrugging it off.
- alias: Bedroom temperature sensor has old data
trigger:
- platform: time
minutes: '\1'
seconds: 00 #this is needed
condition:
- condition: template
value_template: >
{% if states.sensor.soverom_temperature.last_updated is defined %}
{{ (now() - states.sensor.soverom_temperature.last_updated).seconds / 60 >= 5 }}
{% else %}
False
{% endif %}
action:
- service: notify.pushover
data:
title: "Sensor warning"
message: "Temperaturmåling på soverommet er {{ ((now() - states.sensor.soverom_temperature.last_updated).seconds / 60) | int }} minutter gammel"
Well, I see why you’re arguing because I for some reason thought your original result inside the value template was returning true/false when it was actually returning the number of minutes. Which should work. My mistake. Sorry.
So that means your problem lies in your trigger, which is probably because you are missing:
seconds: 00
But this is of course assuming that now() exists inside the value_template environment of the numeric_state. Which it should.
Anyways, if that doesn’t work at all, the value template I posted above will work.
Hey, no problem I really appreciate that you took the time to help me out. I finally made everything work as I wanted. Here’s the working solution to get an alert when the temperature sensor hasn’t sent data for a while (e.g empty battery):
First the intermediate sensor:
sensor:
- platform: time_date
display_options:
- 'time' ## Sensor that updates every minute
Then the automation:
- alias: Bedroom temperature sensor has old data
trigger:
platform: numeric_state
entity_id: sensor.time
value_template: "{{ (now() - states.sensor.soverom_temperature.last_updated).seconds / 60 }}"
above: 5
action:
- service: notify.pushover
data:
title: "Sensor warning"
message: "Temperaturmåler på soverommet sender ikke data"
It will send one notification when data is old, and not repeat it.
I only use sensor.time to trigger the automation once every minute. Then I use the value_template: to create the actual value that is checked with above:. This way I don’t have to use a separate platform: time trigger.
Ah I see why it works then !
sensor.time is a pain because it contains a string HH:MM:SS, not a timestamp. You’d have to convert it if you want to test something else beyond “==”. The workaround you found makes it easier !
Useful entities to choose might be sensor.date which update once per day, or sensor.time which updates once per minute.
Note: Time & Date Sensors used as an update trigger, must be configured. If a template uses more than one sensor they can be listed.
It works because sensor.time changes every minute, and that makes the trigger activate. Then it evaluates the value_template clause, and matches it against the below condition.
5 would work as well, but sensor.time gives me 1, and that works fine. The way I see it your trigger would actually fire more often (on every change in sensor.soverrom_temperature).
I’ll see if I can try your version. Don’t keep your hopes up, though, because I’ve used WAY too much time on this already
im not hoping for anything, simply trying to help create a better automation…
If that were the case, this whole automation would be superfluous, you’re testing if it has older data than 5 minutes are you? If you expect this to fire more often than that, then why create a notification for when it doesn’t.
Any case, fifths works as you say it does, it is undocumented (which is quite possible) and a nice find.
I fear though you are referring here Template trigger does not work - #28 by henrik242 to the new setup of the template sensor, and not anything related to automation triggering.