I’m pretty new when it comes to Hassio scripting but I thought I’d try to create a ‘House mode’ script which would include triggering Philips Hue scene in every room depending on which scene is configured in a group of input_text entities. For now I’ve had them hardcoded but I wanted to see if I could do it in a loop.
This is the code I’ve created, which looks correct in the Template editor, I’m sorry in advance if the formatting is incorrect:
the input_text files have the naming convention “Room name Mode Home” which is why I split with (’ Home’).
This is what the Template editor shows:
- service_template: >-
- service: hue.hue_activate_scene
data_template:
group_name: Living room
scene_name: Home
- service: hue.hue_activate_scene
data_template:
group_name: Office
scene_name: Home
Which is exactly the same as what I have hardcoded (except with it grabbing scene_name from the input_text entity, and without service_template)
And this is the error I’m getting:
Template rendered invalid service: - service: hue.hue_activate_scene
data_template:
group_name: Living room
scene_name: Home
- service: hue.hue_activate_scene
data_template:
group_name: Office
scene_name: Home
Is there anyone who understands what I would need to do to make this work?
I’ve tried removing “- service:” in the loop but I get the same error still.
The reason this is not working is because you’re trying to use Jinja to generate YAML code, but that won’t work. A Jinja template can only generate a single string. So what you’ve created is YAML code with just one parameter – namely service_template – that has a very large, multi-line string value, which is not a valid service name.
You can use loops in Jinja, but it has to be part of a template that generates just one YAML parameter value.
Loops, in general, in YAML are not easy. You’re better off writing a python_script.
How hue groups are created, in your group file, from individual bulbs?
Should python script above be placed under folder /config/python_scripts ? Is the script section above complete?
Do I still need any automation state trigger to change scene when your input_select drop down changes?
Sorry for asking so many questions, I have been trying first hue bulb working with input_select theme but nothing working. There are too many examples in forum using hue.hue_activate_scene and light.hue_activate_scene but for me nothing working.
I tried below code on a single hue bulb, picked up group “4” from hue developer’s page:
I was just going to point out the part about data_template. But also, according to the docs, I think the second parameter should be scene_name, not entity_id.
Not able to understand, which action to use? That should come out once the theme is selected in input_select. Below is full group “4” for “Living room” in hue api: