#Heyo
1 messages · Page 1 of 1 (latest)
Was looking at the code you posted.
- Curious why you use a script to turn lights on/off? Have you considered using a light group instead? (Or does the script do more than just handle lights?)
- Do you have two separate buttons? One to turn the masterlights on and another to turn the master lights off? It is possible to incorporate both on and off scripts into one button with a little bit of extra code.
Here's an example for my All Lights Off button. ```yaml
- type: custom:button-card
template: generic_custom_button
entity: light.all_lights
icon: mdi:lightbulb-group-outline
name: >
[[[ if ((entity.state === 'on')) return "All Lights Off"; else return "All Lights On"]]]
hold_action:
action: navigate
navigation_path: /fire-main/all-lights```The template does all the formatting but notice how the name changes. If any light within light.all_lights group is on, then the group will be on and the name will be "All Lights Off". Pressing the button will toggle the group (turn off) and the name will change to "All Lights On". You could set up something similar for the tap_action to determine if the on or off script needs to run (if you're not able to use a light group.)
Hi bro!
Well I'm using those SwitchBot and Tuya buttons to interact with my lights (renting a place), that's why i'm not using a group (some of them it consider as switch, some as light)
2. Yeah, my lights dashboard UI looks like that:
(I messed up with the size of the shower lights & the 2 master buttons recently and can't find a way to fix that)
that's why i'm not using a group (some of them it consider as switch, some as light)You can set switches to show up as lights instead which could be helpful. (The switch entity will be hidden and a light entity will be created for it.)
EDIT: I think you can create a template entity that can have a combination of light and switch entities. I'm not sure, however, if HA will call the appropriate service for each item if you try to turn off that entity. (light.turn_on /= switch.turn_on)
I messed up with the size of the shower lights & the 2 master buttons
I recommend incorporating templates for the custom:button-card. It is one of the few cards that has that ability. Basically, you design the button the way you want, copy and define the code into the Raw Editor, then each button can reference the template. Makes it way easier when it comes time to change/update so you don't have to go find each instance for each button. https://github.com/custom-cards/button-card#configuration-templates
Yeah it is possible to change switch to be consider as light
I think if you get everything working together (into a light group or a templated entity), it might make things easier to work with. Then you can look into working with the states of the entity rather than having to code how the button handles being pressed (which isn't hard; just a bit more work involved).
State on/off comparison: