stjohnjohnson / smartthings-mqtt-bridge

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

Can't get this working #76

Closed TheCellMC closed 7 years ago

TheCellMC commented 7 years ago

Here are all the steps I did to try to get this working. Would someone mind telling me what I did wrong?

(Also please note that, as I am based in the UK, I use the graph-eu01-euwest1 SmartThings API.)

Setup

I started off by installing the sd card flashed with the Hassbian image.

Then I did:

sudo apt-get update sudo apt-get upgrade

Then to install MQTT:

sudo ./hassbian-scripts/install_mosquitto.sh I entered a username 'pi' and a password 'secret' when prompted.

I then installed node.js

wget https://nodejs.org/dist/v4.3.2/node-v4.3.2-linux-armv6l.tar.gz tar -xvf node-v4.3.2-linux-armv6l.tar.gz cd node-v4.3.2-linux-armv6l sudo cp -R * /usr/local/

Then installed smarthings-mqtt-bridge via NPM

sudo apt-get install npm sudo npm install -g smartthings-mqtt-bridge

And then installed pm2 via NPM

sudo npm install pm2 -g

I then edited the smartthings-mqtt-bridge config

sudo cp /usr/local/lib/node_modules/smartthings-mqtt-bridge/_config.yml ~/config.yml sudo nano ~/config.yml

---
mqtt:
  # Specify your MQTT Broker's hostname or IP address here
  host: 192.168.1.25
  # 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_SUFF$
  # command_suffix: cmd

  # Other optional settings from https://www.npmjs.com/package/mqtt#mqttclients$
  username: pi
  password: secret

  # Port number to listen on
  port: 8080

I then setup the Device Handler and SmartApp following: https://github.com/stjohnjohnson/smartthings-mqtt-bridge

Device Settings
IP: 192.168.1.25
MAC: ma:ca:dr:es:s
Port: 8080

And then added this to the HA configuration.yaml

mqtt:
  broker: 192.168.1.25
  port: 1883
  client_id: home-assistant-1
  username: pi
  password: secret

And then added a switch to the configuration.yaml

switch:
  - platform: mqtt
    name: "MQTT Left Lamp"
    state_topic: "smartthings/Left Lamp/switch"
    command_topic: "smartthings/Left Lamp/switch"
    payload_on: "on"
    payload_off: "off"
    retain: true

Then

pm2 restart smartthings-mqtt-bridge sudo systemctl restart home-assistant.service

I also did a reboot at the end and checked that both services were running

Logs

So here are the SmartThings logs when the switch is turned on (the smarttapp logs):

653e9a65-edb7-4603-b11e-6476d4a52d09  12:41:58 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Left Lamp","value":"on","type":"switch"}}
653e9a65-edb7-4603-b11e-6476d4a52d09  12:41:57 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Left Lamp","value":"turningOn","type":"switch"}}

And here are the SmartThings logs when the switch is turned on (the device logs):

a61bb2ab-d453-471b-8d20-f0a187df4895  12:41:58 PM: debug Sending '{"path":"/push","body":{"name":"Left Lamp","value":"on","type":"switch"}}' to device
a61bb2ab-d453-471b-8d20-f0a187df4895  12:41:57 PM: debug Sending '{"path":"/push","body":{"name":"Left Lamp","value":"turningOn","type":"switch"}}' to device

The HA log:

17-03-11 12:35:36 WARNING (Thread-11) [homeassistant.components.recorder] Ended unfinished session (id=6 from 2017-03-11 11:04:59.344912)
17-03-11 12:35:36 WARNING (Thread-11) [homeassistant.components.recorder] Found unfinished sessions

And the pm2 logs:

pm2 logs smartthings-mqtt-bridge
[PM2] Spawning PM2 daemon with pm2_home=/home/pi/.pm2
[PM2] PM2 Successfully daemonized
[TAILING] Tailing last 15 lines for [smartthings-mqtt-bridge] process (change the value with --lines option)
[STREAMING] Now streaming realtime logs for [smartthings-mqtt-bridge] process

So what should I do to fix this? I see the switch in the HA UI but turning it on or off does nothing (same if I turn it on or off via the SmartThings app) As I already said at the begging: as I am based in the UK, I use the graph-eu01-euwest1 smartthings api. So if any of the scripts use the datbase I might need to change the api? Also there is no portforwarding to do if I am correct?

jjmmss00 commented 7 years ago

Part 1.

