How to reinitialize expire binding when it's not changing states?

Let’s say I do have state holder for all motion sensors, which I want to have expiration of 15mins like this:

Switch      holderMotionPresence    "Motion sensors [MAP(motion.map):%s]"    <motion> (gPresence) { expire="15m,command=OFF" }

Then I have a rule which changes this holder to ON when there is a motion like so

rule "Motion activity"
when
    Member of gMotion received update
then
    var now = new DateTimeType()
    postUpdate(triggeringItem.name+"_t", now.toString)
    postUpdate(gMotion_t, now.toString)

    if(triggeringItem.state == ON){
        postUpdate(holderMotionPresence,ON)
    }
end

But OH does not update ON to ON if that state was before, so expiry is running from first trigger but not from the last one.
How I can re-trigger ON eg. reset expiration timer on EACH triggering.state == ON ?
Do I need to toggle ON/OFF ? (which is weird way) or there is something else I can do?

Thanks

I do postupdate my motion sensor to OFF every time it’s triggerd. So every motion is a new OFF to ON, and this re-trigger my Item with an expire.

this is not about single motion detector (which are operated by mqtt on/off not by expiry)
but this is helper global, which should hold presence information (part of it)

I do have group:switch indeed as well, but I want different item to hold this information for me for various reasons.

Clear,

As far as I know the only way te retrigger the expire binding is let it recieve a ‘new’ ON command. So you will need to toggle something to create a state change from OFF to ON.

But maybe someone else has an other good idea.

I’ll try simply instead of postupudate sendcommand, let’s see

Every time an expire binding item receives any other command other then the command in the expire configuration (in this case command=OFF) the expire time is reset
maybe try sendCommand instead of postUpdate


from the docs
The expiration time will be started or restarted every time an item receives an update or command other than the specified “expire” update/command.

Any future expiring update or command is cancelled if the item receives an update or command that matches the “expire” update/command.

It does, but updates that don’t produce a change are not usually logged in events.log (just to reduce clutter).
You don’t need sendCommand to restart expire timing.

If you don’t believe that, that you can create a simple rule triggered on updated that logs out state. Unfortunately, implicit previousState is not available where there wasn’t actually a change, but looking at a few runs should convince.

There is a completely different question about whether bindings pass a device update to openHAB when there is no change. Generally they do, but this is binding specific.

it seemed like postupdate does not work, but sendcommand did the trick

Here is a demonstration of postUpdate working with expire binding, as documented.
Whatever you thought your problem was, had some other cause.

Switch testSw "slide me" {expire="2m, command=OFF"}
var counter = 0

rule "test expire begin"
when
    System started or 
    Item testSw changed to OFF  // expire completed
then
        // begin timing
    testSw.postUpdate(ON)
    logInfo("test", "postUpdate begins timing")
end

rule "test expire announce"
when
    Item testSw received command OFF
then
    logInfo("test", "Item has expired")
end 

rule "test expire restart"
when
    Time cron "0 0/1 * * * ?"  // every minute
then
    if (counter > 5 && counter < 10) {
           // block expire for 5 mins
        testSw.postUpdate(ON)
        logInfo("test", "postUpdate restarts timing")
    } else {
        logInfo("test", "expire timing allowed")
    }
    counter = counter + 1
end

results

2020-03-03 20:34:52.426 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'doors.rules'
2020-03-03 20:34:58.141 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate begins timing
2020-03-03 20:35:00.004 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:36:00.004 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:36:58.977 [INFO ] [.eclipse.smarthome.model.script.test] - Item has expired
2020-03-03 20:36:58.980 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate begins timing
2020-03-03 20:37:00.003 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:38:00.003 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:38:59.046 [INFO ] [.eclipse.smarthome.model.script.test] - Item has expired
2020-03-03 20:38:59.054 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate begins timing
2020-03-03 20:39:00.007 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:40:00.002 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:41:00.006 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate restarts timing
2020-03-03 20:42:00.007 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate restarts timing
2020-03-03 20:43:00.006 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate restarts timing
2020-03-03 20:44:00.009 [INFO ] [.eclipse.smarthome.model.script.test] - postUpdate restarts timing
2020-03-03 20:45:00.004 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:46:00.004 [INFO ] [.eclipse.smarthome.model.script.test] - expire timing allowed
2020-03-03 20:46:00.169 [INFO ] [.eclipse.smarthome.model.script.test] - Item has expired

Expire (after 2 mins) shown acting normally for 5 mins
Expire “reset” (restarted) by postUpdate for 5 mins
Expire normal working resumed.

I do believe you, I actualy don’t really care if I’m using sendcommand or postupdate, if both are working, better.

I ran this demo on OH3 and apparently postUpdate does not start an expire.

2021-12-18 06:30:36.957 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate begins timing
2021-12-18 06:31:00.867 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:32:05.000 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:33:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:34:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:35:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:36:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed

Strange … I ran this longer and it appears to be working. The initial postupdate failed.

2021-12-18 06:30:36.957 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate begins timing
2021-12-18 06:31:00.867 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:32:05.000 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:33:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:34:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:35:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:36:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:37:00.141 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate restarts timing
2021-12-18 06:38:00.141 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate restarts timing
2021-12-18 06:39:00.141 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate restarts timing
2021-12-18 06:40:00.142 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate restarts timing
2021-12-18 06:41:00.142 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:42:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:42:00.993 [INFO ] [org.openhab.core.model.script.test  ] - Item has expired
2021-12-18 06:42:00.997 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate begins timing
2021-12-18 06:43:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:44:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed
2021-12-18 06:44:01.019 [INFO ] [org.openhab.core.model.script.test  ] - Item has expired
2021-12-18 06:44:01.020 [INFO ] [org.openhab.core.model.script.test  ] - postUpdate begins timing
2021-12-18 06:45:00.141 [INFO ] [org.openhab.core.model.script.test  ] - expire timing allowed

Further research indicates the issue is with “System started” in OH3.