Understanding $device, $devices, $currentEventDevice, etc


#1

Can someone help me understand how to use $device, $devices, $previousEventDevice, and $currentEventDevice? A brief explanation of their use and the syntax used to implement them would likely help with some of the things I’m currently working on and might be useful for other beginners. And apologies if this is already documented and I missed it. I looked but couldn’t find anything.


Run for each look on button press for a number of lights
#2

When there is an event that triggers a piston, for example…

In this case, when “Contact Sensor 3” becomes open, that triggers this piston to run.

“Contact Sensor 3” is the $currentEventDevice

and

“open” is the $currentEventValue

So the push notification will say… “The Contact Sensor 3 is open.”

However, let’s say a minute later “Contact Sensor 1” is opened. “Contact Sensor 1” is now the $currentEventDevice

but… $previousEventDevice is now “Contact Sensor 3” because “Contact Sensor 3” was the device that previously executed this piston.

As for $device and $devices…

First, $device refers to a single device. $devices refers to an array of devices.

In this piston I created a variable called “myTemperatureSensors” and filled it will a few sensors that have the temperature capability.

The for each loop will take the list of devices in “myTemperatureSensors” and loop through it. On each iteration, it takes the current device in the list and assigns it to the $device variable.


Need help with a, should be, easy piston
#3

Great explanation. Thanks for your help.


#4

Thanks for the explanation!


Help with errors and intermittent behavior
#5

What happens when you subscribe to an event using the currentEventDevice?
How long does the subscription last? Does it stack up subscriptions, or do they expire on the next event?


#6

Technically the way you have that piston, you are not subscribing to $currentEventDevice’s events. Whatever device kicked off the event, that will populate the $currentEventDevice variable.


#7

So what if instead I use:
{$currentEventDevice}'s motion stays inactive for 10 minutes

Will the stay inactive event trigger as expected, assuming the currentEventDevice is a motion capable device?


#8

Does anyone know how to convert the value from “previousEvent”?? It looks like a Unix timestamp kind of number, e.g.1521413883705

Never mind…the variable I was using was “Dynamic”. When forced to “Date and Time” its perfect. Sorry for the interruption…go about your business…these aren’t the droids you’re looking for.


#9

Ya, it doesn’t appear to fire the stays inactive event ever when done this way…


#10

Can someone take a look if this can work? Thank you.


#11

There may be other things to note, but what stands out for me right off the bat are your randoms on line 24 in the ONLY WHEN section. I would recommend putting in static (precise) times in this section.

From a logical standpoint, there is over a million milliseconds during 20 minutes. Placing a random in that block means any one of those runs can be either true or false, and any subsequent runs can be the opposite.


Another thing to consider:
Since RGB Bulb 1 is the odd man out, I would remove him from the list of devices, and just call that one device the traditional way.


I also have a hunch that the triple toggle section will not work as you want it to. $randomLevel is a number from 0-100, and $randomHue can actually go up to 360 I believe. I think you may want the commands:

Set level to $randomLevel
Set hue to $randomHue

Also keep in mind that even if the random toggle chooses to keep the light OFF, if the next line sets a level, the light will come on anyways…


#12

Thank you so much for the each detail and good to know I can just set the level to turn it on.


#13

It works on most manufacturer of bulbs. I would just avoid using Set level to 0. Just use a OFF command in those cases.


#14

Got it thanks!


#15

I have no idea how can I have something like {$device} 's switch is on in the expression field. I saw some examples people could do {$device} 's status. After I type 's then everything becomes red and the expression cannot be saved. In line 46 is the line I want to have the logic to see if the device is on then I can set the level and hue.
Those devices are still in the list is because I will have multiple devices soon. Thank you very much.


#16

Line 46 can be:

temp

Which returns:
temp


#18

I see. Thank you so much!


#19

can someone explain a practical use for $devices as opposed to $device?


#20

If you want a single piston to check or control several devices, rather than writing a piston for each one.


#21

I think the real question is when is $devices filled in with anything? $device is used for a for each loop. Is there any other time when $device has a value? When does $devices get a value? At least that’s my question. :slight_smile: