Contact Switch - Log how many times open

Hi Team.

I have a contact switch on the back of our dehumidifier. I use this contact switch as part of an automation to alert me when its full and then stop alerting when the water draw is opened where the contact switch.

What i would like to do is somehow capture how many times the contact switch is set to open. Is this possible at all?

You have to do a count on the state change of that contact switch.

Can you explain a little more please. Where i can set it up and i should be able to work it out.

You need to give me more info. Are you using any integrations, entities, devices or hubs, dongles, etc. It will deal with some scripting, so YAML will most likely be involved. Google HA and reading and counting a contact closure.

Assuming this switch is represented by a sensor in your HA setup…history_stats integration (see its docs)
Below counts for today…by fiddling with start/end you can create week/month/etc.

- platform: history_stats
    name: whatevernameyoulike
    entity_id: binary_sensor.YOURSENSORNAME
    state: "on"
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
1 Like