First piston attempt - Motion sensor, Time issue


#21

ah that makes sense. if im honest, i didnt even noticed the “sunset/sunrise” and “$sunset/$sunrise” so thanks for clearing that up for me.

Changed it again but for some reason im worse off. 7:48 now and nothing happening at all once sensor is active

Edit: Ive just checked in the smart things app and it hasnt recognised any motion since 6:01PM
does this mean i need to remove and re add it to ST?

Feel like im making this harder for my self than it really should be. sorry guys

Edit: I noticed in my piston list that it was reporting “false” so i imported it with the code and it seems to be working now. Motion sensor in the ST app is now reporting it and its “true” on the piston list now. Strange…


#22

One more tidbit… I believe line 18 in your last picture should be switched around. It should say:

Time is not between 30 min past sunrise and 30 minutes to sunset
(Basically, whenever the time is not daytime)

This way, you will not get the issue elf mentions, because it spans noon instead of midnight.

On a different note, I am kind of curious what happens between 19:00 and midnight. I have never made identical triggers with different actions.


#23

If there is a conflict between the two nearly identical aspects, I have an idea that you may like. From the looks of it, you want a random color in the evenings, and a warm white in the mornings. If this is true, why not try this:

If time is BEFORE 30 minutes past sunrise… blah blah blah… Set color to warm white…
If time is AFTER 30 minutes to sunset… blah blah blah… Set color to random

This way there is nothing overlapping


#24

Oh that’s odd. After almost having a mental break down from not managing this piston myself, everything seems to be working fine. Even the morning part. The sensor not being responsive has even cleared up so it appears to be working perfectly. Yes your right, after 7pm the lights change to random colours but I too shared your concern about the overlap. It worked without issue tho. My 1 and only other concern will not come to light until we get further into the year when sunset is > 7pm.


#25

Well don’t feel bad. I will be the first to admit that my pistons never end up the way I originally envisioned them. They always evolve, and usually surpass my original intention.

Can you please clarify one tiny question?
From 6:40pm (sunset-30) to 7:00pm,
do you want random color or Warm Light during that time?
(your code could be streamlined if you answer random)


#26

I suspect with your current code, from 7pm to midnight, motion will turn the bulbs white, and then a moment later, turn them to a random color. (Both commands will run sequentially)


#27

The idea is to have it just white before 7 whilst my wife is in there cooking or what not. Then after 7 to have colour for when we are just passing thru it. That’s why I’m worried that during summer with sunset happening after 7, the piston start state may be with random colours and then swap to white when it’s nearing sunset.

I didn’t notice them changing white but I wasn’t really looking out for it so will report back tonight


#28

By default, pistons run commands sequentially from the top to the bottom, so I think that after dark and after 7pm, both commands will run each time there is motion. (with the random being the last command sent). I would venture to guess that once the sun sets after 7:30pm, she might not ever see the white light come on in the evening. (except for the brief flash each time it runs)

Maybe I am off, but I would try to code it where nothing overlaps. It would make for a slightly longer code, but the running of it would be quicker response. Here is my modification, with 3 sections instead of 2:


#29

I’m going to change to your code as that looks like it will be problem free later in the year so thanks alot for your help with this. Can I ask how you managed to add the green lines of code with those requirements?


#30

The green text is just comments, for reference. No code is run there.

The official way to add comments is to edit any line, and click the cog wheel to add a description.

A faster way is to click on a blank spot to the right on any line… and in the top right section, type your comment where it says “Description”


#31

I see. Thanks for all the help. It’s taught me plenty of useful stuff that will help me out so much in the future


#32

lights seem to be coming on during the day time for some reason. ive checked the logs and for some reason (if im reading them correctly) it thinks that the time is now (at 1:50pm) between -30 sunset and 7pm and then activating the lights

