I’m trying to get a notification when the temperature in a room is too low. The following automation is what I currently use:
###########################################
# Notify if rooms are too cold or too hot #
###########################################
- id: notify_rooms_too_cold_or_hot
alias: Notify if rooms are too cold or too hot
initial_state: True
trigger:
- platform: numeric_state
entity_id: sensor.temperature_xxxxxxxxxxxxxx
below: 17
- platform: numeric_state
entity_id: sensor.temperature_xxxxxxxxxxxxxx
above: 23
action:
- service: notify.notify_phone
data_template:
message: >
{% if states.sensor.temperature_xxxxxxxxxxxxxx.state|float < 17 -%}
The room is too cold ({{states.sensor.temperature_xxxxxxxxxxxxxx.state_with_unit}})
{% elif states.sensor.temperature_xxxxxxxxxxxxxx.state|float > 23 -%}
The room is too hot ({{states.sensor.temperature_xxxxxxxxxxxxxx.state_with_unit}})
{%- endif %}
The notification is sent to a notification group. Using a persistent notification doesn’t change anything.
The goal is to add multiple triggers for rooms being too hot or too cold and using the template to decide what rooms the notification should mention.
I’ve tried to manually lower to value of the sensor using the dev tools, but that does not trigger the notification to be sent. The sensor value is currently set at 16.65 °C.
I have a similar thing set up for my fridge. I have mine as two separate automation’s, one for too hot and one for too cold, I don’t know much about programming but perhaps the two triggers are cancelling each other out? Here’s my fridge automatons for reference just in case it helps.
Your sensors probably aren’t numeric, they are string. Despite what the documentation says, in practice nom-numeric sensors do not work with numeric triggers. You have a couplemof options.
switch to a template trigger
Create a template sensor based off of the real sensor converted to float.
The solution provided by @treno put me into the right direction. Thank you.
Currently I have changed the automation to the following:
###########################################
# Notify if rooms are too cold or too hot #
###########################################
- id: notify_rooms_too_cold_or_hot
alias: Notify if rooms are too cold or too hot
initial_state: True
trigger:
- platform: template
value_template: "{% if states.sensor.temperature_xxxxxxxxxxxxxx.state | float < 17.5 %} true {% endif %}"
- platform: template
value_template: "{% if states.sensor.temperature_xxxxxxxxxxxxxx.state | float > 23.5 %} true {% endif %}"
- platform: template
value_template: "{% if states.sensor.temperature_xxxxxxxxxxxxxx_2.state | float < 17.5 %} true {% endif %}"
- platform: template
value_template: "{% if states.sensor.temperature_xxxxxxxxxxxxxx_2.state | float > 23.5 %} true {% endif %}"
action:
- service: notify.notify_phone
data_template:
message: >
{% if states.sensor.temperature_xxxxxxxxxxxxxx.state|float < 17.5 -%}
The room is too cold ({{states.sensor.temperature_xxxxxxxxxxxxxx.state_with_unit}})
{% elif states.sensor.temperature_xxxxxxxxxxxxxx.state|float > 23 -%}
The room is too hot ({{states.sensor.temperature_xxxxxxxxxxxxxx.state_with_unit}})
{%- endif %}
{% if states.sensor.temperature_xxxxxxxxxxxxxx_2.state|float < 17 -%}
Another room is too cold ({{states.sensor.temperature_xxxxxxxxxxxxxx_2.state_with_unit}})
{% elif states.sensor.temperature_xxxxxxxxxxxxxx_2.state|float > 23 -%}
Another room is too hot ({{states.sensor.temperature_xxxxxxxxxxxxxx_2.state_with_unit}})
{%- endif %}
@BarryHampants perhaps your sensor does get stored numeric and your value '5'is casted to 5 in the background by HASS causing the trigger to fire.
Since @treno made me curious, I looked into the states table of HASS and saw that the event_data column contans the following JSON structure:
And yes my sensors (Xiaomi Aqara) do return a number but because of your question I learned a new way to do things and can condense two automation’s into a single one now.
There’s a really easy way to tell if a sensor is numeric.
Go over to the template editor in developer tools and type this:
{{states.sensor.SENSOR_NAME.state > 0}}
If sensor.SENSOR_NAME is numeric, this will return true or false in the result pane.
If sensor.SENSOR_NAME is not numeric, the result pane will be blank.