kind3r / hass-addons

Integration of the offline TTLock sdk into Home Assistant
59 stars 21 forks source link

No MQ messages #23

Open editter opened 2 years ago

editter commented 2 years ago

Hello, I set up the addon in a second instance on a raspberry pi 3 and got the lock connected but I never see any MQ messages come through. I am not seeing the "MQTT connected" message in the logs so something isn't working but I'm not sure why. I get my birth/will messages when HA starts/stops so I know the MQ stuff is working but nothing from this addon. Thoughts?

Here is my entire configuration.yaml (note I did try adding the default_config entry in case that was important but I didn't see anything different)

configuration.yaml

config:
frontend:
hassio:
http:
webhook:

mqtt:
  discovery: false
  discovery_prefix: hass2
  birth_message:
    topic: "hass2/status"
    payload: "online"

  will_message:
    topic: "hass2/status"
    payload: "offline"
  broker: 192.168.1.55
  port: 1883
  client_id: hass2
  username: !secret mqtt_username
  password: !secret mqtt_password

I also see this in the logs and I am wondering if the service is not enabled but I'm not sure what Service it is referring to.

[08:12:28] ERROR: Got unexpected response from the API: Service not enabled
Debug MQTT
> ttlock-hass-integration@0.2.1 start
> node ./index.js
Monitor started
Server started
editter commented 2 years ago

So I dug into this a little bit and I think I figured out the problem (I am not that familiar with the addon development so I might be wrong). The config.json services > mqtt:want will provide settings if it's an addon service, not just magically pulling it from configuration.yaml and because I am using an MQ broker on another machine it doesn't work for me.

My proposed solution would be to add config options and use that if the addon service isn't available. Thoughts?

config.json

"schema": {
  ...
     "mqtt_host": "str?",
      "mqtt_port": "port?",
      "mqtt_ssl": "bool?",
      "mqtt_username": "str?",
      "mqtt_password": "str?"
  }, 

start.sh

#!/usr/bin/env bashio

if ! bashio::services.available "mqtt"; then
    bashio::log.info "No internal MQTT service found, using addon config"
    export MQTT_HOST=$(bashio::config "mqtt_host")
    export MQTT_PORT=$(bashio::config mqtt "mqtt_port")
    export MQTT_SSL=$(bashio::config "mqtt_ssl")
    export MQTT_USER=$(bashio::config "mqtt_username")
    export MQTT_PASS=$(bashio::config "mqtt_password")
else
    bashio::log.info "MQTT service found, fetching credentials ..."
    export MQTT_HOST=$(bashio::services mqtt "host")
    export MQTT_PORT=$(bashio::services mqtt "port")
    export MQTT_SSL=$(bashio::services mqtt "ssl")
    export MQTT_USER=$(bashio::services mqtt "username")
    export MQTT_PASS=$(bashio::services mqtt "password")

fi
...
kind3r commented 2 years ago

Indeed, it is designed to work with the MQTT addon provided by HA, to make it simple. I will put this on my todo list.