Set dynamic expire intervall for item

Hi there,

I just started with openHAB after receiving my Buderus KM200 gateway. I already managed so far to setup the KM200 binding and define the items file and started to play around with the sitemap.
I am already able to switch the operations mode of my Buderus heating between the three states “auto”, “day” and “night”. I found that there is the “expire” binding to switch back a state of an item after a certain intervall given by expire. I tried this out but it does not work. And I have two questions now:

  1. What am I doing wrong that the operations mode does not switch back after a certain time?
  2. Is it possible to dynamically set the expiration intervall for an item?

Find below the excerpts of my Heizung.items file:

...

String	modeBudHeiz			"Mode-Heizung [%s]"		 				(gHeating) 	{km200="service:/heatingCircuits/hc1/operationMode"}

...

Switch	modeBudHeizNight	"Nightmode-Heizung [%s]"		 		(gHeating) 	{km200="service:/heatingCircuits/hc1/operationMode	on:night	off:auto"}
Switch	modeBudHeizDay		"Daymode-Heizung [%s]"		 			(gHeating) 	{km200="service:/heatingCircuits/hc1/operationMode	on:day		off:auto"}

String	pauseBudHeiz		"5 Min. Pausemodus setzen [%s]"		 	(gHeating) 	{km200="service:/heatingCircuits/hc1/operationMode", expire="5m,command=auto"}

...

The switches are not yet used. They are from the example file …
I have mapped the heatings operationsMode to two items: “modeBudHeiz” and “pauseBudHeiz

modeBudHeiz is intended to set the operations mode generally.

pauseBudHeiz is intented to set temporarily the operations mode to “night=off” and automitcally switch it back after 5 minutes to auto

This is my default.sitemap. It contains also some graphs which are not important here …

sitemap default label="My first sitemap"
{
   
   Text item=budDate label="Datum / Uhrzeit [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" icon="time"

   Text item=modeBudHeiz label="Aktueller Heizungsmodus [%s]" icon="heating"
   
   Selection item=modeBudHeiz label="Heizungsmodus setzen [%s]" icon="switch" mappings=[auto=Programm, day=Tag, night=Nacht]
      
   Selection item=pauseBudHeiz label="5 Minuten Pausemodus [%s]" icon="switch" mappings=[auto=Programm, day=Tag, night=Nacht]

   Chart item=istBudAussen icon="temperature" label="Außentemperatur" refresh=1500 period=1d service="mysql"
   
   Chart item=istBudHeizDruck icon="temperature" label="Heizkreis-Wasserdruck" refresh=1500 period=1d service="mysql"

   Chart item=istBudHeizTemp icon="temperature" label="Raum-Temperatur" refresh=1500 period=1d service="mysql"
   
}

The first selection “modeBudHeiz” works fine and I am able to set the mode and I can see from my RC35 operations panel that the mode is changed correctly.

I made the second selection “pauseBudHeiz” to point the the alternative item which I want to change the operations mode only for 5 minutes (see items file).

Switching the mode works but switching back never happens => see excerpt from “openhab.log”.
I initiated the change via the Basic UI panel at 10:47:57 but even ten minutes later there is no switching back to “auto” as configured with expire => {km200=“service:/heatingCircuits/hc1/operationMode”, expire="5m,command=auto"}

10:47:57.140 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'pauseBudHeiz' received command night
10:47:57.141 [INFO ] [marthome.event.ItemStateChangedEvent] - pauseBudHeiz changed from auto to night
10:48:45.693 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.8999996185302734375 to 16.799999237060546875
10:48:46.496 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:50:34.000+0000 to 2017-10-03T12:51:35.000+0000
10:48:46.626 [INFO ] [marthome.event.ItemStateChangedEvent] - modeBudHeizNight changed from OFF to ON
10:48:47.694 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasser changed from 61.799999237060546875 to 61.90000152587890625
10:48:49.566 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasserM changed from 61.90000152587890625 to 61.799999237060546875
10:48:51.969 [INFO ] [marthome.event.ItemStateChangedEvent] - modeBudHeiz changed from auto to night
10:48:52.704 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 75.6999969482421875 to 75.8000030517578125
10:49:45.526 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:51:35.000+0000 to 2017-10-03T12:52:34.000+0000
10:49:48.336 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasserM changed from 61.799999237060546875 to 61.90000152587890625
10:49:51.547 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 75.8000030517578125 to 76.09999847412109375
10:50:45.601 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:52:34.000+0000 to 2017-10-03T12:53:34.000+0000
10:50:51.255 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 76.09999847412109375 to 76.1999969482421875
10:51:44.492 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.799999237060546875 to 16.700000762939453125
10:51:46.007 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:53:34.000+0000 to 2017-10-03T12:54:35.000+0000
10:51:51.497 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 76.1999969482421875 to 76.3000030517578125
10:52:44.784 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.700000762939453125 to 16.799999237060546875
10:52:45.611 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:54:35.000+0000 to 2017-10-03T12:55:35.000+0000
10:52:48.361 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasserM changed from 61.90000152587890625 to 61.799999237060546875
10:53:44.002 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.799999237060546875 to 16.8999996185302734375
10:53:44.819 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:55:35.000+0000 to 2017-10-03T12:56:33.000+0000
10:53:45.755 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasser changed from 61.90000152587890625 to 61.799999237060546875
10:54:44.036 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.8999996185302734375 to 16.799999237060546875
10:54:44.862 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:56:33.000+0000 to 2017-10-03T12:57:33.000+0000
10:55:44.018 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.799999237060546875 to 16.8999996185302734375
10:55:44.955 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:57:33.000+0000 to 2017-10-03T12:58:33.000+0000
10:56:44.038 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.8999996185302734375 to 16.799999237060546875
10:56:44.863 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:58:33.000+0000 to 2017-10-03T12:59:33.000+0000
10:56:47.410 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasserM changed from 61.799999237060546875 to 61.90000152587890625
10:56:50.549 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 76.3000030517578125 to 76.1999969482421875
10:57:45.395 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T12:59:33.000+0000 to 2017-10-03T13:00:34.000+0000
10:57:47.762 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudWasserM changed from 61.90000152587890625 to 61.799999237060546875
10:57:51.079 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 76.1999969482421875 to 76.09999847412109375
10:58:44.322 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudAussen changed from 16.799999237060546875 to 16.700000762939453125
10:58:45.142 [INFO ] [marthome.event.ItemStateChangedEvent] - budDate changed from 2017-10-03T13:00:34.000+0000 to 2017-10-03T13:01:34.000+0000
10:58:51.563 [INFO ] [marthome.event.ItemStateChangedEvent] - istBudHeizKessel changed from 76.09999847412109375 to 75.90000152587890625

Probably a simple misunderstanding but I would kindly appreciate to get some rookie support :wink:

Cheers
Justus

I’m unsure if command can be used on a String item, try changing “command=auto” to “state=auto” instead…

Hi Alpoy,

thx for your hint, I will try. Seems to me that I had the right idea and I am doing quite right. I just changed my items file and need to wait now for 5 minutes …

Hi again,

tried “state=auto” … same behaviour
now trying “value=auto” …
will try simply “auto” …

keep you posted.

None of the tested above syntax options solved the problem …

I haven’t use the expire binding with a string yet, but you could try:

expire="5m,auto"}

Edit: okay, you already did:

Hi,

I played around a little bit and found that it works with item type Switch. Probably it does not work with item type String? But sihui’s reply indicates that it should work also with String :thinking:

Anyway, here is what I did to make it work for the moment …

excerpt from Heizung.items:

Switch	modeBudHeizPause	"Pausemode-Heizung [%s]"		 (gHeating) 	{km200="service:/heatingCircuits/hc1/operationMode	on:night	off:auto", expire="5m,command=OFF"}
Switch	modeBudHeizParty	"Partymode-Heizung [%s]"		 (gHeating) 	{km200="service:/heatingCircuits/hc1/operationMode	on:day	off:auto", expire="5m,command=OFF"}

and here the excerpt from default.sitemap:

   Selection item=modeBudHeizPause label="Pausemodus  [%s]" icon="switch" mappings=[ON=Nacht, OFF=Prog]
   Selection item=modeBudHeizParty label="Partymodus  [%s]" icon="switch" mappings=[ON=Tag, OFF=Prog]

And here the proof in the openhab.log:

14:50:09.336 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'modeBudHeizParty' received command ON
...
14:50:51.270 [INFO ] [marthome.event.ItemStateChangedEvent] - modeBudHeiz changed from night to day

...

14:54:47.575 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'modeBudHeizPause' received command OFF
14:54:47.576 [INFO ] [marthome.event.ItemStateChangedEvent] - modeBudHeizPause changed from ON to OFF
...
14:55:56.892 [INFO ] [marthome.event.ItemStateChangedEvent] - modeBudHeiz changed from day to auto
14:55:57.473 [INFO ] [marthome.event.ItemStateChangedEvent] - modeBudHeizParty changed from ON to OFF
...

Question remains why item type Switch works but String doesn’t ???
I would be curious if it should work with item type String and how the config should look like then …

But my initial question is also still open: How to set the intervall value dynamically for the expire binding

... , expire="XXm,command=OFF"}   // set the XX value dynamically e.g. from selection in sitemap

I would kindly appreciate any idea!!!

Cheers
Justus

I don’t think that is possible, haven’t read anything about that yet.
But it looks like that is possible with a timer:

Thank You sihui!
I kindly appreciate your the quick response and the idea to use a timer via the rules engine. I have also thought in that direction but this is currently too high sophisticated for my skill level of programming rules …
It starts with the challenge how to create a local “dummy” item which is not part of a sensor or device thing or binding where I can simply store the result of a selection on the sitemap page to define the length of the pause/party interval: e.g. 1h, 2h, … 6h.

Once having this interval value I can create an appropriate rule and start a timer when the state of the switch changes to “ON” and after the timer has run down to change the switch state back.

But I do not know how to define an item that I fill with a value through the sitemap … which is not from a sensor, channel, device, binding, etc. …

I fear that I have to gain some more insight first :nerd_face:

Cheers
Justus

Best place to start is the “Tutorial and Examples” section:

https://community.openhab.org/c/tutorials-examples

Look for the “Design Patterns”.

A quick approach would be:

items file:

Number Test_Delay_Proxy

sitemap file:

Setpoint item=Test_Delay_Proxy minValue=1 maxValue=6 step=1 label="Set delay [%s]"

There may be easier or much better solutions, I’m only a copy and paste programmer :grinning:

Awesome !!! :-:clap::clap::clap:

Did not realize that it is so easy to define such a “dummy” item. Works like a charm!
I created the variable and will now think on how to build the appropriate rule.
Probably tomorrow :wink:

Thanks for your great support …

1 Like

Hi all,

thanks to the great support here in the forum I solved my challenge to implement the so called “Party-Modus” (to extend the heating interval) and “Pause-Modus” (to shorten the heating interval) for my Buderus heating via the KM200. Normally you can only set this with the direct attached controller and it can not be set via the Buderus EasyControl app. With the rules and sitemap that I defined, I found a way to copy this function to openhab!!!

But I am tired today. I will document everything tomorrow or latest next weekend.

Cheers
Justus

2 Likes

Hi @ohb1138: I’m also looking for a way to expire an item for “Party-lights”, which should expire dynamically depending on status… how did you do it in the end? :wink:

Hi Thomas,

this is my “Party” or “Pause” rule:

