Control rollershutter with multiple if conditions

Hi,

I would like to control my rollershutters depending on the luminance + a switch for disable the automatic control + a switch for wind protection.

My rule looks currently as shown below. Unfortunately it doesnt work.
If I use the rule with only 2 if conditions in the script block, then it works.
Is there a limitation on openhab, or do I have to define the rule in a different way?

Any help is very much apreciated.

rule “sensorgesteuerte Beschattung Sued EG”

when

Item kueche_luminance received command  

then

if ((kueche_luminance.state >4500) && (Wind.state==OFF) && (Automatik_aus.state==OFF)) {
sendCommand(Essen,25)
sendCommand(Kueche2,25)

}

end

No there’s no such limit, likely the code you added was bad.

Your curent rule triggers on ‘received command’ which is wrong since a sensor does not send commands (use “received update”).

PS: for a full-fledged shading rule see this.

kueche_luminance.state as Number > 4500

Hi, many thanks for the hints. Unfortunately the as number didn´t bring any effect.

I will try to modify now the code of mstormi. Let´s see if this will bring my rule to fire.

Add some logIfo statements to check the state of your tests items in the if statement BEFORE the if statement
Change the trigger to changed
Change the sendCommand actions into item methods

rule “sensorgesteuerte Beschattung Sued EG”
when
    Item kueche_luminance changed
then
    logInfo("kueche_luminance", kueche_luminance.state.toString)
    logInfo("Wind", Wind.state.toString)
    logInfo("Automatik_aus", Automatik_aus.state.toString)
    if ((kueche_luminance.state > 4500) && (Wind.state == OFF) && (Automatik_aus.state == OFF)) {
        Essen.sendCommand(25)
        Kueche.sendCommand(25)
    }
end

Hi again,

this is what I get from the logs…

2018-10-06 08:40:14.999 [INFO ] [rthome.model.script.kueche_luminance] - 13301
2018-10-06 08:40:15.008 [INFO ] [.eclipse.smarthome.model.script.Wind] - NULL
2018-10-06 08:40:15.016 [INFO ] [smarthome.model.script.Automatik_aus] - NULL
2018-10-06 08:40:15.030 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘sensorgesteuerte Beschattung Sued EG’: Could not cast NULL to java.lang.Number; line 98, column 8, length 20

But why should it cast Null? It should just read the NULL…

By the way… I get the same error when the luminance value is below the threshold of 4500 lux.

You need to accomodate with Xtend rules languages. It has got its rough edges and we all had to learn ourselves…the parser is telling you right where the error in your code is.

It’s good practice to use constants instead of literal numbers such as

val Number luminance_threshold = 4500

global to the rules file and to then use luminance_threshold everywhere you used to use the literal number 4500 before.

Hi, I need again your help. I changed the code as follows, but the rule does not fire …

when
Time cron “0 * 6-17 ? * MON-SUN” or
Item kueche_luminance changed

then
var Lux_Grenzwert_Kueche = Lux_Grenzwert_Sonnenschutz_Kueche.state as DecimalType
var Temp_Grenzwert_Sommer = Aussentemp_Grenzwert_Sonnenschutz_Sued.state as DecimalType

logInfo("kueche_luminance", kueche_luminance.state.toString)
logInfo("Lux_Grenzwert_Sonnenschutz_Kueche", Lux_Grenzwert_Sonnenschutz_Kueche.state.toString)
logInfo("Wind", Wind.state.toString)
logInfo("Beschattungsautomatik", Beschattungsautomatik.state.toString)

if (((Wind.state) !=1) && ((Beschattungsautomatik.state)==1) && ((kueche_luminance.state) >Lux_Grenzwert_Kueche)) {

Essen.sendCommand (25)
Kueche2.sendCommand (25)

}

