Identifying and naming lights which are on from a variable


#1

Hi piston experts!

I’ve got what is currently a simple piston which will notify me if there are one or more lights on during daylight hours but I’d like some help enhancing it please so that the notification refers to the specific light(s) which are on. I think I need to use a variable based on my ‘allLights’ variable to store the names of the lights which are on and then refer to this variable in the notification but I’ve not yet got my head round manipulating variables so I’m a bit lost.

Any help would be much appreciated!


#2

Create a device variable that is empty.

You should have an option under the condition for @allLights is on to save matching list. Save it to your variable. Then you reference the variable in your message

Edit:


#3

Ahh brilliant - learned something new! That ‘save matching devices’ option will come in handy!

And you answered another question I had about how to make sure the notification uses “are” or “is” depending on number of lights on :slight_smile:

Thanks - really loving webCoRE!


#4

Here to help


#5

@c1arkbar - I’m still pretty confused with all the variable options, could you explain the logic behind the variables this is using? Is there a spot in the wiki that explains this? I’ve read through the Wiki but still don’t quite understand it.


#6

Nothing in the wiki yet. Do you have specific questions you are wanting info on?

The different variables in use in the above example are a global device variable which contains all the lights.

The device variable lightsOn is used to store any devices that match the condition. More actions could be taken with this but we are using it to notify what lights are on


#7

I guess its more of an overall of how the variable formula works. In the given piston above, “@alllights” is a global variable that includes several lights, “lightsOn” is the name of the local variable (that I’m assuming has a group of the physical lights selected)? So during the time given, the piston searches if any of the “allLights” are on and compares them to “lightOn” and if true sends the notification, correct?

