Hi all,
A few years back i cobbled together a garage door opener for my mother.
I used a sparkfun thething esp 8266 with a relay attached to it.
I want to be able to open the garage door with Siri (homekit) and via a push button in the garage itself.
The push button works great, however siri sometimes can’t find the esp 8266 or the connection is lost or whatever. The point is that sometimes the “remote” opening isn’t optimal. Also, i am having problems with actually being able to open the garage door with the hardware button in case i don’t have a connection to the wifi.
I guess that wifi reconnect code isn’t that optimal so all the cpu time goes there iso to detect the HW button state.
Anyway, time to get rid of all the hassle.
Now recently i discovered home assistant and ESPHome so i wanted to give that a try. I think this would provide a much more stable platform and i don’t have to re-invent the wheel again with my custom code.
Also, i want to get rid of that MQTT server if possible.
However, for some reason it is a complete mistery on which components i actually need to use to make it work.
I have 3 pins that i use to control the entire setup.
// PINS
#define RELAY_TRIGGER_PIN 12
#define SENSOR_GARAGE_CLOSED_PIN 4
#define BUTTON_PIN 13
// Timings
#define RELAY_TRIGGER_DELAY 300
This is what i currently came up with for ESPHome
binary_sensor:
- platform: gpio
device_class: garage_door
pin:
number: 4
mode: INPUT_PULLUP
inverted: false
name: Garage poort sensor
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_press:
- switch.turn_on: garage_relay
switch:
- platform: gpio
pin: 12
name: Garage Knop
id: garage_relay
icon: "mdi:gate"
on_turn_on:
- delay: 500ms
- switch.turn_off: garage_relay
If possible, i want the software button and the state to be combined in 1 component like it would be in homekit.
I am not even sure which components i actually need to use to make the hardware button work.
I don’t really want to display the hardware button in home assistant since there isn’t really any point to do so.
Can anyone point me in the right direction to make that happen.
The hardware button is on pin 13 and this i how the button currently works.
void checkOpenGarageDoorButtonPressed() {
// read the state of the switch into a local variable:
int reading = digitalRead(BUTTON_PIN);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long enough
// since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
digitalWrite(LED_PIN, HIGH);
triggerRelay();
digitalWrite(LED_PIN, LOW);
}
}
}
// save the reading. Next time through the loop, it'll be the lastButtonState:
lastButtonState = reading;
}
2nd, pin 4 is used to determine if the garage is open or closed via a reed sensor.
Here is how that currently works.
void checkGarageDoorOpenIgnoreLastState() {
int closedState = 0;
closedState = digitalRead(SENSOR_GARAGE_CLOSED_PIN);
if (closedState == HIGH) {
digitalWrite(LED_PIN, HIGH);
client.publish("home/garage/door/status/open", "", false);
}
else {
digitalWrite(LED_PIN, LOW);
client.publish("home/garage/door/status/closed", "", false);
}
}
3rd, pin 12 is used to actually trigger the relay.
This is how it works atm
void triggerRelay() {
if (digitalRead(RELAY_TRIGGER_PIN) == LOW) {
digitalWrite(RELAY_TRIGGER_PIN, HIGH);
delay(RELAY_TRIGGER_DELAY);
digitalWrite(RELAY_TRIGGER_PIN, LOW);
}
}
Oh yeah, i must mention that i actually didn’t upload the yaml code i paste above, because it is kind of important that the garage door keeps working