I’m attempting to create automation that would notify me whenever temperature has changed 5 degrees (in Celcius).
The notification parts is working and also when I’m testing my launch trigger in Developer tools → templates it appears to be correct but it seems I have missed something, as the automation is never triggered.
Initially I created it using the UI Automation editor but at this stage I’ve been switching back and forth when trying to get it to work and doing adjustments. The YAML I pasted was taken from UI Automation editor when set to the “Edit as YAML-file” mode.
If I try to remove the quotes when in the “Edit as YAML-file” mode I get the following error (as expected, I assume): Message malformed: template value should be a string for dictionary value @ data['value_template']
Will try on changing the sensor value from States menu.
Edit: When I set the sensor temperature to 20 or 20.4 manually from Dev Tools → States I got the notification as expected.
One possible reason it may not work is if the sensor changes from one number divisible by 5 to another all in one go. e.g. 20.x to 15.x. In that case the template stays true. It needs to change from false to true to trigger.
Yeah it seems so, I was surprised this morning that I hadn’t gotten any notifications…
…to my embarrassment, upon checking the temperature logs for the night, no 5 degree thresholds had been crossed so no wonder I didn’t get any notifications
Well, for me this was a learning experience on to using Dev Tools → States and hopefully someone will find this useful on how to do these kinds of notification automations. Thanks @tom_l !
If someone happens to find this thread, here’s also a version of the automation with multiple sensors that works for me. Note that if multiple sensors trigger it at the same time some additional checks might be needed but so far it’s been ok for me.
alias: temperature_5deg_step_notification
description: ""
trigger:
- platform: template
value_template: "{{ (states('sensor.outside)|int(0))%5 == 0 }}"
id: outside
- platform: template
value_template: "{{ (states('sensor.storage')|int(0))%5 == 0 }}"
id: storage
- platform: template
value_template: "{{ (states('sensor.livingroom')|int(0))%5 == 0 }}"
id: livingroom
condition: []
action:
- service: notify.mobile_app_jkkataja
data:
title: |
{% if trigger.id == "outside" %}
Outdoor temperature
{% elif trigger.id == "storage" %}
Storage temperature
{% elif trigger.id == "livingroom" %}
Living room temperature
{% endif %}
message: |
{% if trigger.id == "outside" %}
Temperature now - {{ states('sensor.outside') }}
{% elif trigger.id == "storage" %}
Temperature now - {{ states('sensor.storage') }}
{% elif trigger.id == "livingroom" %}
Temperature now - {{ states('sensor.livingroom') }}
{% endif %}
mode: single