Are template lights still a thing?

HA 0.101.2 running on RP3+

First post. Set up HA a couple of weeks ago and very impressed. May have overestimated my technical competence but have managed to figure out everything I needed to. Until today.

Came across the idea of a template light for Alexa integration and thought “I want one of those”. I copied the code direct from https://www.home-assistant.io/integrations/light.template/

# Example configuration.yaml entry
light:
  - platform: template
    lights:
      theater_lights:
        friendly_name: "Theater Lights"
        level_template: "{{ sensor.theater_brightness.attributes.lux|int }}"
        value_template: "{{ sensor.theater_brightness.attributes.lux|int > 0 }}"
        turn_on:
          service: script.theater_lights_on
        turn_off:
          service: script.theater_lights_off
        set_level:
          service: script.theater_lights_level
          data_template:
            brightness: "{{ brightness }}"  

but I just keep getting the message:

Invalid config for [sensor.template]: [lights] is an invalid option for [sensor.template]. Check: sensor.template->lights.

which seems to suggest I can’t create the light this way anymore. Or am I being a fool? (most likely)

If anyone can point out the nature of my foolishness I’d be grateful. Ta

I haven’t tested version 0.101.X yet but maybe one clue to this issue is that it reports sensor.template yet this is a Template Light not a Template Sensor.

Invalid config for [sensor.template]: [lights] is an invalid option for [sensor.template]. Check: sensor.template->lights

1 Like

Good catch, @123!

@Lyshco share the “light” part of your configuration.yaml exactly as it is and include 10 lines or so above and below the light: section. If you have your configuration broken into multiple files, share each of the pieces that lead up to lights and include 10 lines above and below each of those too, just in case. If there isn’t an issue there, then this appears to be a bug in Home Assistant and I recommend opening an issue.

Here’s the embiggened portion of the configuration.yaml. I originally dropped the code in after the bus / train sensor section (which I haven’t included all of) which prompted the error message. So I moved it above thinking maybe it was inheriting the sensor piece, but get same error message. It’s exciting to think I might have discovered an actual bug but given how new to all this I am I was very much assuming the fault was likely to be mine.

person:
    - name: Stu
      id: stu1
      device_trackers:
        - device_tracker.stuart
        - device_tracker.life360_stu
    - name: Fi
      id: fi1
      device_trackers:
        - device_tracker.fiona
        - device_tracker.life360_fi
    - name: Bobs
      id: bob1
      device_trackers:
        - device_tracker.robert
        - device_tracker.life360XXXX
        
####################
#Create Dummy Light
####################
# Example configuration.yaml entry
light:
    platform: template
    lights:
      theater_lights:
        friendly_name: "Theater Lights"
        level_template: "{{ sensor.theater_brightness.attributes.lux|int }}"
        value_template: "{{ sensor.theater_brightness.attributes.lux|int > 0 }}"
        turn_on:
          service: script.theater_lights_on
        turn_off:
          service: script.theater_lights_off
        set_level:
          service: script.theater_lights_level
          data_template:
            brightness: "{{ brightness }}"

#################################
#Set up Sensors for train and bus
#################################
sensor:
  - platform: uk_transport
    app_id: XXX
    app_key: XXX
    queries:
      - mode: train
        origin: XXX
        destination: XXX
      - mode: bus
        origin: XXXX
        destination: XXXXXX
  - platform: template
    sensors:
        next_train_status:
          friendly_name: 'Next train status'

That’s what I was wondering about @123 - whether there might have been a change to how to instigate a template light. As a total noob it’s reassuring that I’m not completely off piste. Thanks

You do have a sensor called sensor.theater_brightness ? It is not included in the snipped you posted.

Indeed. This is an exact copy of the example configuration from the docs, I suspect the OP doesn’t actually have any ‘theatre lights’ and we’re on to a big XY problem.

@Lyshco - please tell us what you are trying to achieve with your template light?

FWIW, I entered that example, verbatim, into my lights.yaml file and in version 0.99 the error message is different. It carps about being unable to update light.theater_lights which is understandable because none of its sensors exist in the configuration.

What it doesn’t do is display the error reported by Lyshco in the first post (using version 0.101.2).

OP has to have some yaml issue. Indenting is different in different sections for one (indicating not careful with that).

Hopefully not an XY problem but you’re right, I don’t have any theatre lights. I did originally localise some of the details but when it didn’t work I went back to first principles to see if I could get the verbatim code to work.

My understanding of a template light - and what I’m trying to achieve - is that rather than exposing everything to Alexa and building whole stack of Alexa routines, I can set up a template light - a device that doesn’t physically exist but can be passed values by Alexa. I can the use these values as triggers for eg firing a script.

FWIW I originally tried a simplified version I found in the forum (Create a virtual Dimmer or light template for Alexa):

 - platform: template
   lights:
     alexa_virtual:
       friendly_name: "Alexa Dummy Light"
       turn_on:

       turn_off:

       set_level:

when that didn’t work I tried the “official” version as per original post.

Hope that all makes sense and much appreciation for the help and guidance

To do this, it’s far easier to make an input_boolean and expose that to Alexa as a switch. I have several of these set up. So Alexa turns on the input_boolean, then as part of the automation/script, I turn it back off so it’s ready for the next time.

1 Like

I think I may see an issue based on the YAML you posted.

“platform: template” in the “light:” section should have a “-” before it as in the example code you copy/pasted.

Large numbers of Input_Boolean switches can be confusing and fill the alexa app . One virtual light switch can represent 99 input_boolean switches . I only use input_boolean switches that alexa can switch on and off directly without additional HA coding. Anything else I use one virtual light bulb, makes coding simpler and keeps the aleax app lean.

Thanks everyone for your help with this. Having gone through it all again, put it higher up in the configuration.yaml, picked through the indentations and adding the missing “-”, I now have a working template light - and it’s not even called “Theatre Lights” anymore.

I’ve also learned about input_booleans which aren’t quite what I wanted in this instance for the reasons @lonebaggie highlighted. But now I know they exist I may well use them in other situations.

So muchos gracias for help with my first HA stumble. Good app, good community. I think I’ve made a good choice. Cheers

1 Like

I guess I don’t see the difference. I can just as easily make one input_boolean and have it switch 99 light bulbs as I can make a virtual switch and have it switch 99 lights, no?

In both cases, you are making a “virtual” entity in HA that represents any number of “real” things. In one case it’s done by coding a template switch, in the other via an input_boolean. To Alexa, it’s all the same.

What am I missing?

An Input_Boolean has two states off or On . A Virtual Bulb dimmer has 100 states 0 to 99

So I can set routines in the Alexa App to set one virtual bulb to any state 0 to 99 and then only have to deal with one switch in HA . Also I use the alexa App to control all my devices when I am off site. Multiple Input Boolean switches “fill the interface” so unless they directly control a “thing” in my house and can be named as such ie TV I use one virtual bulb to replace all the other input Boolean. If you only have a couple of Input Boolean switches , not an issue.