MQTT support

So the homebridge-mqttthing and homebridge-mqttgaragedoor plugins got me close to having the door operate in HomeKit via MQTT, but while you can sometimes open or close close (but not always) neither are reliable about getting the status of the door.

So if someone wants to get the MQTT process working with Homebridge it seems like itā€™s working ok now for me. Install the homebridge-mqttthing plugin, and then use the following configuration. Just replace the ExampleGarageDoor with your door name.

"accessories": [
    {
        "accessory": "mqttthing",
        "type": "garageDoorOpener",
        "name": "Garage Door",
        "url": "http://192.158.0.10:1883",
        "logMqtt": true,
        "topics": {
            "setTargetDoorState": "garadget/ExampleGarageDoor/command",
            "getTargetDoorState": {
                "topic": "garadget/ExampleGarageDoor/status",
                "apply": "return JSON.parse (message).status;"
            },
            "getCurrentDoorState": {
                "topic": "garadget/ExampleGarageDoor/status",
                "apply": "return JSON.parse (message).status;"
            }
        },
        "doorValues": [
            "open",
            "closed",
            "opening",
            "closing",
            "stopped"
        ]
    }
]
2 Likes

I am experiencing the same behavior. I have a slow internet connection at my house and was experiencing random status changes when connected to via cloud (I assume this was cloud related). I changed to MQTT and Cloud (keeping cloud as a backup in case my server went down). My status would not update via MQTT. I switched to only MQTT and it updates correctly. I would still like the option to use both Cloud and MQTT functionality.

I think this can only be resolved with a firmware upgrade.

Iā€™m trying to get my Garadget to work with HASS. I couldnā€™t get the Garadget cover to work so now Iā€™m trying MQTT. I too enabled MQTT + Cloud and now my Garadget app is very slow and HASS is still not operating the Garadget or receiving status from it. Iā€™ll try reconfiguring the Garadget for MQTT-only tomorrow.

I would also prefer to have the MQTT+cloud functionality working!

MQTT+Cloud works fine on my Home Assistant 0.85.0 with Garadget Firmware v1.20
Do you get any errors in HASS logs?

Thanks for your reply. Iā€™m on HASS 0.86.4, also with Garadget firmware 1.20.

I suspect my HASS setup isnā€™t quite right then. Thereā€™s nothing in the log related to Garadget though I havenā€™t played with the log settings, assuming any errors would appear in the log with the default settings.

My HASS configuration. yaml is a combination of things Iā€™ve found that eliminated the errors I got with the configuration on the http://www.homeassistant.io/components/cover.garadget page. I found that neither the ā€œstandardā€ example nor the MQTT example on that page worked for me.

