Get Garage door/windows shutter position in Home Assistant

Hi Guys,

I have been a Home Assistant user for several years and would like to solve a problem that has been nagging at me forever.

In my house I have a home automation system that can control lights, shutters and the garage door. The latter two are three-position switches that work in a loop:

  • opening
  • stop
  • closing

Since I do not know the status of the device in Home Assistant I am unable to create useful automations because I often open the gate when I should close it and vice versa.

I wanted to ask the community if there is a solution by creating some helper that keeps track of the positions or through additional devices (I would prefer the first solution).

It should be borne in mind that these objects can also be triggered by classic wall switches.

Thank you very much for the support, I hope to solve it.

Happy holidays and Merry Christmas,
Alessandro

If you don’t know the status how do you control the shutters? Is the switch smart? Do you have a switch state?

I connected a Shelly 2.5 to my regular shutter switches. Based on the time it goes up or down it can calculate the position. You could probably achieve the same with the state of the switch and some helpers, automations and a cover template.

If you just need an open or close state you could use a contact sensor.

Hi FPro,
my domotic system if from 2008 :slight_smile: So if was designed to control shutters and garage doors from a simple wall button (and remote controller, just the garage). One click to close, one to stop, one to open (in loop sequence).
So when I connect it to HA I can do the same but I always have to check visually the status. Not so smart.

