Trouble with a Temperature Alert yaml

Hi, I’ve been staring at this long enough that I’m likely missing something simple. I’ve got a DHT22 Temperature sensor and the value shows up fine on the HA home page. I want an alert if the temperature (Celcius) is too high. I’ve tried both numeric_state and value template. Manually triggering works fine, but Automation never does. Thanks.

#Send an email is the temperature is out of range

  • alias: High Temperature Warning
    trigger:
    platform: numeric_state
    entity_id: sensor.sn1_temperature
    above: 20
    action:
    service: notify.GMAIL
    data:
    title: ‘High Temperature Warning’
    message: ‘The temperature is {{states.sensor.sn1_temperature.state}} degrees’

  • alias: High Temperature Warning 2
    trigger:
    platform: template
    value_template: “{{states.sensor.sn1_temperature.state > 20}}”
    action:
    service: notify.GMAIL
    data:
    title: ‘High Temperature Warning’
    message: ‘The temperature is {{states.sensor.sn1_temperature.state}} degrees’

1 Like

I think when you include variables, you need to use data_template: instead of data:

# Door Open Alert - If doors are open and I leave, remind me
- alias: 'Door Minder'
  trigger:
    platform: state
    entity_id: device_tracker.rpitera_rpitera
    from: 'home'
    to: 'not_home'
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: binary_sensor.front_entry_opened
        state: 'on'
      - condition: state
        entity_id: binary_sensor.side_entry_opened
        state: 'on'
  action:
    service: notify.pushbullet
    data_template:
      message: >
        Robert, you left one of the entry doors open. Front Door is {{ states.binary_sensor.front_entry_opened.state }}.  Side Door is {{ states.binary_sensor.side_entry_opened.state }}.

Hi Robert, thanks. The action works fine and includes the variable value when I manually trigger, so I think data vs data_template isn’t the problem in this case, more likely the trigger. I did try it, but no luck.

My guess is that your sensor is not reporting a numeric value, but rather a string.
If it’s a string, you can’t use a numeric state trigger, and you have to convert it to an number to compare it to the number 20 like this:
{{ states.sensor.sensorname.state | float > 20}}

2 Likes

I’m sorry, you did specify that in the post but I missed it. @treno is on a much better track.

Yes, somewhere in MQTT the sensor value translated to a string. | float fixed it. Thanks both for your suggestions.

Glad you got it sorted out. Nice catch @treno - I marked your post as the solution!