First of all I would like to thank all of you for the great support this forum gave me during the installation of OpenHap (Raspberry Pi3)
If I may ask a question (as I am really lost and after having checked on the web as well as in the forum I cannot find any solution), I tried to write a rule to close the RollerShutters if the outside temperature is over X.
The rule is the following :
rule "Volets Chaleur"
when
Item Temperature_Ext received update
then
if (Temperature_Ext > 20)
if (cFboxMacOnline2.state==ON || cFboxMacOnline3.state==ON)
Central_Vol.sendCommand(DOWN)
end
Each time that the Temperature_Ext is updated, I can see following error in the log file.
2019-05-01 16:21:56.812 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Volets Chaleur': Unknown variable or command '>'; line 6, column 7, length 20
I tried replacing Temperature_Ext with Temperature_Ext.state, added a () after the .state, nothing seems to work.
In fact I just found another solution (yours is probably also working) which is the following :
rule "Volets Chaleur"
when
Item Temperature_Ext received update
then
var TempVol = Temperature_Ext.state as Number
if (TempVol > 20)
if (cFboxMacOnline2.state==ON || cFboxMacOnline3.state==ON)
Central_Vol.sendCommand(DOWN)
end
Honestly, I really have problems understanding the different types of “values” and comparing them but I am here to learn !
Temperature_Ext is an Item, therefor an object, not a value Temperature_Ext.state is the status of this Item, and it’s a status, not an ordinary value. Temperature_Ext.state as Number is the status of this Item, explicitly casted to the Number Type. openHAB will in most cases do that silently
Sometimes, even casting is not enough and you have to enforce a different special type:
(Temperature_Ext.state as Number).intValue
for example will give explicitly an Integer.
Please be aware that sometimes a Number Item status is not of Type Number at all. If casting explicit to Type Number, that will lead in a null pointer exception, so to be save, before casting to Number, try if there is a Number to be casted:
Thanks a lot for your clear and precise explanation Mr Hartmann !
Concerning my rule, I think I still have a lot to amend as the rollershutter are closing each time Temperature_Ext receives an update … I think I am missing some {} somewhere.
rule "Volets Chaleur"
when
Item Temperature_Ext received update
then
logInfo("Temperature: ", Temperature_Ext.state.toString())
logInfo("Presence1: ",cFboxMacOnline2.state.toString())
logInfo("Presence1: ",cFboxMacOnline3.state.toString())
var TempVol = Temperature_Ext.state as Number
if (TempVol > 20 && cFboxMacOnline2.state==OFF && cFboxMacOnline3.state==OFF)
{Central_Vol.sendCommand(DOWN)}
end
The “values” of the checked items are the following :
If I am correctly reading/understanding my rule (but I really doubt), it should trigger the event only if the 3 conditions are fullfiled but the temperature is well below 20°; however the rollershutter received a “down” command.
I am (again) a little bit lost … if you have 2 minutes to spend (or loose), may I kindly ask you to take a look at my rule and tell me what you would do ?
Thanks once again and have a nice day (and Week-end).
It seems Temperature_Ext is a QuantityType item, which sadly makes comparisons even more difficult in rules.
Here is a thread talking about it, but basically you need to change your comparison from
if (TempVol > 20 &&...
To
if (TempVol > 20|°C &&...
Edit: you might need to remove the as Number statement as well. I haven’t personally worked with QuantityType items, so not sure how it should be done best.
It is working; I just have to write a rule to open the rollershutter when the temp goes down under 20 (or anything else).
Thanks once again for your kind assistance.