stjohnjohnson / smartthings-mqtt-bridge

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

Unable to push events to Smartthings via mosquito_pub #175

Open johntdyer opened 5 years ago

johntdyer commented 5 years ago

So I have the process running and I can see events in the logs when I invoke the garage door from the smartthings IOS App

Oct 26 09:13:23 ubuntu docker[19266]: info: Subscribing to smartthings/Primary.Garage/contact, smartthings/Primary.Garage/contact, smartthings/Primary.Garage/door, smartthings/Primary.Garage/door, smartthings/Primary.Garage/door, smartthings/Primary.Garage/door, smartthings/Contacts/notify, smartthings/Contacts/notify, smartthings/System/notify, smartthings/System/notify
Oct 25 09:13:23 ubuntu docker[19266]: info: Incoming message from SmartThings: smartthings/Primary Garage/door = closing
Oct 25 09:13:24 ubuntu docker[19266]: info: Incoming message from MQTT: smartthings/Primary Garage/door = closing
Oct 25 09:13:24 ubuntu docker[19266]: info: Skipping duplicate message from: smartthings/Primary Garage/door = closing
Oct 25 09:13:29 ubuntu docker[19266]: info: Incoming message from SmartThings: smartthings/Primary Garage/door = closed
Oct 25 09:13:29 ubuntu docker[19266]: info: Incoming message from MQTT: smartthings/Primary Garage/door = closed
Oct 25 09:13:29 ubuntu docker[19266]: info: Skipping duplicate message from: smartthings/Primary Garage/door = closed
Oct 25 09:13:29 ubuntu docker[19266]: info: Incoming message from SmartThings: smartthings/Primary Garage/contact = closed
Oct 25 09:13:29 ubuntu docker[19266]: info: Incoming message from MQTT: smartthings/Primary Garage/contact = closed
Oct 25 09:13:29 ubuntu docker[19266]: info: Skipping duplicate message from: smartthings/Primary Garage/contact = closed

and if I subscribe to all the topics I see some events when I trigger things from the app

smartthings/Primary Garage/door closing
smartthings/Primary Garage/door closed
smartthings/Primary Garage/contact closed
However if I use mosquito_pub to send an event I am unable to get the door to do anything

Examples

mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/contact" -m open
mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/contact" -m closed
mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/door" -m on
mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/door" -m open
mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/contact" -m open
mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/contact" -m close
mosquitto_pub -u homeassistant -P zzzzz  -h 192.168.100.14 -t "smartthings/Primary Garage/contact" -m closed

Am I missing something fundamental here ? I would think publishing an event to the topic would close or open the door. Thoughts?

code-in-progress commented 5 years ago

You need to add /cmd to your topic.

/state reads the state of the device and /cmd publishes to the device.

So, for your door, it would be smartthings/Primary Garage/contact/state for the contact sensor state and smartthings/Primary Garage/contact/cmd to publish (although, there really isn't much reason to publish to a contact sensor).

johntdyer commented 5 years ago

@code-in-progress - So All I am trying to do is to be able to issue a close to the door via MQTT..... So ho does that look via mosquito_pub

jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxxx  -h 192.168.100.14 -t "smartthings/cmd/Primary.Garage/door" -m "open"
jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxxx  -h 192.168.100.14 -t "smartthings/Primary.Garage/cmd/door" -m "open"
jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxx  -h 192.168.100.14 -t "smartthings/Primary.Garage/door/cmd" -m "open"
jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxx  -h 192.168.100.14 -t "smartthings/Primary.Garage/door/cmd" -m "ON"
jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxx  -h 192.168.100.14 -t "smartthings/Primary.Garage/contact/cmd" -m "closed"
jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxx  -h 192.168.100.14 -t "smartthings/Primary.Garage/contact/cmd" -m "closed"
jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxxx  -h 192.168.100.14 -t "smartthings/Primary.Garage/contact/cmd" -m "closed"
code-in-progress commented 5 years ago

jdyer@ubuntu:~$ mosquitto_pub -u homeassistant -P xxxx -h 192.168.100.14 -t "smartthings/Primary Garage/contact/cmd" -m "closed"

That's the correct one, however, I'm not sure what publishing closed to a contact sensor is going to do as isn't it just a contact sensor?

Let's take it a couple of levels up. What it sounds like you want to do is trigger your garage door to open and/or close via MQTT commands, is that correct? Do you have an automated opener on your garage door? What part does the contact sensor play in that?

johntdyer commented 5 years ago

@code-in-progress - Honestly I am not sure which topic I should be publishing in order to close the door... I am trying contact, door, foo, bar.... I am not sure which one will actually close the Go Control Zwave garage door...

code-in-progress commented 5 years ago

Ahhhh... Ok.

  1. Figure out what your garage door control is named in SmartThings (I'm going to assume it's called Primary Garage).
  2. From there, you want to go into the MQTT bridge setup in your Smart Apps (SmartThings App > Automation > SmartApps > MQTT Bridge (or whatever you named it).
  3. Make sure that the door control is added to the relevant sections (I'm going to guess it isn't a contact sensor, but it could show up as something like Door Control or Garage Door Control).
  4. From there, the topic will be smartthings/[Whatever you named your Go Control Zwave garage door]/door/cmd. The command will now look like : mosquitto_pub -u homeassistant -P xxxx -h 192.168.100.14 -t "smartthings/WHAT YOU NAMED YOUR Go Control Garage Door Opener Goes Here/door/cmd" -m "closed"

What you really should do is read the smart app code: https://github.com/stjohnjohnson/smartthings-mqtt-bridge/blob/master/smartapps/stj/mqtt-bridge.src/mqtt-bridge.groovy as it has every control parameter listed. For door and/or garage door, the command is smartthings/[door name]/door/cmd and the state is smartthings/[door name]/door/state.

Trust me, once you get the hang of what is named what, the /state and /cmd topics become crystal clear. :) It took me a few days to really get the gist of it, but now I have every one of my routines in Node-Red using strictly MQTT back and forth between it and ST.

gcaley commented 4 years ago

So i tested this and it worked when i didnt put /cmd on the end

So for those that come after me, check the smartappgroovy code to ensure you can receive actions for that device type, from mqtt, then do something similar to the following topic and payload

topic: smartthings/Lab PDU/switch payload: on

gcaley commented 4 years ago

Maybe something specific to the MQTT publisher? I was using mqtt-spy