PV
createState("sensors.lumi.motion.lobby.occupancy_real", false, {name:"Syntethic state for lumi.sensor_motion Occupancy", type: "boolean", read: true, write: true, role: "sensor.motion"});
createState("sensors.lumi.motion.lobby.occupancy_real_timeout", 15, {name:"Syntethic timeout state for lumi.sensor_motion Occupancy", type: "number", unit: "sec", read: true, write: true, role: "state"});
on({id: "linkeddevices.0.sensors.lumi.motion.lobby.occupancy"/*occupancy*/, change: "ne"}, function (obj) {
var value = obj.state.val;
var oldValue = obj.oldState.val;
var occupancyDelay = getState("sensors.lumi.motion.lobby.occupancy_real_timeout").val * 1000;
console.debug('Occupancy is changed ...');
if (getState("linkeddevices.0.sensors.lumi.motion.lobby.occupancy").val) {
console.debug('... to True');
if (getState("sensors.lumi.motion.lobby.occupancy_real").val) {
console.debug('but realOccupancy is True too. To prevent chnaging it to False, will clear any setStateDelayed');
clearStateDelayed("sensors.lumi.motion.lobby.occupancy_real")
} else {
console.debug('but realOccupancy is False. Going to chanage it to True');
setState("sensors.lumi.motion.lobby.occupancy_real"/*sensors.lumi.motion.lobby.occupancy_real*/, true, true);
}
} else {
if (getState("sensors.lumi.motion.lobby.occupancy_real").val) {
console.debug('but realOccupancy is True. Going to chanage it to False with delay');
setStateDelayed("sensors.lumi.motion.lobby.occupancy_real"/*sensors.lumi.motion.lobby.occupancy_real*/, false, true, occupancyDelay, false);
} else {
console.log('Occupancy is changed to False, but realOccupancy is already False. Please tune the timeout for object');
}
}
});