Getting UI button to show open/closed instead of on/off

I have a Shelly1 connected to garage door to open/close it along with a reed switch to sense when opened. Making a lovelace page for my wife and trying to make it as simple as possible for her.

Problem is, is (switch.shelly_shsw_1_8caab5c4f403) is what activates the garage, but the reed switch (binary_sensor.shelly_shsw_1_8caab5c4f403_switch) is what determines if its opened/closed. Is there a way to have the button tied to the SWITCH , but have the state be tied to the BINARY_SENSOR?

So in the below picture, she would see the garage door as OFF, since the switch is off. But I want her to see the garage door as CLOSED, while still being able to press the button to OPEN it.

1 Like

You can change the binary_sensor displayed text by customizing the device_class:


As far as getting the button to activate the garage door switch and report the state, a custom button card works well for me. Something like this:

                    - type: 'custom:button-card'
                      entity: cover.garage_door
                      name: Garage Door
                      tap_action:
                        action: call-service
                        service: switch.turn_on
                        service_data:
                          entity_id: switch.garage_door_switch

cover.garage_door is my reed switch and switch.garage_door_switch is the switch that open/closes the door. The custom button card can also change the displayed text for each state without messing with the device class.

Why do i get error when trying to follow your code?

Have you installed the custom Button Card?

This line:

type: 'custom: button-card'

refers to a custom Lovelace card (i.e. not part of the standard library of cards). It must be installed before it can be used. For installation instructions, refer to the last link in rccoleman’s post.

I got the repository installed in HACS. I didnt have a ui-lovelace.yaml file. I created one, added in the code it said to, but still the custom card doesnt work

Are you using Lovelace in YAML mode? In other words, is your Lovelace dashboard defined in ui-lovelace.yaml?

If you are not, then you should add resources in Configuration > Lovelace Dashboards > Resources.

Tied my ‘dummy’ binary sensor to a ‘dummy’ switch, maybe usefull??

# Introduce a master key switch
input_boolean:
  master_switch:

switch:
  - platform: template
    switches:
      dummy:
        value_template: "{{ is_state('input_boolean.master_switch', 'on') }}"
        turn_on:
          - service: input_boolean.turn_on
        turn_off:
          - service: input_boolean.turn_off
        icon_template: >-
          {% if is_state('input_boolean.master_switch', 'on') %}
            mdi:toggle-switch
          {% else %}
            mdi:toggle-switch-off
          {% endif %}

( i use this dummy switch to prevent automation when i want to stop all automatipn & nodered :wink:)

@aceindy
Excuse my ignorance as I am still just a few weeks into Home Assistant. Where are you putting this code? In config.yaml? In the raw ui?

Configuration.yaml

# Introduce a master key switch
input_boolean:
  master_switch:

switch:
  - platform: template
    switches:
      dummy:
        value_template: "{{ is_state('input_boolean.master_switch', 'on') }}"
        turn_on:
          - service: input_boolean.turn_on
        turn_off:
          - service: input_boolean.turn_off
        icon_template: >-
          {% if is_state('input_boolean.master_switch', 'on') %}
            mdi:toggle-switch
          {% else %}
            mdi:toggle-switch-off
          {% endif %}

Basically this creates a binary input which you can operate by a switch on a lovelace card, where i can toggle it on/off:
image
ui-lovalace.yaml:

views:
  - title: MasterSwitch
    path: masterswitch
    cards:
      - type: entity-button
        entity: input_boolean.master_switch
        icon: 'mdi:key-variant'

PS: This switch on it self doesn’t do anything, I can use it to enable/disable other things (like f.e. certain logic in NodeRed)
But then again, this is just an example on how to link a switch to a binary input :wink: