Summary:
I want to be able to set a entity state and as much as I have looked I cannot figure out how to change the state of a garage door entity status.
Details:
I have a garage door that can be opened in more than one way, including Home Assistant.
When it is opened in a way other than Home Assistant I have an ultrasonic sensor to detect if the door is open and want to be able to change the state from “Closed” to “Open”.
I can set it in the “Developer Tools”->STATES and can change the cover.garage_door entity to state open or closed with no problem. I just do not know how to do it from the ultrasonic sensor.
sensor:
- platform: ultrasonic
trigger_pin: GPIO4 # D2
echo_pin: GPIO5 # D1
name: "Garage Door Distance Sensor"
id: garage_distance_sensor
update_interval: 60s
internal: false
filters:
# The ultrasonic sensor returns null over ~4 feet.
# I mount the sensor above the door, have tested and know the following works.
# I just cannot figure out how to get the cover.garage_door status updated.
lambda: |-
if (x>0) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
I want to be able to change the cover.garage_door state to OPEN or CLOSED based on the sensor reading.
When using the HA garage door switch there is no problem with the state, it gets changed automatically with no problem. But when my wife uses her garage door remote (that came with the garage door and I still want to be able to use) I want the ultrasonic to update the door state.
My suggestion will probably work. It’s basically the same as what I do with my blinds which I also have a remote for.
Personally I’d go for an ESPHome cover if the garage door relay and distance sensor are on the same esp (this would typically be more reliable), or a HA cover if the garage door and distance sensor need to talk to each other via HA.
More info about hardware and software would help us help. Especially as Nick has mentioned, whether you are using a HA or a ESPHome cover, and which one. But also the details of your cover - does it have other sensors for open/closed like endstops?
I am still not getting the question I have across, so let me try again.
I have a working ESPHome garage door set up. It works fine. It has a single relay which closes for 1 sec and then opens up again. That is the trigger for both opening and closing the door.
When using HA to open and close the door, it works perfectly. The relay opens and closes and the garage door goes from Closed to Open or Open to Closed.
However… if my wife opens the garage door with her older garage door relay, the garage door is open but HA shows it as closed, because HA does not know it has been opened The ultrasonic sensor detection reads 1 when closed and 0 when open because of a logic I put in.
How do I change the status of the variable cover.garage_door when the sensor detects the change?
You cannot programmatically change the state of an entity except from the entity’s code. That is why I keep asking you how your existing garage door is implemented. You have got as far as telling us that it is esphome. Now post your yaml.
Unfortunately it looks like the “on_value_range” is not working.
I put logging into the “above 0” and “below 0” sections, but the works “Setting to xxx based on ultrasonic…” is not getting onto the log.
Here is a copy of the log. I triggered the open button and then the close button, but as you can see the ultrasonic settings are not working.
[20:38:26][D][ultrasonic.sensor:036]: 'Garage Door Distance Sensor' - Distance measurement timed out!
[20:38:26][D][sensor:126]: 'Garage Door Distance Sensor': Sending state nan m with 2 decimals of accuracy
[20:39:26][D][ultrasonic.sensor:040]: 'Garage Door Distance Sensor' - Got distance: 0.84 m
[20:39:26][D][sensor:126]: 'Garage Door Distance Sensor': Sending state 0.83658 m with 2 decimals of accuracy
[20:39:42][D][cover:076]: 'Garage Door' - Setting
[20:39:42][D][cover:086]: Command: OPEN
[20:39:42][D][main:405]: ------- Logging Opening
[20:39:42][D][switch:013]: 'Garage Door Open Switch' Turning ON.
[20:39:42][D][switch:056]: 'Garage Door Open Switch': Sending state ON
[20:39:42][D][cover:170]: 'Garage Door' - Publishing:
[20:39:42][D][cover:176]: State: OPEN
[20:39:42][D][cover:186]: Current Operation: IDLE
[20:39:43][D][switch:017]: 'Garage Door Open Switch' Turning OFF.
[20:39:43][D][switch:056]: 'Garage Door Open Switch': Sending state OFF
[20:39:59][D][cover:076]: 'Garage Door' - Setting
[20:39:59][D][cover:086]: Command: CLOSE
[20:39:59][D][main:416]: ----- Logging Closing
[20:39:59][D][switch:013]: 'Garage Door Open Switch' Turning ON.
[20:39:59][D][switch:056]: 'Garage Door Open Switch': Sending state ON
[20:39:59][D][cover:170]: 'Garage Door' - Publishing:
[20:39:59][D][cover:178]: State: CLOSED
[20:39:59][D][cover:186]: Current Operation: IDLE
[20:40:00][D][switch:017]: 'Garage Door Open Switch' Turning OFF.
[20:40:00][D][switch:056]: 'Garage Door Open Switch': Sending state OFF
[20:40:26][D][ultrasonic.sensor:040]: 'Garage Door Distance Sensor' - Got distance: 0.84 m
[20:40:26][D][sensor:126]: 'Garage Door Distance Sensor': Sending state 0.83692 m with 2 decimals of accuracy