House Themes via dynamically generated scene names

Hey All-

I’m trying to create an automation tied to an input selector where changing the selector will iterate over all groups and attempt to turn on a scene with a name of the group and input selector value concated like: groupName_inputSelectorValue. So for example if I had 2 groups:

  • living_room
  • kitchen

and selected the value ‘warm’ from the input selector, it would try to turn on the scenes:

  • living_room_warm
  • kitchen_warm

So why would I want to do this? Well first of all I figured this was a complicated enough task to get me somewhat familiar with templating in home assistant. Which is something I’ve been avoiding for a while now due to learning curve / complexity. And also I’m lazy and like the idea of being able to add ‘theme’ scenes without needing to update the input select automation every time.

Using the dev console templating section I’ve managed to generate a scene name that matches what I’m trying to do, however the automation doesn’t compile. Time for some code that doesn’t work:

alias: "House Theme Input Selector"
#initial_state: "none"
trigger:
  - platform: state
    entity_id: input_select.house_theme
action:
  - service: scene.turn_on
    data_template: >
     {% for group in states.group.rooms.attributes.entity_id %}
       {% set temp_scene_name = "scene." + group | replace('group.', '') + "_" + states('input_select.house_theme') | lower | default('none') %}
       entity_id: "{{temp_scene_name}}"
     {% endfor %}

which results in the following error when using config-check:

17-04-20 01:23:05 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None. (See ?:?). Please check the docs at https://home-assistant.io/components/automation/

Also if anyone knows if / how I could test for a scene to exist before trying to turn it on for bonus.

Thanks for any help

I wonder if this thread might be of any help?