Reverse Switch Toggle State

Hello,

I’m new to HA.
I have a zwave garage door open connected to my vera unit.
It functions just like a switch.

When the Garage is closed, the icon shows closed, the toggle states shows off.
How can I make the toggle state show on instead. And show off when it’s opened?

I have it grouped in with my Door Locks.
So all of my Door Locks show locked and on.
So I want this to show closed and on.

Is that possible, if so how do I do it?

You can do this with a template switch, have a look at the docs. This may work:

switch:
  - platform: template
    switches:
      garage_inverted:
        friendly_name: Garage
        value_template: "{{ is_state('switch.garage_door', 'off') }}"
        turn_on:
          service: switch.turn_off
          data:
            entity_id: switch.garage_door
        turn_off:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door

You’ll need to replace switch.garage_door in the above example with the actual name of your current switch. And in your group, you will have to add the new switch switch.garage_inverted.

4 Likes

Hi marthocoo,

Thanks for the reply.
That worked, however, now my icons are flipped.
It now shows a yellow closed garage door.
I think I want it to show a blue (closed) garage door when it’s closed…
and a blue (opened) garage door when it’s open. (or if its possible, make the open garage door red?)

The way my locks work are, they are blue when locked and unlocked.
I’m ok with that, but I wonder if there is a way to change the unlocked color to red as well?

Cant you just change the value_template to on instead of off?

value_template: "{{ is_state('switch.garage_door', 'on') }}"

No; that’s what inverts the state of the switch.

You need to use an icon template:

switch:
  - platform: template
    switches:
      garage_inverted:
        friendly_name: Garage
        value_template: "{{ is_state('switch.garage_door', 'off') }}"
        turn_on:
          service: switch.turn_off
          data:
            entity_id: switch.garage_door
        turn_off:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door
        icon_template: "{% if is_state('switch.garage_door', 'on') %}mdi:garage{% else %}mdi:garage-open{% endif %}"

I’m on my phone at the moment so the syntax might be incorrect on that but it looks good to me.

3 Likes

Building off @marthocoo’s answer, here is what I used with my Insteon IOLinc (Garage Door Kit). The sensor and relay show up as 2 different entities. I hid my real entities from the UI via customization and replaced it with this switch on my dashboard:

switch:
  - platform: template
    switches:
      garage_door:
        friendly_name: Garage Door
        value_template: "{{ is_state('binary_sensor.garage_door_sensor', 'off') }}"
        turn_on:
          service: switch.turn_off
          data:
            entity_id: switch.garage_door_relay
        turn_off:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door_relay
        icon_template: "{% if is_state('binary_sensor.garage_door_sensor', 'on') %}mdi:garage{% else %}mdi:garage-open{% endif %}"
2 Likes

Here’s another idea

This is the code I use. In my case I use a Tuya valve turner to operate some DC isolators for a solar system where the isolators are in an inconvenient position behind a rain water tank.

Due to the location and rotation direction of the isolators, the switches end up showing the status reversed (ie off = isolators connected), here’s my solution.
Using this, you can change the wording on the card that is reported per state, the colours and the icons as well as the text positions etc.

It’s doesn’t modify the switch state anywhere except for display on the card, the card is actionable and set to toggle in my case.

You will need custom:button-card installed for this to work.

entity: switch.car_shed_solar_east_array
tap_action:
  action: call-service
  service: switch.toggle
  service_data:
    entity_id: switch.car_shed_solar_east_array
show_name: true
show_icon: true
show_state: false
show_label: true
name: Car Shed Solar East Array
size: 30%
label: |
  [[[
    if (states['switch.car_shed_solar_east_array'].state === "on")
      return "Isolated";
    else if (states['switch.car_shed_solar_east_array'].state === "off")
      return "Connected";
  ]]]                
styles:
  name:
    - left: 0%
    - top: 5%
    - position: center
  card:
    - height: 170px
  label:
    - left: 33%
    - top: 83%
    - position: center
type: custom:button-card
state:
  - value: 'off'
    color: rgb(50, 255, 50)
    icon: mdi:solar-power-variant
  - value: 'on'
    color: rgb(54, 95, 140)
    icon: mdi:solar-power-variant

image

hi i am new and sorry if my terms are not clear. Reverse works very well, but when the switch is passive, it only appears to be closed. Can’t we be passive?