Integration Solutions using MQTT

Gotcha, I’ll try it!

Thanks for confirm!

Works again!

1 Like

Sorry for the confusion guys, I probably wasn’t clear enough in my earlier post.

What I should have said more clearly is that existing devices will continue to operate normally with the driver update. But if you want to create new devices, you’ll need to delete and recreate/reconfigure the MQTT Device Creator device via Add device / Scan for nearby devices.

I’ve made this addressable led lamp with arduino and I would like to take it out of arduino IoT cloud (subscription) and control it with smartthings.

I have started testing the MQTT humidity device.

Zigbee humidity measurement from SmartThings to MQTT broker is operating. Humidity measurement is updated every time the measurement value changes in SmartThings’ hub. This is implemented using Rules API.
Also periodic updates are possible.

Rules API for Zigbee to MQTT sending (when Zigbee humidity measurement changes):

{
  "name": "Humidity Changes - MQTT",
  "actions": [
    {
      "if": {
		"not": {
			"equals": {
			"left": {
            "device": {
              "devices": [
                "id zigbee device"
				],
				"component": "main",
				"capability": "relativeHumidityMeasurement",
				"attribute": "humidity"
				}
			},
			"right": {
            "device": {
              "devices": [
                "id mqtt device"
				],
				"component": "main",
				"capability": "relativeHumidityMeasurement",
				"attribute": "humidity"
				}			
			}
			}
        },
        "then": [
          {
            "command": {
              "devices": [
                "id mqtt device"
              ],
              "commands": [
                {
                  "component": "main",
                  "capability": "partyvoice23922.vhumidityset",
                  "command": "setvHumidity",
                  "arguments": [
                    {
                      "device": {
                        "devices": [
                          "id zigbee device"
                        ],
                        "component": "main",
                        "capability": "relativeHumidityMeasurement",
                        "attribute": "humidity"
                      }
                    }
                  ]
                }
              ]
            }
          }
        ]
	}
	}
	]
}

Rules API for Zigbee to MQTT sending (periodic updates):

{
  "name": "Humidity Every 10 min - MQTT",
  "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 10
                    },
                    "unit": "Minute"
                },
			  "actions": [
						 {
						"command": {
						  "devices": [
							"id mqtt device"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "partyvoice23922.vhumidityset",
							  "command": "setvHumidity",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee device"
									],
									"component": "main",
									"capability": "relativeHumidityMeasurement",
									"attribute": "humidity"
								  }
								}
							  ]
							}
						  ]
						}
					  }
					]
	         }
	     }
	]
}

Copy rule and just change device ids. Don’t change anything else.

1 Like

Awesome! That’s a smart way to construct the Rule :+1:t3:

My Raspberry Pi is publishing these MQTT messages and I want to create a routine to do something when it receives the message.

I have three of your MQTT drivers installed (MQTT Handler V1, MQTT Devices V1.1, and MQTT Test Driver 1)
but I can’t figure out how to do what I want.

I’ve included two screenshots of the configuration on the MQTT Devices V1.1 driver.

wptracy@wptracy:~mosquitto_sub -h 10.0.0.3 -t # -d-d
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0, Options: 0x00)
Client (null) received SUBACK
Subscribed (mid: 1): 0
Client (null) received PUBLISH (d0, q0, r0, m0, ‘monitor/Rpi400/status’, … (6 bytes))
online
Client (null) received PUBLISH (d0, q0, r0, m0, ‘monitor/Rpi400/status’, … (6 bytes))
online
Client (null) received PUBLISH (d0, q0, r0, m0, ‘monitor/Rpi400/pat_tracy_samsung’, … (227 bytes))
{“id”:“00:00:00:00:00”,“confidence”:“100”,“name”:“Pat Tracy Samsung”,“manufacturer”:“Samsung Electronics CoLtd”,“type”:“KNOWN_MAC”,“retained”:“false”,“timestamp”:“Sun Jan 08 2023 09:57:27 GMT-0700 (MST)”,“version”:“0.2.200”}
online
Client (null) received PUBLISH (d0, q0, r0, m0, ‘monitor/Rpi400/pat_tracy_iphone’, … (210 bytes))
{“id”:“00:00:00:00:00”,“confidence”:“100”,“name”:“Pat Tracy iPhone”,“manufacturer”:“Apple Inc”,“type”:“KNOWN_MAC”,“retained”:“false”,“timestamp”:“Sun Jan 08 2023 09:57:39 GMT-0700 (MST)”,“version”:“0.2.200”}
Client (null) sending PINGREQ
Client (null) received PINGRESP


