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.
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 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.
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.
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
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
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.