I have a garage door that I’m controlling with a Shelly 1. Meaning I have a switch I toggle for half a second to open or close the garage and a binary_sensor for a reed switch that tells me if the garage is closed or not.
What I’m trying to do is “fake” the opening and closing states of my cover based on the time elapsed since the binary_sensor or switch state changed. My garage opens and closes in about 21 seconds.
I have confirmed the value_template is working fine using the template page in the Home Assistant UI (including when opening and closing). The b_ts is the time elapsed since the switch was triggered and the s_ts the time elapsed since the sensor changed state.
However I have two issues:
When closing the garage the state immediately goes to closed. I have no idea why this happens. While closing, if I evaluate the value_template using the Home Assistant UI it correctly reports closing.
The reed switch is definitely not closed when this happens.
When opening it takes a full minute change from opening to open. This is expected because the value_template depends on now() which makes it update every minute. I attempted to force a re-evaluation using the toggle_garage_door script by adding a step that updates the cover after 23 seconds:
Thanks for that. It’s not exactly what I was looking for but it lead me to go look at the code for the cover template in GitHub and apparently it doesn’t actually support closing or opening states. Those are valid states, but they are ignored!
It doesn’t even implement the is_opening and is_closing properties described in the cover entity.
I believe I could create my own version of the cover that does that. This would explain issue number 1.
Would love to know how to get around issue number 2. Perhaps I can use one of those time-based cover custom components as inspiration to update the state after a set of time.
One additional consideration: Some garage door automation equipment includes either a magnetic switch or a tilt sensor that indicates whether the door is open or closed. This provides an addition check in case the door doesn’t complete the action. (For example, if something triggers the sensors at the bottom of the door that indicate an obstruction and the door stops closing and re-opens.)
If you have something like that, you can use those to set the open and closed states and set the opening and closing states initially using the garage door sensor only. You can remove the timer completely.
@qoheleth my garage motor does stop if it senses any blockage while running, but I don’t think there’s any way for me to get at that data. At least based on the pins I can connect to.
@Hellis81 that could work yes, it has crossed my mind. I want to try a cleaner approach first.
So far I have created my own custom component based on the Cover Template and augmented that to support closing and opening states. That seems to be working.
Only thing left is have it refresh automatically after a configurable set of time. So when state changes to opening or closing I’ll set a timer to update the entity state.
I’ve only recent started using Home Assistant so I’m not entirely sure how these custom components work (nor am I that experienced in Python…). I’ll try to find another component that does something similar (with a timer) and base it off that.
I run into a similar issue a year ago. I also wanted to use the cover in HomeKit, but turns out the HA cover component, as you said, did not support opening and closing states, only open and closed. I wonder if your implementation, when used with HA HomeKit controller, gives HomeKit opening and closing values. My goal is to implement a fully working HomeKit garage cover integration with a Shelly 2.5 and 2 reeds (or 2 Shelly 1 and 2 reeds) like it’s done with this firmware or via MQTT. This is the one I’m using now and it works great. Two reeds give you real open and closed status and can also give HomeKit a jammed alert if the door does not close in more than X seconds. Let me know what you think.
I think you’d have to make a few changes. IIRC my code assumes 1 reed that’s active for the closed position, and “opening” state is “faked” with a timer (configurable).
So to take advantage of the two reeds there would have to be some changes. You would not need a timer in this case.
Hey man, thanks for the script!! I’d like to use the same setup as yours, I uploaded your custom cover to homeassistant, and used your same config. Still it closes after n° seconds, but when opening it remains “in opening state”.
I tried to create a binary sensor with default close value but still, no luck:
Thanks to @pfandrade for the piece of code, it’s working for my Shelly 1 with one reed switch to get away from MyQ.
For the case of opening to open not occurring immediately, I added this automation:
- id: change_garage_door_state
alias: Change Garage Door State
trigger:
- platform: state
entity_id: cover.garage_door
to: 'opening'
action:
- delay: '00:00:13'
- service: homeassistant.update_entity
entity_id:
- cover.garage_door