Event based Automation with Time

8 years 11 months ago #1360 by Cory
Does anyone have a recommendation on how to create an event based automation that also checks the time (or date)?

For example.

If Motion is detected and time is between 8pm and 8am (8am next day), then turn on a light.
Alternately if motion is detected and time is NOT between 8am and 8pm of the same day, then turn on the light.

The reason I want to use event based is because the cron checks minute by minute and would be "laggy" for something like motion detection.

Please Log in or Create an account to join the conversation.

8 years 11 months ago #1361 by HarryDutch
You can use gw.requestTime(receiveTime) in your sketch to get the time from the server. So in this case as soon as an event has been triggered (your motion detector) your sketch will handle the switching of the light depending on the received time. Let me know if you need more information.

Please Log in or Create an account to join the conversation.

8 years 11 months ago #1363 by Cory
The light relay and Motion detector are different sensors. It would be preferable to keep the sketches simple and use automation to be complex. Also, the light relay's are inside the wall and not easily updated.

I guess i'm asking if its possible to use the real time inside the server automation.
The following user(s) said Thank You: ArneiO

Please Log in or Create an account to join the conversation.

8 years 11 months ago - 8 years 11 months ago #1366 by ArneiO
I have not tried it yet, but could a Cron expression do that?
en.m.wikipedia.org/wiki/Cron
EDIT:
Does anyone know if this Cron setting would cause the automation to run only between 8am and 8 pm every day?
* 8-20 * * *

Please Log in or Create an account to join the conversation.

8 years 11 months ago #1390 by EasyIoT
You can use EventHelper to detect motion event and then check if time is right.

Use following check:
DateTime t = DateTime.Now;
  
  if (t.Hour > 8 && t.Hour < 20)
  {
   // your code to execute
  }
The following user(s) said Thank You: osalval, ArneiO

Please Log in or Create an account to join the conversation.

Time to create page: 0.234 seconds

Forum latest

  • No posts to display.