My "vacation lights" turning on at wrong time


#11

thank you for clarifying that. if you break up that with block, so that the on happens at sunrise - 15 mins and off happens at 9:45 with a random delay of 1 to 30 minute before the on and the off that would do what you are looking for. do you want me to update that sample i posted?


#12

Sure. I was going to attempt it by trial and error, but it’s easier learning from an example then tweaking it to my liking. :slight_smile:


#13

sure. is this an everyday timer or only when SHM is armed/away?


#14

Only when shm is armed/away.


#15

try this one:

  • every day at sunset give or take 15 minutes, if SHM is armed/away then it will turn on all the lights in the device variable devicelist and set a variable to true.

  • every day at 10pm give or take 15 minutes, if variable is true then it will turn on all the lights in the device variable devicelist.

  • i use the isTurned on variable so the light is always turned off if it was turned on by this piston. even if you came back home after it was turned on by this piston and SHM switches away from armed/away it will still get turned off and not skipped because you are back home.


#16

Looks good and I can follow along with what’s happening too. Going to test it out tonight.

What are the number comments after some statements? I see that in a lot of examples. I assume for your own notes.

When you define a variable like that at the beginning of a piston, I assume it’s just for that piston and not global?

Edit: Hit post too soon. Took me a minute to figure out what the addminutes does with random. We’re starting with -15 and adding a random number 0-30 to it.


#17

ok. look forward to hearing how it went. :slight_smile:

those numbers are used when logging is turned on, to refer to that line in the logs.

correct.

edit: correct.


#18

That worked as expected!

Just curious. When does the random time get calculated? I feel like it needs to know the time in order to know when to execute the “every day, at” blocks.


#19

great!

random time gets calculated when:

  1. at the end of each execution of the piston when the next execution of the piston is scheduled
  2. there is a test execution of the piston when the piston is saved and it is not paused
  3. when a paused piston is resumed

it does know the time. :slight_smile:


#20

Are variables defined only within the piston or globally? No I have this piston where I want it, I’m going to make a duplicate for my morning routine.

I want to make sure the isTurnedOn variable from one isn’t seen in the other.

I was going to do it all in one, but two pistons makes it easier to disable one or the other.


#21

Local variables are confined within the piston
Global variables are confined within the instance


#22

This is useful. Is there somewhere I can read about what the ‘async with A’ statement is doing?


#23

If I was to the piston above (gmuuv) & added 5-6 devices would they all turn on & off at the same time.
Mike


#24

yes. just add them to the deviceList variable. in fact thats the entire reason why i used a variable for devices instead of using a single device directly. :slight_smile:


#25

dont know if there is a formal writeup :slight_smile:

but the async tells webcore to execute the next action without waiting for the current action to complete.

the A shows up when you set Task Scheduling Policy to allow multiple wait timers. i am also happy to add that in this case that setting is completely unnecessary and must be a leftover from where i was doing something, some other way. :smile:


#26

Thanks! On the other point about the deviceList variable, I had the same question because what I’d like is to have all the devices in a list and for the piston to then select two of them at random and turn them on for half an hour then switch off and select two others from the list to turn on. Is it something I can change this piston to do or am I better off trying to write one from scratch?


#27

sure thing. i had posted a snippet somewhere here to do something similar in a different piston. let me see if i can find it. combining this example with that snippet would work.

here’s the snippet that you will need to inset in the first every block. change VacLights, RandomLight1 and RandomLight2 to your variables and have them defined. you can remove the portion for RandomLight3 since you only want to pick 2 lights randomly.


#28

Perfect, many thanks @bangali! I will try this out and let you know… :slight_smile:


#29

The async with hung me up when I migrated to webcore.

Makes sense now though. :slight_smile:


#30

cool.