#Button that fires different scenes based on input_boolean state

1 messages · Page 1 of 1 (latest)

solemn hearth
#

I have a button which fires a scene. When the scene fires an automation also gets triggered that toggles an input_boolean to ON. This also updates the button's looks so that it shows the scene is "active".

I have another scene with everything off and would like it to fire when the button is tapped during its "ON" state (aka when the input_boolean is on). Could I go about this with a switch of some sorts?

Here's my current code:

          tap_action:
            action: call-service
            service: scene.turn_on
            service_data:
              entity_id: scene.shower
          icon: mdi:shower-head
          show_name: false
          styles:
            card:
              [irrelevant styling here]
              - background-color: >
                  [[[
                    return states['input_boolean.scene_shower_activity'].state == 'on' ? '#6cd7ff' : '#366d74';
                  ]]]
            icon:
              - color: >
                  [[[
                    return states['input_boolean.scene_shower_activity'].state == 'on' ? 'black' : '#25364f';
                  ]]]
          show_name: false```

Many thanks
void fjord
#

You can put a template in the service call to change the scene it calls based on your boolean.
i.e. Entity_id: if boolean? "scene.shower" : "scene.shower_off"

robust belfry
#

To expand on hilburn's post, I have this as one of my exmaples. yaml type: custom:button-card template: generic_custom_button entity: light.living_room_lights show_label: true label: '[[[ return variables.var_service ]]]' variables: var_service: > [[[ if (states['input_boolean.tester'].state == 'on') return 'call-service'; else return 'none' ]]] tap_action: action: '[[[ return variables.var_service ]]]' service: light.toggle target: entity_id: light.living_room_lights This example looks at the input_boolean.tester. When it is on, the variable var_service will return call-service, otherwise it will be none. You could incorporate this concept for the service or entities.

#

FYI, the custom:button-card is one of the only cards that I've noticed that has the ability to use templates like this.

void fjord
#

Thanks for providing an example, am on my phone on a bus so it's a struggle to write code!

solemn hearth
#

I'll give it a go and send some feedback soon - thanks!

robust belfry
#

If you're curious of using hilburn's syntax for the IF statement, I have an example written up on my GitHub but I've added it here, too.
Using conditional (ternary) operators

(condition) ? return_if_true : return_if_false
``````yaml
type: custom:button-card
name: "[[[ return (states['light.living_room_lights"].state == 'on') ? 'It's on' : 'It's off' ]]]"```
void fjord
robust belfry
#

Good point. I completely overlooked the styling. 😆 And the docs use ternary conditions in the examples.
But, now that I'm looking at it, a lot of that styling could be contained in the state: section (on/off/unknown/etc) if the entity is defined as the input_boolean. It would make the card easier to read.
State
From the examples at the bottom of the page: ```yaml
state:

  • value: 'on'
    styles:
    label:
    - color: red
  • value: 'off'
    styles:
    label:
    - color: green
void fjord
#

Man I love button cards