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

MQTT -> ST Not working #105

Open f00j00 opened 6 years ago

f00j00 commented 6 years ago

I did everythinggggg possible to try to get HASS talk to ST bridge, i ONLY receive notifications from ST, not the other way around, please support

Here are my config:

config.yml

mqtt:
    # Specify your MQTT Broker's hostname or IP address here
    host: mqtt://192.168.2.228
    # 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
   #    username: 
   #     password: 
# Port number to listen on
port: 8098

/etc/mosquitto/mosquitto.conf

pid_file /var/run/mosquitto.pid

user pi
port 1883
persistence_file mosquitto.db

persistence_location /home/pi/mosquitto/
log_dest file /home/pi/mosquitto.log
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true

allow_anonymous true

Logs from mosquitto:

1506469207: Received PUBLISH from mqttc (d0, q1, r0, m68, 'smartthings/Right Stand/switch', ... (3 bytes))
1506469207: Sending PUBACK to mqttc (Mid: 68)
1506469208: Received PUBLISH from mqttc (d0, q1, r0, m69, 'smartthings/Far Right Stand/switch', ... (3 bytes))
1506469208: Sending PUBACK to mqttc (Mid: 69)
1506469209: Received PINGREQ from mqttjs_e4195806
1506469209: Sending PINGRESP to mqttjs_e4195806
1506469219: Received PINGREQ from mqttjs_e4195806
1506469219: Sending PINGRESP to mqttjs_e4195806
1506469221: Received PUBLISH from mqttjs_e4195806 (d0, q0, r1, m0, 'smartthings/Motion Sensor/motion', ... (6 bytes))

mqttc is the client-id for hass

configurations.yaml

mqtt:
  broker: localhost
  keepalive: 60
  port: 9001
  client_id: mqttc
#discovery: true
#discovery_prefix: smartthings

light:
- platform: mqtt
  name: "Far Right Stand"
  brightness_command_topic: "smartthings/Far Right Stand/level/set"
  brightness_state_topic: "smartthings/Far Right Stand/level"
  command_topic: "smartthings/Far Right Stand/switch"
  optimistic: false
  payload_off: "off"
  payload_on: "on"
  qos: 1
  state_topic: "smartthings/Far Right Stand/switch"

- platform: mqtt
  name: "Right Stand"
  brightness_command_topic: "smartthings/Right Stand/level/set"
  brightness_state_topic: "smartthings/Right Stand/level"
  command_topic: "smartthings/Right Stand/switch"
  optimistic: false
  payload_off: "off"
  payload_on: "on"
  qos: 1
  state_topic: "smartthings/Right Stand/switch"

logs from smartthings-bridge:

0|smartthi | info: Listening at http://localhost:8098
0|smartthi | info: Incoming message from SmartThings: smartthings/Motion Sensor/motion = active
0|smartthi | info: Incoming message from SmartThings: smartthings/Motion Sensor/motion = inactive
0|smartthi | info: Starting SmartThings MQTT Bridge - v1.3.4
0|smartthi | info: Loading configuration
0|smartthi | info: Loading previous state
0|smartthi | info: Perfoming configuration migration
0|smartthi | info: Saving current state
0|smartthi | info: Connecting to MQTT at mqtt://192.168.2.228
0|smartthi | info: Configuring autosave
0|smartthi | info: Configuring API
0|smartthi | info: Listening at http://localhost:8098

