pepe2
(Pepe)
January 15, 2025, 3:14pm
1
I like to make an automation that gives a notification on whatsapp, if there is no mqtt sensor update for more then 30 minutes.
The sensor is sending every 15min the current value. Most of the time it is the same value. So I don’t know if the sensor is down or not.
The whatsapp notification works already, but I don’t find a way to test the mqtt sensor update past time.
Is this possible to do?
wimjanse
(Wim Janse)
January 15, 2025, 3:22pm
2
Yes, quite simply, in the automation, check whether sensor becomes unavailable for xx seconds/minutes.
I’ve done this as follows:
trigger: state
entity_id: your.sensor
to: unavailable
for:
hours: 00
minutes : 00
seconds: 15
Hellis81
(Hellis81)
January 15, 2025, 3:36pm
3
I believe he wants to trigger when a value is “stuck”.
You should be able to trigger with a template trigger on the last_updated value.
Troon
(Troon)
January 15, 2025, 3:36pm
4
Or the last_reported
value, which should be updated even if the state remains the same.
{{ (now() - states['ENTITY_ID_HERE']['last_reported']).total_seconds() > 1800 }}
So with a template trigger :
triggers:
- trigger: template
value_template: "{{ (now() - states['ENTITY_ID_HERE']['last_reported']).total_seconds() > 1800 }}"
1 Like
pepe2
(Pepe)
January 15, 2025, 3:41pm
5
@ wimjanse, the automation is not working. If put the sensor down, de mqtt value is still the same.
@troon Is the “last_reported” value something that I have to make myself?
Troon
(Troon)
January 15, 2025, 3:42pm
6
No, see here:
Here’s an example of the difference:
last_reported
shows when the printer was last queried, at xx:37 each hour; the state hasn’t actually changed for a couple of days, but I restarted HA this morning so that is the time reflected in last_updated
.
1 Like
pepe2
(Pepe)
January 15, 2025, 4:04pm
7
So, I have to use last_updated , to know if there is a new value arrived or not.
The automation is running and I have to wait now… to see if it is working.
I’ll be back…
pepe2
(Pepe)
January 15, 2025, 4:32pm
8
While I’am, waiting, can I see the last_updated value of the sensor in the developer tools?
pepe2
(Pepe)
January 15, 2025, 4:36pm
9
I had 1000 sec in the template and I think those are already past, nothing happens.
My automation look like:
alias: whatsapp regenput down
description: ""
triggers:
- trigger: template
value_template: >-
"{{ (now() -
states['sensor.regenwaterput']['last_updated']).total_seconds() > 1000 }}"
conditions: []
actions:
- action: notify.whatsapp
metadata: {}
data:
message: Regenput sensor werkt niet
mode: single
baudneo
(Baudneo)
January 15, 2025, 4:38pm
10
Check the automation trace to see if it ran and why it stopped if it did run.
Troon
(Troon)
January 15, 2025, 4:46pm
11
Of course — see my screenshot above.
I still think you should be using last_reported
or you’ll get false alarms if the reported value doesn’t change between updates.
pepe2
(Pepe)
January 15, 2025, 4:49pm
12
If I run the automation by hand, by pushing run action then I get the notification.
do I have to add Trigger every minute of every hour in the automation?
Troon
(Troon)
January 15, 2025, 4:50pm
13
No.
Take a look at the attribute value in Developer Tools / Template; also look at the whole template in there.
The trigger will fire when the template changes from false to true.
EDIT: Found the problem — remove the quotes around the template. You only need those around single-line templates like mine in the post above.
alias: whatsapp regenput down
description: ""
triggers:
- trigger: template
value_template: >-
{{ (now() -
states['sensor.regenwaterput']['last_reported']).total_seconds() > 1000 }}
conditions: []
actions:
- action: notify.whatsapp
metadata: {}
data:
message: Regenput sensor werkt niet
mode: single
Your version was watching a string that looked like a template but wasn’t evaluating it.
pepe2
(Pepe)
January 15, 2025, 5:03pm
14
@ baudneo, Where/how can I find a screen to see the last_reported. I don’t find it
Troon
(Troon)
January 15, 2025, 5:08pm
15
You can only see it on Developer Tools / Template. Paste in:
{{ states['sensor.regenwaterput']['last_reported'] }}
pepe2
(Pepe)
January 15, 2025, 5:23pm
16
I have a strange date/time in the template. I have to look to the sensor program .
It gives a date and time from yesterday.
2025-01-14 12:44:15.230340+00:00
Many thanks to all. Now I can test and look what is happening.
Hellis81
(Hellis81)
January 15, 2025, 5:25pm
17
It will only trigger when it is less than 1000 seconds and becomes more than 1000 seconds.
pepe2
(Pepe)
January 16, 2025, 1:16pm
18
Hi, >I’am back
If I ckeck {{states['sensor.regenwaterput']['last_reported']}}
I get the time but with 1 hour difference of the time now();
How is that possible?
In Europe we have winter and summer time
or
is it the difference beteen GMT and brussels time ( there is 1 hour difference)
How to solve? Just add 1 hour or can I add a time zone ?
Now I see if the mqtt value is the same like before, the last_reported or the last_updated time is not changing . It is changed if the value is also changed.
How can I detect then if my sensor is not down? I send every 15 min the value to the mqtt server in HA. Mostly it is the same value. But Last_reported or Last_updated is only changing if the value is changed.