|+1ms|╔Received event [Home].test = 1522327618235 with a delay of 3ms|
|---|---|
|+153ms|║RunTime Analysis CS > 19ms > PS > 49ms > PE > 83ms > CE|
|+157ms|║Runtime (40542 bytes) successfully initialized in 49ms (v0.2.102.20180116) (156ms)|
|+162ms|║╔Execution stage started|
|+205ms|║║Comparison (time) 49618403 is_before (time) 1522302420000 = false (6ms)|
|+207ms|║║Condition #21 evaluated false (40ms)|
|+207ms|║║Cancelling statement #21's schedules...|
|+212ms|║║Requesting time schedule wake up at Fri, Mar 30 2018 @ 12:00:00 AM BST|
|+214ms|║║Condition group #18 evaluated false (state did not change) (48ms)|
|+224ms|║║Comparison (time) 49618453 is_between (time) 1522348380000 .. (time) 68400000 = true (6ms)|
|+225ms|║║Time restriction check passed|
|+226ms|║║Condition #31 evaluated true (10ms)|
|+228ms|║║Cancelling statement #31's schedules...|
|+234ms|║║Requesting time schedule wake up at Thu, Mar 29 2018 @ 7:00:00 PM BST|
|+238ms|║║Condition group #22 evaluated true (state did not change) (23ms)|
|+251ms|║║Comparison (enum) inactive is (string) active = false (3ms)|
|+252ms|║║Condition #30 evaluated false (11ms)|
|+252ms|║║Condition group #23 evaluated false (state did not change) (13ms)|
|+255ms|║║Cancelling statement #24's schedules...|
|+263ms|║║Executed virtual command [Kitchen sink, Kitchen strip].wait (2ms)|
|+264ms|║║Requesting a wake up for Thu, Mar 29 2018 @ 1:48:58 PM BST (in 120.0s)|
|+286ms|║╚Execution stage complete. (126ms)|
|+290ms|║Setting up scheduled job for Thu, Mar 29 2018 @ 1:48:58 PM BST (in 119.976s), with 3 more jobs pending|
|+301ms|╚Event processed successfully (301ms)|

#33

have done some playing around and split the whole script into separate pistons according to time.
found out that it is the sunset-7pm line thats causing issues. so ive just changed it to go from 5pm-7pm at the moment.

less than ideal but i guess its better than it being broken and lighting up all day. just dont understand what it didnt like about line 40 :thinking:


#34

What time is sunset at your location? If sunset is currently after 7pm (like it is here in Florida right now) that would probably wreak havoc with line 40.


#35

Ugh… Clocks changed here last week and I didn’t put 2 and 2 together. Makes sense now why it wasn’t working as I expected.

Thanks :+1:


#36

I probably wouldn’t have caught it either but I just happen to be a little sharper than usual this morning. :slight_smile:


#37

Can you confirm that the lights came on in the middle of the day, or is it possible they were somehow left on since sunrise?

The reason I ask is, I am not sure what would happen if the motion was triggered 29 minutes past sunrise. Not sure if it would turn the lights off since the time would not be true after the timer ran out. (I’ve never tested for this, but logically it makes sense)

A way to prevent that would be to add one line of code to “clean up” at 35 minutes past sunrise. (ie: At sunrise+35 turn off light)


#38

Yes the lights would come on at any time. I broke the code down into separate pistons to test out which was misbehaving and it was the sunset section. Since @Oldcomputerwiz pointed out that’s past 7pm now it makes sense that the piston was trying to work all the time as it wasn’t incorrect. Just a bit of an over site :persevere:


#39

Line 40 in my example above was my first time attempting this type of condition. If you really want that white light before sunset during half of the year, maybe change the piston that controls the lights in the evening to something like this:

You might have to ‘Subscribe’ to the motion sensor above,
but I think this will work once the two variables populate correctly.

In the middle of the day, the variables will be 10 + 1 = No action
When sun sets at 7pm, from 6:30-7 you will have 20 + 1 = White light
Every day of the year, from 7-midnight you will have 20 + 2 = Random color

I would then keep your other piston that controls the lights from midnight to sunrise.
I believe this covers all of your scenarios.


#40

Oh wow that’s a very confusing thing to look at before my morning coffee lol. I’ll give it ago, even if I havnt got a clue what it is I’m trying to read :joy:. Not really sure what you mean by subscribe?