Setting modes based on time of day and presence

mode
presence

#82

FYI - when I clicked test to bring up the trace option, it evaluated and set the mode to Home - Afternoon as it should.

I wonder if it has to do with the 20s past portion? Maybe I should extend that time to let’s say 1 min? Maybe it’s not evaluating the 20s and saying 7:30:20 = 7:30:00??
Just thinking out loud.


#83

Yes, perfect. The grey numbers coincide with the numbered events in your logs.


Changing the time one minute may very well help… Actually, I would make sure it is at least 65 seconds different since my pistons tend to run one second early.

If it is still acting up, please post the log events (and if your code is changed, also the green snapshot) so we can see what is going on.


#84

It’s worth a shot. I’m going to back off each time setting by one minute (IE: morning - 7:29am) and set it to fire 65s after.

Next run should be roughly 45min so I’ll know soon enough.


#85

At 4:30pm it set the mode to Home - Afternoon instead of Home - Evening

Code and Log

Blockquote
1/13/2019, 4:30:04 PM +140ms
+1ms ╔Received event [47 Carsdale].time = 1547411405000 with a delay of -861ms
+463ms ║RunTime Analysis CS > 137ms > PS > 266ms > PE > 60ms > CE
+467ms ║Runtime (52985 bytes) successfully initialized in 266ms (v0.3.109.20181207) (464ms)
+468ms ║╔Execution stage started
+491ms ║║Comparison (enum) not present is (string) present = false (2ms)
+496ms ║║Comparison (enum) present is (string) present = true (2ms)
+498ms ║║Condition #7 evaluated true (20ms)
+506ms ║║Comparison (string) :46711365570d03ce3b78577e2ee8859f: is_not (string) :c7db4daaef8d8f12a541db3807b02850: = true (3ms)
+508ms ║║Condition #151 evaluated true (9ms)
+509ms ║║Condition group #3 evaluated true (state did not change) (32ms)
+512ms ║║Cancelling statement #8’s schedules…
+560ms ║║Calculating (time) 59400000 > (time) 82740000 >> (boolean) false
+573ms ║║Calculating (time) 59400000 < (time) 82740000 >> (boolean) true
+584ms ║║Calculating (time) 59400000 < (time) 59340000 >> (boolean) false
+595ms ║║Calculating (time) 59400000 < (time) 43140000 >> (boolean) false
+606ms ║║Calculating (time) 59400000 < (time) 26940000 >> (boolean) false
+3157ms ║║Executed virtual command setLocationMode (2546ms)
+3176ms ║║Comparison (enum) not present is (string) not present = true (3ms)
+3181ms ║║Comparison (enum) present is (string) not present = false (2ms)
+3184ms ║║Condition #142 evaluated false (22ms)
+3186ms ║║Condition group #141 evaluated false (state did not change) (23ms)
+3708ms ║║Comparison (time) 59407840 happens_daily_at (time) 26940000 = false (1ms)
+3710ms ║║Condition #140 evaluated false (11ms)
+3712ms ║║Cancelling statement #140’s schedules…
+3724ms ║║Requesting time schedule wake up at Mon, Jan 14 2019 @ 7:30:05 AM AST
+3736ms ║║Comparison (time) 59407869 happens_daily_at (time) 43140000 = false (0ms)
+3739ms ║║Condition #136 evaluated false (10ms)
+3741ms ║║Cancelling statement #136’s schedules…
+3750ms ║║Requesting time schedule wake up at Mon, Jan 14 2019 @ 12:00:05 PM AST
+3760ms ║║Comparison (time) 59407893 happens_daily_at (time) 59340000 = true (1ms)
+3762ms ║║Time restriction check passed
+3764ms ║║Cancelling condition #137’s schedules…
+3765ms ║║Condition #137 evaluated true (12ms)
+3767ms ║║Cancelling statement #137’s schedules…
+3777ms ║║Requesting time schedule wake up at Mon, Jan 14 2019 @ 4:30:05 PM AST
+3781ms ║║Cancelling condition #135’s schedules…
+3782ms ║║Condition group #135 evaluated true (state changed) (84ms)
+3787ms ║║Cancelling statement #63’s schedules…
+3797ms ║║Calculating (string) Home - Afternoon + (string) was initiated on >> (string) Home - Afternoon was initiated on
+3802ms ║║Calculating (string) Home - Afternoon was initiated on + (string) Sun, Jan 13 2019 @ 4:30:07 PM AST >> (string) Home - Afternoon was initiated on Sun, Jan 13 2019 @ 4:30:07 PM AST
+3807ms ║║Executed virtual command setState (1ms)
+4124ms ║╚Execution stage complete. (3656ms)
+4147ms ║Setting up scheduled job for Sun, Jan 13 2019 @ 11:00:05 PM AST (in 23396.715s), with 4 more jobs pending
+4157ms ╚Event processed successfully (4157ms)


