stjohnjohnson / smartthings-mqtt-bridge

Bridge between SmartThings and MQTT
https://hub.docker.com/r/stjohnjohnson/smartthings-mqtt-bridge/
MIT License
366 stars 242 forks source link

Connection to MQTT:MQTT 2 #72

Open rsissons opened 7 years ago

rsissons commented 7 years ago

Hi,

Since my other post was closed, I figured I would explain where I am now. The read.me is not clear and the code example in the config.yml is not working for me.

After trying to use the instructions that was linked to, that I saw before, it still doesn't work. All I changed was the host to localhost, IP address, and neither worked and the HA wouldn't even start up. I put the code in my main configuration.yaml file.

mqtt:

Specify your MQTT Broker's hostname or IP address here

host: 192.168.1.206 
# Preface for the topics $PREFACE/$DEVICE_NAME/$PROPERTY
preface: smartthings
# Suffix for the state topics $PREFACE/$DEVICE_NAME/$PROPERTY/$STATE_SUFFIX
# state_suffix: state
# Suffix for the command topics $PREFACE/$DEVICE_NAME/$PROPERTY/$COMMAND_SUFFIX
# command_suffix: cmd
# Other optional settings from https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
# username: AzureDiamond
# password: hunter2

Port number to listen on

port: 8080

So after researching, I found Bruh's MQTT setting that seem to work except it still wants to connect to MQTT:MQTT instead of my localhost. I start it by using PM2 start smartthings-mqtt-bridge. Check the status and it's there. If I run smartthings-mqtt-bridge I get: info: Starting SmartThings MQTT Bridge - v1.3.4 info: Loading configuration info: Loading previous state info: Perfoming configuration migration info: Saving current state info: Connecting to MQTT at mqtt://mqtt Connecting to MQTT at mqtt://mqtt

Here is my configuration.yaml MQTT section. mqtt: broker: 192.168.1.206 port: 1883 client_id: home-assistant-1 username: pi password: xxxxxxxx birth_message: topic: 'homeassistant/status' payload: 'online' qos: 1 retain: true will_message: topic: 'homeassistant/status' payload: 'offline' qos: 1 retain: true

HA seems to like this and I can toggle the switch back and forth and can see the messages being received by subbing to the it using mosquitto_sub -d -u pi -P xxxxxxxxx -t smartthings/#, it just doesn't know about connecting to the localhost.

The link you sent, is it suppose to exist as a separate yaml file? Am I not supposed to use the MQTT section in my main configuration.yaml?

stjohnjohnson commented 7 years ago

That config is supposed to go into the mqtt bridge, it's the local config.yml file in there. Not the configuration for Home Assistant.

rsissons commented 7 years ago

Thank you.

That config is supposed to go into the mqtt bridge

I have a _config.yml(not yaml, like I expected) in the ./opt/nodejs/lib/node_modules/smartthings-mqtt-bridge.

I updated it with my ip address and restarted. No change. Connecting to MQTT at mqtt://mqtt

I changed the file name to .yaml. No Change. I change the file name to config(no underscore).yaml(and yml) still no change. I am stabbing in the dark and trying things to figure it out and not post things here.

I may be stepping on my own toes too. I have it running under PM2, which seems to work: │ smartthings-mqtt-bridge │ fork │ online │ 1 │ 50% │ 13.4 MB

and can read messages being sent to it when I flick the switch on the HA screen: Client mosqsub/22668-roosterpi received PUBLISH (d0, q0, r0, m0, 'smartthings/RonsLivingRoomLamp/switch', ... (2 bytes)) on Client mosqsub/22668-roosterpi received PUBLISH (d0, q0, r0, m0, 'smartthings/RonsLivingRoomLamp/switch', ... (3 bytes)) off

or running it stand alone, which tries to connect to MQTT://MQTT that doesn't work: smartthings-mqtt-bridge

I just don't see it in Smartthings.com logs after having setup the device handlers, smart apps and devices.

or maybe I'm just stupid.

johnypony3 commented 7 years ago

hi,

please try: host: mqtt://192.168.1.206

revert any other changes.

rsissons commented 7 years ago

please try: host: mqtt://192.168.1.206

Where? I am not supposed to have it in my main HA configuration.yaml file. I get that now .

Am I updating this in the ./opt/nodejs/lib/node_modules/smartthings-mqtt-bridge/_config.yml file ?

