Problem with Automation -> action -> variables with templates

Hi,

i have an automation where i call a script, for that script i use variables. That works great, but when i change the static variables to variables filled by template the script will not be called. Maybe something is wrong or is it not possible. Here is the action part of my automation.

action:
  - service: notify.Wohnung
    data:
      message: 'Keiner mehr zuhause - Awaymode aktiviert'
  - service: input_boolean.turn_on
    entity_id: input_boolean.nobody_home
  - service: input_select.select_option
    entity_id: input_select.scene_select
    data:
      option: 'Alles aus'
  - service: script.turn_on
    entity_id: script.awaymode_heating
    data_template:
      variables:
        temperature: '{% if states.sensor.yweather_temperature.state < 17 %}17{% else %}4{% endif %}'
        message: 'Keiner mehr zuhause, drehe Heizung runter'

I hope someone can help me get that working.

Try

- service: script.awaymode_heating

for that last service. Instead of using script.turn_on with an identity_id.

But it is working when i write

temperature: 17

only if using a template it is not fire the script. So i think that service is correct.

I could fix it myself, problem was that the state could not be compared to a number. It works with this change (adding the int to convert the state value)

temperature: '{% if states.sensor.yweather_temperature.state|int < 17 %}17{% else %}4{% endif %}'

1 Like

Great! Don’t forget - you can test templates using the template dev tool (button at bottom of sidebar).