Setting up Astro, Cron, Presence Rules

Hey guys,

I am still fairly new to the rules engine and I’ve dug through the documentation and done some google searching but have not found what I’m looking for or not seen it.

I have a few rules that seem to be working that are created in the Paper UI. I want to move these to the .Rules file so I can add more rules.

I have two rules I could use some help with:

Rule #1

When:
If Astro Sun Data (Astro:sun:home:daylight#event) Starts

Do:
Turn on Bed Light

Condition:
Only If gPresence = ON

** This is the part I’m unsure about **

ONLY IF day of week = MON-FRI

Not sure if I can use Cron with " 0 0 0 * MON-FRI ?"
Can someone help to explain how to drive a rule only on weekdays?

*Goal = The bed light turns on Mon-Fri to get ready for work but will not turn on on the weekends to sleep in.

Rule #2

I have a rule firing at sunset to turn on lights if I’m home.

I’d like the rule to turn on lights when the gPresence status updates if it’s between sunset and midnight

** Rule Concept as I understand it **

When:
gPresence Status = ON

Do:
Den_Light = ON

Condition: (Unsure Part)
IF Current Time > than Sunset and Current Time < Midnight

  • Goal = that when I come home after sunset and my phone connects to the wifi the rule will fire and turn on lights while I get out of the car.

Thanks for the help guys.

There is no “But only if…” in .rules. You need to write an if statement to cover those cases and exit the Rule if there is nothing to do.

if(gPresence.state == OFF) return;

It would be useful I think to review the Design Pattern: Time Of Day. Even if you don’t use it, it can help you understand how to do date/time comparisons.