rule "Party/Pause Modus setzen"
when Item modeBudHeiz received command
     then
     ManualOverWrite.postUpdate(1)
     Thread::sleep(5000)
     if (modeBudHeiz.state=="day" && intvlBudHeiz.state > 0) {

        logInfo("FILE", "***** PARTY Modus aufgerufen !!! ***** ")
        logInfo("FILE", "Heizungsmodus ist: " + modeBudHeiz.state)
        logInfo("FILE", "Dauer (in Stunden): " + intvlBudHeiz.state)

        count = intvlBudHeiz.state

		    intvlBudHeiz.postUpdate(0)

        //timer = createTimer(now.plusMinutes(count.intValue)) [|
        timer = createTimer(now.plusHours(count.intValue)) [|
           modeBudHeiz.sendCommand("auto")
           ManualOverWrite.postUpdate(0)
           Thread::sleep(3000)
           logInfo("FILE", "Heizungsmodus ist: " + modeBudHeiz.state)
           logInfo("FILE", "Dauer (in Stunden): " + intvlBudHeiz.state)
           logInfo("FILE", "***** PARTY Modus beendet !!! ***** ")
        ]
     }
     if (modeBudHeiz.state == "night" && intvlBudHeiz.state > 0) {

    	  logInfo("FILE", "***** PAUSE Modus aufgerufen !!! ***** ")
        logInfo("FILE", "Heizungsmodus ist: " + modeBudHeiz.state)
        logInfo("FILE", "Dauer (in Stunden): " + intvlBudHeiz.state)

        count = intvlBudHeiz.state

        intvlBudHeiz.postUpdate(0)

        timer = createTimer(now.plusHours(count.intValue)) [|
           modeBudHeiz.sendCommand("auto")
           ManualOverWrite.postUpdate(0)
           Thread::sleep(3000)
           logInfo("FILE", "Heizungsmodus ist: " + modeBudHeiz.state)
           logInfo("FILE", "Dauer (in Stunden): " + intvlBudHeiz.state)
           logInfo("FILE", "***** PAUSE Modus beendet !!! ***** ")
        ]
     }
     if (modeBudHeiz.state == "auto") {
        logInfo("FILE", "***** AUTO Modus gesetzt: Do Nothing !!! ***** ")

        ManualOverWrite.postUpdate(0)
        intvlBudHeiz.postUpdate(0)

        Thread::sleep(3000)
        logInfo("FILE", "Heizungsmodus ist: " + modeBudHeiz.state)
        logInfo("FILE", "Dauer (in Stunden): " + intvlBudHeiz.state)
     }
end

The most important part for the dynamic time setting is this part:

        ...

        count = intvlBudHeiz.state

        intvlBudHeiz.postUpdate(0)

        timer = createTimer(now.plusHours(count.intValue)) [ |
           modeBudHeiz.sendCommand("auto")
           ManualOverWrite.postUpdate(0)
           Thread::sleep(3000)
           logInfo("FILE", "Heizungsmodus ist: " + modeBudHeiz.state)
           logInfo("FILE", "Dauer (in Stunden): " + intvlBudHeiz.state)
           logInfo("FILE", "***** PAUSE Modus beendet !!! ***** ")
        ]

     ...

The variable count gets the value of a Setpoint trigger in the default.sitemap at the Basic UI web frontend:

   Setpoint item=intvlBudHeiz minValue=0 maxValue=12 step=1 label="1. Dauer [%d h]" icon="qualityofservice"

So count gets an hour value from intvlBudHeiz

Then comes the timer. This is accomplished by the following code leveraging the count variable:

     timer = createTimer(now.plusHours(count.intValue)) [ |
     // put your commands here
     ]

Please recognize the bracket and pipe characters at the end of the timer line: [ | which marks the beginning of the entity and the ] in the third line which marks the end of the timer entity.

So to explain everything without the rule code:

  1. Create a variable/item that you gets set a value through the sitemap
  2. Define a variable in your rule which takes this value (you could probably do it directly)
  3. Leverage the createTimer function to set the runtime for the timer (there are also counters for seconds and minutes: now.plusSeconds and now.plusMinutes
  4. Put the appropriate commands into the the timer brackets [ | and ] which are run after the timer is finished.

I hope that I explained it well how it works. Otherwise just ask back :slight_smile:

3 Likes