Template using temperature doesn't trigger automation

I’m trying to trigger an automation, that will to turn off a switch if temperature is 66 degrees (or warmer). Below is my code. When I check it in developer tools/templates it returns the correct value, however the automation never triggers. Any help would be appreciated.

- id: '1618412717997'
  alias: heater off
  description: ''
  trigger:
  - platform: template
    value_template: '"{{states(''sensor.multisensor_temperature'') | float >= 66}}"'
  condition: []
  action:
  - type: turn_off
    device_id: 8e4af6e186942961f94402f18e3c73c3
    entity_id: switch.heater
    domain: switch
  mode: single

Hi,

I can’t honestly say I fully understand templating & the nuances of syntax, but i feel that the ‘value_template’ line doesn’t look quite right to me. Too many quote characters i feel. Also, i do know that often templates like that are often placed on a new line. Perhaps something like this might make a difference.

value_template: >
  {{ states('sensor.multisensor_temperature') | float >= 66 }}

maybe?

Nick

The template is fine.

Is your temperature already >= 66?

Try this method instead:

trigger:
  - platform: state
    entity_id: sensor.multisensor_temperature # trigger on any change of sensor state or attribute change
  - platform: homeassistant
    event: start
condition:
  - condition: numeric_state
    entity_id: sensor.multisensor_temperature
    above: '66'
action:
...etc

I tried that and it seemed to only trigger when the temp was exactly 66. but if it say jumped from something under 66 to say 66.5 it would not trigger.

That sounds like you supplied a trigger to: state.

Don’t.

Then the automation will trigger on all state changes, then check the conditions to see if the value is above 66. If you need 66 and above 66 set the condition to above 65.99 instead.

if I understand correctly, your suggesting something like this.

- id: '1638857259629'
  alias: heater off (Duplicate)
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.multisensor_temperature
    above: '65.99'
  condition: []
  action:
  - type: turn_off
    device_id: 8e4af6e186942961f94402f18e3c73c3
    entity_id: switch.heater
    domain: switch
  mode: single

I just noticed ,
I see this warning in my logs

  • Template warning: ‘float’ got invalid input ‘unknown’ when rendering template ‘"{{ states(‘sensor.multisensor_temperature’) | float >= 68}}"’’ but no default was specified. Currently ‘float’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1

No. I specifically said:

Do it like this:

- id: '1638857259629'
  alias: heater off (Duplicate)
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.multisensor_temperature # trigger on all sensor state changes
  - platform: homeassistant # also check when home assistant starts
    event: start
  condition:
  - condition: numeric_state
    entity_id: sensor.multisensor_temperature # check if 66 or above
    above: '65.99'
  action:
  - type: turn_off
    device_id: 8e4af6e186942961f94402f18e3c73c3
    entity_id: switch.heater
    domain: switch
  mode: single

That is referring to another issue with your template that would not have changed it’s operation until next year.

You will soon need to define a default for the |float filter. It can be as simple as changing |float to |float(0). However this would make no difference to your issue. Try my automation above.

that was it, works perfectly now. Thanks so much for your help

1 Like