[SOLVED] Rule with Weather-Item

Hi,
i’m goint to tune my roller shutters rules (at the moment there is only a simple “up in the dawn” and “down in the dusk” by astro binding.
Now i’d like to add some shading by the weather-binding (https://www.openhab.org/addons/bindings/weather1/) with openweathermap.org
my Items work more or less: on one hand i get the ERROR “Can’t retreive weather data” on the other hand i see Item-changes:

.
… so i think in principle the weather-binding works.

question is how to integrate this Item in a roller shutter rule. i’m so bad in programming :sob:
First i’ve searched similarities to my astro-rules - but they work with channels; here i’ve items.

And then i need to create a “greater than” oder “less than” - condition (… but ITEM need “changed” or “received update”).

my last and poorly try was this rule:

rule "Rolladen Wohnzimmer runter wenn es warm ist"

when
    ITEM Temperatur_AIT.state changed < "10.00"
then
    Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)

end

Can anyone help?
Thanks in advantage

Tom

Put the condition as an if statement inside the Rule.

when
    Item Temperature_AIT changed
then
    if(Temperature_AIT.state as Number < 10) Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)
end

Pay attention to the changes I made. Case matters.

Edit: Grrrr. I sit there and say “case matters” and have a case error in the code I posted. :flushed:

1 Like

For easier transition to OpenHAB 3 you may want to try one of the OH2 weather provider bindings.

Thanks so much (as always) … but there must be still some error, which i can’t correct:

Case matters … as Number :wink:

Case matters,Case matters,Case matters :thinking::thinking::thinking:.
I would like to understand it so much … but i don’t …:sob:

i’ve tried to put the 10 in “”, i tried 10,00 and “10.00”. all failed. :face_with_symbols_over_mouth:

Can i buy another hint?

Case matters,
number and Number
See the difference?

n - lowercase
N - uppercase

case matters

Sorry about that. I focused so much on ITEM which needed to be Item that I made a case error on the Number.

Thanks - i’ve missunderstood “case” … :exploding_head:

unfortunaly it’s still not working
The latest Coding looks like this:

rule "Test Rolladen bei Temperatur
when
Item Temperature_AIT changed
then
if (Temperature_AIT.state as Number < 15) Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)
end

and i get this error:

2019-09-11 23:36:32.999 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Rolladen_Wohnzimmer_Sonne.rules’ has errors, therefore ignoring it: [8,43]: no viable alternative at input ‘15’

…?..

You got to bracket that
if ( (Temperature_AIT.state as Number) < 15)

It’s really worth looking through other forum posts on similar topics, there are lots of example of rules like this, which would allow to see how things should be put together.

Not always. This is a case where there is no ambiguity to the extra parens shouldn’t be necessary.

Hi,
seems that the brackets brought the solution - and please belive me, that i’ve searched trough this forum posts - it’s difficult to find a key word (if you don’t know where the problem is).

Anyway: thanks a lot!

Tom

Thanks - indeed i’ve switched now to openweathermap - binding :+1:

1 Like

Yes, I agree. There is value in looking at only vaguely related posts along “compare temperature rule” or even “compare Number” and suchlike, just to see how rules coding is applied. For openHAB you’re just not going to get it all from a manual.

maybe my time comes with OH3 and a great successor of the experimental rules engine … :partying_face:

ups, another error:

i’ve tried to adjust the rule in the java.- direction with “{” / “}”:

rule "Rolladen Wohnzimmer runter wenn es warm ist"
when
 Item Wetterdaten_Aussentemperatur_Openweathermap changed
then
 if ( (Wetterdaten_Aussentemperatur_Openweathermap.state as Number ) < "25") 
{Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)}
end

… but it don’t help :sleepy:

Try that:

rule "Rolladen Wohnzimmer runter wenn es warm ist"
when
    Item Wetterdaten_Aussentemperatur_Openweathermap changed
then
    logInfo("Wetterdaten_Aussentemperatur_Openweathermap", "Value = " + Wetterdaten_Aussentemperatur_Openweathermap.state.toString)
    if ((Wetterdaten_Aussentemperatur_Openweathermap.state as Number) < 25) {
        Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)
    }
end

With this change i get the value in the log:

the “could not invoke method” - error is no more in the log - which surprises me!
… but the shuttes still do not move :face_with_symbols_over_mouth:

This is because the value is a Number:Temperature

There are two approaches to this.
Convert the Number:Temperature to a plain number or compare with a temperature:

Solution 1:

rule "Rolladen Wohnzimmer runter wenn es warm ist"
when
    Item Wetterdaten_Aussentemperatur_Openweathermap changed
then
    logInfo("Wetterdaten_Aussentemperatur_Openweathermap", "Value = " + Wetterdaten_Aussentemperatur_Openweathermap.state.toString)
    if  ((Wetterdaten_Aussentemperatur_Openweathermap.as QuantityType<Number>).doubleValue < 25) {
        Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)
    }
end

Solution 2:

rule "Rolladen Wohnzimmer runter wenn es warm ist"
when
    Item Wetterdaten_Aussentemperatur_Openweathermap changed
then
    logInfo("Wetterdaten_Aussentemperatur_Openweathermap", "Value = " + Wetterdaten_Aussentemperatur_Openweathermap.state.toString)
    if (Wetterdaten_Aussentemperatur_Openweathermap.state <  25 | "°C") {
        Rolladen_Wohnzimmer_BlindsControl.sendCommand(50)
    }
end