I’m not positive I’m reading your MQTT trace correctly, but it looks like there are two different kinds of messages being published.

  • One is a simple text message of "online’.
  • Another is a JSON-formatted object with various key/value items.

So the question would be what field are you wanting to trigger off of, and what action do you want to take.

I’m guessing by the data this is a status of your iphone presence. So one thing you could do is use the HTTP Devices driver and create a virtual presence device. Then you could configure that device to go into ‘present’ state when the string ‘online’ is received.

If you are trying to key off of something in the JSON-formatted messages, you need to set the “Expected Message Format” device Setting value to ‘JSON’. Then you could base the ‘present’ and ‘not present’ state off of one of the key-values in the JSON message. For example, if you are using the ‘confidence’ field, then your PRESENT value setting would be ‘confidence’, because that’s the key of the value you want.

Never mind. I got it subscribed by configuring the Device creator with the Broker.




Like this, in the screenshot?

When I try to refresh, I get a Refresh requested message in logcat, below, but the Driver Status shows Not Subscribed.

How would it know where the broker is. Or does that matter.


2023-01-08T22:22:23.770217280+00:00 TRACE MQTT Devices V1.1 Received event with handler capability
2023-01-08T22:22:23.775895072+00:00 INFO MQTT Devices V1.1 <Device: 91037e3d-6c9a-4611-a609-5c99f7d4fa17 (MQTT Switch)> received command: {“args”:{},“capability”:“partyvoice23922.refresh”,“command”:“push”,“component”:“main”,“positional_args”:{}}
2023-01-08T22:22:23.779458155+00:00 TRACE MQTT Devices V1.1 Found CapabilityCommandDispatcher handler in MQTT Devices
2023-01-08T22:22:23.782494072+00:00 INFO MQTT Devices V1.1 Refresh requested
2023-01-08T22:22:23.827190405+00:00 DEBUG MQTT Devices V1.1 MQTT Switch device thread event handled

So is it working as you expect now?

Yes, It works great. But I’m still testing, before I post what I did.

Thanks for the great drivers.

1 Like

Thanks @TAustin, for instructions on how to configure your MQTT Devices V1.1 driver.

I got it configured and working to monitor MQTT messages from Andrew J Freyer’s Raspberry Pi blue-tooth presence App

I configured the device as a switch to trigger two rules when iPhone presence is Away and Home.

In the rules, I call your google sheets app via your Webrequestor app to log the events in google sheets.

For viewers wishing to create the Raspberry Pi blue-tooth presence device and to monitor and record events, I’ve added the following screenshots.







1 Like

Great project; thanks for sharing. What has been your experience so far with the Bluetooth presence app?

The app was working, now it stops scanning for the presence of the iphone and samsung.

I had it installed on a Rpi400 running ubuntu. Now I’ve installed it on Rpi 4 4G. It just now detected that the samsung phone has departed (confidence 0). It took 6 minutes to scan for departures.

Andrew Freyer wrote the installation procedure and app for a $15 Pi Zero. Pre-orders sold out 2 years ago.

I pulled the samsung phone out of the Faraday Bag a few minutes ago. It detected presence 12 minutes later.

I’ll use the verbose debug option next to see if it
reveals anything.

