Would like to change Button Icon (3 possibilities) based on Binary Sensor Inputs

I am a zero new guy to YAML
I would like to change the Button Icon (3 possibilities) based on Binary Sensor Inputs:
Can you please help me put these two pieces of code together

CURRENT BUTTON

show_name: true
show_icon: true
type: button
tap_action:
  action: toggle
entity: switch.shellyplus1_441793a3c398_switch_0
name: Door 1
show_state: false
icon: mdi:garage-variant

WOULD LIKE TO ICON TO CHANGE BASED ON FOLLOWING SENSOR LOGIC

    {% if is_state('binary_sensor.shellyplusi4_d4d4da7e242c_input_0_input','on') %}
    mdi:garage-variant
    {% elif is_state('binary_sensor.shellyplusi4_d4d4da7e242c_input_1_input','on') %}
    mdi:garage-open-variant
    {% else %}
    mdi:garage-alert-variant
    {% endif %}

You have a button with an associated switch which has TWO states.
And you need to show THREE icons dependingly on 2 binary sensors.
Is there any connection between these switch & sensors?

Use a Mushroom template entity.

THANK YOU FOR HELPING OUT!Its the old garage door thing. The button is auto-shutoff in the shelly hardware (so i don’t treat it as a momentary in HA). The momentary switch cycles through 3 states (open->stop->close). The Door can be closed, in-between or open; hence the 3 icons. One binary sensor shows full closed or other, the second binary shows full open or other. Too add a bit more: say the door is stopped at 1/2 open, i want my alert icon to show. Now I hit the button again, door starts moving (could be up or down {simply the opposite direction before it stopped [either by hitting a limit switch (which will trip a binary) or hitting the HA button]}. Anyway we left off in the example door was stopped 1/2 open, icon shows alert anytime its not fully open or fully closed, hit the HA button, door starts moving. HA will still show alert until the door stops fully open or fully closed.
This logic also allows HA to track the door when someone uses the hardwired buttons.

I have not seen this integration for garage doors and it makes sense to me. I use binary inputs tied to my physical limit switches (3 states; but you don’t actually know for several seconds if the door is moving or stopped;; which I can live with).

Sorry for long explanation.

I have 8 doors, so keeping track of all of them would be great!

Thanks for feedback! I will research a Mushroom template entity. till your reply, I hadn’t heard of it.

The best way to do this would be to create template cover.

There are action sequences for open, close and stop, you can use the same button push for all three.

Do you also have a binary sensor to indicate if the door is open and/or closed?

Share the entity ids for the sensor and the button and I can help you.

Thank you! BTW, I was just reading about templates when you answered me.

From my code above:

The button is ‘switch.shellyplus1_441793a3c398_switch_0’ it uses the auto-turnoff feature in shelly after 30s

The door closed sensor is ‘binary_sensor.shellyplusi4_d4d4da7e242c_input_0_input’
The door open sensor is ‘binary_sensor.shellyplusi4_d4d4da7e242c_input_1_input’

The 3 possibility would be not open and not closed.

I got a mushroom-template version working (below) but would still like to learn how to do it without mushroom.

Hi Neil,

I got the following working as desired, but would still like to learn how to do it without mushroom.
THANK YOU

type: custom:mushroom-template-card
primary: West-South
secondary: Garage Door
icon: >-
  {% if is_state('binary_sensor.shellyplusi4_d4d4da7e242c_input_0_input','on')
  %}
    mdi:garage-variant
  {% elif is_state('binary_sensor.shellyplusi4_d4d4da7e242c_input_1_input','on')
  %}
    mdi:garage-open-variant
  {% else %}
    mdi:garage-alert-variant
  {% endif %}
icon_color: |-
  {% if is_state('switch.shellyplus1_441793a3c398_switch_0', 'on') -%}
    (0,150,0)
  {%- else -%}
    blue
  {%- endif %}
tap_action:
  action: toggle
entity: switch.shellyplus1_441793a3c398_switch_0
card_mod:
  style: |
    :host {
      --mush-icon-symbol-size: 0.75em;
    }

Hi, welcome to the forum!

Have a look at the custom:config-template-card as an alternative to the mushroom card.

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: "{{ states('sensor.garage_state') }}"
        open_cover:
          service: switch.turn_on
          target:
            entity_id: switch.shellyplus1_441793a3c398_switch_0
        close_cover:
          service: switch.turn_on
          target:
            entity_id: switch.shellyplus1_441793a3c398_switch_0
        stop_cover:
          service: switch.turn_on
          target:
            entity_id: switch.shellyplus1_441793a3c398_switch_0

For the new state sensor create this triggered template sensor in configuration.yaml:

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.shellyplusi4_d4d4da7e242c_input_0_input
        from: 'off'
        to: 'on'
        id: 'closed'
      - platform: state
        entity_id: binary_sensor.shellyplusi4_d4d4da7e242c_input_0_input
        from: 'on'
        to: 'off'
        id: 'opening'
      - platform: state
        entity_id: binary_sensor.shellyplusi4_d4d4da7e242c_input_1_input
        from: 'off'
        to: 'on'
        id: 'open'
      - platform: state
        entity_id: binary_sensor.shellyplusi4_d4d4da7e242c_input_1_input
        from: 'on'
        to: 'off'
        id: 'closing'
   sensor:
     - name: "Garage State"
       state: "{{ trigger.id }}"

You should then have a new entity called cover.garage_door that has changing icons and buttons to allow you to open close and stop the door.

You will need to manually open or close the door once first to get an initial state for the sensor. After that it should keep track of its state.

3 Likes