Automation - Template error on recalling a scene

Hi,

I’m trying to create simple automation, but I get an error. Basically, it should recall a different scene based on an input_select value:

- id: 'turn_on_light'
  alias: room lights
  description: turn on lights
  trigger:
  - device_id: dbfae518679e47da8b11dc1abc6f32f6
    domain: deconz
    platform: device
    subtype: turn_on
    type: remote_button_short_release
  condition: []
  action:
  - data_template:
    entity_id: scene.lights_"{{ states('input_select.home_status')|lower }}"
    service: scene.turn_on

I’ve tried some codes alternatives, but without success. I’m still getting this error:

Invalid config for [automation]: expected a dictionary for dictionary value @ data[‘action’][0][‘data_template’]. Got None not a valid value for dictionary value @ data[‘action’][0][‘entity_id’]. Got None.

What am I missing?

Thank you!

PS: this is my first post. I’ve read this post, and I hope I did it well. If not, forgive this noob.

I don’t know about your trigger, if that works fine then maybe just leave it alone but your indentation doesn’t look correct. I haven’t tested myself but see if the action written like the code below works.

- id: 'turn_on_light'
  alias: room lights
  description: turn on lights
  trigger:
    platform: device
    device_id: dbfae518679e47da8b11dc1abc6f32f6
    domain: deconz
    subtype: turn_on
    type: remote_button_short_release
  condition: []
  action:
    - service: scene.turn_on
      data_template:
        entity_id: "scene.lights_{{ states('input_select.home_status')|lower }}"
    

Edit: I moved the " as per Taras’ observation.

1 Like

Initial double-quote was in the wrong place.

    entity_id: "scene.lights_{{ states('input_select.home_status')|lower }}"

You can also call it directly, like this (without data_template and entity_id):

  service_template: "scene.lights_{{ states('input_select.home_status')|lower }}"

Many thanks!

Your post initially did not have the correct answer but then you changed it after you saw my reply?

:man_shrugging:

My instructions were for Stefano to move the double-quote.

My post was marked as the solution but I’m sure you are correct, so I changed it to be accurate for anyone who reads this topic in the future.

You’re saying it was marked as Solution before it incorporated the correct location of the double-quote?

If so, it was untested before it was chosen as solving the error message.

Yes. It was marked as being the Solution before I added the edit.

Oh well, as long as the OP is happy.

Thanks @AJStubbsy, thanks @123! Just to clarify, I’ve implemented Adam solution before the edit, and it is working fine without the quotes. I’ve just tried with the quotes and it works also. I guess that the main issue was the indentation (as usual). Thank you both! :slight_smile:

2 Likes