Garage door sensor - convert binary sensor frequency into a state

Hello,

I successfully connected my garage door control unit RG1 24DL to home assistant with Shelly 1.
The problem is that the only signal I can use to detect whether garage is open is output for indicator light, which is off when door closed, on when door open, but flashing with 0.5Hz frequency if opening and with 1 Hz frequency if closing.

I would prefer opening and closing to be identified as separate state rather than fast/slow alternating open/closed state.

Is anybody able to point me in some easy way how to do it?

Thanks in advance.

You could create a history stats sensor to count the number of on-off transitions in a fixed time period and then use the state of that sensor to say if the state is opening or closing.

here is an example of what I came up with to sense a boolean that cycles on and off every second:

sensor:
  - platform: history_stats
    name: toggles
    entity_id: input_boolean.toggle_full_hertz
    state: "on"
    type: count
    start: "{{ as_timestamp(now()) - 3 }}"
    end: "{{ now() }}"

the state of the sensor will be 2 at 1 hz toggle.

you can use the same sensor for your .5 hz toggle and I think the state should be twice as much.

then use the state of the sensor in a template:

{% if states('sensor.toggles') | int == 2 %}
  closing
{% elif states('sensor.toggles') | int == 4 %}
  opening
{% elif states('sensor.toggles') | int == 0 and states('sensor.door') == 'on' %}
  open
{% else %}
  closed
{% endif %}

or something to that effect.

I haven’t fully tested it since I don’t have any entities that toggle at .5 hz but you should get the idea.

1 Like

. I personally don’t need info if door is opening or closing, just if it’s closed or not. So, I installed reed relay contact for closed position. Then you need a module with inputs (or make it -modify existing, if you know how) and you have binary indication when door is closed. Say, Shelly i4 - it has 4 inputs, so if you want you can install reed switch for open position also, that way you’ll also be able to “predict” which direction door is moving (if “open” switch toggles door is closing, if “closed” switchtoggles it’s opening).