Choose random devices


#9

Whoops jumped into the middle of this


#10

hey, we all got to start somewhere :wink:


#11

Thanks to both of you!


#12

sure thing. if you would still like to select 3 random devices from a list of devices, happy to provide a snippet for that as well.


#13

Please do!


#14

using your variables … off the top of my head …

set RandomLight1 = arrayItem( random( count( VacLights ) -1 ), VacLights)
do
   set RandomLight2 = arrayItem( random( count( VacLights ) -1 ), VacLights)
while
   RandomLight2 == RandomLight1
end do
do
   set RandomLight3 = arrayItem( random( count( VacLights ) -1 ), VacLights)
while
   RandomLight3 == RandomLight1
   or
   RandomLight3 == RandomLight2
end do

My "vacation lights" turning on at wrong time
#15

Hi bangali, where can I find array functions? I searched the wiki for arrayItem and nothing found.


#16

probably not added to wiki yet :slight_smile: open up a piston in edit mode and type it in the expression field.


#17

way ahead if you, used it as soon as I saw your post and makes a randomized away lighting routine very simple. I went searching in hopes there was a place I missed with other cool stuff :slight_smile:


#18

sorry, didnt realize that snippet had worked for you … it has been a while :slight_smile:

all the cool stuff is here spread out over this forum.


#19

Yeah I read stuff I’m not necessarily interested in just to discover things lol. What I used from your snippet was the arrayItem function, here’s what I have running now (tested but not used when we were away yet, that comes tomorrow).


#20

cool. sounds like fun :slight_smile:


#21

Ooo this is basically what I was just about to start trying to create myself! Or change another piston to do! Only difference is I was planning to have two devices randomly turned on at any given time and then randomly switched off, whereas this piston does it to one. I think I can achieve my aim by creating a ‘RandomDevice1’ and ‘RandomDevice2’ and getting the piston to check that the two are not the same light before executing the actions…

Will give it a go…


#22

So with the one light at a time logic, I’ve updated the piston to switch off all lights once one or more of us get home and then as a result of the SHM mode changing the piston shouldn’t run anymore anyway.

Will this work?


#23

Yep, that should be simple to do, if you don’t mind share when done? Also, I just purchased a light sensor so that I can change the Time test to be when its dark.


#24

Cool will do. Need to test this over the next few days and then share. I’ve not actually shared a piston before so how do I do that?!

The other bit I’m curious to test is the push notifications - my initial instinct was to put a separate notification when the light is turned on and then a separate one when it’s turned off but that might result in too many notifications!


#25

There’s a camera button under the code of the piston that takes a pic and lets you save it for posting here. I do a push of the on and off time just for testing, once its solid I’ll only have that go to Notices.


#26

Ah OK got it. What’s Notices?


#27

Sorry, Notifications in ST app.


#28

Thought I’d jump in here because @bangali seems to know what’s going on and we’re all working from the same piston. What I’m trying to achieve is to turn a single light on, randomly, only once between sunset and midnight. I’m having a hard time trying to work out the random wait, as I can’t use minutes because in a few months with the time change it will be out of sync. Is there anyway to turn as light on randomly between sunset and midnight?