Reverse the reported state of a switch in HA?

Hello,

I am new to HA and my goal is to reverse the reported state of my FortrezZ (WV-01) Water Valve within HA which shows up as a switch (in HA).

The WV-01 Valve is joined to my Vera Hub
I have the latest Vera Integration installed in HA.

The valve is recognized in HA as a switch as entityID “switch.house_main_314”.
HA will open and close the valve by toggling the switch toggle in HA, however the state shows as reversed.

Meaning when the valve is CLOSED HA shows the icon and switch toggle as ON, and when the valve is OPEN the icon and switch toggle show as OFF.

I would like is so when the valve is OPEN HA shows as ON, and when CLOSED HA shows as OFF.

Any pointers or examples of would be greatly appreciated.

HA is installed on a QNAP NAS Docker instance:
—-------------------------------------------
Version core-2022.4.7
Installation Type Home Assistant Container
Development false
Supervisor false
Docker true
User root
Virtual Environment false
Python Version 3.9.9
Operating System Family Linux
Operating System Version 5.10.60-qnap
CPU Architecture x86_64
Timezone America/New_York
---------------------————————————

Thank you in advance,

-bh

You can create a template switch to do that.

2 Likes

Thank you, this got me on the right track and got my head screwed on in how HAAS thinks in this situation and now others.

I found a post here that was helpful https://community.home-assistant.io/t/reverse-switch-toggle-state/35120

The template that I used to get my FortrezZ WV-01 showing as a Valve vs a Switch and reversing the state that was incorrectly being reported by HA is as follows:

I placed the below into the configuration.yaml. The HA entity ID for the valve in question is “switch.irrigation_main_314”

Note that this creates a new additional switch named ‘irrvalve’ in HA with a friendly name of “Irrigation Valve tpl”, meaning the actual entity is still present in HA but you will need to either hide it or not use it in your dashboard cards (I chose the latter) and use the new one that this template creates. I know this would be obvious to most, but it wasn’t for me thinking like an HA newbie.

For QNAP container station HA Docker users. Restarting HA from within the HA GUI doesn’t reload the configuration.yaml. Go into container station and restart the HA container there, I know that’s a bit hard core, but that’s what I found that works vs Configuration->Settings->Server Control->Restart Home Assistant in the HA GUI.

switch:
  - platform: template
    switches:
      irrvalve:
        friendly_name: "Irrigation Valve tpl"
        value_template: "{{ is_state('switch.irrigation_main_314', 'off') }}"
        turn_on:
          service: switch.turn_off
          data:
            entity_id: switch.irrigation_main_314
        turn_off:
          service: switch.turn_on
          data:
            entity_id: switch.irrigation_main_314
        icon_template: "{% if is_state('switch.irrigation_main_314', 'on') %}mdi:valve-open{% else %}mdi:valve-closed{% endif %}"
1 Like

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

1 Like