Hi everyone,
I am curious to ask wheter it is possible to “pause” the expire flag for a certain time.
So sometimes it is necessary to be in a room longer than the normal “expiry time” because you need to do some craftsman things or if you clean the room up for a longer time. And then you do not want to turn on the light every 3 minutes or something like that. And for my wife it is not possible to change the expire time herself before doing the things or when I am not at home.
As I do not want to buy presence sensors for all rooms where I use the expire flags I want to know if there is any possibility to pause it (as long as a specific switch item is ON or something similar) without a change in the code to remove the expire flags.
As a thought, you can manipulate the metadata that controls the expire functionality from within a rule. For example:
var OPENHAB_CONF = Java.type("java.lang.System").getenv("OPENHAB_CONF");
load(OPENHAB_CONF+'/automation/lib/javascript/core/metadata.js');
var metadata = get_value('TestSwitch', 'expire');
logger.info(metadata);
//is currently set to 5s
set_value('TestSwitch', 'expire', '0h0m20s,command=OFF');
//now set to 20s
I tested this and observed that if the switch is ON when the rule runs the expire won’t happen. Once the switch is toggled it will though, using the new timing that was defined.
Using this method to remove the expire metadata, then readding it when the control is deactivated may just work. If you want to make sure the expire takes effect after it’s put back in place (say the light is still on) you can do this:
All samples above were tested with 3.0.1, using UI defined Javascript rules. The metadata.js file referenced is a slightly modified version of the one released some time ago for OH2 in the openhabscripters repo.