A better strategy for cron only if someone is home (but could come home after the cron time)

Folks,

Is there a better strategy for this?

I have a rule

rule "Kids - Ready for bed"
when
        Time cron "0 00 19 ? * MON,TUE,WED,THU,SUN *"     //19:00 SUN-MON
    or  Time cron "0 01 20 ? * SAT,FRI *"                 //20:01 FRI-SAT
then
    logInfo("Kids - Ready For Bed", "Turning On")
    g_KidsReadyForBed.sendCommand(ON)
end

I don’t want this to fire if no one is home. That’s easy.
I could add

if (SomeoneHome.state != ON){
return;
}

SomeoneHome is a presence Item I have and drives a lot of things.

However, what if someone comes home at 19:20? I would like to turn it on.
I should only turn it on though if someone comes home and it’s between the time frame.

Simply, I can have the cron or SomeoneHome event and then check to see that the hour of the day is between the cron but that smells.

I’m not sure I want to remove the cron boundaries and make it run every 5 minutes and check inside the rule. That too smells :slight_smile:

Any other options people use for checking this type of “AND/OR” trigger?
I’ve got a few examples like this so trying to work out a solution which will be generic.

C

Do this:

rule "Kids - Ready for bed"
when
        Time cron "0 00 19 ? * MON,TUE,WED,THU,SUN *"     //19:00 SUN-MON
    or  Time cron "0 01 20 ? * SAT,FRI *"                 //20:01 FRI-SAT
then
    logInfo("Kids - Ready For Bed", "Turning On")
    KidsReadyForBedTime.postUpdate(ON)
    if (SomeoneHome.state == ON) {
        g_KidsReadyForBed.sendCommand(ON)
    }
end

Rule "someone came home"
when
    Item SomeoneHome changed to ON
then
    if (KidsReadyForBedTime.state == ON) g_KidsReadyForBed.sendCommand(ON)
end

At the cron times set another item KidsReadyForBedTime to ON
If someone is home then do as before and send a command to your group

When someone comes home and KidsReadyForBedTime is set to ON (ie: in the time window)
then send a command to your group

Don’t forget to reset the new item to OFF later on

Did you have a look at the DP: Time of Day? You are on the right track

That’s great. thanks.

I was going down the group “Armed” group route. Have a group AND(OFF,ON) and all items in there. When the group becomes ON then they’re all set.

I think I prefer your option though.

Thanks again.

C

To make it generic, I could have all my “isArmed” items in a group.
If SomeoneHome == OFF for a specific rule, I can find and set the partner isArmed item to on.

I can then have a rule which triggers when someone home and it runs over the isArmed=ON items and sets sends command to the partner item to actually action the event.

Doable but lumpy. :slight_smile: