Reverse the reported state of a switch in HA?


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,


You can create a template switch to do that.


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

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.

  - platform: template
        friendly_name: "Irrigation Valve tpl"
        value_template: "{{ is_state('switch.irrigation_main_314', 'off') }}"
          service: switch.turn_off
            entity_id: switch.irrigation_main_314
          service: switch.turn_on
            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
  action: call-service
  service: switch.toggle
    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";
    - left: 0%
    - top: 5%
    - position: center
    - height: 170px
    - left: 33%
    - top: 83%
    - position: center
type: custom:button-card
  - value: 'off'
    color: rgb(50, 255, 50)
    icon: mdi:solar-power-variant
  - value: 'on'
    color: rgb(54, 95, 140)
    icon: mdi:solar-power-variant