Lights on in morning but only during school days


#1

1) Give a description of the problem
Want my hall light switch to turn on every morning at 6:45am but only M-F and only on school days. Also want them to turn off at 7:20am on those same days - currently trying this with two pistons.

2) What is the expected behavior?
Hall light switch turns on at 6:45am M-F during school days only (ideally off at 7:20am same parameters)

3) What is happening/not happening?
Light switch not turning on.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
Just turned logging on - no logs yet.


#2

You need to add the “turn on” command to the line after “wait until 7:25am”.
Also set the task cancellation policy to “never cancel tasks” on that last “with” statement


#3

Sorry - system pasted wrong image


#4

Personally, I try to avoid the Wait command. Seems to make things screwy sometimes, and have to really understand task cancellation policy.

If I were you, I would just add another top level execute in there for happens daily at 7:20am and date is not, etc. Copy the whole statement, change the time to 7:20, then have a turn off instead of a turn on.

Alternatively, could you just shut the switch off at 7:20 Monday-Friday even if it isn’t a school day?


#5

The wait is only there because I couldn’t figure out how to get rid of the else statement and i tried making that state “do nothing” but since that didn’t work and a previous version with a wait statement did, I put it back. I was trying to make two of these pistons - one for turn lights on at 6:45am and one for turn lights off at 7:20am but once I did that everything stopped working. I’d love to have it all in one piston but can’t figure out how. I’m very new at this and not really a programmer by nature.


#6

I think I am really overthinking it. Inside your existing if…then…else, why don’t you just
Then
with switch 1
turn on
wait until 7:20
turn off

Your Else statement is never going to execute on school days, except on the specific days in your list.


#7

I like that idea. Still not sure what to put in the Else statement since I don’t really want it to begin with.


#8

Leave the else blank. Don’t have to have anything in there.


#9

So like this?


#10

Yup. I think that will do what you want. Turn on the lights M-F (except the dates listed) at 6:45, wait until 7:20, and shut the switch back off.


#11

Great. Thanks so much for the help. We’ll see if it works tomorrow morning. I added the TCP never command as suggested earlier as well.


#12

Just an observation, you may want to switch all your “Date is not between…” to OR statements rather than AND.
edit:, won’t quite work, I’m taking a look at something now and will try and post an alternate piston for ya.


#13

Well, I think both ways will work. It may be more efficient in terms of processing the code to use the “OR” statements. Or maybe it doesn’t make a difference at all, I don’t know. LOL


#14

Thanks. We’ll see if my existing change works tomorrow morning. If not, I’ll try separating the dates out using OR statements as you suggest. I was trying to do that within the existing statement but found they all had to be AND or OR. Didn’t think to separate them the way you did so thanks for that idea!


#15

@allrak I don’t think the OR for the dates can possibly work. Any date at all will pass at least one of those tests making the whole statement evaluate as true. Example: Memorial day, May 28. No school, lights shouldn’t turn on. In this big list of OR statements, it would fail the first, but pass all the rest. If it passes any one, the whole statement is true.

Remember, those are the dates there is NOT school - Memorial Day, summer vacation, Labor Day, etc. So @frankjann is correct with the AND statement. It needs to be 6:45 on a weekday AND not be a holiday.

@frankjann let us know if it works right tomorrow! :slight_smile:

milhouse


#16

I would think each condition block will have to evaluate to TRUE in order to process the IF.
So if the date was 6/5/18 and it ran, it would evaluate TRUE on the second condition.
If the date is 6/6/18, it should evaluate FALSE.

Maybe my logic is off?


#17

Ah, good old boolean logic…
(date is not May 28
or date is not Sep 3
or date is not Nov 6)
and
(time is)
…
On memorial day (no school):
(False
or True
or True)
and
(True)
…
(True)
and
(True)
…
True, so lights turn on and off.

Definitely need to “AND” all those statements need to be true. Not May 28, Not Sept 3, Not Nov 6…


#18

Yeah, i get it now. All will return TRUE except for possibly one. Gotta use the AND!
Stuff can make your head spin sometimes.


#19

For all those ‘between’ dates, the 2nd date needs to be the date you want the piston to resume. There are no dates ‘between’ 5/28 and 5/28 so it will run on the 28th. Make it between 5/28 and 5/29 and it will not run on the 28th, and resume on the 29th.

Likewise between 6/6 and 8/19 will not run on 6/6 but it will run on 8/19.


#20

Thanks very much for that tip. I’ve adjusted the dates accordingly.