Template for scene creates error when used in automation action

I am using scenes to fetch the right settings for lights throughout the day, using three scenes: daytime, evening and night. Below is the action I call within my automation.

action:  
  service: scene.turn_on
#    entity_id: scene.daytime
   entity_id: "scene.{{ states('sensor.time_of_day') }}"

The entity_id line produces the error

Invalid config for [automation]: not a valid value for dictionary value @ data['action'][0]['entity_id']. Got None. (See ?, line ?). 

The template scene.{{ states('sensor.time_of_day') }} parses to scene.daytime, when the State of sensor.time_of_day is daytime

I have even used just entity_id: scene.daytime with no luck.
When commenting out this automation the check pass.

What am I missing here?

Your spacing before entity_id is off. Need to move one space to the left (that’s why it’s not working with just the entity ID). But…you need to use data_template: above entity_id when templating the entity ID for Home Assistant to parse it correctly.

action:  
  service: scene.turn_on
  data_template:
    entity_id: "scene.{{ states('sensor.time_of_day') }}"

See here for more info.

That was a typo when putting the code here :slight_smile:

Thank you for helping me out :slight_smile:

Ah gotcha. Also, if what I wrote above doesn’t work, post the full automation.

1 Like

It passed the syntax check, so I assume its working as expected.
Thanks again :slight_smile: