Change color of a button while automation is running

Hi Everyone (& please forgive my English),
I do have a buton on my dashboard that is supposed (at least that’s what I try to achieve) to change color while the automation (garden sprinkler for 15 mn) is running. The automation in itself is running fine, but the color never change on the button.
I’ve read a lot of different post, tried with different method including the custom button card, but I’m not able to make it work. >Htere has to be something quite obvious that I m not getting.
If some might enlight me there, I ll more than thanks full :slight_smile:
my automation is

alias: Arrosage_15_mn
description: lance l arrosage automatique pendant 15 mn
trigger: []
condition: []
action:
  - if:
      - condition: device
        type: is_off
        device_id: e5196d2aca238fc0f383efc3af3effcb
        entity_id: 98dc579b33fd39717d73d311c419346e
        domain: switch
    then:
      - type: turn_on
        device_id: e5196d2aca238fc0f383efc3af3effcb
        entity_id: 98dc579b33fd39717d73d311c419346e
        domain: switch
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
          milliseconds: 0
      - type: turn_off
        device_id: e5196d2aca238fc0f383efc3af3effcb
        entity_id: 98dc579b33fd39717d73d311c419346e
        domain: switch
mode: single

and my button is:

type: button
name: Arrosage 15 mn
icon: mdi:sprinkler-variant
entity: automation.arrosage_15_mn
show_state: true
state_color: true
tap_action:
  action: call-service
  service: automation.trigger
  service_data:
    entity_id: automation.arrosage_15_mn

thanks for your time,
Laurent

Whether it is running or not, an automation’s state is always ‘on’ if it is enabled. So you can’t use the automation as the entity for the button card if you want the state color of the button to change.

You have a couple options… Set up a template sensor based on the value of the automation’s current attribute or use one of the custom cards like Mushroom Cards or Custom Button card that allows the use of templates.

Thanks a lot! I LL try that tomorrow !

You should do things the other way around.

You have no trigger in your automation. That makes it just a script, so use a script. Call that script from your button. While the script is running the button will be “on”.

You can then call that same script from an automation too.

1 Like

Hi Pieter, thank you so much for your answer.
That’s a good point. I was able to make it work as suggested by Drew, so I won’t touch it anymore, but I ll keep your remark in my head for my next automation/script.
I’m not that handy with HA, to my sadness, but I ll keep on learning as much as I can !
Thanks again,
Laurent

1 Like