0|smartthi | info: Incoming message from SmartThings: smartthings/Motion Sensor/motion = active
0|smartthi | info: Incoming message from SmartThings: smartthings/Motion Sensor/motion = inactive
0|smartthi | info: Incoming message from SmartThings: smartthings/Far Right Stand/switch = turningOff
0|smartthi | info: Incoming message from SmartThings: smartthings/Far Right Stand/switch = off
0|smartthi | info: Incoming message from SmartThings: smartthings/Far Right Stand/switch = turningOn
0|smartthi | info: Incoming message from SmartThings: smartthings/Far Right Stand/switch = on
0|smartthi | info: Incoming message from SmartThings: smartthings/Motion Sensor/motion = active
0|smartthi | info: Incoming message from SmartThings: smartthings/Motion Sensor/motion = inactive
0|smartthi | info: Saving current state
0|smartthi | info: Subscribing to smartthings/Bedroom/hue, smartthings/Color Spot/hue, smartthings/Far Right Stand/hue, smartthings/Right Stand/hue, smartthings/Bedroom Home/trackData, smartthings/Bedroom Home (DLNA) Speaker/trackData, smartthings/Chromecast/trackData, smartthings/Chromecast (DLNA) Speaker/trackData, smartthings/PC VLC/trackData, smartthings/Plex Web (Chrome)/trackData, smartthings/Plex Web (Chrome) #2/trackData, smartthings/Plex Web (Chrome) #3/trackData, smartthings/VSX-1121 Speaker/trackData, smartthings/XboxOne/trackData, smartthings/Multipurpose Sensor/acceleration, smartthings/Motion Sensor/temperature, smartthings/Multipurpose Sensor/temperature, smartthings/RBPCommands/temperature, smartthings/Raspberry Pi/temperature, smartthings/Bedroom Home/trackDescription, smartthings/Bedroom Home (DLNA) Speaker/trackDescription, smartthings/Chromecast/trackDescription, smartthings/Chromecast (DLNA) Speaker/trackDescription, smartthings/PC VLC/trackDescription, smartthings/Plex Web (Chrome)/trackDescription, smartthings/Plex Web (Chrome) #2/trackDescription, smartthings/Plex Web (Chrome) #3/trackDescription, smartthings/VSX-1121 Speaker/trackDescription, smartthings/XboxOne/trackDescription, smartthings/Bedroom/level, smartthings/Bedroom Cam/level, smartthings/Color Spot/level, smartthings/Far Right Stand/level, smartthings/Goodbye/level, smartthings/Goodnight ST/level, smartthings/Right Stand/level, smartthings/Right Spot/level, smartthings/My Magic/level, smartthings/Left Spot/level, smartthings/Hello/level, smartthings/Bedroom Home/level, smartthings/Bedroom Home (DLNA) Speaker/level, smartthings/Chromecast/level, smartthings/Chromecast (DLNA) Speaker/level, smartthings/PC VLC/level, smartthings/Plex Web (Chrome)/level, smartthings/Plex Web (Chrome) #2/level, smartthings/Plex Web (Chrome) #3/level, smartthings/VSX-1121 Speaker/level, smartthings/XboxOne/level, smartthings/Power Outlet/power, smartthings/Harmony Hub/activities, smartthings/Arrival Sensor/rssi, smartthings/Motion Sensor/motion, smartthings/Bedroom/colorTemperature, smartthings/Color Spot/colorTemperature, smartthings/Far Right Stand/colorTemperature, smartthings/Right Stand/colorTemperature, smartthings/Bedroom Home/mute, smartthings/Bedroom Home (DLNA) Speaker/mute, smartthings/Chromecast/mute, smartthings/Chromecast (DLNA) Speaker/mute, smartthings/PC VLC/mute, smartthings/Plex Web (Chrome)/mute, smartthings/Plex Web (Chrome) #2/mute, smartthings/Plex Web (Chrome) #3/mute, smartthings/VSX-1121 Speaker/mute, smartthings/XboxOne/mute, smartthings/Multipurpose Sensor/threeAxis, smartthings/Bedroom Home/status, smartthings/Bedroom Home (DLNA) Speaker/status, smartthings/Chromecast/status, smartthings/Chromecast (DLNA) Speaker/status, smartthings/PC VLC/status, smartthings/Plex Web (Chrome)/status, smartthings/Plex Web (Chrome) #2/status, smartthings/Plex Web (Chrome) #3/status, smartthings/VSX-1121 Speaker/status, smartthings/XboxOne/status, smartthings/Bedroom Cam/image, smartthings/Harmony Hub/currentActivity, smartthings/Computer/switch, smartthings/MacMini/switch, smartthings/Party Time/switch, smartthings/22/switch, smartthings/23/switch, smartthings/24/switch, smartthings/25/switch, smartthings/26/switch, smartthings/27/switch, smartthings/Antimatter/switch, smartthings/Bedroom/switch, smartthings/AC/switch, smartthings/Bedroom Cam/switch, smartthings/Bedroom Home/switch, smartthings/Bedroom Home (DLNA) Speaker/switch, smartthings/Byebye [Harmony Activity]/switch, smartthings/Chromecast/switch, smartthings/Color Spot/switch, smartthings/Chromecast (DLNA) Speaker/switch, smartthings/HDMI Switch/switch, smartthings/Far Right Stand/switch, smartthings/Custom group for $lights/switch, smartthings/Computer/switch, smartthings/Good morning [Harmony Activity]/switch, smartthings/Goodbye/switch, smartthings/Goodnight ST/switch, smartthings/Goodnight [Harmony Activity]/switch, smartthings/PInputPS4/switch, smartthings/PInputMacMini/switch, smartthings/PInputChromecast/switch, smartthings/PInputAppleTV/switch, smartthings/PC Activity [Harmony Activity]/switch, smartthings/PC Activity G/switch, smartthings/OSN Hot [Harmony Activity]/switch, smartthings/OSN/switch, smartthings/KHDMI3/switch, smartthings/KHDMISwitch/switch, smartthings/Left Spot/switch, smartthings/MacMini/switch, smartthings/Hello/switch, smartthings/Home cold [Harmony Activity]/switch, smartthings/Home hot [Harmony Activity]/switch, smartthings/Info/switch, smartthings/KHDMI2/switch, smartthings/My Magic/switch, smartthings/PC VLC/switch, smartthings/PInputRBP/switch, smartthings/PInputPC/switch, smartthings/PS4OFF/switch, smartthings/Party Time/switch, smartthings/Pioneer AV Receiver/switch, smartthings/Play PS4 [Harmony Activity]/switch, smartthings/PS4ON/switch, smartthings/PInputXbox/switch, smartthings/Plex Web (Chrome)/switch, smartthings/Plex Web (Chrome) #2/switch, smartthings/Plex Web (Chrome) #3/switch, smartthings/RBPCommands/switch, smartthings/Raspberry Pi/switch, smartthings/Right Spot/switch, smartthings/Power Outlet/switch, smartthings/XboxOne/switch, smartthings/VSX-1121 Speaker/switch, smartthings/VLC Play/switch, smartthings/VLC Pause/switch, smartthings/Turn On Everything/switch, smartthings/TV/switch, smartthings/Right Stand/switch, smartthings/Xbox Control Cold [Harmony Activity]/switch, smartthings/Xbox Control Hot [Harmony Activity]/switch, smartthings/Multipurpose Sensor/contact, smartthings/RBPCommands/contact, smartthings/Raspberry Pi/contact, smartthings/Contacts/notify, smartthings/System/notify, smartthings/Arrival Sensor/battery, smartthings/Motion Sensor/battery, smartthings/Multipurpose Sensor/battery, smartthings/Arrival Sensor/lqi, smartthings/Ahmed's iPhone/presence, smartthings/Arrival Sensor/presence, smartthings/Bedroom/saturation, smartthings/Color Spot/saturation, smartthings/Far Right Stand/saturation, smartthings/Right Stand/saturation, smartthings/Bedroom/color, smartthings/Color Spot/color, smartthings/Far Right Stand/color, smartthings/Right Stand/color

