How would I create a light with 'discrete' colors, ie. not the full pallette?

I have a ‘star heaven’ fiberlight. I bought this years ago, and 2 years ago I swapped the light source with a new box, that has an RF remote to it.
The remote looks like this


It’s a rather simple remote, but as it’s RF there is no feedback to the sender of the state.
I’ve created a lght that can be turned on / off with a Broadlink RM4 pro, and I’ve learned the codes from the remote into HA.
To have a ‘state’ for the light, I created a boolean, but I’m not sure if that is necessary.

The template light looks like this:

- platform: template
  lights:
    trappe:
      friendly_name: "Trappe"
      value_template: "{{  is_state( 'input_boolean.stairs_light' , 'on' ) }}"
      turn_on:
        - service: remote.send_command
          data:
            entity_id: remote.stuen_remote_sender_remote
            device: stairslight
            command: Turn on
        - service: homeassistant.turn_on
          data:
            entity_id: input_boolean.stairs_light
      turn_off:
        - service: remote.send_command
          data:
            entity_id: remote.stuen_remote_sender_remote
            device: stairslight
            command: Turn off
        - service: homeassistant.turn_off
          data:
            entity_id: input_boolean.stairs_light

But how do I get all the other buttons into it. I don’t have a color wheel, but I can set specific colors, like, red, green, blue, yellow, cyan and purple. I can adjust the levels on the arrow buttons, but that seems like overkill, so I would just settle with the preset ‘discrete’ colors.
And how do I get the effects added to the light as well?

Did you ever figure this out? I’m trying to do something similar with IR-controlled ceiling lights. I’ve been using scripts to send the signals signals, which works, but isn’t represented in the light template, so things like blueprints can’t use those as part of the light entity.

I suspect “effects” are the right way, but I can’t find any examples of using effects in this way.

There are plenty of examples, even the link you posted has an example.

Here’s a succinct example with 3 colors, excluding all the other light template attributes that uses a preset input_select.

  1. create input_select with red, green, blue through the UI or through this yaml.
input_select:
  my_effect_list:
    name: My Effect List
    options:
    - red
    - green
    - blue

template option 1

        effect_list_template: "{{ state_attr('input_select.my_effect_list', 'options') }}"
        effect_template: "{{ states('input_select.my_effect_list') }}"
        set_effect:
          - service: light.turn_on
            target:
              entity_id: light.my_light
            data:
              rgb_color: >
                {% if effect == 'red' %}
                  [255, 0, 0 ]
                {% elif effect == 'green' %}
                  [0, 255, 0 ]
                {% else %}
                  [0, 0, 255 ]
                {% endif %}

template option 2

If you plan on adding alot of colors, the if/elif can be cumbersome to copy/paste… this might fit better. Keep in mind it will default to [255, 255, 255] when the color doesn’t exist in the rgb_color template. (.i.e. you made a spelling or clerical error).

        effect_list_template: "{{ state_attr('input_select.my_effect_list', 'options') }}"
        effect_template: "{{ states('input_select.my_effect_list') }}"
        set_effect:
          - service: light.turn_on
            target:
              entity_id: light.my_light
            data:
              rgb_color: >
                {% set colors = {
                  'red': [255, 0, 0],
                  'green': [0, 255, 0],
                  'blue': [0, 0, 255],
                } %}
                {{ colors[effect] if effect in colors else [255, 255, 255] }}
2 Likes

That looks like what I need. Thank you very much for the succinct example, @petro

Let me know if it works… If it does, it might be worth adding to the docs

1 Like

@petro , what can I say, you are a star! I’ll go and experiment with this as well…

I didn’t test your code exactly, but my code loosely based on your works perfectly. It was your use of the input_select helper and expanded use of the effect variable which gave me the a-ha moment I needed. This would certainly be helpful in the Template Light documentation for those trying to use effects.

Hi @petro

I’m trying to work my way through this, but I’m a bit at a loss as to what I’ve misunderstood
As I originally described, the light has certain set values, which is defined on the remote, I’ve learned all of them into HA.

