I’m trying to use OH3 GUI as much as posible to define rules but I have one question regarding the way to manage rules where you want to save current status of a light (for instance) to go back to it in the future.
Let’s me try with an example. I have this defined into a rules file
var vDS_LightCeilingHall_Brightness_PreviousState = null
rule “Turn on light when open closet”
when
Item DS_Closet_Magnet changed from CLOSED to OPEN
then
if((DS_MotionSensor_Illuminance.state as Number).floatValue < 100) {
vDS_LightCeilingHall_Brightness_PreviousState = storeStates(DS_LightCeilingHall_Brightness)
DS_LightCeilingHall_Brightness.sendCommand(50)
}
endrule “Restore light when close closet”
when
Item DS_Closet_Magnet changed from OPEN to CLOSED
then
if(vDS_LightCeilingHall_Brightness_PreviousState !== null) {
restoreStates(vDS_LightCeilingHall_Brightness_PreviousState)
vDS_LightCeilingHall_Brightness_PreviousState = null
}
else {
DS_LightCeilingHall_Brightness.sendCommand(0)
}
end
I think it is pretty straightforward but the idea is just turn on a light when I open a closet door and go back to its previous status (off or on with another brightness) when I close the same door.
This code is working at OH3 RC2 with no issue but, as I said, if I set it into a rules file the graphical rules editor says it is not editable and I would like to have as much as posible rules editable into the GUI.
Is it posible to have this rule/behavior not using .rules files in OH3?
At my understanding, putting the variables out of the rules themselves make them available for other rules hence the “vDS_LightCeilingHall_Brightness_PreviousState” is defined out of the “rules”.
At my understanding too, in OH3 rules editor, you can’t define those kind of global variables.
Are my understandings right? I’m new at OH but I’m trying to read here and there and I can be misunderstanding something.
Thank you in advance