Automations with template triggers not working

Hi,

I need help getting automations with a template trigger to work. I’ve tried creating several and never fire.
Here’s a simple example just evaluating two numbers to try to get it to work.
What am I doing wrong?

alias: Template test
description: ''
trigger:
  - platform: template
    value_template: '{{ 5 > 4 }}'
condition: []
action:
  - service: notify.alexa_media_ron_s_office_echo_show
    data:
      message: It's working
      data:
        type: tts
mode: single

An automation will be triggered if the condition is becoming true in your case… Yours is not having that behaviour, it is true all the time so there is no change in state to trigger the automation…

Thanks for the reply. The original intent is to trigger an automation if the outside temperature is hotter than the inside temperature:

alias: Outside v Inside Temperature Check (Duplicate)
description: ''
mode: single
trigger:
  - platform: template
    value_template: >-
      {{ state_attr('weather.home', 'temperature') | float(0) >
      states('sensor.nest_thermostat_temperature') | float(0) }}
condition:
  - condition: state
    entity_id: binary_sensor.door_and_window_sensors
    state: 'on'
action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.ron_s_living_room_dot
      volume_level: '0.70'
  - service: notify.alexa_media_ron_s_living_room_dot
    data:
      message: >-
        Close the windows
      data:
        type: tts

This also never gets triggered.

I would suggest trying out the template in the Developer Tools template to make sure you’re actually getting something that evaluates to True or False.

Also, are you sure that it’s sensor.nest_thermostat_temperature? I can only get my current temperature from my thermostat off of a climate object, not a sensor object.

I tried it in the developer console and it does evaluate to either true or false depending on the values of each. I also entered both sensors individually ({{ state_attr(‘weather.home’, ‘temperature’) }} and {{ states(‘sensor.nest_thermostat_temperature’) }}) to make sure they were showing the temperature values I expected and they did. Because the automation never gets triggered, there aren’t any logs that might suggest what the issue is.

I just reread what you’ve got. Looks like you may have your condition incorrect. You’re stating that the binary_sensor.door_and_window_sensors is on. Most sensors are ‘on’ when they are in a closed position.

I would suggest than that you remove the condition with the window sensors and try without it…

This is “on” when one or more doors or windows is open

I removed the condition, but the initial trigger is never getting hit (making sure that it evaluates to true). If the condition was the problem, I should be getting a trace log with a failure on the condition, but I’m not.

but the template with the temperature should become false before triggering the automation… So if the template was true and you remove the condition with the door/window, the automation will only trigger if the template is becoming false before… so to test, I would hack the condition like this…

Create an input_boolean like test… than you create the following condition:

 {{ (state_attr('weather.home', 'temperature') | float(0) * (states('input_boolean.test') | int(0))) >
      states('sensor.nest_thermostat_temperature') | float(0) }}

Remove the “condition:” and test by changing the state of the input_boolean.test from on to off and on again…more than once and see if the automation triggers… it should…

Not sure that I’m following. The statement “states(‘input_boolean.test’) | int(0)” always evaluates to 0. If i remove the default (0), I get this: “ValueError: Template error: int got invalid input ‘on’ when rendering template ‘{{ states(‘input_boolean.templatetest’) | int }}’ but no default was specified”

So 0 is always less than the inside temperature, whether the boolean is on or off.

I tried taking the original statement and changing the > to a <, verified in Developer Tools that it evaluates to either true or false depending on the direction of the >… removed the condition from the automation… and still no trigger

You are right, my mistake… Replace the input_boolean by an input_select where you can assign the value of 0 or 1… and test with 0 and 1 to see if the automation triggers…

It finally triggered this morning. I don’t know what did it, to be honest, because I couldn’t get it to fire at all yesterday, but it’s working now, so I’ll take it. Thanks for the help!

2 Likes