rsissons commented 7 years ago

Gentlemen.

I am going to format and reinstall everything again from scratch using the Raspbian _Jessie image, and using the HA All-In_one installer. I will them, again, install the bridge using the instructions from the readme.

This can't be that difficult.

johnypony3 commented 7 years ago

lets not brash decision the _config.yml file should be copied or renamed to config.yml it is meant to be an example then it should look like this for you:

---
mqtt:
    # Specify your MQTT Broker URL here
    host: mqtt://192.168.1.206
    # Example from CloudMQTT
    # host: mqtt:///m10.cloudmqtt.com:19427

    # Preface for the topics $PREFACE/$DEVICE_NAME/$PROPERTY
    preface: smartthings

    # Suffix for the state topics $PREFACE/$DEVICE_NAME/$PROPERTY/$STATE_SUFFIX
    # state_suffix: state
    # Suffix for the command topics $PREFACE/$DEVICE_NAME/$PROPERTY/$COMMAND_SUFFIX
    # command_suffix: cmd

    # Other optional settings from https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
    # username: AzureDiamond
    # password: hunter2

# Port number to listen on
port: 8080

since youre not making any real changes to it, if you like, you can shorten it down to:

---
mqtt:
    host: mqtt://192.168.1.206
    preface: smartthings

port: 8080
rsissons commented 7 years ago

Ok. i will attempt to figure this out with your help.

  1. the _config.yml has been renamed to config.yml. and made sure it had the minimum information in it as you suggested.

  2. I took the MQTT information I had in the HA configuration out: mqtt: broker: 192.168.1.206 port: 1883 client_id: home-assistant-1 username: pi password: r51550n5 birth_message: topic: 'homeassistant/status' payload: 'online' qos: 1 retain: true will_message: topic: 'homeassistant/status' payload: 'offline' qos: 1 retain: true

  3. I saved it, and restarted with sudo reboot. After starting, I started the bridge using PM2 Start Smarthings_MQTT Bridge and confirmed it running using PM2 Status.

[11:16:28] pi@roosterpi1:~$ pm2 start smartthings-mqtt-bridge [PM2] Spawning PM2 daemon with pm2_home=/home/pi/.pm2 [PM2] PM2 Successfully daemonized [PM2] Starting /opt/nodejs/bin/smartthings-mqtt-bridge in fork_mode (1 instance) [PM2] Done.

** I left my Switch info in the HA config at this point, but HA wouldnt start after I took the MQTT info out. switch: platform: mqtt name: "RonsLivingRoomLamp" state_topic: "smartthings/RonsLivingRoomLamp/switch" command_topic: "smartthings/RonsLivingRoomLamp/switch" brightness_state_topic: "smartthings/RonsLivingRoomLamp/level" brightness_command_topic: "smartthings/RonsLivingRoomLamp/level" payload_on: "on" payload_off: "off" retain: true
so I removed the switch information as well and rebooted again. HA starts now.

So, now that I have the Bridge config.yml updated with just the bare minimum information. What do i need to put in my HA config to it knows to use it? Anything?

johnypony3 commented 7 years ago

didnt you say your ha was writing to the queue before?

here is what i think it should be (HA):

mqtt:
  broker: 192.168.1.206
  port: 1883
  client_id: home-assistant-1
  birth_message:
    topic: 'smartthings/homeassistant/status'
    payload: 'online'
    qos: 1
    retain: true
  will_message:
    topic: 'smartthings/homeassistant/status'
    payload: 'offline'
    qos: 1
    retain: true

also, the two products use different configs

  1. bridge: host: mqtt://192.168.1.206
  2. HA: broker: 192.168.1.206
rsissons commented 7 years ago

Yup, that's what I have in both.

And when I sub to it, I see it receiving info when I toggle the switch on the HA screen. mosquitto_sub -d -u pi -P r51550n5 -t smartthings/#

Subscribed (mid: 1): 0 Client mosqsub/20150-roosterpi received PUBLISH (d0, q0, r1, m0, 'smartthings/Ron's Living Room Lamp/switch', ... (3 bytes)) off Client mosqsub/20150-roosterpi received PUBLISH (d0, q0, r1, m0, 'smartthings/RonsLivingRoomLamp/switch', ... (3 bytes)) off

What would be the next step to troubleshoot\debug it communicating with smartthings?