if ((Wind.state !=1) && (Beschattungsautomatik.state==1) && ((kueche_luminance.state) >Lux_Grenzwert_Kueche) && (Multi1_temp.state as Number >Temp_Grenzwert_Sommer)) {

sendCommand(Kueche1,100)
sendCommand(Schlafen,25)
sendCommand(Buehne,100)
timer = createTimer(now.plusSeconds(60)) [|

sendCommand(Kueche1,75)
timer = null

]
}

end

Can someone help me with the code?
I added the relevant items and setpoint item in the sitemap for the Grenzwert…
The logs still bring the same result as before…

First of all use the methods…
sendCommand(Kueche1, 100) will be Kueche1.sendCommand(100)

The second point:
you are using the same states PLUS another one for the second if-clause. I would try to use the one with the most states as first and then go further with else-if-statements…
That means, first check if wind, automatic, luminance and tempeature are in the used case, if not (= else if) do the next check…

The third point:
if you have the states of Wind and Beschattungsautomatik both set to NULL, something is not initialized correctly… I think you will have a wind sensor and a switch for the Beschattungsautomatik. If not, you should set-up one in your System…

BR,
Andreas

Ok,

This is the equivalent rule:
When you say it doesn’t work, what do you see in the logs when the rule executes?

var Timer timer = null

rule "dummy"
when
    Time cron "0 * 6-17 ? * MON-SUN" or
    Item kueche_luminance changed
then
    var Lux_Grenzwert_Kueche = Lux_Grenzwert_Sonnenschutz_Kueche.state as DecimalType
    var Temp_Grenzwert_Sommer = Aussentemp_Grenzwert_Sonnenschutz_Sued.state as DecimalType

    logInfo("kueche_luminance", kueche_luminance.state.toString)
    logInfo("Lux_Grenzwert_Sonnenschutz_Kueche", Lux_Grenzwert_Sonnenschutz_Kueche.state.toString)
    logInfo("Wind", Wind.state.toString)
    logInfo("Beschattungsautomatik", Beschattungsautomatik.state.toString)

    if ((Wind.state !=1 ) && (Beschattungsautomatik.state == 1) && (kueche_luminance.state > Lux_Grenzwert_Kueche)) {
        Essen.sendCommand(25)
        Kueche2.sendCommand(25)
        if (Multi1_temp.state as Number > Temp_Grenzwert_Sommer) {
            Kueche1.sendCommand(100)
            Schlafen.sendCommand(25)
            Buehne.sendCommand(100)
            timer = createTimer(now.plusSeconds(60), [ |
                Kueche1.sendCommand(75)
                timer = null
            ])
        }
    }
end

Hi, unfortunately the code fromVincent doesn´t work as well. IN the logs I see only this entry.

2018-10-13 10:12:51.283 [WARN ] [arketplace.internal.MarketplaceProxy] - Retrying again in a minute
2018-10-13 10:12:51.585 [WARN ] [arketplace.internal.MarketplaceProxy] - Failed downloading Marketplace entries: : Received fatal alert: handshake_failure
2018-10-13 10:12:51.586 [WARN ] [arketplace.internal.MarketplaceProxy] - Retrying again in a minute
2018-10-13 10:12:51.773 [INFO ] [rthome.model.script.kueche_luminance] - 30000
2018-10-13 10:12:51.778 [INFO ] [pt.Lux_Grenzwert_Sonnenschutz_Kueche] - 4500
2018-10-13 10:12:51.783 [INFO ] [.eclipse.smarthome.model.script.Wind] - NULL
2018-10-13 10:12:51.787 [INFO ] [e.model.script.Beschattungsautomatik] - ON
2018-10-13 10:12:51.881 [WARN ] [arketplace.internal.MarketplaceProxy] - Failed downloading Marketplace entries: : Received fatal alert: handshake_failure

That’s because wind is NULL and Beschattungsautomatik is ON
Beschattungsautomatik is a Switch

Therefore your rule line should be:

    if ((Wind.state !=1 ) && (Beschattungsautomatik.state == ON) && (kueche_luminance.state > Lux_Grenzwert_Kueche)) {

Yes
you got it. I thought ON and 1 are equal in a switch. It is working now.
Many thanks for your support