Help with modes


#1

1) Give a description of the problem
So, newbie right here!!
I have the below piston to play around with my 8 modes. But there are problems at Monday.

2) What is the expected behaviour?
Piston, on weekdays, should get “WakeUpTime” as “WakeUpWeekDay”, from Monday to Friday.

3) What is happening/not happening?
Piston, on MONDAYS, is getting “WakeUpTime” as “WakeUpWeekEnd”. It works fine from Tuesday to Sunday, is only Mondays is going wrong.

**4) Post a Green Snapshot of the piston!

Your help is very appreciated.


#3

Your piston is only going to run when the global variable for the empty house changes, or at the times mentioned in the ‘between’ statements. Each time it runs, the piston schedules the next timed run.

So I think your problem is that when it last runs on a Sunday night, the piston sets the time of its next run based on Sunday’s timings. In other words it runs at 7:30am or sunrise, when you want it to run at 5:30am or sunrise.

You don’t see the problem moving from Friday to Saturday because if it wakes up too early it’ll reschedule for later.

In terms of fixing the issue, you could make the piston run early on a Monday morning (or every morning) just to force the schedules to be updated.


#4

@orangebucket is correct. The thing to remember with pistons is the next execution time is always set by the last time it ran. So when it runs on Sunday, it thinks it is Sunday and sets the Monday wakeup time as if it was Sunday. You could try using an offset $dayofweek (i.e., look for 0-4 instead of 1-5 for weekday) or add an every day 1 AM run to make sure the times are right. Just make sure you don’t use the EVERY command as that will only run what is inside that block. You can just add a block like this anywhere in your piston:

if time happens daily at 01:00:00 
then
endif

Note that time is selected as a virtual device.

One other lesson for you: $sunrise can be a confusing thing. $sunrise is the time of sunrise today (that is, this morning). Whenever you span midnight, the time check can get confused. Time is between $sunset and $sunrise is always using the values for the wrong days (either $sunrise is in the past or $sunset is after the next $sunrise). To avoid this, you want to use a negative: Time is NOT between $sunrise and $sunset will always give you the night time as true.

Hope this all helps. Let us know if my explanation was too confusing. We’re all happy to help.


#5

I wouldn’t suggest ‘time happens daily’ as things stand. It is a trigger and the piston doesn’t currently have any triggers, only conditions, so adding it would mean the piston would only run at 1am. Something similar using a time condition would do e.g. ‘time is after 3:30am’ (might as well use a later time and get DST fixed into the bargain).

For @angolandriver , the basic theory is to have your piston fired on Monday morning before 5:30am or sunrise. That should cause it to recalculate the values in your ‘time between’ statements and then wake up on the Monday schedule. It is a common trick that is often used when precise sunrise and sunset timings are required, and also helps with daylight savings changeover.

That’s not to say there isn’t a way of avoiding the problem in the first place, I just haven’t thought about what it is.

Something else you might like to be aware of about ‘time between’ is that the piston code always assumes that the first time occurs before the second time. So if you said ‘time is between sunset and 7:30pm’ and sunset is actually at 8:00pm the comparison is ‘between 8:00pm and 7:30pm’. If the current time is before 7:30pm webCoRE would evaluate this as true, assuming you meant 8pm last night. If the current time is after 8pm webCoRE would again evaluate it as true, assuming you meant 7:30pm tomorrow. In effect it is ‘NOT (between 7:30pm and 8pm)’. So you can probably see why many users prefer to explicitly use the latter form as it makes it clear what the calculation really is. This is the same idea as @guxdude discussed with ‘between sunset and sunrise’. It is not that webCoRE gets things wrong, it just makes it more obvious that it is right. Whichever way you choose to write things, when using a range with one or more variable times you mustn’t allow the earlier/later relationship between the limits to flip.


#6

Excellent point! I missed that. Thanks.


#7

Thanks for your help guys, very much appreciated!!!

For now I’ll try a mix between @orangebucket and @guxdude. I made a small piston that triggers only on Mondays at 1:00 am to call the main piston to run. Lets see.

I’ll get you a feedback on Monday!!!

Thanks again.

Rgds,


#8

Looks good! You could also just add that block (without the execute task) to your main piston. When triggered, the piston will run all the other code top to bottom even with this block empty.


#9

Normally, this would work @guxdude but not with this piston.
Adding that block would convert all condition triggers back into standard conditions.


Edit: Upon closer inspection, I notice that he forced subscriptions to those conditions, so your suggestion might actually work.


#10

Thanks for your input as well @WCmore.

Rgds,


#11

Oops, I didn’t notice that either.


#12

Hi guys:

After two mondays I can say it worked!!!

Many, many thanks for your help!

Cheers,