Hi folks!
I’m using a home baked solution with an ESP8266 + a 5v relay + 2 reed switches to control my garage door.
The garage is a single button operation - press to go up, press to go down. Couldn’t be simpler. I’ve got the ESP and relay working a treat, I can send a MQTT topic a payload of “1” and the relay activates the door. It’s a win there!
I want to report on the state of the door - open / closed / ajar. It doesn’t look like there is an “ajar” state available in the MQTT Door object, but I can live with just open + close.
My yaml looks like:
Garage control
garage_door:
platform: mqtt
state_topic: “house/indoors/garage/door/state”
command_topic: “house/indoors/garage/door/command”
name: “Double garage door”
optimistic: true
qos: 0
retain: true
state_open: “STATE_OPEN”
state_closed: “STATE_CLOSED”
service_open: “1”
service_close: “1”
value_template: ‘{{ value.x }}’
My code from my arduino:
#define topic5 “house/indoors/garage/door/command” // send “1” as actuator
#define topic6 “house/indoors/garage/door/state” // send “closed/open” as state
Door_Open_Val = digitalRead(Door_Sensor_Open_Pin); // read Door_Sensor_Pin
Door_Closed_Val = digitalRead(Door_Sensor_Closed_Pin); // read Door_Sensor_Pin
long DoorNow = millis();
if (DoorNow - DoorCheckedMsg > 2000) {
DoorCheckedMsg = DoorNow;
if (Door_Closed_Val == HIGH) {
// If Door_Sensor N.C. (no with magnet) -> HIGH : Door is open / LOW : Door is closed
// If Door_Sensor N.0. (nc with magnet) -> HIGH : Door is closed / LOW : Door is open
Serial.println(“Door closed.”);
client.publish(topic6, “STATE_CLOSED”, true);
} else {
if (Door_Open_Val == HIGH) {
Serial.println(“Door open.”);
client.publish(topic6, “STATE_OPEN”, true);
} else {
Serial.println(“Door ajar.”);
client.publish(topic6, “STATE_OPEN”, true); // no ajar state available - yet!
}
}
}
This gets me some debug along the lines of:
Door closed.
Door closed.
Door closed.
Door ajar.
Light intensity: 0lux
Humidity: 45.70%
Temp: 19.70c
Dew point: 7.64c
Door ajar.
Door open.
Door open.
Door open.
So I know the values are ok. I have looked at the MQTT channels and they seem to be filled with the right content.
I just can’t seem to get the toggle in the HASS UI to represent the state of the door. It sends the “1” I need to toggle the door state - but HASS doesn’t seem to get the MQTT state info and represent it in the toggle switch.
Where have I fluffed things up?
Thanks folks! I’m loving this stuff!