Using ESPhome to build a water flow rate meter

Ok, I have implemented the valve to my water line coming to the house. The only issue i have now, is to show it correctly in home assistant and getting it working correctly with ESPHOME.

I got only the toggle option working, but as i turn it on the toggle will switch to on and then off. But the valve is still close.

Any ideas? i tried the switch.turn.on option and the toggle in home assistant will do the same, but the relay will stay on. But as i click the toggle to turn off the relay, nothing happends to the relay and stays on.

switch:

  • platform: gpio
    pin: GPIO05 #D1
    id: relay
    restore_mode: ALWAYS_OFF

  • platform: template
    name: Water Valve Control
    icon: mdi:valve-closed
    turn_on_action:

    • switch.toggle: relay
      turn_off_action:
    • switch.toggle: relay