Light template(s) from HA guide and forums don't work

Hi All,

I’ve just installed HA OS on my Raspberry Pi and am trying to get a dimmable light template for Alexa working. However I can’t seem to get the template to work. I tried some from the forums, like for example pasting yaml from “Create a virtual Dimmer or light template for Alexa” (had to remove link due to newbie limit) in the configuration.yaml.

Failing miserably I went to Template Light, where it clearly says

To enable Template Lights in your installation, add the following to your configuration.yaml file:

But even then, I’m getting following error:

Logger: homeassistant.config
Source: config.py:1300
First occurred: 7:10:35 PM (1 occurrences)
Last logged: 7:10:35 PM

Invalid config for ‘light’ from integration ‘template’ at configuration.yaml, line 27: some but not all values in the same group of inclusion ‘effect’ ‘lights->theater_lights->’, got None, please check the docs at https://wwwhome-assistant.io/integrations/template
I didn’t do any changes in the yaml code, copied from the guide and still noting.

Where am I going wrong with it?

Hello rokfor2000,

Welcome to the forum. Let’s see if I can be of any assistance.

First, we would need to see what you tried that gave you the error.
Show us in the yaml format, and the </> button helps with formatting that.

More hints can be found in the Site FAQ
https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question.

Please clarify what you mean by the above statement. The sample configuration provided in the Template Light docs includes a lot of optional controls, you may want to start with just the basics that are required for a dimmable light:

light:
  - platform: template
    lights:
      alexa_light:
        friendly_name: Alexa Light
        level_template: #Your "Brightness" detection template Goes Here
        value_template: #Your "On/Off" detection template Goes Here
        turn_on:
          action: #Your "On" Action Goes Here 
        turn_off:
          action: #Your "Off" Action Goes Here
        set_level:
          action: #Your "Brightness" Action Goes Here 

Because of the way Amazon has designed Alexa, there can be significant barriers using HA to control devices that are connected only through Alexa. If possible, you may want to consider integrating the device directly into Home Assistant.

1 Like

Thanks Didgeridrew. Strangely your template seems to be identical to the one I mentioned I found on the forums, but yours works.

I know about emulated hue limitations, my previous “smart” home setup used devices as triggers to run automations in Broadlink. For now the I’m just going to do it the same so the family doesn’t complaint when I build on it.

Anyway. That still leaves 2 questions I have:

  1. Even though I got it working, why did the template from the guide just copied as is into configuration.yaml cause an error? I mean the “theater_lights” failed to be created on startup before I even tried to expose it to Alexa or do anything with it. It’s just against what’s in the guide.

  2. Why do I need level_template? It seems that the set_level is triggered regardles and brightness attribute of the alexa_light is updated. Meaning I can just use it by reading it out directly from there once the set_level part is runnign.

@rokfor2000 I’m not clear on what you are trying to do. Are you just trying to control a light that you have connected to Home Assistant from Alexa? You don’t need to create a template to control lights from Alexa using Emulated Hue. If you configure Emulated Hue correctly to make your light visible, then ask Alexa “Alexa, Discover Devices”, Alexa will then be aware of the light and you can say for example, “Alexa, set living room light to 50%”
If you can be more specific on what you are trying to do, I’m sure someone here can help.

it’s missing effect_template

level template is the value you see when you look at the light in the UI. set_level is called when you adjust the slider.

1 Like

Hi SlyJester,

I already did what I wanted to do. Just to clarify that point, for example. I have a RF projector screen. Broadlink has the codes. When I say “Alexa, lower the screen”, the turn_on of the emulated hue lowers the screen via the Broadlink. I have an emulated dimmer mapped the same way to control TVs volume via Broadlink. With Didgeridrew’s help it now works so I don’t need help making it work anymore. Thanks all for support, it was really quick!

Nonetheless I would like to understand for the future why copying the template from Template Light (as described at the top of the page) doesn’t work and causes an error on HA startup.

And the 2nd question what’s the purpose of level_template as it seems redundant to me because I can detect it by for example:
states.light.alexa_virtual.attributes.brightness
in this section:

        set_level:
          action: #Your "Brightness" Action Goes Here

EDIT:

Got ya, thanks. As I understand then is that the demo code on that page is incorrect and it’s not something I missed, right?

P.S. thanks for the level_template explanation as well :slightly_smiling_face:

If you don’t define a level_template, “optimistic mode” is enabled and the brightness level value is maintained internally. This won’t be completely reliable. In some circumstances Alexa may not push updated brightness values to Home Assistant when the brightness is changed via voice command or the Alexa app. Likewise, reloading the integration or restarting Home Assistant may cause the value to be lost.

It may not be necessary for your current use case, but it can cause reliability issues if you have automations with conditional logic that depends on those brightness values.

1 Like