I recently saw this video (https://www.youtube.com/watch?v=SxEHslRKqrw) to restore light status and I was wondering if there is a way to do something similar.

The old system doesn’t provide any status for shutters and garage doors.

I still don’t understand what kind of information you have and how you control it from home assistant. Is there a switch entity? Does it have a state?

There is two ways to handle states,detected state and assumed state.
Detected state needs a detector, like a sensor.
Assumed state require an ability to catch all the control commands.
Detected state is often using assumed state to improve response times, like when you request a light bulb to be turned on, then the integration set the state to on based on assumed state and then a little later set the state to, hopefully, turned on again based on detected state.
Detected state is clearly the best one, because assumed state is very error prone. A missed catch of a command and the state is wrong and command not accepted, but still catched will also make the state wrong.

You seem to have no options for a detected state in your current case, so assumed state would be needed in some way or the other.
The garage door can probably easily be fitted with some door/window sensors to detect some states, like one for completely open and completely closed, but two sensors next to each other can also be used to detect opening and closing states.

With assumed state you need to catch all commands, so you will not be able to use remotes or buttons that can not be detected by HA.
Assumed state require a helper to store the assumed state. It could be a number helper with 0 for closing, 1 for stop and 2 for opening.

You need to set the state on each catched command.
You would probably also need to be able to reset the state. One way is to allow extra commands of the same kind, like an opening command following an opening command.
Another way is when an opening command is running longer than it takes to go from completely closed to completely open, then you can assume that the state would be stop.

Thank you so much for you response. I’m trying to solve this problem in a smart and actionable way.
This is my ideato to solve the garage door problem:

Sensors set-up:

Option 1:
Use a NodeMCU board with two limit switches to know the full close and full open position. I gonna solve the intermediate state with the following automation.

Option 2:
Use the same board with a IMU sensor (like the MPU6050) to get the x/y axis rotation variation to know the full open and full close position. The apply the same automation for the intermediate state.

The Automation:

  • trigger the door switch to activate a random open/close action
  • then wait n seconds to leave the door to arrive to the full open/close position
  • then read the position (through the limit switches or the axis variation)
  • if the position is correct the automation is ended
  • if the position is opposite to my request, trigger again the action open/close to finally arrive to my desired position.

Of couse this automation is triggered only when full close/full open position is not detected at the beginning. In this case I know that one trigger action will open/close the garage door directly.

What do you think about? Make it sense?

UPDATE:

I’m testing the Option 1 if someone can help me

Have you considered using the ratdgo board?

It’s meant for garage door openers manufactured by Chamberlain/Liftmaster but it also supports the use of wired contact sensors to detect the door’s position (open/closed).

Thank you for the link but I think is overcomplicated for my solution.
With my way I can easily know when the door is full open o full closed. Then I just need to manage the unknown position in the middle. I don’t care to know the open percentage.

Simple in logic and in words but for me hard to set-up the code.

I already have a full_close sensor and a full_open sensor. Do you suggest me to run an automation? The goal is, as in the open post, to update the garage entity status.

In that case, you should consider using the Template Cover integration to model the operation of your door.

You will need to create a template for value_template that uses the state of your limit switches to accurately report if the door is open or closed.

Given that you can only toggle the door’s state (meaning you have only one command capable of opening/closing the door), the close_cover and open_cover options will both call the same command

How shoud i setup the sensors in the ESPhome yaml?

They are not switches…

My familiarity with ESPHome is very limited; someone else will need to help you with that.

I had a script to send explicit open/close commands to, the script would retry until it got the desired status. At the time the doors would occasionally hang, so default retries are high.

Worked well, but the hanging problem was actually the openers beginning to fail. I have since moved to all Chamberlain with ratgdo.

Not my best work, but like most of my HA, once it is good enough I move on. Not much sense in trying to optimize.

alias: Garage - Move Door
fields:
  door:
    description: his or hers
    example: hers
  action:
    description: open or close
    example: close
  timeout:
    description: seconds to wait before retry
    example: 15
variables:
  max_tries: 8
  default_timeout: 18
  default_action: close
  l_action: "{{ action if (action == 'open' or action == 'close') else default_action }}"
  l_timeout: "{{ timeout if (timeout is number) else default_timeout }}"
  target_status: "{{ 'open' if l_action == 'open' else 'closed' }}"
sequence:
  - repeat:
      until:
        - condition: template
          value_template: >-
            {{ is_state('cover.garage_door_' + door, target_status) or
            repeat.index > max_tries }}
      sequence:
        - if:
            - condition: template
              value_template: "{{ is_state('cover.garage_door_' + door, target_status) }}"
          then:
            - stop: door is {{ target_status }}
        - variables:
            y_current: >-
              {{ states.sensor['vibration_garage_' + door +
              '_angle_y'].last_changed }}
            z_current: >-
              {{ states.sensor['vibration_garage_' + door +
              '_angle_z'].last_changed }}
        - if:
            - condition: template
              value_template: "{{ l_action == 'close' }}"
          then:
            - service: cover.close_cover
              data: {}
              target:
                entity_id: cover.garage_door_{{ door }}
          else:
            - service: cover.open_cover
              data: {}
              target:
                entity_id: cover.garage_door_{{ door }}
        - wait_template: >-
            {{ as_timestamp(states.sensor['vibration_garage_' + door +
            '_angle_y'].last_changed) != as_timestamp(y_current) or
            as_timestamp(states.sensor['vibration_garage_' + door +
            '_angle_z'].last_changed) != as_timestamp(z_current) }}
          continue_on_timeout: true
          timeout: "{{ l_timeout }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 250
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 250
  - if:
      - condition: template
        value_template: "{{ is_state('cover.garage_door_' + door, target_status) }}"
    then:
      - service: notify.persistent_notification
        data:
          message: Door {{ door }} successfully {{ target_status }}
        enabled: false
  - if:
      - condition: template
        value_template: "{{ not is_state('cover.garage_door_' + door, target_status) }}"
    then:
      - service: notify.persistent_notification
        data:
          message: Door {{ door }} FAILED to {{ action }}
        enabled: true
mode: parallel
max: 10

Did you mean to reply to al31c0 instead of me? I’m not the one attempting to control their garage door.

Yeah. Hopefully @al31c0 sees it.

Guys I’m testing with success this automation but I’m looking forward to do solve in a smarter way:

alias: Test 05/01/2024
description: ""
trigger:
  - platform: device
    type: turned_on
    device_id: eece9e46761e9d1dd03b767f24ae95ce
    entity_id: 77db126746e511e81d28b9afdca69d12
    domain: light
condition: []
action:
  - if:
      - condition: state
        entity_id: binary_sensor.full_close
        state: "on"
    then:
      - device_id: 73b147c76b74494780cfc43252097639
        domain: cover
        entity_id: b9538a7ed11b13214fa4fb2253b8e1c7
        type: open
  - if:
      - condition: state
        entity_id: binary_sensor.full_open
        state: "on"
    then:
      - service: notify.mobile_app_iphone_di_alessandro14
        data:
          message: é già aperta
      - stop: È già aperta
  - if:
      - condition: state
        entity_id: binary_sensor.full_close
        state: "off"
      - condition: state
        entity_id: binary_sensor.full_open
        state: "off"
    then:
      - device_id: 73b147c76b74494780cfc43252097639
        domain: cover
        entity_id: b9538a7ed11b13214fa4fb2253b8e1c7
        type: open
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
      - if:
          - condition: state
            entity_id: binary_sensor.full_close
            state: "on"
        then:
          - device_id: 73b147c76b74494780cfc43252097639
            domain: cover
            entity_id: b9538a7ed11b13214fa4fb2253b8e1c7
            type: open
      - if:
          - condition: state
            entity_id: binary_sensor.full_open
            state: "on"
        then:
          - service: notify.mobile_app_iphone_di_alessandro14
            data:
              message: si è già aperta
          - stop: ""
mode: single

My garage door use a simple button to open/stop/close (in loop). The same happen with the radio controller.

So I don’t think I can send explicit open/close commands unless I send multiple commands in series. is that how you solved it?

But please tell me more about the RatDo.

Do you suggest me to implement it too?

The script was used for genie openers. I used the cover open/close commands in the script, but in reality both just act as a toggle like yours.

For Liftmaster/Chamberlain Security+ 2.0 openers ratgdo offers more functionality than anything else available - distinct open and close, light control, obstruction status, remote lock control, and wall panel motion sensor support - all with a simple three wire hookup.

For other openers, it offers no real advantage to your relay/sensor approach other than consolidating the sensor connections and relay into a pre-made esp board with pre-compiled firmware.

Since you apparently already have the hardware needed, I wouldn’t recommend changing.

Ok thank you for the advice. I will study the solution but for now I think I’ll stay with mine that works good