How to build a string in my piston


#1

1) Give a description of the problem
Here is my current piston. It works, but I need to make it better. I have a few improvements I would like to make. I just don’t know where to begin and I certainly don’t know how to do it effectively.

2) What is the expected behavior?
First off, I would like to build a string based on various conditions before passing as a push message. For example, “Front Door has been unlocked.” or “Side Door has been unlocked by Frank’s user code.” When I add the locking messages in, I want it to say things like “Back Door locked (Side Door, Front Door still unlocked).” or “Front Door locked (All doors now locked).” or “Front Door, Side Door locked (Back Door still unlocked w/ timeout).”

So one of my first hurdles has been that $args.usedCode is either null to represent that it was unlocked by the deadbolt or via SmartThings, or 0-32 where 0 is the programing code and 1-32 are user codes. How do I assemble an if statement based on $args.usedCode to detect these values and then use the value to look up a list of strings representing names assigned to the user code numbers?

As a nice to have, is there a way to capture multiple device events to achieve my last message request so that if a command to lock all doors is done, it will respond in that manner?

3) What is happening/not happening?
Just don’t know where to begin.

**4) Post a Green Snapshot of the piston


#2

You can create a string variable like below for the code/name pair you want…
image

And then access the names using arrayItem(codeNumber,nameList) – there’s probably a more elegant way to do that, someone might be able to streamline that down the road.

For your other question regarding reporting… there’s an option to Save matching devices to a variable. So if you capture events for the doors and locks, you can continually update that variable so you can have webcore spit out the names of the devices that are still open or unlocked.

I have one example I use for a house report, before I leave the house. This one is triggered by “Alexa, I’m leaving”


#3

Great example. I appreciate it. One thing I don’t fully understand is in your post code, you have this when statement as a nested trigger?


#4

You could set up 2 dvice type variables. Name them whatever you want

Then you could use an if statement

If any of (select your devices) Is closed
Save matching devices to (one of your device variables)
Save non matching devices to ( the ither variable)

Then use the variable that is saving the devices that are not closed on your message

I’m mobile right now, but I could whip up an example tonight when I get home if you need


#5

I think I understand what to do. Thanks!


#6

Also, if I command one of locks to unlock via SmartThings app, is there an event that gets registered prior to the event of the device actually locking? Or a different method? If so, this would allow me to differentiate between the deadbolt and ST since they are not null for $args.usedCode. Thanks!


#7

Here is my latest, working iteration! Still need to add the light switch functions.


Webcore does not use oxford commas
#8

Thank God I found my old thread. I forgot I posted this here and I need to import this into Hubitat.