Hi, I have having the same problem and have at this point achieved some but not total success. I would thank the code authors for some great work. However there does not seem like there is much in the way of diagnostics if things aren't working after a person follows direction in getting things installed. I am a newbie to Linex, SmartThings, Raspberry Pi, and Networking, which is also a problem

So here are some of approaches I used to trouble shoot. First, get the various pieces running on different computers. I installed Mosquito on my windows PC, along with a free Microsoft Networking Monitoring Tool. I installed Ubuntu Linux on an old laptop, and then the Docker Utility, and finally the Mqtt-Bridge itself. I also installed a free networking monitoring utility called Wireshark. Then I left the HomeAssistant running on the RPi.

After that I was able to work on the HA config and Mosquito config to verify that Mosquito was working and talking to HA. This took some trial and error, as getting the HA config file working was problematic for me. Note there is also several free iOS applications that I was able to download on my iPad to test out the MQTT itself. Finally it was instructive to watch the network traffic back and forth on the network monitor (Microsoft Network Monitor).

I will continue in part 2. After a break.

jjmmss00 commented 7 years ago

Part 2.

Per my count there are 5 significant software pieces to this system:

1) HA on the RPi 2) Mosquito MQTT Broker (temporarily running on a windows PC) 3) MQTT-Bridge (temporarily running on an old laptop with UBantu) 4) MQTT-Bridge and associated device (on the ST Hub) 5) MQTT-Smart App (on the ST Hub)

I believe that it qualifies as a complex system.

I have renamed the ST hub pieces to reduce ambuiguity. The MQTT-Bridge I remamed the MQTT-Bridge-Driver, and the associated device that showed up in ST app I call the MQTT-Bridge-Device. The name for the smart app seems good but one can make some minor code edits to get this to show up in the ST web development pages.

Next I worked on getting the ST to MQTT interface working. For a while it seemed that the ST hub was not sending out messages. As I changed the IP address in ST to send test messages to my PC where I had the network monitor, and there weren't any received packets. Then I commented out the call to "hubAction" at the end of the driver code and experimented with my own test hubAction calls and finally got the hub to send out TCP messages.

At this point I installed the MQTT-Bridge on the old laptop with UBantu and found that the Bridge was sending back error messages to the ST hub. (I was now monitoring the network with the wireshark program). My substitute call to the hubAction routine was not sending out proper messages. I went back and tried the original code for hubAction and found it was now working and in fact everything was working. I don't know why things weren't working in the first place.

My next steps will be to try and integrate everything onto the RPi.

Note: one possible problem may be (not sure of this) that during the first call to set things up in Docker one needs to specify a port. Subsequently one also needs to specify a port in the MQTT-Bridge configuration file. I suspect that the docker port and the bridge port refer to different config values, however they must be the same for things to work. I changed the bridge port to 9090 because other software uses 8080. But the Docker startup value was still 8080 in the RPi setup. On the UBantu laptop I was careful to use 9090 in both places. Another potential problem is that the raspberry pi Docker file is different from the regular Docker file on gitHub. I am pretty sure I used the regular Docker file when I was first started out with the RPi. Later I tried the correct file, but still it was not working at that point.

So my purpose in writing this is not really to give information on installation points that may be wrong, but to suggest some tools that a person could use to do some trouble shooting.

Another note: sometimes the MQTT-Bridge was sending messages to the Docker website. I think this may have been when things weren't working. This is probably harmless, but may be a privacy concern to some.

wkethman commented 6 years ago

@TheCellMC Did you ever get this working? Figure out what you did wrong? I am having the same issue

TheCellMC commented 6 years ago

I followed these instructions: https://github.com/gilhaz/HomeAssistant_SmarthThings_Homebridge

However, I recently stopped using SmartThings and got an Aeon Labs ZWave stick. I left Smartthings because of the fact that SmartApps can’t run locally. This created delays and meant that my Alarm wouldn’t work without and internet connection.

jjmmss00 commented 6 years ago

Yes I did finally get it to work quite a while ago. I believe the secret is to get experience with the individual pieces so that you can troubleshoot the communication problems. I would recommend starting with the mosquitto MQTT. There are some utilities out there (some can run on my iPad) that can manually send and receive messages. Make sure your HA setup is sending out and receiving the verification messages when you switch something.

I would note that I have stopped using the raspberry pi as it started to have some reliability problems (especially with the flash). I now use an Intel nuc running UBuntu, and I have been much more happy with that.