My "vacation lights" turning on at wrong time


#1

I robbed some parts of this from another users piston but made it a little more basic for my uses.

The light turns on some random time after 10:00pm, then off between 2-3 hours after. I’m thinking I need to change the between sunset and 10:00pm, to happens daily at sunset.

The range was there in the parts I used, so I assumed it was needed.


#2

Yes it will. At 10pm your piston will start then you have a wait for 1 to 29 mins before it actually turns on lights. Then it is waiting 120-180 mins to turn lights off. I think you need a trigger or an execute command.Put something like this at the beginning:

.


#3

I’m missing something here. What do I need to add, the “Execute, every minute”? I have that in my example.

Your example might be the one that I robbed pieces from on the main forum a month or two ago. :slight_smile:


#4

Sorry I didn’t see that Execute at the beginning. Maybe @bangali or someone with a little more knowledge than me.
Sorry.


#5

normally prefer not to jump in when someone else from the community is already helping another user, but @jsinderb since you invited me let me jump in :slight_smile:

@scoob8000 have you seen this post? what i explained there may be most of the reason this is not working as you expect. once you have read that post, please let me know if that explains things otherwise happy to go in to more details.


#6

this might be all you need to get the results you are looking for. there are naturally other ways to achieve the same result, i am keeping this example as close to yours as possible :slight_smile:


#7

How about something like this. Works flawlwssly for me.
The ‘Only When’ is a switch to turn off the piston (and many others) should I need to.
It just cycles round and round as I’m using a ‘while’.
image


#8

yes, this would work for one light. since the user had a device variable, was thinking of that piston being used for multiple devices in the device variable. :slight_smile:


#9

Yes, that’s how I use it.
Have 3 of these for different lights.
I could put them all into one piston i suppose but I like things simple and not too cluttered. But that’s just me. :slight_smile:
Also in the first post I could only see one device in the device variable.
As has been said many times, lots of ways to achieve the same thing. That’s the beauty of webCoRE.


#10

The post about piston operating bottom up mostly makes sense.

So the piston state business is what was hanging me up. I’m not even sure what the purpose of it was for. The example I robbed this code from was a lot more complicated than I needed. Multiple switches and ways to override.

I imported your example and set the time window for a near time and the on/off delays short enough to watch. The contents of the async with statement will continue to loop as long as the time is within the window above it seems. Actually not my intended behavior, but makes sense since the original example was to turn lights on and off at random intervals.

I just want to turn them on near sunset and off near 10:00pm. (Near to allow a little randomness.)

I feel like there’s a much easier way to accomplish this. :slight_smile:


#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.