- platform: template
  lights:
    stars:
      friendly_name: "Stjerner"
      effect_list_template: "{{ state_attr('input_select.farveliste', 'options') }}"
      effect_template: "{{ states('input_select.farveliste') }}"
      turn_on:
        service: remote.send_command
        data:
          entity_id: remote.livingroom_sender_remote
          device: stairslight
          command: Turn on
      turn_off:
        service: remote.send_command
        data:
          entity_id: remote.livingroom_sender_remote
          device: stairslight
          command: Turn off
    set_effect:
      service: light.turn_on
      target:
        entity_id: light.stars
      data:
        rgb_color: >
          {% if effect == 'Rød' %}
            service: remote.send_command
            data:
              entity_id: remote.livingroom_sender_remote
              device: stairslight
              command: Red
          {% else %}
            - service: remote.send_command
              data:
                entity_id: remote.livingroom_sender_remote
                device: stairslight
                command: White
          {% endif %}

There are a lot more buttons, but I think this is the smallest amount, and it just shows more errors.
So it complains that I have a service call under
Doing a syntax check I get a lot of messages:

Invalid config for [light.template]: extra keys not allowed @ data['lights']['set_effect']['data']. Got OrderedDict([('rgb_color', "{% if effect == 'Rød' %}\n  service: remote.send_command\n  data:\n    entity_id: remote.livingroom_sender_remote\n    device: stairslight\n    command: Red\n{% else %}\n  - service: remote.send_command\n    data:\n      entity_id: remote.livingroom_sender_remote\n      device: stairslight\n      command: White\n{% endif %}\n")])
extra keys not allowed @ data['lights']['set_effect']['service']. Got 'light.turn_on'
extra keys not allowed @ data['lights']['set_effect']['target']. Got OrderedDict([('entity_id', 'light.stars')])
required key not provided @ data['lights']['set_effect']['turn_off']. Got None
required key not provided @ data['lights']['set_effect']['turn_on']. Got None
some but not all values in the same group of inclusion 'effect' @ data['lights']['stars'][<effect>]. Got None. (See ?, line ?). 

So I guess it doesn’t want a service call under the data:
But how do I then accomplish this?

You’re templating the rgb_color field with a service call. Ask yourself, “Does the rgb_color field accept a full service call?”

I have asked myself, but that impolite bastard doesn’t answer! :laughing:

I believe this is how you’d configure your light. Of course I haven’t tested this.

input_select:
  farveliste:
    name: Farveliste
    options:
    - red
    - green
    - blue
    - yellow
    - cyan
    - purple

Then, assuming each remote RF command was saved exactly as those names:

- platform: template
  lights:
    stars:
      friendly_name: "Stjerner"
      turn_on:
        service: remote.send_command
        data:
          entity_id: remote.livingroom_sender_remote
          device: stairslight
          command: Turn on
      turn_off:
        service: remote.send_command
        data:
          entity_id: remote.livingroom_sender_remote
          device: stairslight
          command: Turn off
      effect_list_template: "{{ state_attr('input_select.farveliste', 'options') }}"
      effect_template: "{{ states('input_select.farveliste') }}"
      set_effect:
        - service: remote.send_command
          target: 
            entity_id: remote.livingroom_sender_remote
          data:
            device: stairslight
            command: "{{ effect }}"
       # It's also necessary to update the light template effect after sending the command
        - service: input_select.select_option 
          target: 
            entity_id: input_select.farveliste
          data: 
            option: "{{ effect }}"

To change effects, you should see a dropdown in the light’s card or you can call it as a service.

service: light.turn_on
  target:
    entity_id: stars
  data:
    effect: 'red' # or any color from the list
1 Like

Ok, now I get it, ít looks very plausible, I’ll try it out…

Ok, I got it, and I even understand what’s going on, thankyou very much for spelling out, even for me :smiley: @kylehase

- platform: template
  lights:
    stars:
      friendly_name: "Stjerner"
      effect_list_template: "{{ state_attr('input_select.farveliste', 'options') }}"
      effect_template: "{{ states('input_select.farveliste') }}"
      turn_on:
        service: remote.send_command
        data:
          entity_id: remote.livingroom_sender_remote
          device: stairslight
          command: Turn on
      turn_off:
        service: remote.send_command
        data:
          entity_id: remote.livingroom_sender_remote
          device: stairslight
          command: Turn off
      set_effect:
        - service: remote.send_command
          target:
            entity_id: remote.livingroom_sender_remote
          data:
            device: stairslight
            command: "{{ effect }}"
        - service: input_select.select_option
          target:
            entity_id: input_select.farveliste
          data:
            option: "{{ effect }}"
1 Like