I am controlling my garage door with a espeasy flashed esp8266 nodemcu board. I also have reed sensor to check if it is open or closed (no tilt/travel sensor) connected to same esp8266 board.
I currently check it’s state using node-red. Sometimes the status goes out of sync (because of wifi dropping mqtt packet etc). So in node-red I query espeasy’s status json to get latest state (open/close) before executing any action (when a new garage related mqtt message/command arrives)
Now I am migrating to HA. In HA I tried creating a ‘cover’ mqtt entity.However, I am not sure how to solve the out of sync problem.
Is it possible that whenever there is a mqtt message or any event triggered from HA, then HA calls the rest api and get updates correct status , and then continues the flow ?
I’ve D1 mini flashed with ESPHome and have two reed switches (top and bottom) on the garage door cover. This code has been working for me without any problems even after power outages.
#The substitution block has all the configurable details
substitutions:
name_of_board: garagecover
ip_address: !secret ip_address_garage_cover
api_password: !secret garage_cover_api_password
api_encryption_key: !secret garage_cover_api_encryption
ota_password: !secret garage_cover_ota
relay_time: 0.5s
############################################
#YOU SHOULD NOT NEED TO EDIT BELOW THIS LINE
############################################
esphome:
name: $name_of_board
platform: ESP8266
board: d1_mini
packages:
wifi_settings: !include common/basic_components.yaml
basics: !include common/basic_sensors.yaml
binary_sensor:
- platform: gpio
device_class: door
pin:
number: D1
mode: INPUT_PULLUP
name: ${name_of_board} Bottom Contact Sensor
id: contact_sensor_bottom
#internal: true
- platform: gpio
device_class: door
pin:
number: D2
mode: INPUT_PULLUP
name: ${name_of_board} Top Contact Sensor
id: contact_sensor_top
- platform: template
device_class: door
name: ${name_of_board} State
lambda: |-
if ( !(id(contact_sensor_bottom).state) and (id(contact_sensor_top).state)) {
return false;
} else {
return true;
}
switch:
- platform: gpio
pin: D5
name: ${name_of_board} Relay
id: relay
internal: true
cover:
- platform: template
device_class: garage
name: ${name_of_board}
icon: mdi:cover
id: template_cov
lambda: |-
if ( !(id(contact_sensor_bottom).state) and (id(contact_sensor_top).state)) {
return COVER_CLOSED ;
} else {
return COVER_OPEN;
}
open_action:
- switch.turn_on: relay
- delay: $relay_time
- switch.turn_off: relay
- logger.log: "Open Script is running"
close_action:
- switch.turn_on: relay
- delay: $relay_time
- switch.turn_off: relay
- logger.log: "Close Script is running"
stop_action:
- switch.turn_on: relay
- delay: $relay_time
- switch.turn_off: relay
- logger.log: "Current movement interrupted"