Using the MQTT Garage control - any tips?

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!

I’ve build almost the exact same Opener, but mine sends 4 states over mqtt (opening/open/closing/closed).

Try to change your value_template to ‘{{ value }}’

Greets
Jacko

Thanks for that, will give it a try tonight…

Did you ever get this fixed to show the state of the door. I can’t seem to figure it out either. I only have one reed switch but basically if it is a closed circuit then the door is closed and open circuit then the door is open. I can’t get it to display the status. I am able to open and shut the door though. My config file is very similar to yours too. I have a RPi rather than the ESP8266 but it should still work the same way.

I did! I’m on the daily commute into work right now, but I’ll put together a post in the next 24 hours. Are you using Mqtt? Can you see the value that is being posted to the relevant topic? Double checked your topic subscriptions on both ends (sensor and HA)…

The value posted is where I found my fault. I have also reduced my layout to one Reed as HA had no way of indicating a intermediate state between open and close as far as I could tell…

More later!

brendanheyu I think i got this figured out. I am not exactly sure what fixed it but it seems to be working now. Yes I am using MQTT. It would be nice if you could tell if the state was in between open or closed on the UI because there is definitely a lag between when you push the button and when it registers closed since it takes time for the reed switch to actually close.

Thanks for the quick response though and good luck with the rest of you automation.

Hi grangemd,

Good you got it all hooked up. Sorry I didn’t follow through with the post!

As an aside - how is that satisfaction when you get it working? Pretty sweet I reckon!

B

It is awesome. Finally figured out MQTT and it is easy now that I understand it. I will definitely be using it in my future projects

Just curious, has anyone tried to integrate a Chamberlain model 6066 (remote door open sensor)? I’m looking to make a door controller similar to what the OP has but not sure if it would be worth while trying to wire into the sensor or if I should just go the reed switch route. When I bought my house it came with the sensor and after some surgery (loose solder joint on the transmitter battery holder) I’ve got it working great. When the door is closed the green LED is solid. When it’s open the red LED blinks. I’ve also seen where someone connected an esp to a spare wireless remote to control the door. The indoor sensor receiver runs on a 12v 100ma wall wart which should be easy to grab 5 volts from and there’s enough room in the case I can probably mount the ESP inside.