I’m trying to create template switches that can control the brightness of a light. I need to do this because it is for API.AI integration that converts speech to text and is then matched via templating (example below).
The current flow is like this:
Google Home voice recognition -> HASS action triggered with recognized entities (room, on/off, brightness, etc)
Here is the API.AI configuration that will illustrate why I need to use the template switch platform rather than the light platform:
light.onoff:
speech: Turning {{ room }} lights {{ on_off }}
action:
- service_template: >
{%- if on_off == "on" -%}
switch.turn_on
{%- else -%}
switch.turn_off
{%- endif -%}
data_template:
entity_id: "switch.light_{{ room | replace(' ', '_') }}"
So as you can see, I have to match exactly the variable room
which comes from API.AI with my entity_id
("switch.light_{{ room | replace(' ', '_') }}"
). Example: If I say “Turn off the living room lights”, “living room” gets sent to HASS in the room
variable and is matched with my template switch switch.light_living_room
. Since so many lights have generated garbage on their entity ids (my actually living room light entity_id is light.recessed_lights_level_9_0
), I need to use the template switch to effectively rename the entity.
switch:
- platform: template
switches:
light_living_room:
value_template: "{{ is_state('light.recessed_lights_level_9_0', 'on') }}"
turn_on:
service: light.turn_on
entity_id: light.recessed_lights_level_9_0
turn_off:
service: light.turn_off
entity_id: light.recessed_lights_level_9_0
Now my problem arises when I try to perform some other action besides simply turning on the switch. My next project is to get brightness manipulations working, which requires passing the brightness
parameter in to the light.turn_on
service method. From the documentation of the template switches, I do not see an option for passing in attributes to the configured turn_on
/turn_off
service calls.
Is there some way to do something like this? Or am I looking at a feature request here?
Thanks for any help on this.