Conversion from m/s to km/h, what am I doing wrong?

Just wondering what I am doing wrong with this rule…

rule “Wind speed conversion m/s to km/h”

when

Item Weather_WindSpeed_External changed

then

postUpdate(kmh, Weather_WindSpeed_External *3.6)

end

In general, you are not giving enough info in your post. Here some thoughts:

  • I think you need to look into transformations (https://www.openhab.org/addons/transformations/javascript/) rather than doing this in your rule.
  • You did not post any errors, but I am not aware that you can do math in postUpdate statements.
  • Please remember all items are objects, if you want to access the state of them, you need to specifically do so, e.g., Weather_WindSpeed_External.state. Depending how you defined `Weather_WindSpeed_External’, you may also need to cast it into the type Number.
  • And, is kmh an item? Or something else?
  • As a follow-up you may want to post all relevant item definitions.
1 Like

@lipp_markus did a good job providing all the info needed. :+1:

I’ll throw in an example of converting Celcius to Fahrenheit in a rule.

rule "temp"
when
	Item Basement_HT_Temperature received update
then 
	var celsius = Basement_HT_Temperature.state as Number
    var Number fahrenheit = (celsius * 1.8) + 32

    Basement_HT_Temperature1.postUpdate(fahrenheit)

end

Hope this helps understand some of the bullet points above e.g. the 3rd one. :wink:

lipp_markus

Thank you for the info, will read up on your suggestions.

H102

This worked !

So here is my working rule however there is one problem, Weather_Windspeed_External1 does not seem to be able to be found in Grafana ?. When I mean found it does not come up in the selection as per below…

I did add Weather_Windspeed_External1 to my persist file.

rule “Convert m/s to km/h”

when

Item Weather_WindSpeed_External received update 

then

var kmh = Weather_WindSpeed_External.state as Number

var Number metric = (kmh * 3.6)

Weather_WindSpeed_External1.postUpdate(metric)

end

Update: Disregard it came up, had to wait for the strategy to update :frowning: