Hi everyone im having some trouble with a simple rule
what im trying to do is create a rule that checks every two mins if lights and motion detectors report as off if they are all off set a switch too OFF if any are on set the switch to ON my attempt below
rule "Motion Detection"
when
Time cron " 0 0/2 * 1/1 * ? *" //Every 2 mins
then
if( BULB1DSKITCHEN_Brightness.state == 0 ) {
if( Lamp1_Brightness.state == 0 ) {
if( BULB3LAMAIN_Brightness.state == 0 ) {
if( BULB4DSFDMAIN_Brightness.state == 0 ) {
if( BULB5TOMAIN_Brightness.state == 0 ) {
if( BULB7DSBACKDOOR_Brightness.state == 0 ) {
if( BULB8USBATHROOM_Brightness.state == 0 ) {
if( HUE_Motion.state == OFF ) {
if( HUE_Motion2.state == OFF ) {
if( HUE_Motion3.state == OFF ) {
if( HUE_Motion4.state == OFF ) {
if( HUE_Motion5.state == OFF ) {
House_Motion.sendCommand ("OFF") }
else {House_Motion.sendCommand ("ON")}
}}}}}}}}}}}}
end
Im still pretty newish too this I didn’t know there was an && operator the problem is with the switch part of the rule not the checking of item states I mainly make do with just using the if operator
rule "Motion Detection"
when
Time cron "0 0/2 * 1/1 * ? *" //Every 2 mins
then
if ((gHueMotions.state == OFF) && ((gTotalBrightness.state as Number) == 0)) {
House_Motion.sendCommand(OFF)
} else {
House_Motion.sendCommand(ON)
}
end
Haha there is alot of them it’s the only way I knew how too do what I wanted I have used the same rule slightly different before works perfect just couldent get it running for this use case
Correct. If you put all conditions in one if-statement with && between them all must be true for the code to run, if only one of them is false the else-code is run instead.
I use vscode to edit my files it has made it alot easier to create these files but I have been getting an error so its not working properly Im not sure what’s wrong and I just havent got around too finding the problem it says there is a server error check openhab log