How to send notification if temperature is above/below limits set in helpers

Hello all,
I’m trying to create automation that sends notification if a temperature goes above or below a certain threshold. Those threshold limits are set with Number Helpers using an Entities Card.

My automation failed to save with the error:
Message malformed: expected float for dictionary value @ data['above']

How is this done?

The Automation (gives the error above when I try to save it)

alias: Temperature outside limits
description: Send notification to all if temp. is out of limits
mode: single
trigger:
  - type: temperature
    platform: device
    device_id: 1d1df34b60806385eb674a2c129394f5
    entity_id: sensor.lumi_lumi_weather_temperature
    domain: sensor
    above: input_number.temp_hall_high
    below: input_number.hiti_hall_low
action:
  - service: notify.all_user_devices
    data:
      title: Temperature outside limits
      message: The thermometer reads {{ trigger.event.data }}. The limit is {{ trigger.below }} - {{ trigger.above }}.

The Entities Card Configuration:

type: entities
entities:
  - entity: input_number.temp_hall_high
  - entity: input_number.hiti_hall_low
title: Viðvaranamörk fyrir holið
state_color: false

The Number helpers:

input_number.temp_hall_high
input_number.hiti_hall_low
1 Like

Use numeric_state triggers. They support supplying entities in the above and below options. Device triggers don’t.

Also device triggers, conditions and actions are terrible. Don’t use them.

1 Like

You need use two trigger. One trigger for above and another for below. Now, your trigger only fire when the value is above that temp_hall_high AND below that hit_hall_low.

2 Likes

That’s true but his current trigger won’t fire at all as device triggers do not support entities in the above or below options.

You are of course right @MiguelAngelLV. I hadn’t start to debug because I could not save the automation at all. Turns out that this kind of trigger doesn’t support Helper entity.

Thanks @tom_l, I will try that.

Could you please tell me why device triggers, conditions and actions are terrible. Are they buggy, with limted features, or hard to understand? Regarding actions, I still need those with numeric_state triggers, don’t I ?

Device triggers and conditions are aimed at beginners, so they are easier, at first. However as soon as you start trying to do more advanced things like use helpers or templates they don’t work and people wonder why. It’s because device triggers and conditions don’t support this sort of advanced use.

As well as that, if you ever have to replace a device because it breaks, or is lost or stolen, then you have to change the device id everywhere the old one was used, in all triggers, conditions and actions. As there is no option to change the device id of the new device.

If you use triggers, conditions and services that only require an entity_id (like state or numeric_state) then this entity id can be changed in one place to match the old one and all your automations and scripts keep working.

Yes you do. You are using a service call. That’s good. It only requires entity ids. Device actions require device ids, which is bad if you ever have to replace it, as outlined above.

1 Like

Very well explained, @tom_l. I did use Home Assistant back in 2018 and am revisiting the project now. It is amazing how it has evolved and matured in this time - mostly very well. However, there are some things that seem a bit to complicated and the options to many, like in this case. I guess it’s very hard to manage a large open source project without falling into the trap of adding too many types and options. The hard part is to clean it up afterwards when tons of people are already using all features.

This can be done simply and elegantly with Home Assistant. Here is how it can be done.

I have three temperature meters indoors.

Helpers:
I’m using two Number type helpers:

Entity id: input_number.temperature_inside_max
Entity id: input_number.temperature_inside_min

Entities card:

type: entities
entities:
  - entity: input_number.temperature_inside_max
  - entity: input_number.temperature_inside_min
title: Warning limits - inside temperature
state_color: false
show_header_toggle: true

Automation:

alias: Warning if temperature inside is to high/low
trigger:
  - platform: numeric_state
    entity_id: sensor.temperature_hall
    below: input_number.temperature_inside_min
  - platform: numeric_state
    entity_id: sensor.temperature_kitchen
    below: input_number.temperature_inside_min
  - platform: numeric_state
    entity_id: sensor.temperature_livingroom
    below: input_number.temperature_inside_min
  - platform: numeric_state
    entity_id: sensor.temperature_hall
    above: input_number.temperature_inside_max
  - platform: numeric_state
    entity_id: sensor.temperature_kitchen
    above: input_number.temperature_inside_max
  - platform: numeric_state
    entity_id: sensor.temperature_livingroom
    above: input_number.temperature_inside_max
action:
  - service: notify.all_user_devices
    data:
      message: '{{ trigger.to_state.name }} too high/low!'

I hope this helps someone.

3 Likes

i call it via this automation:

alias: AD110 Temperature Call automation
description: ""
trigger:
  - hours: "*"
    minutes: /2
    platform: time_pattern
condition: []
action:
  - service: automation.trigger
    data: {}
    target:
      entity_id: automation.warning_if_temperature_inside_is_to_high_low
mode: single

but i get this error…

Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'