MQTT Bridge [device + app]

smartapp_misc
mqtt

(Mike Coscia) #367

Okay, some minor progress. I changed the SmartThingsBridge Broker Host to the IP address of my smartthings hub. I also changed the login and password to just “”. I am now seeing events being pushed to home assistant in the logs of my smartthings hub…

[ccc8fef1-9945-4579-87db-0d3b8fefe9dc](https://graph.api.smartthings.com/ide/logs#ccc8fef1-9945-4579-87db-0d3b8fefe9dc) 7:54:52 PM: debug Sending '{"path":"/push","body":{"name":"DR Lights","value":"off","type":"switch"}}' to device

[ccc8fef1-9945-4579-87db-0d3b8fefe9dc](https://graph.api.smartthings.com/ide/logs#ccc8fef1-9945-4579-87db-0d3b8fefe9dc) 7:54:51 PM: debug Sending '{"path":"/push","body":{"name":"DR Lights","value":"on","type":"switch"}}' to device

[ccc8fef1-9945-4579-87db-0d3b8fefe9dc](https://graph.api.smartthings.com/ide/logs#ccc8fef1-9945-4579-87db-0d3b8fefe9dc) 7:54:51 PM: debug Sending '{"path":"/push","body":{"name":"DR Lights","value":"on","type":"switch"}}' to device

So, I assume everything is working. But I am not seeing a database file or anything in Home Assitant for me to grab all the subscribed devices from.


(Amauri Viguera) #368

Yeah that doesn’t sound right… the IP of the ST hub doesn’t belong anywhere. :slight_smile:

The bridge device in ST should be configured to have the MAC and IP of the broker, along with the port.

The bridge itself should be configured with the IP and port of the broker, and the same port as the bridge device.

So if your broker is on 10.10.10.10 port 1883, your bridge would be set up with that info, and say listen on port 2080. Assuming that the bridge and the broker are on the same device (they don’t have to, but they can be), then the bridge would be configured to point to 10.10.10.10 on port 2080, with the MAC of that machine.


(Mike Coscia) #369

I think I am getting hung up on the terminology, in other words which device is responsible for what part of the chain. This is how each device is configured…

SmartThings Hub
MQTT Bridge Device
IP - IP of Home Assistant Hub
MAC - Adress of Home Assistant Hub
Port - 2080

Home Assistant Hub (Raspberry PI w/Hassio)
SmartThingsBridge Add-on

    {
      "broker_host": "172.17.0.1",
      "broker_port": 1883,
      "preface": "smartthings",
      "state_suffix": "state",
      "command_suffix": "cmd",
      "login": "",
      "password": "",
      "bridge_port": 2080
    }

Logs are showing this…

starting version 3.2.2
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://172.17.0.1:1883
events.js:160
throw er; // Unhandled ‘error’ event
^
Error: Connection refused: Not authorized
at MqttClient._handleConnack (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/mqtt/lib/client.js:735:9)
at MqttClient._handlePacket (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/mqtt/lib/client.js:296:12)
at process (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/mqtt/lib/client.js:238:12)
at Writable.writable._write (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/mqtt/lib/client.js:248:5)
at doWrite (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at Writable.write (/usr/lib/node_modules/smartthings-mqtt-bridge/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at Socket.ondata (_stream_readable.js:555:20)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)

Mosquitto Broker Add-On

    {
      "logins": [],
      "anonymous": false,
      "customize": {
        "active": false,
        "folder": "mosquitto"
      },
      "certfile": "fullchain.pem",
      "keyfile": "privkey.pem"
    }

Configuration.yaml

mqtt:
broker: localhost
discovery: true
discovery_prefix: smartthings


(Amauri Viguera) #370

Plus the SmartApp, right? :slight_smile:

And depending on what you’re using, you might not be able to use localhost for the broker. If you’re using the hass.io image or docker, you might need to specifically reference the IP on the box, because of the networking limitations of the container.

And looking at the broker, you can’t have anonymous set to false and then no logins… that’s not right… :slight_smile: Either create the logins and specify that or enable anonymous logins.

EDIT:

Yeah this here tells the tale:

The bridge can’t connect to the broker because of an authorization issue. Either create the logins or enable anonymous and at least that problem should go away :slight_smile:


(Mike Coscia) #371

Yeah, I have the ST Smart App running too…lol. I changed local host to the IP address of my Raspberry Pi running Home Assistant and anonymous to true. Switched a few lights on and off…I think it might be working :slight_smile:.

SmartThingsBridge Logs

starting version 3.2.2
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://172.17.0.1:1883
info: Configuring autosave
info: Configuring API
info: Listening at http://localhost:2080
info: Incoming message from SmartThings: smartthings/DR Lights/switch/state = on
info: Incoming message from SmartThings: smartthings/DR Lights/switch/state = off

MQTT Broker Log

[INFO] Setup mosquitto configuration
[INFO] No local user available
[INFO] Initialize Hass.io Add-on services
[INFO] Initialize Home Assistant discovery
[INFO] Start Mosquitto daemon
1548972081: mosquitto version 1.4.15 (build date 2018-03-04 15:35:59+0000) starting
1548972081: Config loaded from /etc/mosquitto.conf.
1548972081: *** auth-plug: startup
1548972081: ** Configured order: http
1548972081: Opening ipv4 listen socket on port 1883.
1548972081: Opening ipv6 listen socket on port 1883.
1548972081: Opening websockets listen socket on port 1884.
1548972081: Opening ipv4 listen socket on port 8883.
1548972081: Opening ipv6 listen socket on port 8883.
1548972081: Opening websockets listen socket on port 8884.
1548972081: Warning: Mosquitto should not be run as root/administrator.
1548972113: New connection from 172.30.32.1 on port 1883.
1548972113: New client connected from 172.30.32.1 as mqttjs_xxxxxxxx (c1, k10).
1548972142: New connection from xxx.xxx.xxx.150 on port 1883.
1548972142: New client connected from xxxx.xxx.xxx.150 as 5324c300-78b0-48b4-b8ae-c86ba6831a63 (c1, k60).

Besides the warning that the MQTT broker should not be run as root/administrator, it looks like its working? I’m at least closer anyway. However, I can’t find the file with all the subscribed devices, it says it listed at /etc/mosquitto.conf., but there is no file by that name in that directory.

BTW, did I say thank you yet? Because seriously…thank you for all the help :slight_smile:!


(Amauri Viguera) #372

Yeah forget about the configuration file… you have your topic right there in the log: smartthings/DR Lights/switch.

What you do is edit the yaml file for the device with the topic information:

switch:
  platform: mqtt
  name: "DR Lights"
  state_topic: "smartthings/DR Lights/switch"
  command_topic: "smartthings/DR Lights/switch"
  brightness_state_topic: "smartthings/DR Lights/switch"
  brightness_command_topic: "smartthings/DR Lights/switch"
  payload_on: "on"
  payload_off: "off"
  retain: true

You’ll probably need to restart the bridge and/or the whole of HA once you get that in there before it shows up.


(Mike Coscia) #373

Just updated to 86.4 and rebooted everything. Got alot more going on in the SmartThingBridge logs, looks like it’s picking up everything I selected in the ST smart app. I am still not seeing any mosquitto file in /etc/mosquitto.conf. In fact, I’m not even seeing it listed in the MQTT Broker logs anymore, but I am seeing a /data/mosquitto.db.. Of course I don’t see any mosquitto.db in that directory either. Although, I am assuming I have everything I need in the SmartThingsBridge logs to add them to the sensor.yaml file. Just don’t understand why those files are not listed where the logs say they are.

SmartThingsBridge Logs

starting version 3.2.2
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://172.17.0.1:1883
info: Configuring autosave
info: Configuring API
info: Listening at http://localhost:2080
info: Saving current state
info: Subscribing to smartthings/Garage Door/door/cmd, smartthings/Contacts/notify/cmd, smartthings/System/notify/cmd, smartthings/DR Lights/switch/cmd, smartthings/Deck Front/Yard Lights/switch/cmd, smartthings/Deck Lights/switch/cmd, smartthings/Deck Side Light/switch/cmd, smartthings/BSMT Lights/switch/cmd, smartthings/BSMT Dog House Light/switch/cmd, smartthings/BSMT Theater Lights/switch/cmd, smartthings/BSMT Storage Lights/switch/cmd, smartthings/FF Hallway Lights/switch/cmd, smartthings/FFBA Fan/Light/switch/cmd, smartthings/FFBA Vanity/switch/cmd, smartthings/Front Porch Light/switch/cmd, smartthings/GB Closet/switch/cmd, smartthings/GB Lights/switch/cmd, smartthings/GB Plug/switch/cmd, smartthings/Gutter Heat/switch/cmd, smartthings/KIT Cabinet Lights/switch/cmd, smartthings/KIT Lights/switch/cmd, smartthings/KIT Table Light/switch/cmd
info: Saving current state
info: Saving current state
info: Subscribing to smartthings/Garage Door/door/cmd, smartthings/Contacts/notify/cmd, smartthings/System/notify/cmd, smartthings/DR Lights/switch/cmd, smartthings/Deck Front/Yard Lights/switch/cmd, smartthings/Deck Lights/switch/cmd, smartthings/Deck Side Light/switch/cmd, smartthings/BSMT Lights/switch/cmd, smartthings/BSMT Dog House Light/switch/cmd, smartthings/BSMT Theater Lights/switch/cmd, smartthings/BSMT Storage Lights/switch/cmd, smartthings/FF Hallway Lights/switch/cmd, smartthings/FFBA Fan/Light/switch/cmd, smartthings/FFBA Vanity/switch/cmd, smartthings/Front Porch Light/switch/cmd, smartthings/GB Closet/switch/cmd, smartthings/GB Lights/switch/cmd, smartthings/GB Plug/switch/cmd, smartthings/Gutter Heat/switch/cmd, smartthings/KIT Cabinet Lights/switch/cmd, smartthings/KIT Lights/switch/cmd, smartthings/KIT Table Light/switch/cmd
info: Saving current state
info: Saving current state
info: Subscribing to smartthings/Garage Door/door/cmd, smartthings/Contacts/notify/cmd, smartthings/System/notify/cmd, smartthings/DR Lights/switch/cmd, smartthings/Deck Front/Yard Lights/switch/cmd, smartthings/Deck Lights/switch/cmd, smartthings/Deck Side Light/switch/cmd, smartthings/BSMT Lights/switch/cmd, smartthings/BSMT Dog House Light/switch/cmd, smartthings/BSMT Theater Lights/switch/cmd, smartthings/BSMT Storage Lights/switch/cmd, smartthings/FF Hallway Lights/switch/cmd, smartthings/FFBA Fan/Light/switch/cmd, smartthings/FFBA Vanity/switch/cmd, smartthings/Front Porch Light/switch/cmd, smartthings/GB Closet/switch/cmd, smartthings/GB Lights/switch/cmd, smartthings/GB Plug/switch/cmd, smartthings/Gutter Heat/switch/cmd, smartthings/KIT Cabinet Lights/switch/cmd, smartthings/KIT Lights/switch/cmd, smartthings/KIT Table Light/switch/cmd
info: Saving current state
info: Saving current state
info: Subscribing to smartthings/Garage Door/door/cmd, smartthings/Contacts/notify/cmd, smartthings/System/notify/cmd, smartthings/DR Lights/switch/cmd, smartthings/Deck Front/Yard Lights/switch/cmd, smartthings/Deck Lights/switch/cmd, smartthings/Deck Side Light/switch/cmd, smartthings/BSMT Lights/switch/cmd, smartthings/BSMT Dog House Light/switch/cmd, smartthings/BSMT Theater Lights/switch/cmd, smartthings/BSMT Storage Lights/switch/cmd, smartthings/FF Hallway Lights/switch/cmd, smartthings/FFBA Fan/Light/switch/cmd, smartthings/FFBA Vanity/switch/cmd, smartthings/Front Porch Light/switch/cmd, smartthings/GB Closet/switch/cmd, smartthings/GB Lights/switch/cmd, smartthings/GB Plug/switch/cmd, smartthings/Gutter Heat/switch/cmd, smartthings/KIT Cabinet Lights/switch/cmd, smartthings/KIT Lights/switch/cmd, smartthings/KIT Table Light/switch/cmd
info: Saving current state
info: Saving current state
info: Subscribing to smartthings/Garage Door/door/cmd, smartthings/Contacts/notify/cmd, smartthings/System/notify/cmd, smartthings/DR Lights/switch/cmd, smartthings/Deck Front/Yard Lights/switch/cmd, smartthings/Deck Lights/switch/cmd, smartthings/Deck Side Light/switch/cmd, smartthings/BSMT Lights/switch/cmd, smartthings/BSMT Dog House Light/switch/cmd, smartthings/BSMT Theater Lights/switch/cmd, smartthings/BSMT Storage Lights/switch/cmd, smartthings/FF Hallway Lights/switch/cmd, smartthings/FFBA Fan/Light/switch/cmd, smartthings/FFBA Vanity/switch/cmd, smartthings/Front Porch Light/switch/cmd, smartthings/GB Closet/switch/cmd, smartthings/GB Lights/switch/cmd, smartthings/GB Plug/switch/cmd, smartthings/Gutter Heat/switch/cmd, smartthings/KIT Cabinet Lights/switch/cmd, smartthings/KIT Lights/switch/cmd, smartthings/KIT Table Light/switch/cmd
info: Saving current state
info: Incoming message from SmartThings: smartthings/Front Porch Light/switch/state = on
info: Incoming message from SmartThings: smartthings/Deck Front/Yard Lights/switch/state = on
info: Incoming message from SmartThings: smartthings/Deck Lights/switch/state = on
info: Incoming message from SmartThings: smartthings/Front Porch Light/switch/state = off
info: Incoming message from SmartThings: smartthings/KIT Table Light/switch/state = on
info: Saving current state
info: Subscribing to smartthings/Garage Door/door/cmd, smartthings/Contacts/notify/cmd, smartthings/System/notify/cmd, smartthings/DR Lights/switch/cmd, smartthings/Deck Front/Yard Lights/switch/cmd, smartthings/Deck Lights/switch/cmd, smartthings/Deck Side Light/switch/cmd, smartthings/BSMT Lights/switch/cmd, smartthings/BSMT Dog House Light/switch/cmd, smartthings/BSMT Theater Lights/switch/cmd, smartthings/BSMT Storage Lights/switch/cmd, smartthings/FF Hallway Lights/switch/cmd, smartthings/FFBA Fan/Light/switch/cmd, smartthings/FFBA Vanity/switch/cmd, smartthings/Front Porch Light/switch/cmd, smartthings/GB Closet/switch/cmd, smartthings/GB Lights/switch/cmd, smartthings/GB Plug/switch/cmd, smartthings/Gutter Heat/switch/cmd, smartthings/KIT Cabinet Lights/switch/cmd, smartthings/KIT Lights/switch/cmd, smartthings/KIT Table Light/switch/cmd
info: Incoming message from SmartThings: smartthings/Deck Lights/switch/state = off
info: Incoming message from SmartThings: smartthings/Deck Front/Yard Lights/switch/state = off

MQTT Broker Logs

1548972113: New connection from 172.30.32.1 on port 1883.
1548972113: New client connected from 172.30.32.1 as xxxxxx (c1, k10).
1548972142: New connection from xxx.xxx.xxx.150 on port 1883.
1548972142: New client connected from xxx.xxx.xxx.150 as xxxxxx(c1, k60).
1548973882: Saving in-memory database to /data/mosquitto.db.
1548975683: Saving in-memory database to /data/mosquitto.db.
1548976354: Client xxxxxx disconnected.
1548976419: New connection from xxx.xxx.xxx.150 on port 1883.
1548976419: New client connected from xxx.xxx.xxx.150 as xxxxxxx (c1, k60).
1548977484: Saving in-memory database to /data/mosquitto.db.


(Amauri Viguera) #374

Yeah the broker logs are gonna be slim unless you change the options, but if things seem to be working then you can relax?

This whole thing gives you a new appreciation for the easy stuff that you just plug in and click a couple of times. :slight_smile:


(Mike Coscia) #375

Lol, yeah at least it appears to be running as it should. I should be able to tweak and experiment with things now. I’ll start adding some sensors and switches to my yaml files this weekend. Thanks again for everything!


(Amauri Viguera) #376

Ok so now that I had a chance to look at my configuration, I see that the mqtt yaml entry I posted is not right… I’m using /state and /cmd:

- platform: mqtt
  name: "Garage Light"
  state_topic: "smartthings/Garage Light/switch/state"
  command_topic: "smartthings/Garage Light/switch/cmd"
  payload_on: "on"
  payload_off: "off"
  retain: true

And this is what my groups.yaml using that switch:

default_view:
  name: Home
  view: yes
  entities:
    - group.people
    - group.weather
    - group.office

garage:
  name: Garage
  view: yes
  entities:
    - group.garage_lights

people:
  name: People
  entities:
    - device_tracker.pixel_2_xl

weather:
  name: Weather
  entities:
    - sensor.yr_symbol
    - sun.sun

garage_lights:
  name: Garage Light
  entities:
    - switch.garage_light

(Scott Bronder) #377

I have had Mosquito and the MQTT bridge running on a Linux server I have. I started to move this over to a VM running under Virtual Box on a Windows Server 2016 box and have some issues. Mosquito is just fine and I can send an receive message just fine. I am sort of assuming the bridge is also OK because when I add devices from the smart app and then select this new bridge the smart app saves and I see the logs on the ST site.

However.

My mqtt-bridge logs never show anything nor does mosquito. On my physical server I always see some action when i change the devices I want to forward on to the mqtt-bridge.

I am using the MAC address from the Windows 2016 server to configure the device and I’m at a bit of a loss. Anyone else get the bridge/mosquito working successfully running on a virtual?


(Dmoses1969) #378

I was having a lot of trouble figuring out SmartThings Bridge and Mosquitto broker. I ran across this program last week and it really helped me as far as being able to see what each device was seeing/sending.


(Carlos Ravelo) #379

Making an HA exporter from the bridge would be a great addition. Maybe it can be done like a plug-in to the bridge since not everyone uses HA. I’m curious why use HA and smartthings? Are you using the hub a safe zwave/zigbee antena basically?


(Carlos Ravelo) #380

Use the Mac address from the VM. I had it running on xen server on a Fedora VM before.


(Mike Coscia) #381

So, I think I finally have the bridge and broker working well. I had a little issue with retain set to true (lights randomly turning off), but I set it to false and its to be working okay for now. My question is the difference between switches and lights. I am mostly using leviton z-wave switches. I enabled them under “switch” in the SmartThingsBridge App and they work fine in Home Assistant. I also have a few dimmers and fan controllers, they worked fine as switches but I was not getting the dim function. I put them under “switch level” category instead. The brightness feature was available, but the lights are not turning on. This is how I set them up in the yaml file…

- platform: mqtt
  name: "Office Lights"
  state_topic: "smartthings/OFC Lights/level/state"
  command_topic: "smartthings/OFC Lights/level/cmd"
  brightness_state_topic: "smartthings/OFC Lights/level/state"
  brightness_command_topic: "smartthings/OFC Lights/level/cmd"
  brightness_scale: 100
  payload_on: "on"
  payload_off: "off"
  retain: false

Is there something I am missing?


(Ulf Thomas) #382

I came across this setup and I have gotten everything up except for the ST app, and it is driving me crazy. :stuck_out_tongue:

When I try to add the app from the ST client I only get a spinning wheel and then it just stops. When I go back and list my installed apps the MQ app is there but I cannot access it. I then have to remove it from the web gui. I have removed device, dth and app - rebooted st and then readded. No luck.

Nothing is logged in ST either.

Any pointers?

//UlfThomas


(Peter Galbavy) #383

A switch will drive changes, while a light will report on state it is changed to - at least that’s how I assume it works.


(Davin K Dameron) #384

I’m having a heck of a time with this. I can’t add any devices to the smart app as when I click save, it just spins for a while and then tells me an error occurred. I also can’t delete the smart app. Same error. I can’t even delete it from the Ide. I get 500 error there. Ugh.


(Mike Coscia) #385

So should I have the dimmers under “switch” instead of “switch level”. If I do, how do I get the dim function working? What about fan controllers?