Java Runtime Environment: which java platform is used and what version
openHAB version: 2.4
I’m trying to calculate windchill and display it in a sitemap. I have the following:
In items:
Group Weather <Temperature>
Number OWM_Current_Windchill "Current Windchill [%.1f °C]" <temperature>
(Weather)
In sitemap:
Frame label="Weather" {
Group item=Weather
}
In rules:
rule "Windchill_Calculate"
when
Item OWM_Current_Temperature received update
then
OWM_Current_Windchill.postUpdate(13.12 +
0.6215 * OWM_Current_Temperature.state -
11.37 * Math.pow((OWM_Current_Windspeed.state * 3.6), 0.16) +
0.3965 * OWM_Current_Temperature.state * Math.pow((OWM_Current_Windspeed.state * 3.6), 0.16)
)
end
I can see the Windchill item in my sitemap but it just appears as - °C. I know the problem is with the rule but can’t figure out how to get it working. Here is the error in the log:
2019-01-12 13:38:21.551 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Windchill_Calculate’: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.DoubleExtensions.operator_multiply(double,byte) on instance: null
I believe it’s something to do with needing to cast something but it’s been 20 years since I’ve written a line of java.
Thanks. Are you able to tell me how to cut and paste from vim in openhabian into the post edit window. I’ve tried ctrl-c, simple highlight, V, etc… It seems to copy but how do I paste it into the post edit box?
Ok, I’ve installed VS Code and that is an impressive piece of software . I’m just a beginner at this so I may have messed up something (or quite a few somethings…). Just to provide more info, here is how I defined OWM_Current_Temperature and OWM_Current_Windspeed in items:
Number OWM_Current_Temperature "Current Temperature [%.1f °C]" <temperature>;
(Weather)
{ channel="openweathermap:weather-and-forecast:86b42b76:local:current#temperature" }
Number OWM_Current_Windspeed "Current Wind Speed [%.1f m/s]" <wind>
(Weather)
{ channel="openweathermap:weather-and-forecast:86b42b76:local:current#wind-speed" }
Here are the errors I’m getting in VS Code:
Within my rule:
OWM_Current_Temperature.state
error: “Type mismatch: cannot convert from State to byte”,
The 3rd and 6th multiplication sign have the following error:
cannot be resolved
OWM_Current_Temperature.state
error:Type mismatch: cannot convert from State to byte
Again, any suggestions or help would be appreciated. By the way, I’m aware there may be easier ways to do this, but I’m just trying to figure out the rules syntax…
Thanks. Please see my very first post at the top for the entire rule. Also I updated my items to include the UOM. Nothing changed after that update. Still getting the same errors.
BTW, my reasoning for not including the UOM in the item definitions was that including the UOM would make the item a ‘quantity’ object instead of a decimal (due to the presence of the unit). Maybe that doesn’t matter. I actually had the UOM there before but removed it as part of my troubleshooting.
That’s a lot of math in a postUpdate. I wish I could easily solve this like @vzorglub, @rlkoshak, @Udo_Hartmann and several other’s but I know when I’m in over my head. This will be a good topic for me to follow and learn how to deal with lot’s of math.
Please consider to do some val setting plus logging:
rule "Windchill_Calculate"
when
Item OWM_Current_Temperature received update
then
if(!(OWM_Current_Windspeed.state instanceof Number)) {
logWarn("windchill","Windspeed not of Type Number!")
return;
}
else
val speed = Math.pow(((OWM_Current_Windspeed.state as Number) * 3.6), 0.16)
if(!(OWM_Current_Temperature.state instanceof Number)) {
logWarn("windchill","Temperature not of Type Number!")
return;
}
else
val temp = OWM_Current_Temperature.state as Number
logInfo("windchill","Temp: {} Speed: {}",temp,speed)
OWM_Current_Windchill.postUpdate(13.12 + 0.6215 * temp - 11.37 * speed + 0.3965 * temp * speed )
end
Ok Udo. I’ve substitued your rule in place of mine. The variables speed and temp make the equation a bit simpler. Here’s what I’m getting now in VS Code:
no viable alternative at input ‘val’
Type mismatch: cannot convert from BigDecimal to double
no viable alternative at input ‘val’
Message 1 refers to the following line (error col referred to is the very start of the line pointing to the v in val):
val speed = Math.pow(((OWM_Current_Windspeed.state as Number) * 3.6), 0.16)
Message 2 refers to the same line as above but to the second open bracket after Math.pow
Message 3 refers to following line (error col referred to is the very start of the line pointing to the v in val):
val temp = OWM_Current_Temperature.state as Number
There are no warnings in the log about temperature or windspeed not of type number.
As soon as I saved the rule I got the following output in the log (17,9 and 29,9 both point to the beginning of each of your ‘val’ lines:
2019-01-13 17:46:20.985 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'default.rules' has errors, therefore ignoring it: [17,9]: no viable alternative at input 'val'
[23,9]: no viable alternative at input 'val'
Let me know if there is anything other info you’d like…