Rule with complex time/cron+trigger based events

Hi,
i have a motioneye webcam that detects motion that triggers the setting of an item + based on a rule only informs me when its after 6pm and before 6am…so during the night.
What i would like to extend is that it does the same as currently implemented for Mo-Fr…however during weekend it should inform me anytime that a trigger happens…

How could that work? i thought about cron time but this only works for the examples if i use “when time…”.

Could you please be so kind and give me same advice/example…many thanks! Norbert

rule "NG4CarPort Presence - Timestamp"
when
    Item NG4_cpPIR received update
then
    postUpdate(NG4cpMotion, new DateTimeType())
    if (now.getHourOfDay() >= 18 || now.getHourOfDay() <= 6) {
                sendPushoverMessage(pushoverBuilder("Log | MotionDetection").withTitle("NG4 | CarPort").withSound("siren")) }
end

Just use now.getDayOfWeek as your first if clause.

1 Like

great, thanks for this…
Could you be so kind and shortly cross check if this is an efficient way to do so…
a little mixed up time & day…but if SAT or SUN it will trigger anytime, and for the rest only from 6pm to 6am…

if (now.getDayOfWeek >= 6 || now.getHourOfDay() >= 18 || now.getHourOfDay() <= 6) {
                sendPushoverMessage(pushoverBuilder("Log | MotionDetection").withTitle("NG4 | CarPort").withSound("siren")) }

There is a capability in 2.5 called Ephemeris. https://www.openhab.org/docs/configuration/actions.html#ephemeris that lets you define holidays and days if the week.

Then in your Rule you just call if(isWeekend || now.getHourOfDay() >= 18 || now.getHourOfDay() <= 6).

1 Like