What's the cleanest method to turn something off at 30 minutes past sunrise?


#1

1) Give a description of the problem
Wondering how people have handled turning something off at least 30 minutes later that came on because of a motion sensor. I have an automation set up to turn on the pendant lights over the island when I come down between midnight and sunrise. IF they are on, then I want to have them turn off at 30 minutes after sunrise. What happens is the piston sets a wakeup call for the right time, but comes when the piston fires again the if section is false and so it quits. As you can see I’ve literally tried 49 different versions which inevitably do not work as I had hoped. The one that always works is ‘every day at 30 minutes past $sunrise’ but I was hoping for something that only fires when the light is on. This seems overkill to run every time when there may be nothing to do.

2) What is the expected behavior?
I want to turn the lights off if the piston turned them on. I know I can set up an ‘every day at 30 minutes past $sunrise’ section, but it seems pointless to run every day (even though it does nothing) when it may not have ever come on, like when I come downstairs after sunrise or am out of town.

3) What is happening/not happening?
Wait causes the piston to rerun, but lights do not turn off. I even tried an else if to test that the lights are on.

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach any logs (From ST IDE and by turning logging level to Full)
Sorry I don’t have a log for this, but hoping the issue is obvious and an answer will be quick and easy, or just a confirmation that I should just do the ‘every day’ brute force action.

Thanks.


#2

If you are looking JUST to turn off 30 mins after…


#3

Same as above but with a condition that the lights most be on


#4

Is this what you are looking for?


#5

Thanks Alan for the suggestions.

First one runs every day even if the light was never turned on. While this will certainly work, it seems excessive.

Second one with the ‘and if light is on’ isn’t really necessary because Webcore will know the light is off and cancels the command, right? Seems like I saw that in one of my logs where it cancelled as light was already off. Still runs every day.

Not sure the last one vy8e will work right. Won’t it set a wake up for 30 minutes past sunrise, then exit on the first statement. Seems like that’s what’s happened on about 40 of my iterations. I was hoping maybe to set up a while loop or something so it fires/turns off only if it was turned on that day.

Maybe it doesn’t matter and I should just set up the ‘every day’ block. Do you typically put the every day at the end of the same ‘turn on’ piston? Or a separate piston?


#6

I’m not sure I understand exactly what you goal is. Can you rephrase? I’ll try to help if I can understand the goal.

You said
I want to turn the lights off if the piston turned them on. - This we can do by using this (this is just the start)


#7

If I understand what you are looking for this should do it


#8

Let me try that last one and see what happens. Will report back Sun or Mon when I get back. Thanks.


#9

Here is my two cents for the cleanest method:

temp

It uses less resources, no wake up calls, no variable checks, is rock solid reliable, and only sends the off command if the lights are on at the time.

Badda-boom, badda-bing.


#10

He also ONLY wants it to happen if the light was turned on my a piston and not physical.


#11

Maybe I missed it, but I do not see this mentioned anywhere in this thread…


#12

@WCmore This is what makes me ‘think’ hes looking for only when a piston turned it on. Either way maybe we gave him some ideas!


#13

You could very well be right.
If that is your intention @crevasse, then please ignore my posts, LOL


#14

So I decided to just go with the every day block as shown above. Since the entire piston fires again due to a long Wait statement, trying to fancy code some thing still runs the piston’s codeset after the wait. I was sort of hoping there was a way for the piston to literally wait at the wait statement instead of setting a wake up call. But I understand why it doesn’t. So, either method [re]runs a block of code. This one is just more obvious as to its intention without having to think about it.

Alan, I couldn’t get your last piston to turn on the lights initially, because the variable was not true. Is there a way to check if a boolean variable is either true or null? I suppose some setting it to a string instead of boolean then checking for null or “not run today yet” in some way might work. But again, lots of complexity for something that shouldn’t be that difficult a concept to do, literally the exact thing every one of us does every day:

turn on the lights when I come downstairs and it’s dark, then turn them off later when it’s light.

Yes, there are lots of ways seemingly unnatural methods to accomplish the above, but none of them are what I would call natural like speech or thought. My brain never sets a variable to tell me if I turned them on, nor do I hit the OFF switch when the lights are already off.

I do appreciate the conversation though, and I’m sure I’ll be back for more. My latest automation is finally getting VLC Thing set up on an old Dell Venue 8 tablet which is connected to my Echo Dot by Bluetooth to either speak phrases or play sound bites. My wife laughs every time one of the external doors (front, back, garage) opens up and the Star Trek door_open.mp3 plays! Next is to notify when doors or windows are open and the hvac is running.