custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.83k stars 227 forks source link

State-dependent actions #850

Open hilburn opened 1 month ago

hilburn commented 1 month ago

I have a button which I would like to call different services on tap_action depending on state.

Ideally the current action format could be implemented in the state list, along with color, icon, styles etc

Current;y I have implemented the following with templates for which service/targets to use:

tap_action:
  action: call-service
  service: >-
    [[[ if (variables.boost_on) return "schedule_state.clear_overrides"; else
    return "input_button.press" ]]]
  data: {}
  target:
    entity_id: >-
      [[[ if (variables.boost_on) return "sensor.heating_schedule"; else return
      "input_button.heating_boost" ]]]

Which works ok for the moment, but could see getting rather unwieldy with more than 2 states, or more difficult if e.g. wanting to target a label rather than an entity in one of the states

beringtom commented 2 weeks ago

2nd this! Using a toggle action on blinds with tilt needs a script or automation to trigger it,