How to make a rule with a time-window-exclution?

Dear Community,

i am trying to make a rule that reacts to a changed state of a device (if that speicific device gets offline) but only within a certain time window.

i would like to have the rule active nearly 24/7 except from 06:30 - 06:50 at every day.

I tried it like that:

rule "inform on power loss"    
when
    Item network_pingdevice_df634471_online changed from ON to OFF
  then
    //excluded time
    if ((now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(50)))!=1) {
    //send message
        logInfo("inform_on_power_loss", "send message to me")
        sendBroadcastNotification("send message to me")
        }

But it always send the message if the device changed from ON to OFF. My time exception does not work.

Would be glad if somebody can help me here!

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Rev 1.2
    • OS: Raspbian GNU/Linux 8 (jessie)
    • Version: openHAB 2.4.0-1 (Release Build)

with best regards
habpower

What’s the “!=1)” part supposed to do?

what i tried to achieve is:
“only if the time window 06:30 till 06:50 IS NOT valid/true/1/now send the message”

but i am open to complete different ways. I believe there is a simpler solution.

I would try the opposite , check if now isbefore 06:30 OR now isafter 06:50

but isn’t anytime before 06:30 that is not 06:30 ? The same goes with after 06:50 ?

you mean like that?
if (now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(30)) || now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(50))) {

Not understood!

i tried it like this

if (now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(30)) || now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(50))) { send…}

and like this:

if (now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(30)) || now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(50))) { send…}

also like that:

if ((now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(30)) && now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(50)))!=1) { send…}

and last but not least like that

if ((now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(30)) || now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(50)))!=1) { send…}

it unfortunately never worked. I believe i did not get your idea. Would you be so kind and emphasize on it a liitle bit more?

best regards
habpower

I’m sorry, however I am away from home so I can’t check to correct syntax ATM.

I do have time :slight_smile: i am open to any suggestions!

Thanks in advance

is there any advice?

best wishes

Such should work:

if ((now.isAfter(startOfDay.plusHours(6).plusMinutes(50)) ||
   			 now.isBefore(startOfDay.plusHours(6).plusMinutes(30))) {
			DoYourStuff...