Hardware
zwave garage door opener
esp device with sonar
Problem I am trying to solve:
zwave opener gets stuck on opening closing and unknown states which leads to automations not closing or opening garage.
Solution so far:
I installed an wemos d1 mini with sonar on the roof of my garage to detect garage open state (bonus I can tell if the car is in the garage).
with my zwave opener If the sensors are stuck in a state then the cover open close actions do not work but there is a switch entity that I can toggle and that will activate the opener.
once I got this working and updated my automations to use the sonar for garage door state detection and called the opener switch entity to togle for the action all is good.
Of course now I want to combine the zwave opener with the sonar sensor and I wanted to do it in esphome. I have somewhat succeded with much googling but I think it is a messy way of doing it.
cover:
- platform: template
name: "Garage Door 1e"
lambda: |-
if (id(garage_state).state == "Garage open") {
return COVER_OPEN;
} else if (id(garage_state).state == "Garage closed") {
return COVER_CLOSED;
} else {
return {};
}
open_action:
- homeassistant.service:
service: script.garage_door_1
close_action:
- homeassistant.service:
service: script_garage_door_1
this is from the esphome and makes a cover entity that looks great, but the open close actions will not call the script or a switch toggle in Home Assistant.
in developer tools this is the feedback I get.
event_type: call_service
data:
domain: cover
service: open_cover
service_data:
entity_id: cover.garage_door_1_sonar_garage_door_1e
origin: LOCAL
time_fired: "2024-12-14T18:11:28.397686+00:00"
context:
id: 01JF35WJGDB856TTAX6HRNQY3E
parent_id: null
user_id: 1b6d6068dab14f2d9429b8099c92abb0
It doesn’t matter what I put in the esphome code it just does this.
I got around this by using an automation with that service call as a trigger, this works but it seems a little convoluted and I was wondering if there was a neater/simpler way. preferably with the esphome device just calling the switch toggle no scripts or automations in home assistant.
for completeness here is the esphome config
binary_sensor:
- platform: template
name: "parking space 1"
device_class: presence
lambda: |-
if (id(ultrasonic_sensor1).state < 1.8) {
// car is in the garage
return true;
} else {
// no car
return false;
}
#switch:
# - platform: gpio
# pin: GPIO12
# id: relay
# - platform: template
# icon: "mdi:arrow-up-down-bold-outline"
# name: "Garage Door 1 Control"
# turn_on_action:
# - switch.turn_on: relay
# - delay: 500ms
# - switch.turn_off: relay
sensor:
- platform: ultrasonic
id: ultrasonic_sensor1
trigger_pin: GPIO05
echo_pin: GPIO04
name: "Garage Door 1 Sonar"
update_interval: 5s
filters:
- filter_out: nan
- median:
window_size: 7
send_every: 4
send_first_at: 3
timeout: 4m
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 30s
text_sensor:
- platform: template
name: "Garage state"
id: garage_state
lambda: |-
if (id(ultrasonic_sensor1).state >= 0.18 && id(ultrasonic_sensor1).state <= 0.24) {
return {"Garage open"};
} else if (id(ultrasonic_sensor1).state >= 1.10 && id(ultrasonic_sensor1).state <= 1.6) {
return {"Garage closed"};
} else if (id(ultrasonic_sensor1).state >= 3.1 && id(ultrasonic_sensor1).state <= 3.25) {
return {"Garage closed"};
} else {
return {"unknown"};
}
update_interval: 20s
- platform: template
name: "parked"
lambda: |-
if (id(ultrasonic_sensor1).state >= 0.18 && id(ultrasonic_sensor1).state <= .24) {
return {"Unknown"};
} else if (id(ultrasonic_sensor1).state >= 1.10 && id(ultrasonic_sensor1).state <= 1.6) {
return {"Car Home"};
} else if (id(ultrasonic_sensor1).state >= 3.1 && id(ultrasonic_sensor1).state <= 3.25) {
return {"Car Away"};
} else {
return {"unknown"};
}
update_interval: 20s
cover:
- platform: template
name: "Garage Door 1e"
lambda: |-
if (id(garage_state).state == "Garage open") {
return COVER_OPEN;
} else if (id(garage_state).state == "Garage closed") {
return COVER_CLOSED;
} else {
return {};
}
open_action:
- homeassistant.service:
service: script.garage_door_1
close_action:
- homeassistant.service:
service: script_garage_door_1
I don’t use the switch part but have left it commented in case I add a relay to the esp device.
Thanks
Craig