Just wondering if anyone could help me out with how to ‘stack’ embedded IF and ELSE statements in a rule correctly.
Basically, i want the main part of the rule to run when ‘FilterSetting’ = 2. If that is true, i need the top half to run if UV_Filter == OFF and the second half to run if UV_Filter is ON.
Rule runs great, but it seems that the second half (else { if (hr1gain > 0) { runs even when UV_Filter == OFF, even though the IF statement above is True.
Here is my rule:
rule "Solar Adaptive"
when Time cron "0 0/15 * ? * * *"
then
if (FilterSetting.state == 2) {
var hr1gain = (SolarGain.sumSince(now.minusHours(1), "rrd4j"))
if (UV_Filter == OFF) {
if (hr1gain > 600) {
sendHttpGetRequest("http://192.168.86.24/white/2?turn=on&timer=3660")
logInfo("Pond Rule", "Solar Gain more than 10W, filter on for 1 hour (" + hr1gain + "value)") }
if (hr1gain > 1200) {
sendHttpGetRequest("http://192.168.86.20/white/3?turn=on&timer=3660")
logInfo("Pond Rule", "Solar Gain more than 20W, UV filter on for 1 hour" ) }
}
else {
if (hr1gain > 0) {
sendHttpGetRequest("http://192.168.86.24/white/2?turn=on&timer=3660")
sendHttpGetRequest("http://192.168.86.20/white/3?turn=on&timer=3660")
logInfo("Pond Rule", "Solar Gain >0 Filters to remain on (" + hr1gain + " value)") }
}
}
else
logInfo("Pond Rule", "Solar not set to Adaptive")
end
rule "Solar Adaptive"
when
Time cron "0 0/15 * ? * * *"
then
if (FilterSetting.state == 2) {
var hr1gain = SolarGain.sumSince(now.minusHours(1), "rrd4j")
if (UV_Filter.state == OFF) {
if (hr1gain > 600) {
sendHttpGetRequest("http://192.168.86.24/white/2?turn=on&timer=3660")
logInfo("Pond Rule", "Solar Gain more than 10W, filter on for 1 hour ({} value)", hr1gain)
}
if (hr1gain > 1200) {
sendHttpGetRequest("http://192.168.86.20/white/3?turn=on&timer=3660")
logInfo("Pond Rule", "Solar Gain more than 20W, UV filter on for 1 hour")
}
} else {
if (hr1gain > 0) {
sendHttpGetRequest("http://192.168.86.24/white/2?turn=on&timer=3660")
sendHttpGetRequest("http://192.168.86.20/white/3?turn=on&timer=3660")
logInfo("Pond Rule", "Solar Gain >0 Filters to remain on ({} value)", hr1gain)
}
}
} else {
logInfo("Pond Rule", "Solar not set to Adaptive")
}
end
You have to care about indentation yourself simply use <tab> for indentation, VSCode will keep the indentation. It’s also possible to change indentation for more than one line at once (both directions).