stjohnjohnson / smartthings-mqtt-bridge

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

cannot get home assistant to control ST outlet thru MQTT bridge #54

Closed iambdud closed 7 years ago

iambdud commented 7 years ago

I need help :(

I cannot get home assistant to control my ST outlet (the only ST device I have). HASS does accurately show the state of the switch (on/off) when I control it through ST. However, when I try to turn it off or on thru HASS, it never makes it to ST.

I followed the guide here. I used Docker for all things and I'm running them individually. I verified that the network ID and MAC address match in the ST IDE. What else am I missing? What can I look at to troubleshoot the issue?

stjohnjohnson commented 7 years ago

Hey @bdudle1, which MAC address did you use? It should be the MAC address of the host, not the docker container. Can you give me an output of ifconfig from your host?

iambdud commented 7 years ago

@stjohnjohnson Thank you so much for the response. I've tried the mac of my linux VM running Ubuntu (and mqtt), the docker container, and the host machine that runs the VM.

Here's a screenshot of my current device config in ST IDE. By the way, do you know why it goes to "inactive" for me after a day? http://i.imgur.com/lSthAwH.png

Here's ifconfig from my ubuntu machine (running hass, mqtt, and mqtt-bridge in docker containers):

docker0   Link encap:Ethernet  HWaddr 02:42:ca:b7:fe:9d
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:caff:feb7:fe9d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4609471 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11170741 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1030144364 (1.0 GB)  TX bytes:16214637086 (16.2 GB)

eth0      Link encap:Ethernet  HWaddr 00:15:5d:0a:05:02
          inet addr:10.10.10.101  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::8aca:ddb8:25:46f0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:35598055 errors:0 dropped:395 overruns:0 frame:0
          TX packets:14978022 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:51334992148 (51.3 GB)  TX bytes:3681848763 (3.6 GB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:64858 errors:0 dropped:0 overruns:0 frame:0
          TX packets:64858 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:5694128 (5.6 MB)  TX bytes:5694128 (5.6 MB)

veth0173673 Link encap:Ethernet  HWaddr ea:1f:aa:0f:af:97
          inet6 addr: fe80::e81f:aaff:fe0f:af97/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12057 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23107 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:873061 (873.0 KB)  TX bytes:1633038 (1.6 MB)

veth8add0e8 Link encap:Ethernet  HWaddr 5e:1a:77:af:6a:74
          inet6 addr: fe80::5c1a:77ff:feaf:6a74/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21342 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14430 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1551803 (1.5 MB)  TX bytes:1224352 (1.2 MB)
stjohnjohnson commented 7 years ago

Interesting, I haven't tested VMs. So the problem is that SmartThings ignores all messages from IP/Mac addresses it doesn't recognize.

Can you show me the contents of events.log from the bridge?

iambdud commented 7 years ago

Is there any log on the Hub or ST that shows incoming/dropped messages?

It's pretty slim because i deleted it recently. The last couple events are from me trying to turn off the switch using hass:

2016-11-18T19:03:23.487Z - info: Starting SmartThings MQTT Bridge - v1.3.3
2016-11-18T19:03:23.489Z - info: Loading configuration
2016-11-18T19:03:23.497Z - info: Loading previous state
2016-11-18T19:03:23.499Z - info: Perfoming configuration migration
2016-11-18T19:03:23.501Z - info: Saving current state
2016-11-18T19:03:23.503Z - info: Connecting to MQTT at mqtt://10.10.10.101
2016-11-18T19:03:23.583Z - info: Configuring autosave
2016-11-18T19:03:23.585Z - info: Configuring API
2016-11-18T19:03:23.719Z - info: Listening at http://localhost:8080
2016-11-18T19:03:23.728Z - info: Incoming message from MQTT: smartthings/MPS Backdoor/acceleration = inactive
2016-11-18T19:03:23.728Z - info: Skipping duplicate message from: smartthings/MPS Backdoor/acceleration = inactive
2016-11-18T19:03:23.729Z - info: Incoming message from MQTT: smartthings/MPS Frontdoor/acceleration = inactive
2016-11-18T19:03:23.729Z - info: Skipping duplicate message from: smartthings/MPS Frontdoor/acceleration = inactive
2016-11-18T19:03:23.729Z - info: Incoming message from MQTT: smartthings/MPS Backdoor/temperature = 73
2016-11-18T19:03:23.729Z - info: Skipping duplicate message from: smartthings/MPS Backdoor/temperature = 73
2016-11-18T19:03:23.729Z - info: Incoming message from MQTT: smartthings/MPS Frontdoor/temperature = 68
2016-11-18T19:03:23.730Z - info: Skipping duplicate message from: smartthings/MPS Frontdoor/temperature = 68
2016-11-18T19:03:23.732Z - info: Incoming message from MQTT: smartthings/Motion Sensor/temperature = 67
2016-11-18T19:03:23.732Z - info: Skipping duplicate message from: smartthings/Motion Sensor/temperature = 67
2016-11-18T19:03:23.739Z - info: Incoming message from MQTT: smartthings/Outlet/power = 0
2016-11-18T19:03:23.740Z - info: Skipping duplicate message from: smartthings/Outlet/power = 0
2016-11-18T19:03:23.740Z - info: Incoming message from MQTT: smartthings/Motion Sensor/motion = inactive
2016-11-18T19:03:23.740Z - info: Skipping duplicate message from: smartthings/Motion Sensor/motion = inactive
2016-11-18T19:03:23.741Z - info: Incoming message from MQTT: smartthings/MPS Backdoor/threeAxis = 31,1055,-3
2016-11-18T19:03:23.741Z - info: Skipping duplicate message from: smartthings/MPS Backdoor/threeAxis = 31,1055,-3
2016-11-18T19:03:23.744Z - info: Incoming message from MQTT: smartthings/MPS Frontdoor/threeAxis = 16,1045,-7
2016-11-18T19:03:23.744Z - info: Skipping duplicate message from: smartthings/MPS Frontdoor/threeAxis = 16,1045,-7
2016-11-18T19:03:23.750Z - info: Incoming message from MQTT: smartthings/Outlet/switch = on
2016-11-18T19:03:23.750Z - info: Skipping duplicate message from: smartthings/Outlet/switch = on
2016-11-18T19:03:23.753Z - info: Incoming message from MQTT: smartthings/MPS Backdoor/contact = closed
2016-11-18T19:03:23.753Z - info: Skipping duplicate message from: smartthings/MPS Backdoor/contact = closed
2016-11-18T19:03:23.755Z - info: Incoming message from MQTT: smartthings/MPS Frontdoor/contact = closed
2016-11-18T19:03:23.755Z - info: Skipping duplicate message from: smartthings/MPS Frontdoor/contact = closed
2016-11-18T19:03:23.765Z - info: Incoming message from MQTT: smartthings/MPS Backdoor/battery = 100
2016-11-18T19:03:23.765Z - info: Skipping duplicate message from: smartthings/MPS Backdoor/battery = 100
2016-11-18T19:03:44.922Z - info: Incoming message from MQTT: smartthings/Outlet/switch = off
2016-11-18T19:03:56.730Z - info: Incoming message from MQTT: smartthings/Outlet/switch = on
stjohnjohnson commented 7 years ago

Click the save button in the Smart App, it will update the device. What do the logs in SmartThings say about the device/smartapp?

iambdud commented 7 years ago

I can see events for the device in the IDE side:

MQTTBridge (Device) Events — displayed | all | from device 
Date    Source  Type    Name    Value   User    Displayed Text  Changed
2016-11-18 2:18:33.946 PM EST
moments ago COMMAND         deviceNotification      deviceNotification({"path":"/subscribe","body":{"devices":{"notify":["Contacts","System"],"acceleration":["MPS Backdoor","MPS ...   true
2016-11-18 2:18:33.723 PM EST
moments ago APP_COMMAND         deviceNotification          true
2016-11-18 2:17:37.629 PM EST
moments ago COMMAND         deviceNotification      deviceNotification({"path":"/subscribe","body":{"devices":{"notify":["Contacts","System"],"acceleration":["MPS Backdoor","MPS ...   true
2016-11-18 2:17:37.393 PM EST
moments ago APP_COMMAND         deviceNotification          true
2016-11-18 2:13:06.603 PM EST
6 minutes ago   COMMAND         deviceNotification      deviceNotification({"path":"/push","body":{"name":"Motion Sensor","value":"68","type":"temperature"}}) command was sent to MQT...   true
2016-11-18 2:13:06.583 PM EST
6 minutes ago   APP_COMMAND         deviceNotification          true
2016-11-18 2:02:37.742 PM EST
16 minutes ago  COMMAND         deviceNotification      deviceNotification({"path":"/subscribe","body":{"devices":{"notify":["Contacts","System"],"acceleration":["MPS Backdoor","MPS ...   true
2016-11-18 2:02:37.472 PM EST
16 minutes ago  APP_COMMAND         deviceNotification          true
2016-11-18 1:48:28.338 PM EST
30 minutes ago  COMMAND         deviceNotification      deviceNotification({"path":"/push","body":{"name":"MPS Frontdoor","value":"inactive","type":"acceleration"}}) command was sent...   true
stjohnjohnson commented 7 years ago

The only thing that could be causing this is SmartThings throwing away the messages because the MAC address that the message comes from does not match what you saved. But I don't know what your computer is sending. :(

iambdud commented 7 years ago

Is there any way to see what it is sending? Could I do some sort of packet capture somehow?

iambdud commented 7 years ago

Also... is it only verifying by MAC address? Or is it also verifying on IP address?

stjohnjohnson commented 7 years ago

I bet you could perform a tcpdump between your VM and the ST Hub. It's all HTTP so it should be easy

iambdud commented 7 years ago

ben@hass:~/hass/hass-config/scripts$ sudo tcpdump dst host 10.10.10.70 -v -e -i eth0 tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes 15:17:02.906418 00:15:5d:0a:05:02 (oui Unknown) > d0:52:a8:35:b7:9c (oui Unknown), ethertype IPv4 (0x0800), length 74: (tos 0x0, ttl 63, id 12299, offset 0, flags [DF], proto TCP (6), length 60) hass.theduds.local.50180 > 10.10.10.70.39500: Flags [S], cksum 0x28ed (incorrect -> 0x9e4a), seq 1615732284, win 29200, options [mss 1460,sackOK,TS val 64302647 ecr 0,nop,wscale 6], length 0 15:17:02.906883 00:15:5d:0a:05:02 (oui Unknown) > d0:52:a8:35:b7:9c (oui Unknown), ethertype IPv4 (0x0800), length 66: (tos 0x0, ttl 63, id 12300, offset 0, flags [DF], proto TCP (6), length 52) hass.theduds.local.50180 > 10.10.10.70.39500: Flags [.], cksum 0x28e5 (incorrect -> 0x3cb0), ack 623111038, win 457, options [nop,nop,TS val 64302647 ecr 26734179], length 0 15:17:02.907092 00:15:5d:0a:05:02 (oui Unknown) > d0:52:a8:35:b7:9c (oui Unknown), ethertype IPv4 (0x0800), length 253: (tos 0x0, ttl 63, id 12301, offset 0, flags [DF], proto TCP (6), length 239) hass.theduds.local.50180 > 10.10.10.70.39500: Flags [P.], cksum 0x29a0 (incorrect -> 0x7dbc), seq 0:187, ack 1, win 457, options [nop,nop,TS val 64302647 ecr 26734179], length 187 15:17:02.940514 00:15:5d:0a:05:02 (oui Unknown) > d0:52:a8:35:b7:9c (oui Unknown), ethertype IPv4 (0x0800), length 66: (tos 0x0, ttl 63, id 12302, offset 0, flags [DF], proto TCP (6), length 52) hass.theduds.local.50180 > 10.10.10.70.39500: Flags [.], cksum 0x28e5 (incorrect -> 0x3bbd), ack 45, win 457, options [nop,nop,TS val 64302655 ecr 26734183], length 0 15:17:02.957221 00:15:5d:0a:05:02 (oui Unknown) > d0:52:a8:35:b7:9c (oui Unknown), ethertype IPv4 (0x0800), length 66: (tos 0x0, ttl 63, id 12303, offset 0, flags [DF], proto TCP (6), length 52) hass.theduds.local.50180 > 10.10.10.70.39500: Flags [F.], cksum 0x28e5 (incorrect -> 0x3bb6), seq 187, ack 46, win 457, options [nop,nop,TS val 64302659 ecr 26734184], length 0 15:17:07.918225 00:15:5d:0a:05:02 (oui Unknown) > d0:52:a8:35:b7:9c (oui Unknown), ethertype ARP (0x0806), length 42: Ethernet (len 6), IPv4 (len 4), Request who-has 10.10.10.70 tell hass.theduds.local, length 28

jonasrosland commented 7 years ago

Hi, just wanted to chime in with a Home Assistant config that works for me, with this I can control and check status of an ST outlet (the one in the current kit):

switch:
  platform: mqtt
  state_topic: "smartthings/Outlet/switch"
  command_topic: "smartthings/Outlet/switch"
  qos: 0
  payload_on: "on"
  payload_off: "off"
  optimistic: false

Might help you troubleshoot some more.

iambdud commented 7 years ago

Thanks. My problem doesn't appear to be HASS config related. It seems that my hub is just ignoring the request. I even did manual requests with mosquitto as well as just straight HTTP posts to the hub and it doesn't do anything.

I'm going to try to send the messages from the host machine and see if that works. If it does, then I should just need to put the host's mac into the settings (but I doubt it will work). The VM must be adding something to the post that ST doesn't like.

@stjohnjohnson Is there any documentation on what the ST hub should be expecting? (I know I could probably find it...)

iambdud commented 7 years ago

just FYI, i had a spare laptop laying around... i setup HASS, MQTT, and MQTT-bridge on it and everything works as expected... So, it's definitely not something I'm doing wrong :)

Ideally, I can figure out how to get this to work on the VM. Any thoughts on how to troubleshoot further? ST doesn't like the request coming from the bridge, but I don't know how to figure out why.

stjohnjohnson commented 7 years ago

Honestly, the documentation for this interaction is missing and/or terrible. I pieced all of this together from forum posts and the tiny amount of docs.

As far as I'm aware, the hub doesn't respond to messages from a mac address not listed as a device.

iambdud commented 7 years ago

Thanks. I really appreciate you trying to help me. I'll keep playing with it and see if I can find anything out.

I'm curious if anyone else is doing this with a VM and having success. If there's an issue, it might be worth mentioning in the project somewhere.

iambdud commented 7 years ago

For what it's worth... I did finally get this working... The only thing I did differently was to restart all 3 components after updating the MAC and IP address on the device in the ST IDE. It is working fine now on my VM.