Hello to all.
I want to use two diffrent actions in one automation depending on the input. Problem is that the actions require diffrent data Dictionaries which I try to acomplish by using templating.
More Background Info:
I am trying to control my lights (Philips Hue) with a Dropdown Helper. Each Room has its own Dropdown Helper with some light moods (actually Philips Hue Scenes) and one option called “Aus” to turn the light off.
Per helper I have one automation where I check for new selected Inputs.
If the new input is a light mood (for example “Arbeitslicht” or “Fernsehen”) it should call the hue.hue_activate_scene action with the selected input as scene name.
If the new input is “Aus”, it should call the light.turn_off action with the group_name of the room. (for example “light.wohnzimmer”)
Here is my working example:
alias: Wohnzimmer Lichter Steuern
description: Input Selector -> Philips Hue Room
trigger:
- platform: state
entity_id: input_select.wohnzimmer_licht
condition: []
action:
- service: >-
{% if is_state(trigger.entity_id, 'Aus') -%} light.turn_off {%- else -%}
hue.hue_activate_scene {%- endif %}
data:
'{%- if is_state(trigger.entity_id, ''Aus'') -%}entity_id{%- else -%}group_name{%- endif -%}': >-
{%- if is_state(trigger.entity_id, 'Aus') -%}light.wohnzimmer{%- else
-%}Wohnzimmer{%- endif -%}
'{%- if is_state(trigger.entity_id, ''Aus'') -%}transition{%- else -%}scene_name{%- endif -%}': >-
{%- if is_state(trigger.entity_id, 'Aus') -%}-1{%- else
-%}{{states(trigger.entity_id)}}{%- endif -%}
mode: single
Problem is with this example, that I have a fixed structure of two keys and two values for every action.
I want to create a version where for the action hue.hue_activate_scene both required values are set and for the light.turn_off only the only one required value. My workaround uses an second optional value transition to keep the same dictonary structure, but the transition setting creates problems with my lights.
I read that it is possible to output a native type, like a dictionary, with templating, but I dind’t got it to work.
It should look like this:
If trigger.entity_id = “Aus” then
data:
entity_id: light.wohnzimmer
else
data:
group_name: Wohnzimmer
scene_name: trigger.entity_id
Thanks a lot for your help.