Use Condition in Template Light?

I have created a widget using Template Light, and everything works well. I’d like to add a condition to the turn_off function. I’ve tried like this. . .

- platform: template
  lights:
    my_light:
      turn_off:
        condition:
          condition: state
          entity_id: sun.sun
          state: "above_horizon"
        service: blah, blah, blah...

But when I validate my configuration, I get the following error. . .

Invalid config for [light.template]:
Unexpected value for condition: 'OrderedDict([('condition', 'state'), ('entity_id', 'sun.sun'), ('state', 'above_horizon')])'.
Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['lights']['my_light']['turn_off'][0].
Got None. (See ?, line ?).

I’ve tried various permutations of combinations of writing a condition, but none of it works. Is it possible to add a condition in a template? Or do I have to use an automation?

If you are going to supply more than one action you need to make them a list:

- platform: template
  lights:
    my_light:
      turn_off:
        - condition:
            condition: state
            entity_id: sun.sun
            state: "above_horizon"
        - service: blah, blah, blah...
1 Like