HOWEVER, only ST can talk with HASS, NOT the other way around

I ensured my MAC is inputted for my RBP not docker, i dont use docker, i tried with and without ":"

it NEVER worked, if i turn off or on the light switch from ST , the switcher in HASS is synced...but when i press any switch in HASS it just wont work

f00j00 commented 6 years ago

Man, i am going NUTSSSS to paste PROPER CODE!!!!! WHY DOES the post end up like this!!!!

Damn i HATE code!

I hope you're able to read my shi**!!

stjohnjohnson commented 6 years ago

Use three backticks next time. I fixed your code.

So it looks like the bridge doesn't see the changes being pushed to mqtt. I wouldn't set optimistic to false since you have the same state/command topic. Also, try without qos.

Your brightness topics won't work because they are configured for suffixes but you didn't set suffixes.

Not sure, you can try enabling debug here: https://home-assistant.io/docs/mqtt/logging/

f00j00 commented 6 years ago

Nope, tried without qos, set optimistic to true, nothing worked, here is logs after debug:

pi@raspberrypi:~ $ /srv/homeassistant/homeassistant_venv/bin/python3 /srv/homeassistant/homeassistant_venv/bin/hass -c /home/pi/.homeassistant Config directory: /home/pi/.homeassistant 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=turn_off, domain=homeassistant> 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=turn_on, domain=homeassistant> 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=toggle, domain=homeassistant> 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=stop, domain=homeassistant> 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=restart, domain=homeassistant> 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=check_config, domain=homeassistant> 2017-09-27 08:57:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=reload_core_config, domain=homeassistant> 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=create, domain=persistent_notification> 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: service=dismiss, domain=persistent_notification> 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.loader] Loaded frontend from homeassistant.components.frontend 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.loader] Loaded api from homeassistant.components.api 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.loader] Loaded http from homeassistant.components.http 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.loader] Loaded mqtt from homeassistant.components.mqtt 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.loader] Loaded logger from homeassistant.components.logger 2017-09-27 08:58:00 INFO (MainThread) [homeassistant.setup] Setting up logger 2017-09-27 08:58:11 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: on 2017-09-27 08:58:12 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 08:58:12 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/level: 100 2017-09-27 08:58:12 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/level: 100 2017-09-27 08:58:37 WARNING (Thread-7) [netdisco.ssdp] Found malformed XML at http://192.168.2.152:49155/description0.xml: 2017-09-27 08:58:37 WARNING (Thread-7) [netdisco.ssdp] Found malformed XML at http://192.168.2.152:49155/description2.xml: 2017-09-27 08:58:43 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 2017-09-27 08:58:44 WARNING (Thread-2) [homeassistant.components.light.hue] Connected to Hue at 192.168.2.198 but not registered. 2017-09-27 08:58:57 WARNING (MainThread) [homeassistant.components.remote] Setup of platform harmony is taking over 10 seconds. 2017-09-27 08:58:57 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds. 2017-09-27 08:58:57 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds. 2017-09-27 08:59:40 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: off 2017-09-27 09:02:32 WARNING (Thread-10) [homeassistant.components.mqtt] Disconnected from MQTT (1). Trying to reconnect in 1 s 2017-09-27 09:02:33 WARNING (Thread-10) [homeassistant.components.mqtt] Disconnected from MQTT (1). Trying to reconnect in 2 s 2017-09-27 09:02:35 INFO (Thread-10) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server 2017-09-27 09:02:45 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:02:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: off 2017-09-27 09:02:48 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: off 2017-09-27 09:02:52 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: on 2017-09-27 09:02:54 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: on 2017-09-27 09:02:57 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:03:00 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:04:25 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: off 2017-09-27 09:04:26 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: off 2017-09-27 09:04:29 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:04:31 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:04:34 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: on 2017-09-27 09:04:39 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: off 2017-09-27 09:04:39 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: off 2017-09-27 09:10:00 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: on 2017-09-27 09:10:01 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:10:04 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on 2017-09-27 09:10:23 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: off 2017-09-27 09:10:23 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: off 2017-09-27 09:10:24 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Far Right Stand/switch: on 2017-09-27 09:10:25 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on smartthings/Right Stand/switch: on

