Radio button like functionality

I have created some buttons on a flashed NS Panel to control LED strips and I’m trying to get it to work where only one pattern can be selected at a time. I have created some automations which works but it’s messy and not scalable. The automations look like this:

If button 1 is pressed then turn off buttons 2 and 3
If button 2 is pressed then turn off buttons 1 and 3
If button 3 is pressed then turn off buttons 1 and 2

Is there an easier more scalable way to achieve this?

Thanks

Use an input select helper.

1 Like

But I don’t want a drop down? I have 6 buttons and I want them to be exclusive so when I turn 1 on the previous selected one is turned off. The same way a radio button works in HTML.

Post the automations.

Here are the full details of what I’m trying to achieve. I have an NS Panel which I’m using nspanel-lovelace-ui on. I have a cardGrid which has 3 buttons, each of these buttons currently calls a different preset on WLED.

Here is my app.yaml:

    cards:
      - type: cardGrid
        title: The Bar Lights
        key: cardgrid1
        entities:
          - entity: light.button_1
            name: Button 1
            icon: mdi:led-strip-variant

          - entity: light.button_2
            name: Button 2
            icon: mdi:led-strip-variant

          - entity: light.button_3
            name: Button 3
            icon: mdi:led-strip-variant

          - entity: input_select.tester_radio
            name: test input
            icon: mdi:led-strip-variant

light.button_1 references a group which in turn references the following 3 light options (3 because I have 3 separate WLED controllers):

# Button 1
  - platform: template
    lights:
      bar_cp_button10:
        friendly_name: "The Bar CP Button 10"
        turn_on:
          service: select.select_option
          data:
            entity_id: select.outer_lights_preset
            option: G-Fireworks
        turn_off:
          service: select.select_option
          data:
            entity_id: select.outer_lights_preset
            option: Power Up

  - platform: template
    lights:
      bar_cp_button11:
        friendly_name: "The Bar CP Button 11"
        turn_on:
          service: select.select_option
          data:
            entity_id: select.bar_lights_preset
            option: G-Fireworks
        turn_off:
          service: select.select_option
          data:
            entity_id: select.bar_lights_preset
            option: Power Up

  - platform: template
    lights:
      bar_cp_button12:
        friendly_name: "The Bar CP Button 12"
        turn_on:
          service: select.select_option
          data:
            entity_id: select.ceiling_matrix_preset
            option: G-Fireworks
        turn_off:
          service: select.select_option
          data:
            entity_id: select.ceiling_matrix_preset
            option: Power Up

Then I have an automation which turns off buttons 2 and 3 when button 1 is selected:

alias: Light Button 1
description: ""
trigger:
  - platform: state
    entity_id:
      - light.button_1
    from: "off"
    to: "on"
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.button_2
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.button_3
mode: single

I have to duplicate these automations for each button so 6 buttons equals 6 automations.

Hope that makes sense.

This automation turns off all lights except the one that just turned on.

alias: Light Button 
description: ""
trigger:
  - platform: state
    entity_id:
      - light.button_1
      - light.button_2
      - light.button_3
      - light.button_4
      - light.button_5
      - light.button_6
    from: "off"
    to: "on"
condition: []
action:
  - variables:
      lights:
        - light.button_1
        - light.button_2
        - light.button_3
        - light.button_4
        - light.button_5
        - light.button_6
  - service: light.turn_off
    data: {}
    target:
      entity_id: "{{ lights | reject('eq', trigger.entity_id) | list }}"
mode: single
1 Like

That works perfectly! Thank you.

1 Like

This service call should work a bit more efficiently. Instead of turning off all lights except the one that just turned on, it only turns off the lights that are currently on but should now be off.

  - service: light.turn_off
    data: {}
    target:
      entity_id: >
        {{ expand(lights) | selectattr('state', 'eq', 'on')
          | map(attribute='entity_id')
          | reject('eq', trigger.entity_id) | list }}
2 Likes