#86

Very strange… At 4:30:07 PM:

  • #136 evaluated false (afternoon)
  • #137 evaluated true (evening)

Maybe the block on lines 52-60 should be at the very top of this piston…

At first glance, it appears that the piston state is not displaying the real location mode. Perhaps you can confirm this??


The way I usually code for a project like this is:

Every day at 7:30AM
    IF Any of Presence Sensor 3 & 5 are present
    Then
        Set location to Home - Morning
    END IF
END EVERY

Every day at 12:00PM
    IF Any of Presence Sensor 3 & 5 are present
    Then
        Set location to Home - Afternoon
    END IF
END EVERY

etc etc…


#87

Also, from these lines from the log…
It checks IF greater than 11PM first… then IF less that 11PM second… and that second line is the only one that evaluates as true. Something is definitely wonky with this piston… I have never seen it evaluate backwards before.


Maybe change your Ternary operators to reflect something like
isBetween($now, morning, afternoon)
instead?

An example can be found here.


#88

Hopefully @Robin can chime in since he is the one most familiar with this piston.
(I don’t use this piston, I was just trying to help)


#89

Every day at 7:30AM
IF Any of Presence Sensor 3 & 5 are present
Then
Set location to Home - Morning
END IF
END EVERY

I liked this piston because of the flexibility of expanding to additional time slots without having to individually code them all, but I think I may just keep it simple and do it exactly this way.


#90

Copying by dragging and dropping makes that part much easier.


#91

If you made it this far in the post, you’ve probably figured out that there is a problem using $time24.

In morning hours, time24 returns 0:15, 1:15, 2:15, 3:15, etc. There is no leading zero so a 3:15 returns higher than something like 13:15, because the 3 is higher than the 1 in 13. Faulty logic.

Okay, how to fix: Convert military time into # of minutes since midnight.

Create a variable called CurrentTime. Default it with the expression (($hour24 * 60) + $minute). Use CurrentTime in place of all your $time24.

This will give you a result in minutes since midnight. Convert all your time variable to integers and calculate the time since midnight. Enter that as the value.

My 6:30 am variable is now “390”, which is (60 * 3 + 30).


#92

I am very late to the table here, but I am using the $now24 variable and its all working for me. Curious if they have fixed the issue or if I am just lucky?

Anyone know?


#93

Okay, I’m even later to the game since I hosed my simple pistons the other day and haven’t been able to recover. Therefore it time to set variable fresh start.

Rizlah, since you seem to have the last incarnation of this piston can you please post the code?

Thanks
W


#94

Not sure what you mean, you can see all the pistons that you have posted by scrolling up in this post.


#95

@MRobi, is this piston still working for you?


#96

Trying to simplify this piston and I cant get the SHM to turn off when I am home. Anybody see what I am doing wrong? It should be turning off at 7am but it doesnt. It evaluates to disarm the SHM but it doesnt actually do it.


#97

SHM was part of the Classic app and that was shutdown last week. At this point, you can not directly manage STHM in the new app using webcore.

You can indirectly control STHM using virtual devices.