Triggering on payload contents

Posted on
Sat Apr 01, 2023 10:04 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Triggering on payload contents

I wish to monitor my wireless sprinkler system to be sure no watering events are missed. The key to this is the sprinkler controller that sends a MQTT message at the start and end of each session. I would like to trigger on the end-of-session messages and use them to reset a timer. Then, if the timer ever runs down, I will know I have a problem.

The question is, how do I trigger on an MQTT payload rather than the topic? For example, here is a typical end of session message:
Code: Select all
cm/LinkTap2/up/0C928728004B1200 {"cmd":7,"gw_id":"27D88728004B1200","dev_stat":{"dev_id":"0C928728004B1200","plan_mode":0,"plan_sn":0,"is_rf_linked":true,"is_flm_plugin":true,"is_fall":false,"is_broken":false,"is_cutoff":false,"is_leak":false,"is_clog":false,"signal":83,"battery":100,"child_lock":0,"is_manual_mode":false,"is_watering":false,"is_final":false,"total_duration":0,"remain_duration":0,"speed":0.00,"volume":0.00,"volume_limit":0.00,"failsafe_duration":0}}
The key, in fact the only, part of that message I care about is the "cmd":7 (end of watering).

I know I can read the last_payload from the MQTT Connector in a script and reset the timer that way. But, I was wondering if there is a way to do this just using the MQTT plugins.

TIA

Posted on
Sat Apr 01, 2023 10:11 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Triggering on payload contents

You could create a "Generic" shim device and then trigger on the state corresponding to the "cmd" field.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Apr 01, 2023 10:15 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Triggering on payload contents

FlyingDiver wrote:
You could create a "Generic" shim device and then trigger on the state corresponding to the "cmd" field.
Thanks. Makes sense.

Posted on
Sat Apr 01, 2023 10:39 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Triggering on payload contents

FlyingDiver wrote:
You could create a "Generic" shim device and then trigger on the state corresponding to the "cmd" field.
Well, it sounded good. This configuration...
Screenshot 2023-04-01 at 18.35.59.png
Screenshot 2023-04-01 at 18.35.59.png (197.46 KiB) Viewed 1765 times
Throws this...
Code: Select all
   MQTT Received                   cm/LinkTap/up/67AF5F25004B1200_2 {"cmd":3,"gw_id":"5150D91D004B1200","dev_stat":{"dev_id":"67AF5F25004B1200_2","plan_mode":0,"plan_sn":0,"is_rf_linked":true,"is_flm_plugin":true,"is_fall":false,"is_broken":false,"is_cutoff":true,"is_leak":false,"is_clog":false,"signal":72,"battery":100,"child_lock":0,"is_manual_mode":false,"is_watering":true,"is_final":true,"total_duration":3091,"remain_duration":961,"speed":0.00,"volume":161.52,"volume_limit":0.00,"failsafe_duration":0}}
   MQTT Shims Error                Error in plugin execution runConcurrentThread:

  File "plugin.py", line 138, in runConcurrentThread
  File "plugin.py", line 165, in processMessages
  File "plugin.py", line 289, in update
type: 'int' object has no attribute 'strip'

   MQTT Shims Error                plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

Posted on
Sat Apr 01, 2023 10:50 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Triggering on payload contents

That's not going to work. The "Unique ID" for for identifying the specific device sending the MQTT messages, In your case, it's the string "67AF5F25004B1200_2" in the message topic. So you need to change those fields to location = topic, field = 3 (zero based), value = "67AF5F25004B1200_2".

Then put a period "." in the Multi-Key States field, and when you get a message the plugin should populate the "cmd" custom state with the value.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Apr 01, 2023 10:56 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Triggering on payload contents

FlyingDiver wrote:
That's not going to work. The "Unique ID" for for identifying the specific device sending the MQTT messages, In your case, it's the string "67AF5F25004B1200_2" in the message topic. So you need to change those fields to location = topic, field = 3 (zero based), value = "67AF5F25004B1200_2".

Then put a period "." in the Multi-Key States field, and when you get a message the plugin should populate the "cmd" custom state with the value.
Ah. That is a problem then. I don’t really care which device actually watered, Just if some device watered. So, any message with cmd=7 is sufficient. If I key on the specific device, I’d need 8 shim devices. (the cmd:3 was a status update message that happened to arrive when I saved the device)

Posted on
Sat Apr 01, 2023 10:57 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Triggering on payload contents

Then use field 1 and the value "LinkTap".

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Apr 01, 2023 11:05 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Triggering on payload contents

FlyingDiver wrote:
Then use field 1 and the value "LinkTap".
I realize I oversimplified this. In fact, I have two MQTT sources, LinkTap and LinkTap2. So, the pattern (re) is:
Code: Select all
cm/*/up/*  '{"cmd":7, .*}
I guess I can key on field 2, value = "up"

Posted on
Sat Apr 01, 2023 11:08 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Triggering on payload contents

Yeah, that should work. Just make sure your connector trigger is going to work for both:

Match: cm
Any:
Match: up
Any:

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Apr 01, 2023 11:09 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Triggering on payload contents

Or create two triggers but with the same Message Type.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Apr 01, 2023 11:54 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Triggering on payload contents

FlyingDiver wrote:
Yeah, that should work. Just make sure your connector trigger is going to work for both:

Match: cm
Any:
Match: up
Any:
All the rest of the parts were already working, so all I needed to do was find an easy and visible means to restart the timer. That is all working now. Thanks again.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests