Setting modes based on time of day and presence

mode
presence

#9

Nice!

Just thinking it would be nice if 12:34:56 was automatically recognised as a time on its own and evaluated as 45240000


#10

btw… does anyone know the correct terminology for daily times displayed as number strings?

I was thinking it could be Epoch or Unix but that refers to a running string starting January 1, 1970, whereas the expressions are using a running string starting at 00:00 daily.

time to decimal (ms)?


#11

Are you referring to 13:12:11 format? That can be called “international standard notation” or more commonly in programming by the name of the standard, “ISO 8601 time format.”


#12

No, I’m referring to 18000000 format (i.e. 5am)


#13

Ah, up to you I suppose. In this context “time” implies “since midnight” so you could refer to it as time in milliseconds, timeMS, etc. just not epoch or unix timestamp since as you mentioned those are different.


#14

Did you guys invent a new language. I’m pretty sure only 10% of that was English :joy:


Routine director piston not firing
#15

:roll_eyes: uhoh, this doesn’t work. This also ignores the seconds, so time(datetime('12:34:05')) is the same as time(datetime('12:34:56')) because datetime('12:34:05') is the same as datetime('12:34:56')… hmm


#16

This seems to trace back to the SmartThings timeToday function only accepting the hh:mm portion. Based on that I’m not sure of any clean way to make a time literal with seconds… we’re left with representing 14:15:16 as something ugly like time(addSeconds(datetime('14:15'), 16))

Lots of mystery surrounding this datetime function.


#17

Anyway, I just changed my ternary operator to use < instead of <= so the seconds no longer matter.


#18

Hey all,

Ok so I need some assistance on how to get the correct expression. Here is what I am hoping to do:

Variable FutureTime = +5 minutes from current time

While time($now) != time(FutureTime) do
…these checksums, etc
end while

Basically I am trying to run a while statement to check for motion sensor changes in a given timeframe to reset my timeout period before turning off the lights. I am using EcoLink Motion Sensors using the test pin and they reset in 30 secs which is great. But if you are sitting idle in the room and it goes inactive during the end of a predetermined wait period it shuts off the lights as your If statement became true. Any help is appreciated!


#19

Can you post your current piston snapshot… sounds like you might be over complicating things.

In a nutshell, this should be all you need:

IF
motion is active
THEN
Turn on light
ELSE
Wait 5 minutes
Turn off light


#20

My issue has been knowing if a room is really occupied or vacant. I believe I just found my solution with Rooms Manager. Does almost everything I need for both security true motion detection and light automation based on true occupancy.


#21

Thanks for sharing this! I made a simplified version for myself based on your variables and it works great to set the correct mode when arriving home.


#22

@Robin

So I have been using this Piston for a few months that you helped me streamline. So far it has been working fairly well but there are a couple of issues that I would like assistance with addressing.

  1. When night time mode triggers (11:00PM) it doesn’t turn off the lights in the light variable. I thing this might be a simple change but I’m not sure.
  2. Sometimes when leaving certain lights will not go off, I’m not 100% how to troubleshoot this issue as it is random when it happens.
  3. How hard would it be to set Arlo mode based on presence in this same Piston?

#23

Hi All,

Im new here. Please go soft! :slight_smile:

I have tried to install this app. I get this error when I run the test…

Error setting location mode. Mode ‘Home - Day’ does not exist.

Where do you need to create the Home - Day location? Within the IDE im guessing? Do you need one for each mode?


#24

Modes have to be created and named in the IDE.

You need a mode matching each one on listed in post 1, or rename them in the piston as desired.


#25

Got it. Thanks. :slight_smile:


#26

This works great Robin! Thanks for putting together…

If I wanted to add a few new modes in would it just be a case of adding the new “time” then defining in the “time of home” and “time of night”…

I wanted to add a new day mode from 10am to 2pm then a evening mode (between 6pm and 6:30pm) and then one between 6:30pm and 20:00


#27

It’s a bit more in depth than that… ternary operators need updating.

If I get time later I’ll see if I can update it for you.


#28

This should do the trick:

Rather than trying to guess your mode names, I’ve just called them:

  • Sleep
  • Home - 1
  • Home - 2
  • Home - 3
  • Home - 4
  • Home - 5
  • Home - 6
  • Away - 1
  • Away - 2
  • Away - 3
  • Away - 4
  • Away - 5
  • Away - 6

You just need to change these mode names to your desired names in both of the ternary operators (‘timeOfDayHome’ & ‘timeOfDayAway’)

If you don’t need all the steps, just have 2 of 3 times in the middle apply the same mode name.