@garadget, any chance you could share your working configuration (with IDs, passwords etc deidentified of course)? I suspect thereā€™s some subtlety to the configuration that the docco hasnā€™t kept up with. Iā€™ve come across other references to that possibility in my research (eg: https://github.com/home-assistant/home-assistant/issues/20420#issuecomment-457998017 ).

Sure, hereā€™s configuration.yaml

logger:
  default: warning
  logs:
    homeassistant.components.mqtt: debug

mqtt:
  password: *******


# Garadget
cover:
  - platform: mqtt
    name: "Garage Door"
    command_topic: "garadget/Home/command"
    state_topic: "garadget/Home/status"
    value_template: '{{ value_json.status }}'
    icon_template: >-
      {% if is_state('cover.garage_door', 'closed') %}
        mdi:garage-open
      {% else %}
        mdi:garage
      {% endif %}
    payload_open: "open"
    payload_close: "close"
    payload_stop: "stop"

sensor:
  - platform: mqtt
    name: 'Garage Door'
    state_topic: 'garadget/Home/status'
    value_template: '{{ value_json.status }}'
    icon_template: '{% if is_state("sensor.garage_door", "closed") %}mdi:garage{% else %}mdi:garage-open{% endif %}'

  - platform: mqtt
    name: 'Garage Brightness'
  state_topic: 'garadget/Home/status'
    unit_of_measurement: '%'
    value_template: '{{ value_json.bright }}'

Thanks Denis,

Iā€™ll tweak my settings to match yours when I get home from work later today.

BTW, I use the ā€œsecrets.yamlā€ file for my passwords. I assume thereā€™s no problem with doing that for the mqtt password?

Cheers,

Rob Hills
Waikiki, Western Australia

Hi Denis,

Iā€™ve tweaked my configuration to match yours, but Iā€™m still not quite there. Part of my original problem was that Iā€™d missed making a pinhole in my firewall between LAN and WiFi networks for MQTT traffic but Iā€™ve sold now. What I see in the log now (with debug turned on) is the following:

2019-02-05 00:30:22 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to garadget/My_Street/status
2019-02-05 00:30:22 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to garadget/My_Street/status
2019-02-05 00:30:22 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to garadget/My_Street/status
2019-02-05 00:35:17 ERROR (MainThread) [hbmqtt.broker] Invalid connection from (client @=192.168.23.157:12218) : [MQTT-3.1.2-1] Incorrect protocol name: "MQIsdp"
2019-02-05 00:36:14 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on garadget/My_Street/command: close

Iā€™m not sure why Iā€™m getting the ā€œIncorrect Protocolā€ error.

I donā€™t see any status change in response to the ā€œcloseā€ command and the door doesnā€™t close.

TIA,

Rob
Waikiki, Western Australia

Iā€™ve upgraded HA to 0.86.4 and hereā€™s the relevant log from the first boot (looks healthy):

|2019-02-04 16:50:21|stdout|e[36m2019-02-04 09:50:21 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on garadget/Home/status: b'{"status":"closed","time":"102m","sensor":97,"bright":11,"signal":-41}'e[0m|
|2019-02-04 16:50:21|stdout|e[36m2019-02-04 09:50:21 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to garadget/Home/statuse[0m|
|2019-02-04 16:50:21|stdout|e[36m2019-02-04 09:50:21 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on garadget/Home/status: b'{"status":"closed","time":"102m","sensor":97,"bright":11,"signal":-41}'e[0m|
|2019-02-04 16:50:21|stdout|e[36m2019-02-04 09:50:21 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on garadget/Home/status: b'{"status":"closed","time":"102m","sensor":97,"bright":11,"signal":-41}'e[0m|
|2019-02-04 16:50:21|stdout|e[36m2019-02-04 09:50:21 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to garadget/Home/statuse[0m|
|2019-02-04 16:50:21|stdout|e[36m2019-02-04 09:50:21 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to garadget/Home/statuse[0m|

Re. white spaces in name: I donā€™t find anything about them not being allowed, but Iā€™d at least test with SomeStreet as the name. For debugging you can try getting mosquitto broker and use their client to manually connect/subscribe with home assistant and see if there are any errors.

Hi Denis,

Thanks for your reply. Sorry, but I suspect I updated my post while you were writing the reply. I discovered and fixed a firewall issue and now I have a new problem (see updated previous post).

It may respond to the Mosquitto broker suggestion, but I figured if yours works with the inbuilt mqtt broker, mine should too ?

Cheers,

Rob

Please try using the password setting as in my config, at least to rule out that as the source of the error.

Hi Denis,

I notice in your log it says Subscribing to garadget/Home/statuse rather than ā€œstatusā€. Can you confirm that your state_topic value is ā€œgaradget/Home/statusā€ and not ā€œgaradget/Home/statuseā€? I suspect the log output is some sort of log formatting anomaly, but thought Iā€™d check.

Iā€™ve tried moving the mqtt password from secrets.yaml into the main configuration.yaml file but the only change Iā€™ve seen since then, which may or may not be related, is that Iā€™ve now lost the ā€œincorrect protocol nameā€ error I was getting before. Still no status messages in the log and no response to attempts to open it.

I changed back to my original configuration (with the password in secrets.yaml) and now have the same outcome as the previous step: no ā€œincorrect protocol nameā€ but no status messages, no response to attempts to open it.

I think the next step will be to try changing the ID on the Garadget itself from ā€œMy Streetā€ to ā€œMyStreetā€ as you mentioned previously.

Cheers,

Rob Hills
Waikiki, Western Australia

Not getting protocol error message is already a positive result. Iā€™d keep that version while trying to make other things to work. Then when everything works it would be a good time to figure out the way to separate the password.

In case anyone else runs into this: apparently the max number of characters for the mqtt password for garadget is 31, and it will silently truncate to 31 if you put in something longerā€“which prevents the garadget client from connecting to an mqtt server expecting the full password (lots of ā€œSocket error on clientā€ errors in the mosquitto server log).

Are there any plans to expand garadget mqtt support? Iā€™d like to use ssl with certs from letsencrypt on my mqtt server, but I donā€™t see any way for garadget (connecting to IP only, only authenticating via username/password) to support that configuration as it currently stands.

Seems like perhaps the sample brightness-updating automation isnā€™t valid anymore. We have to use time_pattern now:

- alias: 'Update Garage Brightness'
trigger:
- platform: time_pattern
  minutes: '/2'
action:
  service: mqtt.publish
  data:
    topic: "garadget/Home/command"
    payload: "get-status"

icon_template doesnā€™t work anymore either but I added device_class: 'garage' to the cover for the same icon effect

1 Like

I also had to change value_template for the cover to fix the above unknown-state bug. I got it to show an open state when itā€™s anything but closed, making the icon the open state when the door reports being partway through as ā€˜openingā€™ and ā€˜closingā€™

value_template: >-
     {% if value_json.status == 'closed' %}
      closed
     {% else %}
      open
     {% endif %}

Iā€™m using MQTT-only but Iā€™m not sure if thatā€™s required to make this work.

1 Like

Just wanted to let you all know that I open sourced the Garadget integration for Homebridge, using MQTT project. Everything was especially easy to code up thanks to the great work of the team over at Garadget! Keep up the excellent work!

2 Likes