Reverse the reported state of a switch in HA?

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