alias: NOTIFY_Weather Statement
description: Sends a notice when the weather sensor changes from null to populated
trigger:
- platform: template
value_template: >-
{% if states('sensor.weather_location_1_warnings') != "" %}True{%
endif %}
condition: []
action:
- service: notify.mobile_app_phone1
data:
title: Weather Alert!
message: >-
There is a weather alert presently. Be advised of
{{states('sensor.weather_location_1_warnings')}}.
data:
tag: weather_alert
- service: notify.mobile_app_phone2
data:
title: Weather Alert!
message: >-
There is a weather alert presently. Be advised of
{{states('sensor.weather_location_1_warnings')}}.
data:
tag: weather_alert
mode: single
Now essentially when the sensor has no warning or weather statement it’s null. And this (I’m not sure if it even works yet as I only made it today but the state in the developer tab seems to work). But this would only fire when it changes from null to something.
How would I have it fire when it changes from one warning to another?
For example from snow storm warning to blizzard warning.
Note that these are warnings from the “Environment Canada” weather integration.
I recommend you use this instead (State Trigger vs Template Trigger).
alias: NOTIFY_Weather Statement
description: Sends a notice when the weather sensor changes from empty string to populated
trigger:
- platform: state
entity_id: sensor.weather_location_1_warnings
condition: "{{ trigger.to_state.state != '' }}"
action:
- variables:
msg: 'There is a weather alert presently. Be advised of {{ trigger.to_state.state }}.'
- service: notify.mobile_app_phone1
data:
title: Weather Alert!
message: '{{ msg }}'
data:
tag: weather_alert
- service: notify.mobile_app_phone2
data:
title: Weather Alert!
message: '{{ msg }}'
data:
tag: weather_alert
mode: single
The Template Trigger you created is triggered when the sensor’s value changes from an empty string to a non-empty string. When that happens, the Template Trigger is “set”. It will be “reset” only when the sensor’s value changes to an empty string. That means if the sensor’s value changes from one non-empty string to another non-empty string (“Winter Storm Warning” to “Blizzard Warning”) it will not trigger. It must first change to an empty string before it can be triggered again.
The State Trigger I have suggested doesn’t share this behavior and is triggered by any change to the sensor’s value. The condition ensures only non-empty strings are accepted.
That’s because, by default, a State Trigger will also trigger if the value of any of the entity’s attributes changes. That particular sensor has an observation_time attribute whose value is updated when data is received.
To limit the State Trigger to listen to changes of the state value only (i.e. ignore changes to attribute values) simply append an empty to: option to the State Trigger.
- platform: state
entity_id: sensor.weather_location_1_warnings
to: