Status light toggle button problem

Recently, I have created one simple page in Lovelace, where all my lights are listed, to be able to see at once all lights buttons.
I have one button that is set to turn on few different power plugs that drive lamps connected in it.
I have created simple automation to toggle it all together and it work just nice.

Now, when toggle other lights, icon get yellow or monochrome to show the status of the light as it should by default and that is ok, only the button that trigger automation (group of lights/plugs) does not toggle the color status but toggle lights on and off just fine.
How to trick it to toggle status light?

Here is my code:

show_name: true
show_icon: true
type: button
name: Dnevna Lampe
icon: mdi:lightbulb-on
entity: automation.lampe_pali_gasi_dnevna_soba
show_state: false
tap_action:
  action: call-service
  service: automation.trigger
  target:
    entity_id: automation.lampe_pali_gasi_dnevna_soba
  data:
    skip_condition: false

Highly appreciate any help, I am too dumb to solve this myself.

The automation is ON (i.e. ready to be triggered).
Since this entity is the “main entity” of the button-card - the icon is “yellowish” (“active”):

If you need an icon of “inactive” color:

  1. Define same entity or any other entity with “state_color: false”:
type: button
show_name: true
name: call automation
show_icon: true
icon: mdi:car
entity: sun.sun
state_color: false
tap_action:
  ......

image

  1. Or create an input_button helper - specially to trigger the automation, then use this entity as the “main” in the button card.
1 Like

Thank you very much for help.
I have tried your other suggestion (sims like easier and more elegant for me) but guess I miss something there, not sure what. I have created helper, cannot see that for button helper some extra settings, and it does not work for some reason. It does trigger automation and toggle lights fine but still not change the color according to state.

show_name: true
show_icon: true
type: button
name: Dnevna Lampe
icon: mdi:lightbulb-on
entity: input_button.lampednevnagrupa
show_state: false
tap_action:
  action: call-service
  service: automation.trigger
  target:
    entity_id: automation.lampe_pali_gasi_dnevna_soba
  data:
    skip_condition: true

Ill try to decrypt first suggestion and try :slightly_smiling_face:

the button color will reflect the value of that input_button.

so that means in your automation, you’ll need to set the value of your helper input_button.lampednevnagrupa to the correct value.

i’d caution you not to simply set it to true/false each time it runs, but instead to set it to the actual value of the group of lights/plugs at the end of the automation run. otherwise at some point it’ll get out of sync.

also you should then set it to the proper value at system boot time to get it in the right state to begin with.

1 Like

You call it a group, but you use an automation. Two things stand out to me.

If it is actually a group of which you’d want to turn them on or off simultaneously, you could just create an actual group helper. Groups reflect the state of the entities in it and can be operated on. Set that group in the button and remove the automation.

If the required action needs more logic, then a sensor to see what state the entities are in, and something to change it to a certain state makes more sense, which brings me to the second bit:

Not specificly related to the question, but a general remark on how to best tackle these things: if a sequence of commands is started from something outside (a button, a voice command, another automation or script) then a script would be the best choice, Automations contain triggers and conditions that are ignored when you call an automation. So it is advised not to call automations externally, as it is confusing.

So:

  1. when several entities need to do the same thing: consider a group. It automatically reflects the state of all members (the options below do not).
  2. If you want multiple entities to go to specific states that are not exactly the same, consider a scene (I barely use them because they cannot contain conditionals, they activate when you edit them and they do not show if they are active).
  3. If you have a sequence of statements that you want to be able to run when you ask it to, use a script.
  4. When you want to react to something happening and then do something, use an automation (I have automations that call scrips, because I use each script in several ways).

The last three cannot tell if the entities involved are in the state you want them. That is why the advice above is to create another entity that shows if it is active. For a group that is done by the group. For the others, it takes some work. It is quite easy to see when you activate the button, but it is much harder to tell if something changed so it should turn off. So setting the color to inactive always is not bad advise. Is is the easiest solution besides the group.

1 Like

Thank you all for the suggestions, Edwin, thank you for the simplest solution and for the tips.
Get that there are probably many ways to solve the same task as other suggested but this one is (now) obvious, logical and simple.
I have created a Switch group of all the power outlets and just toggle it with the button as other entities while yellow light respond accordingly to the state.
Thanks again everyone.

1 Like