Variable of devices gets This piston does not subscribe to any events


#1

1) Give a description of the problem
If i create a set of physical devices in a variable for use by foreach, the variable does not subscribe to events…is that expected ? I have since rewritten as 3 separate pistons but would like to understand if I should have been able to do in a for loop

2) What is the expected behaviour?
I expect that I could check devices in a for loop ( in this case “stays open”)

3) What is happening/not happening?
I get the msg This piston does not subscribe to any events

4) Post a Green Snapshot of the pistonimage


5) Attach logs after turning logging level to Full
sorry I didnt even get running…are logs of any use?

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Your only potential trigger is in a for loop using the $device loop variable, Pistons can’t trigger on that since they have no idea what they will be until executed. You could wrap a trigger around your loop and then within the loop just use is.

if myGarageDoors contact changes to open then
   for each $device in myGarageDoors
      if $device contact is open then
         ...
      end if
   end for
end if

Simpler might be:

device myGarageDoors = ...
device openGarageDoors

if myGarageDoors contact changes to open then
      if myGargeDoors contact is open
           save matching devices to openGarageDoors
      then
          speak openGarageDoors is open
      end if
endif

#3

Thanks so much for explaining…i will play with your ideas.
Really appreciate you taking the time to explain !
Tim