MQTT Bridge [device + app]

I finally decided to track down what’s causing smartthings-mqtt-bridge to not update devices added through the smartapp.

What I found in the logs is the following error gets thrown:

java.lang.NullPointerException: Cannot get property ‘value’ on null object @line 502 (doCall)

I set up a new MQTTBridge SmartApp and one by one went through each option finding those that are causing the problem. I found the following:

  • My wireless tags break Contact Sensors. (Customized Handler)
  • My custom temp/humidity dev handler breaks Switch Level. (Custom Handler) Checked the code and I only have the Switch Level capability defined but the lines that use it are commented out.
  • Echo Dots break Music Player. (Amazon Official)
  • My wireless tags break Presence Sensor (Customized Handler)
  • I can’t add anything to Switch without it breaking (I think my code changes are the problem here as I specifically modified Switch to work with my esp8266 switches running custom Homie code)

Here’s the code that’s causing the issue. I seem to remember seeing a pull request related to this. I need to go back and check. I haven’t yet tried the latest SmartApp code as I’ve added a lot to the code for it to work with my various custom devices and apps. I’m going to do that now as a new smartapp and we’ll see what happens.

Line 502:

settings[key].each {device -> attributes[attribute].push(device.displayName)

I think this is the line that’s causing the problem. I haven’t dug into why value is null since everything looks good to me with the devices that are an issue.

value: device.currentState(attribute).value

Code related to line 502:

// Update the bridge"s subscription
def updateSubscription() {
    def attributes = [
        notify: ["Contacts", "System"]
    ]
    CAPABILITY_MAP.each { key, capability ->
        capability["attributes"].each { attribute ->
            if (!attributes.containsKey(attribute)) {
                attributes[attribute] = []
            }
            settings[key].each {device -> attributes[attribute].push(device.displayName)
                // Send current value
            	inputHandler([
                    displayName: device.displayName,
                    value: device.currentState(attribute).value,
                    name: attribute
                ])
            }
        }
    }
    def json = new groovy.json.JsonOutput().toJson([
        path: "/subscribe",
        body: [
            devices: attributes
        ]
    ])

    log.debug "Updating subscription: ${json}"
    bridge.deviceNotification(json)
}

I’m not sure why it needs the current value to subscribe so I just commented out

value: device.currentState(attribute).value,

I have numerous virtual devices that can certainly have null values at times. There’s no reason to get/check these values during subscription that I can find.

After commenting out that line, I was able to add devices with no issues.

(My first post to this forum. If I’m doing it wrong, please tell me.)
My goal is to press a SmartThings Button and have it toggle a GE SmartBulb currently controlled by Google Home.

tl;dr: The button always registers a pressed event as seen on the SmartThings App on my phone. That same event does not always make it to my MQTT broker. Something seems to be blocking it before it reaches the MQTT Bridge SmartApp installed in the SmartThings IDE.

More details:

I have an MQTT Broker running (mosquitto on a Raspberry Pi 3). I also wrote a quick/dirty MQTT client that subscribes to smartthings/Basement stairs light switch/button and uses Google Assistant SDK to toggle the bulb. That side of things works perfectly. Every time I publish, the bulb toggles. Now to wire up the SmartThings Button.

I’ve successfully installed

  • stjohnjohnson/smartthings-mqtt-bridge (i.e. a docker container running this image)
  • SmartThings IDE:
    ** stj : MQTT Bridge in Device Handlers
    ** MQTT Device in Devices (as type MQTT Bridge)
    ** stj : MQTT Bridge in Smart Apps
    Configured everything in SmartThings Classic on my phone.

I say “successfully” because the first time I pushed the button the bulb toggled. Woo hoo!

But - it only works intermittently. Sometimes it works 10x in a row. Sometimes it fails for 3 or 5 times before working. Sometimes it works every other time. Whether or not the bulb toggles, it always shows the event in the SmartThings app on my phone - every time.

By tailing the log, whenever smartthings-mqtt-bridge gets a message, it successfully publishes to MQTT and the bulb toggles. Each event logs the following line:

2020-01-14T03:20:47.838Z - info: HTTP POST /push statusCode=200, url=/push, accept=*/*, user-agent=Linux UPnP/1.0 SmartThings, host=192.168.1.88:8080, content-type=application/json, content-length=72, method=POST, httpVersion=1.1, originalUrl=/push, , responseTime=0

Similarly, when I watch the log in SmartThings IDE under My Apps->MQTT Bridge, each event logs these lines:

bc4f4a29-c333-42d5-80a4-b6c34102773b 10:22:18 PM: debug Parsing 'index:8C, mac:001517669E5C, ip:C0A80158, port:1F90, requestId:ff42738e-29c6-4e50-8c4e-3c88f51b9147, headers:SFRUUC8xLjEgMjAwIE9LDQpYLVBvd2VyZWQtQnk6IEV4cHJlc3MNCkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA0KQ29udGVudC1MZW5ndGg6IDE1DQpFVGFnOiBXLyJmLXYvWTFKdXNDaFR4clFVelB0TkFLeWNvb09UQSINCkRhdGU6IFR1ZSwgMTQgSmFuIDIwMjAgMDM6MjI6MTggR01UDQpDb25uZWN0aW9uOiBrZWVwLWFsaXZl, body:eyJzdGF0dXMiOiJPSyJ9'
bc4f4a29-c333-42d5-80a4-b6c34102773b 10:22:18 PM: debug Parsing 'index:8C, mac:001517669E5C, ip:C0A80158, port:1F90, requestId:ff42738e-29c6-4e50-8c4e-3c88f51b9147, headers:SFRUUC8xLjEgMjAwIE9LDQpYLVBvd2VyZWQtQnk6IEV4cHJlc3MNCkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA0KQ29udGVudC1MZW5ndGg6IDE1DQpFVGFnOiBXLyJmLXYvWTFKdXNDaFR4clFVelB0TkFLeWNvb09UQSINCkRhdGU6IFR1ZSwgMTQgSmFuIDIwMjAgMDM6MjI6MTggR01UDQpDb25uZWN0aW9uOiBrZWVwLWFsaXZl, body:eyJzdGF0dXMiOiJPSyJ9'
0efaf6ae-f51e-4cb0-bf7b-509b96f7f3f8 10:22:18 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Basement stairs light switch","value":"pushed","type":"button"}}
bc4f4a29-c333-42d5-80a4-b6c34102773b 10:22:18 PM: debug Sending '{"path":"/push","body":{"name":"Basement stairs light switch","value":"pushed","type":"button"}}' to device
bc4f4a29-c333-42d5-80a4-b6c34102773b 10:22:18 PM: debug Sending '{"path":"/push","body":{"name":"Basement stairs light switch","value":"pushed","type":"button"}}' to device

I’m not sure where else to look. Can you help me?

So I’m playing with this. Having messed around with it I’m now ready to start over and re-install clean.

Only

The Device handler, the Device and the SmartApp have become all pervasive and simply refuse to be deleted by SmartThings. Either via the app on the phone or the API pages

Error

500: Internal Server Error
URI
/device/update
Reference Id
46bc1b68-5dc9-4246-9619-6299f3f80c28
Date
Wed Feb 05 15:22:28 UTC 2020

Don’t suppose anyone else has had this problem?

Ah I"m having the same issue. Did you ever fix this?

I was annoyingly fighting with multiple aspects of this as well. Hope this helps someone. I found 2 major issues:

Issue: Failed installs / uninstalls
Cause: The Device Network Id on the bridge device in smartthings IDE
It seems to ignore anything I put in here and creates its own. Leave the live logging running in another window the whole time you are doing the install. During setup it should make a statement about assigning a Network Device Id. It was not the Id I assigned. Copy and paste the auto-assigned Id into your device. Not fixing this before adding/activating the smartapp through the ST classic app initially led me to multiple failed and stuck installs. I could not delete them until the next day. I’m guessing server cleanup or releasing locked resources after a long enough timeout is what eventually allowed me to delete/uninstall. After the failed uninstall I didn’t do anything but wait until the next morning and try to delete/uninstall again.

Issue: Smartthings talks to bridge, but does not accept commands from bridge
Cause: Mac address property set wrong on bridge device in ST IDE
Not sure exact how it decides which mac it needs. I am using Wifi to connect, but it needed my eth0 mac instead. I think it may have something to do with the mac being sent to the bridge for use. I believe the bridge uses an internal route through eth0 localhost to get to the broker instead of using the Wifi network device. Just a guess. This aligns with people needing to use the docker mac as that would be the internal path from the bridge to the broker. To clarify, I believe it needs the mac address of the device targeted by the bridge to communicate with the broker.

Is anyone interested in a slight rewrite of this? I think it’s better to just use the “JSON Complete API” smartapp. No device handler needed, only need a similar nodejs app.

1 Like

Is anyone interested in reworking the bridge code so that it parse the messages from smartthings and makes them workable with discovery function of HA Mqtt?

I’m a novice/amateur at code and think I could do it but it would probably take me months to figure it out. Someone more knowledgeable would be a big help.

Hi All,

I tried to get this to work and got somewhere…but not completely where I need to be:

  • Installed bridge on Raspberry PI (same where my Broker is running)
  • Installed Device handler and created device succesfully
  • Installed Smartapps and created smart app succesfully (input = a button)

When I press the button, I see the event in my MQTT Device (from the Device handler). I also see the event in the log of my Bridge. However, in MQTT fx which is connected to the same broker, I dont see any traffic passing by (I’m supossed to see the event of pressing the button right?).

Hopefully someone can assist me. I am very new at this.

Thanks

How do I make this work between MQTT Alarm Panel and Smartthings? I have the SmartApp, Device Handler and Mosquitto running. Does WebCore need to be in the mix?

Does anyone know if this still works post migration to the new app?
I just got the dreaded upgrade notification and heavily rely on this, so the last thing that I want to do is migrate before knowing if it’s going to mess up a bunch of my automations.