what does the x2 mean?
what does the x2 save matching devices mean/do?
Is there any place to find out how to write, or why the {lightson (lightson>1?" are" : is")} works to extract which lights are on?

I’m sorry for the ignorance and multiple questions but I’m really just trying to learn more about this and how/why it all works. The options that Webcore has and information you can pull/gather/send/use are endless and it’s amazing. I have zero background with any developing/programming or HA, but this has now all become a hobby (obsession) hahaha.


#8

I think @c1arkbar will explain better but the LightsOn variable is holding the result of the if condition which checks if any of the lights in the allLights variable are on. So the values in the LightsOn variable are determined on the fly, not pre-determined. Now in that variable I have the lights which are on and I can then reference the variable in my notification. It’s nothing to do with comparing the two variables to decide whether the notification is sent. The LightsOn >1 bit is basically saying "if the LightsOn variable has more than one device in it, use the word “are” in the notification and if there is only one device in it, then use the word “is”. It’s just some logic to ensure the notification can be grammatically correct depending on whether one light is being talked about or multiple.


#9

You pretty much nailed all the points. Good job!

@Jrrobertson3 the x2 is just an icon denoting a variable action.


#10

@c1arkbar @freddyq - Thanks guys! That actually helps a lot and makes sense. I’ll have to play with them a bit to see if I can replicate for my own set ups.


#11

No problem - glad I can help, I’m going through the same learning curve but it really is a fantastic tool and could have been so complicated but the designers have done a really good job of simplifying the process of writing logic as much as possible.


#12

Thanks for this, it’s very helpful. I am however having issues with the “are” and “is”. No matter how may lights are on, it always seems to use the “is”. I’ve got it coded as you do - It’s daytime and the {lightsOn (lightsOn>1?" are" : " is")} on!". Any thoughts on where i’m going wrong? I’ve tried e-mail, sms, and push and they are all handling it the same and always using “is”. Thanks…


#13

Post up your piston that you are using


#14

Here you go. Thanks!


#15

Looks right. Assuming all your lights are in that global variable? Also can you post up some logs from when it last executed but sent the wrong message


#16

Thanks. Yes, all the lights are in that global variable. Here are the logs:

1/15/2018, 10:17:03 AM +19ms
+1ms ╔Received event [Home].test = 1516033023015 with a delay of 4ms
+108ms ║RunTime Analysis CS > 20ms > PS > 54ms > PE > 30ms > CE
+113ms ║Runtime (40570 bytes) successfully initialized in 54ms (v0.2.101.20171227) (112ms)
+117ms ║╔Execution stage started
+159ms ║║Comparison (time) 37023141 is_between (time) 1516022040000 … (time) 1516056300000 = true (9ms)
+160ms ║║Time restriction check passed
+162ms ║║Condition #4 evaluated true (40ms)
+166ms ║║Cancelling statement #4’s schedules…
+177ms ║║Requesting time schedule wake up at Mon, Jan 15 2018 @ 3:45:00 PM CST
+233ms ║║Comparison (enum) off is (string) on = false (2ms)
+235ms ║║Comparison (enum) off is (string) on = false (1ms)
+237ms ║║Comparison (enum) off is (string) on = false (1ms)
+239ms ║║Comparison (enum) off is (string) on = false (1ms)
+241ms ║║Comparison (enum) off is (string) on = false (1ms)
+243ms ║║Comparison (enum) on is (string) on = true (1ms)
+246ms ║║Comparison (enum) on is (string) on = true (2ms)
+249ms ║║Comparison (enum) off is (string) on = false (2ms)
+251ms ║║Comparison (enum) off is (string) on = false (1ms)
+254ms ║║Comparison (enum) off is (string) on = false (1ms)
+264ms ║║Condition #5 evaluated true (83ms)
+265ms ║║Condition group #1 evaluated true (state did not change) (144ms)
+267ms ║║Cancelling statement #2’s schedules…
+284ms ║║Calculating (integer) 0 > (integer) 1 >> (boolean) false
+289ms ║║Calculating (string) Patio East Coach Light and Patio West Coach Light + (string) is >> (string) Patio East Coach Light and Patio West Coach Light is
+292ms ║║Calculating (string) It’s daytime and the + (string) Patio East Coach Light and Patio West Coach Light is >> (string) It’s daytime and the Patio East Coach Light and Patio West Coach Light is
+295ms ║║Calculating (string) It’s daytime and the Patio East Coach Light and Patio West Coach Light is + (string) on! >> (string) It’s daytime and the Patio East Coach Light and Patio West Coach Light is on!
+324ms ║║Executed virtual command sendSMSNotification (21ms)
+336ms ║╚Execution stage complete. (222ms)
+342ms ║Setting up scheduled job for Mon, Jan 15 2018 @ 3:45:00 PM CST (in 19676.64s)
+353ms ╚Event processed successfully (353ms)
1/15/2018, 10:15:47 AM +235ms
+1ms ╔Received event [Home].test = 1516032947235 with a delay of 0ms
+108ms ║RunTime Analysis CS > 21ms > PS > 50ms > PE > 34ms > CE
+111ms ║Runtime (40570 bytes) successfully initialized in 50ms (v0.2.101.20171227) (110ms)
+112ms ║╔Execution stage started
+158ms ║║Comparison (time) 36947352 is_between (time) 1516022040000 … (time) 1516056300000 = true (12ms)
+161ms ║║Time restriction check passed
+163ms ║║Condition #4 evaluated true (46ms)
+176ms ║║Cancelling statement #4’s schedules…
+187ms ║║Requesting time schedule wake up at Mon, Jan 15 2018 @ 3:45:00 PM CST
+256ms ║║Comparison (enum) off is (string) on = false (4ms)
+258ms ║║Comparison (enum) off is (string) on = false (1ms)
+260ms ║║Comparison (enum) off is (string) on = false (1ms)
+261ms ║║Comparison (enum) off is (string) on = false (1ms)
+264ms ║║Comparison (enum) off is (string) on = false (1ms)
+266ms ║║Comparison (enum) on is (string) on = true (1ms)
+268ms ║║Comparison (enum) on is (string) on = true (1ms)
+270ms ║║Comparison (enum) off is (string) on = false (1ms)
+271ms ║║Comparison (enum) off is (string) on = false (1ms)
+274ms ║║Comparison (enum) off is (string) on = false (2ms)
+282ms ║║Condition #5 evaluated true (77ms)
+283ms ║║Condition group #1 evaluated true (state did not change) (167ms)
+285ms ║║Cancelling statement #2’s schedules…
+299ms ║║Calculating (integer) 0 > (integer) 1 >> (boolean) false
+303ms ║║Calculating (string) Patio East Coach Light and Patio West Coach Light + (string) is >> (string) Patio East Coach Light and Patio West Coach Light is
+306ms ║║Calculating (string) It’s daytime and the + (string) Patio East Coach Light and Patio West Coach Light is >> (string) It’s daytime and the Patio East Coach Light and Patio West Coach Light is
+308ms ║║Calculating (string) It’s daytime and the Patio East Coach Light and Patio West Coach Light is + (string) on! >> (string) It’s daytime and the Patio East Coach Light and Patio West Coach Light is on!
+345ms ║║Executed virtual command sendSMSNotification (30ms)
+378ms ║╚Execution stage complete. (266ms)
+389ms ║Setting up scheduled job for Mon, Jan 15 2018 @ 3:45:00 PM CST (in 19752.377s)
+398ms ╚Event processed successfully (398ms)


#17

What is @allCoachLights?


#18

If I had to take a guess it is because your devices are stored in a global variable and so they are not in the storage app for this piston. Try moving them into a local device variable and run it


#19

@c1arkbar Will give that a try, thanks. @eibyer it’s a global variable with all of lights. Thanks!