rgerrans commented 6 years ago

I'm having similar issues. I tried sending 'on' to a dimmer switch which gave me the following log entry in mqtt-bridge:

0|smartthi | info: Incoming message from MQTT: smartthings/Light_GF_Dining_Wall/switch/set = on
0|smartthi | info: Passing level instead of switch on

So I tried to just send a level instead and here is what I got.

0|smartthi | info: Incoming message from MQTT: smartthings/Light_GF_Dining_Wall/level/set = 50
0|smartthi | info: Skipping level set due to device being off

One side question. Does mqtt-bridge operate locally or is it going out to smarthings.com each time there is a change on either side?

stjohnjohnson commented 6 years ago

@rgerrans that's because inside SmartThings they ignore requests to turn dimmers on/off. Instead you have to send the level you want (like 99 for max brightness). When you send "on" it sends the last saved "level". So it should work.

Also, it works as locally as SmartThings allows. Which is the Hub talks to MQTT bridge over local network. But the Hub is doing all the smart logic in the cloud, so it does talk to smarthings.com.

rgerrans commented 6 years ago

@stjohnhohnson Thanks for the clarification on execution location.

On the dimmer, that makes the log entry related to 'on' make sense. The part I realized I forgot to include in my earlier post is that the physical dimmer isn't turning on when I send that request. I'm just testing Smartthings so am not yet enough familiar with where to find their log files to confirm it's getting the command? Off does work do we are at least 1/2 ways there.

Thanks.