neil-w
November 30, 2022, 10:43am
1
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
1 Like
tom_l
November 30, 2022, 11:58am
2
Use an input select helper.
1 Like
neil-w
November 30, 2022, 12:42pm
3
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.
1 Like
neil-w
November 30, 2022, 1:15pm
5
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.
123
(Taras)
November 30, 2022, 1:37pm
6
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
neil-w
November 30, 2022, 1:52pm
7
That works perfectly! Thank you.
1 Like
123
(Taras)
November 30, 2022, 2:01pm
8
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
thermiek
(thermiek)
April 15, 2025, 7:18pm
9
i made a template with 2 inputs , and a single off protection
alias: Consolidated Radio Button Control
description: Maintains single active state between two input_booleans
triggers:
- entity_id:
- input_boolean.een
- input_boolean.twee
from:
- "on"
- "off"
to:
- "on"
- "off"
trigger: state
conditions: []
actions:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
sequence:
- target:
entity_id: |
{{
['input_boolean.een', 'input_boolean.twee']
| reject('eq', trigger.entity_id)
| list
}}
action: input_boolean.turn_off
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'off' }}"
- condition: template
value_template: |
{{
['input_boolean.een', 'input_boolean.twee']
| select('is_state', 'off')
| list
| count == 2
}}
sequence:
- target:
entity_id: "{{ trigger.entity_id }}"
action: input_boolean.turn_on
mode: queued