Making a generic piston for use with multiple devices


#1

1) Give a description of the problem
I have a simple piston I use to turn on a light in my walk-in closet when motion is detected, very basic stuff. I’d like to make it so I can setup a variable with a list of motion devices and make them trigger the corresponding light without having the create the same code for each and every combination of devices. In the code in the screenshot below, I figured I’d replace the first if with if $motionSensorList motion is changes to active and then do another if that would do something like if $currentEventDevice = ‘Walk-In Motion Sensor’ then set $matchingLight = Walk-In Closet Light. It’s the first part of that if that I’m struggling with, I’m not seeing how to make a simple equality on the device, it seems to want me to use a property of said device, which is not what I’m after.

2) What is the expected behavior?
Being able to define a list of motion sensors and corresponding light sensors and be able to use the same code for all

3) What is happening/not happening?
Can’t seem to do $currentEventDevice = Some Specific Physical Device

4) Post a Green Snapshot of the pistonimage
Can’t find a place to upload, but here’s a link: https://app.box.com/s/x6asl3sph9qir8ttylpj2gp8v8ibwpnm


#2

Create a variable as a device type variable and then pick your desired sensors from there. Physical devices and check the ones you want


#3

This may illustrate better what I’m trying to do. Here’s a piston I worked on that illustrates what I want to do, but doesn’t quite work right. If I had to guess, it probably has to do with scoping, I’m not really sure if the local variables are scoped to the event or what. Here’s the scenario. My bathroom is one of those that has a separate room for the toilet, so I have a motion sensor in the bathroom and one in the room with the toilet. When I walk into the bathroom, the lights come on, and then when I enter the room with the toilet, the light also comes on. Problem is if I walk out of the bathroom entirely, which is a common scenario, one of the lights turns off (the bathroom one) but the other one stays on. And then if I go back in the bathroom light no longer turns on.


#4

Do you mean something like this:


It relies on the sensor/dimmer sharing a common first word with the light, i.e. Bedroom Motion and Bedroom Light.


#5

Yes! That’s perfect, exactly what I was trying to do. So I guess expressions are the answer, wasn’t familiar with how to use them. Much appreciated.