you lost me there, Im not quite sure what the 2 switches are for and why the gpios are different. This may be specific to how the switching is done inside a Shelly, I didn’t realize that was the hardware you were using.
what are you using for reed switches? are they wired back to the shelly?
Yes… two of these Security Alarm Reed Switch - Double Throw | Jaycar Electronics. Have them wired normally open.
I assumed (still do) that the two reed switches must be wired to different pins or how does esphome know which one is giving the open and which one the closed signal?
yes they need to be wired to seperate pins, I’m just looking at your notes and you have notes to ground to “L” and the other not ground to “L”. The two switches I was talking about was in your gpio and output switches.
I’m sorry Justin… I’m confused now… I suspect I’m missing something obvious but not sure exactly what your question is.
At the risk of further missing the point… my notes are to remind me not to blow up my device… as I did with an earlier attempt when I connected the wrong DC voltage. One of the reed switches is wired on the same side as the Shelly’s main terminals. The L terminal is shared with the 24 V power supply in my case. And the other wire from the reed switch goes to the SW terminal (which is also GPIO 5). The other reed switch is wired to the standard GPIO pins… they’re tiny and impractical on the Shelly Plus 1 so I now use the older but still functional Shelly 1 which has standard sized pins.
Edit… but on rereading the few comments above… I now realise that maybe you didn’t even have a question… were just commenting.
thats what I was trying to figure out.
I finally have this working. The buttons in the cover aren’t greyed out, but they only work when it’s appropriate. Have also added a notification in case the door is left partially open or closed… after someone uses the original wired button.
It’s a bit hacked together… can no doubt be improved.
# the globals and related conditions prevent the cover getting out of sync with the door's actions
# notification is in case the original wired button is used
# but probably will be better to add open and close movement binary sensors
esphome:
name: "gdo-s1"
platform: ESP8266
board: esp01_1m
logger:
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "gdo-s1"
password: "#######"
captive_portal:
globals:
- id: global_last_direction
type: int
restore_value: yes
initial_value: '99'
# 1=opened, 2=closed, 99=initial value
- id: global_last_operation
type: int
restore_value: yes
initial_value: '0'
# 1= previous operation was opening, 2=closing, 0=idle
switch:
- platform: gpio
pin: GPIO4
id: relay
name: "Relay"
binary_sensor:
# reedswitch_1 to the SW (GPIO5) terminal and grounded to L
# reedswitch_2 is to GPIO3 and ensure it is grounded using the small GND pin nearby (NOT to L)
- platform: gpio
name: "Reed Switch 1"
id: reedswitch_1
pin: GPIO5
filters:
- delayed_on_off: 500ms
on_release:
then:
- logger.log: "** CLOSE ENDSTOP WENT OFF **** WAITING FOR AN ENDSTOP TO GO ON "
- delay: 35s
- logger.log:
format: "SSSSSSSSS 35 seconds passed SSSSSSSSSSSSSSSS"
- if:
condition:
and:
- binary_sensor.is_off: reedswitch_2
- binary_sensor.is_off: reedswitch_1
then:
- logger.log: "******** ROLLER DOOR PROBLEM? ***** NEITHER ENDSTOP IS ON"
- homeassistant.service:
service: notify.my_notification_group
data:
message: Roller Door Problem. May be partially open/closed!
- platform: gpio
name: "Reed Switch 2"
id: reedswitch_2
pin:
number: GPIO3
inverted: yes
mode:
input: true
pullup: true
filters:
- delayed_on_off: 500ms
on_release:
then:
- logger.log: "* OPEN ENDSTOP WENT OFF ** WAITING FOR AN ENDSTOP TO GO ON *****"
- delay: 35s
- logger.log:
format: "SSSSSSSSSSSSSS 35 seconds passed SSSSSSSSSSSSSSSSSSS"
- if:
condition:
and:
- binary_sensor.is_off: reedswitch_2
- binary_sensor.is_off: reedswitch_1
then:
- logger.log: "***** ROLLER DOOR PROBLEM? ************* NEITHER ENDSTOP IS ON"
- homeassistant.service:
service: notify.my_notification_group
data:
message: Roller Door Problem. May be partially open/closed!
# feedback cover for two reed switches
cover:
- platform: feedback
name: "Garage Roller Door"
id: garage_roller_door
has_built_in_endstop: true
max_duration: 40s
device_class: garage
open_action:
- if:
condition:
and:
- lambda: |-
return id(global_last_direction) != 1;
- lambda: |-
return id(global_last_operation) == 0;
then:
- switch.turn_on: relay
- delay: 0.5s
- switch.turn_off: relay
- lambda: |-
id(global_last_direction) = 1;
id(global_last_operation) = 1;
- logger.log: "*********** OPENING **************"
open_endstop: reedswitch_2
# open_sensor: open_movement_binary_sensor
open_duration: 27s
on_open:
- lambda: |-
id(global_last_direction) = 1;
id(global_last_operation) = 0;
- logger.log: "*********** OPENED **************"
close_action:
- if:
condition:
and:
- lambda: |-
return id(global_last_direction) != 2;
- lambda: |
return id(global_last_operation) == 0;
then:
- switch.turn_on: relay
- delay: 0.5s
- switch.turn_off: relay
- lambda: |-
id(global_last_direction) = 2;
id(global_last_operation) = 2;
- logger.log: "*********** CLOSING **************"
close_endstop: reedswitch_1
# close_sensor: close_movement_binary_sensor
close_duration: 22s
on_closed:
- lambda: |-
id(global_last_direction) = 2;
id(global_last_operation) = 0;
- logger.log: "*********** CLOSED **************"
stop_action:
- if:
condition:
lambda: |-
return id(global_last_operation) != 0;
then:
- switch.turn_on: relay
- delay: 0.5s
- switch.turn_off: relay
- lambda: |-
id(global_last_operation) = 0;
- logger.log: "*********** STOPPED **************"
# open_action:
# - switch.turn_on: relay
# - delay: 0.5s
# - switch.turn_off: relay
# open_endstop: reedswitch_2
# # open_sensor: open_movement_binary_sensor
# open_duration: 27s
# close_action:
# - switch.turn_on: relay
# - delay: 0.5s
# - switch.turn_off: relay
# close_endstop: reedswitch_1
# # close_sensor: close_movement_binary_sensor
# close_duration: 22s
# stop_action:
# - switch.turn_on: relay
# - delay: 0.5s
# - switch.turn_off: relay
i’m confused why you have one sensor inverted and not the other?
tbh, I can’t tell you. I copied it from someone else who was using the Shelly 1 with two reed switches. I wondered the same thing myself… guessed it had to do with the GPIO pins being wired differently to the connections on the other side. I was going to do some reading to understand it better but the relays worked just as expected and continue to do so reliably. Perhaps it’s another redundant aspect of my shabby coding. If I get time, I’ll try it without the pin inverted… though iirc, it didn’t work when I tried that early on in my journey.
I’ve never been more frustrated with anything like this cover is making me. everytime I try to get position control the states dont update right. The one I have now though it works and the correct button is greyed out though. It shows the up and down position in the logs as its moving but im not sure how to get that data and use it.
My latest addition of conditions has prevented buttons being active when they shouldn’t be - but not greyed out. Am currently working on adding open and closing movement sensors - maybe that will do the trick!
I’m lucky enough not to be frustrated… the feedback cover worked pretty well in the first place and more so since I added the two reed switches. For me it’s a puzzle to sort out and I’ve learnt heaps about esphome and covers in the process.
lol I understand that. I ordered some rotary encoders the other day so once those come I hope to put this project in the “done” pile and move on to the next one, they’re piling up faster than I can do them but, thats a good problem to have.
Please let me know if the rotary encoders do the trick… I’ve repurposed a time of flight distance sensor for my opener. But its range is too short so it only senses opening or closing states for half of the door’s journey
Hello
I am looking at using the Feedback Cover with a Rotary encoder and I stumbled onto this thread.
I have the encoder working with this code and if gives me a nice incrementing count that will go up and down with motor direction.
But its not clear to me from the docs how I hook this into the cover feedback. I feel like I want to pass that count value to the cover but none of the config variables would seem to take it. I dont want to pass it into a binary sensor and lose the position information.
sensor:
- platform: rotary_encoder
name: "Rotary Encoder"
pin_a: GPIO36
pin_b: GPIO39
pin_reset:
number: GPIO34
mode: input
As I understand it, from the documentation, the feedback cover only gets its position from its open and close durations.
It’s not clear? It sais right at the top that the feedback cover doesn’t support tilt control. It supports open, stop, close, toggle and position is based on time.
Look through this, someone else got that working. It was the second Google search result when I typed “esphome rotary encoder covet” FYI.
Yes, I saw post too.
He is using template cover not feedback cover, and that has been my approach too.