Rule Push Message to iOS App when Window longer Open

Hello,

my Openhab Installation works (myopenhab also works) now and now I wanna start whit some rules (but I am very bad a this).

I want some rules but the first one should do:

If Temperatur Outside (I have an Item for that) is lower the 12 Degrees and Window is open longer than 15 Minutes then
push a Message “Windows Bath still open” on my iOS Device (via OpenhabApp)

But I have no Idea About the Syntax :frowning:

p.s. if the myopenhab push is not so good I already can create a Telegram Bot.

I already found this but this doesn’t help me a lot.

sendBroadcastNotification("Hello world!")

i do a simple test script and this works.

rule "test"
when
	Item FensterSchalfzimmer_FensterZustand changed to OPEN
then
    if(Wetterinformation_Temperatur.state <= 10) {sendBroadcastNotification("Fenster Schlafzimer ist offen test")}
end

but I have no idea how what code I need for "windows longer open as 10 Minutes ".

var Timer FensterSchlafzimmer_Timer = null

rule "test"
when
    Item FensterSchalfzimmer_FensterZustand changed
then
    if (FensterSchalfzimmer_FensterZustand.state==CLOSED) {
        if (FensterSchlafzimmer_Timer!=null) {
            FensterSchlafzimmer_Timer.cancel
            FensterSchlafzimmer_Timer=null
        }
    }
    else if (FensterSchalfzimmer_FensterZustand.state==OPEN) {
        if (FensterSchlafzimmer_Timer==null) {
          FensterSchlafzimmer_Timer=createTimer(now.plusMinutes(10)) [|
            if(Wetterinformation_Temperatur.state <= 10) {
              sendBroadcastNotification("Fenster Schlafzimmer ist länger als 10 Minuten geöffnet")
            }
          ]
        }
    }
end

There is a Typo in your Item Name :wink: Schalfzimmer

BigThx this Works :slight_smile:
and yeah there is an bad typo :wink:

First
Maybe you or someone else can help me with to more Ideas.

First can I add some how in the brodcast Message the Outside temperature like
(“Fenster Schlafzimmer ist länger als 10 Minuten geöffnet und and Outside Temperatur is Wetterinformation_Temperatur.state” Degrees)

Should I create a extra Rule for every room?

Second Question

the same Idea from the first rule but no timer rather.

rule "test2"
when
     Item FensterSchalfzimmer_FensterZustand=OPEN 
then
     if (Time is Between 6:35 and 7:00 on Weekdays and temperature <=10degrees) {.    
//How I set Time and Weekdays  e.g. Monday till Friday and add the temperature

      sendBroadcastNotification("Fenster Schlafzimmer zu machen")}

You can make the message be anything you want.

sendBroadcastNotification("Fenster Schlafzimmer ist ist länger als 10 Minuten geöffnet und and Outside Temperatur is  
  • Wetterinformation_Temperatur.state.toString + " Degrees")

Depends on your specific requirements. I use one Rule and whenever any door (in my case) has been open for too long I send a single report with ALL the doors that have been open for too long. That way I can handle everything within on Rule as the message doesn’t depend on which sensor timer went off.

Check out the [Deprecated] Design Pattern: Time Of Day. With a little work you can expand it to include a state for weekday verses weekend and then your rules would use:

if(vTimeOfDay.state.toString == "EVENING" && vDayType == "WEEKDAY" && Wetterinformation_Temperatur.state <= 10)

Also see Design Pattern: Separation of Behaviors for ways to centralize your alerting so you can do some of these sorts of checks in a central location. For example, at night I use a different alerting mechanism than I do during the day. I send out alerts to specific phones sometimes and broadcast at others (e.g. broadcast when no one is home. But all this logic is in one place so I don’t need these kind of if statements everywhere I generate an alert.

Thx for your help :slight_smile:

I added the

Wetterinformation_Temperatur.state.toString + " Degrees")

string and it works perfect :slight_smile:
One question about it

Wetterinformation_Temperatur. <- this is the Item
.state.toString <-how I get this information , e.g. I wanna ad a state Like closed/open?

The second idea I think I need some Time to Understand this, this is all very new to me :slight_smile:

.state gives you the current state of the Item.

.toString converts the state to a string.

If your Item is a Contact Item, MyContactItem.state.toString will give you the string “OPEN” or “CLOSED” depending on the state of MyContactItem.