[SOLVED] Calculating windchill


(David Maillie) #1
  • Platform information:
    • Hardware: RaspberryPi 2
    • OS: OpenHabian
    • 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 for any help.


(CM6.5 H102) #2

This would be a good place to start.


(Vincent Regaud) #3

I use this binding. It works very well.


(David Maillie) #4

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?


(CM6.5 H102) #5

If using a mouse try pressing the wheel down to paste. Not sure what the official name is Wheel click?

You may want to look at samba share and VSCode w/ openhab extension for text editing and such.:wink: Makes OH life way easier.


(Vincent Regaud) #6

I don’t use vim, I use nano.

You have openhabian so you should have a samba share of your folder: https://www.openhab.org/docs/installation/openhabian.html#further-configuration-steps
Which you can access from another computer

Then install VS Code on that computer to edit your openHAB files: VS Code openHAB Extension!


(David Maillie) #7

Thanks good idea. I’ll try it that way.


(CM6.5 H102) #8

@vzorglub thanks for adding the Samba and VS Code links.:+1:


(Vincent Regaud) #9

Part of the service. I still don’t charge


(CM6.5 H102) #10

Oh… but image all things you could buy if you did.:rofl:


(Vincent Regaud) #11

Yes a shelly would be nice, ha, ha


(David Maillie) #12

Ok, I’ve installed VS Code and that is an impressive piece of software :smile:. 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…


(Vincent Regaud) #13

The rule would help


(Vincent Regaud) #14

Also you need to use the UoM:

Number:Temperature OWM_Current_Temperature "Current Temperature [%.1f °C]" <temperature> (Weather) {  channel="openweathermap:weather-and-forecast:86b42b76:local:current#temperature" }
Number:Speed OWM_Current_Windspeed "Current Wind Speed [%.1f m/s]" <wind> (Weather) { channel="openweathermap:weather-and-forecast:86b42b76:local:current#wind-speed" }

(David Maillie) #15

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.


(CM6.5 H102) #16

If you would please edit the rule and use code fences, this makes it easier to read and understand. Its the paper icon beside the smile face.

Thanks


(David Maillie) #17

Done. Please see the first post which has been updated.


(CM6.5 H102) #18

That’s a lot of math in a postUpdate.:stuck_out_tongue_winking_eye: 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.:laughing: This will be a good topic for me to follow and learn how to deal with lot’s of math.:wink:


(Udo Hartmann) #19

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

(David Maillie) #20

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:

  1. no viable alternative at input ‘val’
  2. Type mismatch: cannot convert from BigDecimal to double
  3. 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…