I made a short rule but I do not know what I am doing wrong. I also did not find any solution in this Community.
Please help me!
I want to shut my roller shutters in the summer when the sun comes around the house down and want to run them automatically again up.
Before this I want just to send an email to check the times. Later I will replace this section.
Here is my code:
rule "Rollladen EG halb runter und wieder hoch"
when
Item Lokale_Sonnendaten_Azimut received update
then
if(UrlaubRollladenHochRunter.state == ON){
if((VarHochRunterNachmittags.state as Number == 0) && ((Lokale_Sonnendaten_Azimut.state as Number) > 95) && ((Lokale_Sonnendaten_Azimut.state as Number) < 100)){
//Roller Shutter half way down
VarHochRunterNachmittags.sendCommand(1)
val mailActions = getActions("mail","mail:smtp:bergserversmtp")
mailActions.sendMail("chris@...com", "Rollladen geht runter auf 18", "Rollladen geht runter auf 18")
EGRollladenSuedrechts.sendCommand(18)
}else if((VarHochRunterNachmittags.state as Number == 1) && ((Lokale_Sonnendaten_Azimut.state as Number) > 200) && ((Lokale_Sonnendaten_Azimut.state as Number) < 205)){
//Roller Shutter up again
VarHochRunterNachmittags.sendCommand(0)
val mailActions = getActions("mail","mail:smtp:bergserversmtp")
mailActions.sendMail("chris@...com", "Rollladen geht wieder auf", "Rollladen geht wieder auf")
EGRollladenSuedrechts.sendCommand(100)
}
}
end
You are checking (Lokale_Sonnendaten_Azimut.state as Number) but it’s most likely that the Item is of Type Number:Angle, so at least you would have to use (Lokale_Sonnendaten_Azimut.state as Number).floatValue to ensure there is no unit.
rule "Rollladen EG halb runter und wieder hoch"
when
Item Lokale_Sonnendaten_Azimut changed // will be sufficient
then
if(UrlaubRollladenHochRunter.state != ON) // rule not active?
return;
if(!(newState instanceof Number)) // Itemstate not valid?
return;
val mailActions = getActions("mail","mail:smtp:bergserversmtp") // get handle for message
val nAzimut = (newState as Number).floatValue // get Float Value (i.e. without °)
if(nAzimut > 95 && nAzimut < 100 && VarHochRunterNachmittags.state == 0) {
VarHochRunterNachmittags.sendCommand(1)
mailActions.sendMail("emailaddress", "Rollladen geht runter auf 18", "Rollladen geht runter auf 18")
} else if(nAzimut > 200 && nAzimut < 205 && VarHochRunterNachmittags.state == 1) {
VarHochRunterNachmittags.sendCommand(0)
mailActions.sendMail("emailaddress", "Rollladen geht wieder auf", "Rollladen geht wieder auf")
}
end
And if VarHochRunterNachmittags is just an Item without any link to a channel, it’s very likely that .postUpdate(value) is the better and more direct method. A Switch Item would be even better for that purpose
I think you helped me. My test worked. If it will work the next days I will post my finished code and will close this issue. I guess the biggest help was to replace by
(Lokale_Sonnendaten_Azimut.state as Number).floatValue
rule "Roller shutter down because of the light and in the afternoon up again"
when
Item Lokale_Sonnendaten_Azimut changed
then
val nAzimut = (Lokale_Sonnendaten_Azimut.state as Number).floatValue
val nHochRunter = VarHochRunterNachmittags.state as Number
val mailActions = getActions("mail","mail:smtp:bergserversmtp")
//Check of my holiday switch and the holiday switch for the roller shutters
if(Urlaubsschalter.state == ON && UrlaubRollladenHochRunter.state == ON){
//Check of the Azimut
if(nHochRunter == 0 && nAzimut > 110 && nAzimut < 115){
VarHochRunterNachmittags.sendCommand(1)
//Roller shutter half way down
EGRollladenSuedrechts.sendCommand(18)
}else if(nHochRunter == 1 && nAzimut > 195 && nAzimut < 200){
//Roller shutter up again
VarHochRunterNachmittags.sendCommand(0)
EGRollladenSuedrechts.sendCommand(100)
}
}
end