Counter switch on

Hello, could you help me with counter switch on?

          - if:
                lambda: |-
                  if (id(Relay_ON).state) {
                    return true;
                  } else {
                    return false;
                - switch.turn_on: relay_output
                # counter = counter + 1

It won’t be able to remember it’s count when it loses power.
You could count a counter inside HA via a service call from ESP-Home.
The problem is that if you restart HA and this counter wants to count while restarting then it will skip this count.

You could put a on_turn_on trigger on the relay that increments a global.

I believe the global will persist through reboots if you restore_value.

Ok, perfect.

1 Like