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?

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.