[-] 0.2.200 09-01-2023 10:06:21 AM [CMD-MQTT] monitor/Rpi400/pat_tracy_samsung { … confidence : 100 … }
[-] 0.2.200 09-01-2023 10:06:24 AM [CMD-MQTT] monitor/Rpi400/pat_tracy_iphone { … confidence : 100 … }
[-] 0.2.200 09-01-2023 10:06:30 AM [CMD-NAME] 00:00:00:00:00:00 William’s Galaxy S9 Samsung Electronics CoLtd
[-] 0.2.200 09-01-2023 10:06:30 AM [CMD-NAME] 00:00:00:00:00:00 iPhone (5) Apple Inc
[-] 0.2.200 09-01-2023 10:12:16 AM [DEL-RAND] RAND 00:00:00:00:00:00 expired after 160 seconds
[-] 0.2.200 09-01-2023 10:12:21 AM [CMD-MQTT] monitor/Rpi400/pat_tracy_samsung { … confidence : 90 … }
[-] 0.2.200 09-01-2023 10:12:33 AM [CMD-MQTT] monitor/Rpi400/pat_tracy_samsung { … confidence : 45 … }
[-] 0.2.200 09-01-2023 10:12:36 AM [CMD-MQTT] monitor/Rpi400/pat_tracy_samsung { … confidence : 0 … }
[-] 0.2.200 09-01-2023 10:12:36 AM [CMD-NAME] 00:00:00:00:00:00 Pat Tracy Samsung Samsung Electronics CoLtd
[-] 0.2.200 09-01-2023 10:14:45 AM [CMD-NAME] 00:00:00:00:00:00 Pat Tracy Samsung Samsung Electronics CoLtd
[-] 0.2.200 09-01-2023 10:16:23 AM [CMD-NAME] 00:00:00:00:00:00 Pat Tracy Samsung Samsung Electronics CoLtd
[-] 0.2.200 09-01-2023 10:16:36 AM [DEL-RAND] RAND 00:00:00:00:00:00 expired after 162 seconds
[-] 0.2.200 09-01-2023 10:18:36 AM [DEL-RAND] RAND 00:00:00:00:00:00 expired after 152 seconds
[-] 0.2.200 09-01-2023 10:16:36 AM [DEL-RAND] RAND 00:00:00:00:00:00 expired after 162 seconds
[-] 0.2.200 09-01-2023 10:18:36 AM [DEL-RAND] RAND 00:00:00:00:00:00 expired after 152 seconds
[-] 0.2.200 09-01-2023 10:24:44 AM [CMD-MQTT] monitor/Rpi400/pat_tracy_samsung { … confidence : 100 … }
[-] 0.2.200 09-01-2023 10:24:45 AM [CMD-NAME] 00:00:00:00:00:00 William’s Galaxy S9 Samsung Electronics CoL

If you are in the mood to experiment, there is another solution that attempts to report phone presence by yours truly: phonepresence/README.md at main · toddaustin07/phonepresence · GitHub

This uses a different approach than the one you are trying. This scans the local ARP table to see if the device IP is present.

Several folks are using it and have said it’s been reliable for them. Your mileage may vary. Android phones work quite reliably, whereas iPhones can sometimes be problematic because of the way they deep sleep. You also have to be careful the way you have some iPhone settings configured to be make sure your phone is reporting and responding to a consistent IP address: Private Wifi Address turned off; Limit IP Address Tracking turned off.

I’ll try this. Thanks. I’ll get back to you.

Both the iPhone and Samsung have reserved IPs in my router and they both show offline status in router. But I know they’re both working on wi-fi.

I’m not too pleased with the Rpi blue-tooth presence app. It’s erratic.

I probable don’t have something configured right.

wptracy@wptracy:~/Downloads/phonepresence-main$ python3 phonetrack.py
Mon Jan 9 12:51:32 2023 Using ‘IP’ to find tracked devices
Mon Jan 9 12:51:32 2023 Pinging
Mon Jan 9 12:51:32 2023 iphone Presence changed to = True
Mon Jan 9 12:51:32 2023 samsung Presence changed to = True
Mon Jan 9 12:51:32 2023 Scan complete
Mon Jan 9 12:51:44 2023 Pinging
Mon Jan 9 12:51:44 2023 Scan complete
Mon Jan 9 12:51:56 2023 Pinging
Mon Jan 9 12:51:56 2023 Scan complete

So far so good. Now you can monitor it to see how accurate it is for you.

You may need to adjust the retry and ping interval parameters in the config file to optimize results.

I’ll also do the smartthings device settings