rule "chiusura"
when
Item LivingRoom_Light1 changed to ON
then
var Number x = 0
if(DimmerCam.state instanceof Number)
x = ((DimmerCam.state as Number) * 0.24).intValue
tApertura?.cancel
tApertura = createTimer(now.plusSeconds(x)) [|
LivingRoom_Light1.sendCommand(OFF)
]
end
In the “THEN” i want that the system evoides to execute a rule (ex rule “apertura”).
How do i this?
and why in this situation is Auto.state always NULL?
rule "Scendi"
when
//Every weekday at 21:19 hours
Time cron "0 02 23 ? * MON-SUN *"
then
logWarn("Alarm", "The {} orario1", Auto.state)
Auto.state == 0
logWarn("Alarm", "The {} orario2", Auto.state)
// update item to switch on light here
LivingRoom_Light1.sendCommand(ON)
end
2019-03-21 23:02:00.471 [WARN ] [eclipse.smarthome.model.script.Alarm] - The NULL orario1
If Auto is a Number Item, you should use Auto.postUpdate(0) to set it. But that will take place outside your rule, if you immediately read the state again it will probably still be the “old” state.
All Items start off as NULL state until something updates them.
logWarn("Alarm", "The {} dovrebbe essere zero", Auto.state)
if (Auto.state == 0) {
Auto.state == 1
logWarn("Alarm", "The {} dopo messo a 1", Auto.state)
return;
}
2019-03-22 21:42:40.567 [WARN ] [eclipse.smarthome.model.script.Alarm] - The 0 dovrebbe essere zero
2019-03-22 21:42:40.576 [WARN ] [eclipse.smarthome.model.script.Alarm] - The 0 dopo messo a 1
rule "Scendi"
when
//Every weekday at 21:19 hours
Time cron "30 51 22 ? * MON-SUN *"
then
logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)
if (LivingRoom_Light2.state == ON) {
createTimer(now.plusSeconds(24))
}
Auto.postUpdate(0)
//dire Auto.postUpdate(0) significa dire che Auto.state == 0. con i numeri si scrive cosi
// logWarn("Alarm", "The {} dopo messo a 0", Auto.state)
// update item to switch on light here
LivingRoom_Light1.sendCommand(ON)
end
When your rule runs (at 22:51 each day), if LivingRoom_Light2 is on at that time, the rule creates a timer that does nothing. I expect it’ll generate an error actually, due to the missing lambda part.
That’s the end of the if() part.
Whether the if() runs or not, Auto will get updated to 0.
rule "Scendi"
when
//Every weekday at 21:19 hours
Time cron "30 58 22 ? * MON-SUN *"
then
logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)
//
if (LivingRoom_Light2.state == ON) {
createTimer(now.plusSeconds(24)) [|
LivingRoom_Light1.sendCommand(ON)
return;
]
}
//
Auto.postUpdate(0)
//dire Auto.postUpdate(0) significa dire che Auto.state == 0. con i numeri si scrive cosi
// logWarn("Alarm", "The {} dopo messo a 0", Auto.state)
// update item to switch on light here
LivingRoom_Light1.sendCommand(ON)
end
end
rule "Scendi"
when
//Every weekday at 21:19 hours
Time cron "00 00 20 ? * MON-SUN *"
then
logWarn("Alarm", "The {} all'inizio", LivingRoom_Light2.state)
//
if (LivingRoom_Light2.state == ON) {
logWarn("Alarm", "The {} dentro", LivingRoom_Light2.state)
when LivingRoom_Light2 received update
then
Auto.postUpdate(0)
LivingRoom_Light1.sendCommand(ON)
return;
}
end