Item type issues in Netatmo? Wind rules not triggering

I have been setting up the Netatmo anemometer lately (OH 2.3), with some problems setting rules… (all else works fine).
The following instruction simply is not executed and I do not see errors in the logs:

if (Netatmo_Wind_Angle.state < 8) {
	Netatmo_Winds_Dir.postUpdate(0)    //THIS IS NOT DONE
	logInfo("netatmo", "0")    //THIS COMMENT NEVER SHOWS IN LOG
	}

The “if” is never true.
I understood there is something to do with the item type, which is declared as per documentation:

Number:Angle Netatmo_Wind_Angle "Direzione del vento [%d\u00B0]" <mywind> { channel...

In fact, the following does work perfectly:

var int Netatmo_Prev_WindDir     //USING A VARIABLE SINCE HAVING MANY IFs
(...)
Netatmo_Prev_WindDir = (Netatmo_Wind_Angle.state as Number).intValue
if (Netatmo_Prev_WindDir < 8) {
	Netatmo_Winds_Dir.postUpdate(0)
	logInfo("netatmo", "0")
}

Same thing seems to happen with wind strength, but not with temperatures.
Is that normal or am I doing something wrong?

By the way, I have to say that the new item types for numbers with units is quite confusing… In my opinion the user/programmer shall know what the number represents without telling the system.

P.S.: just for info, the above code is part of a rule to discretize 360deg for having dynamic wind arrow icon shown: the documented methods for dynamic icons (e.g. “icon-0”, “icon-15”, “icon-30”, etc) is not working with wind angle unless pecisly set (e.g. if the angle is 188 deg I must have a “icon-188”, not “icon-187” nor “icon-190”) . May this have to do with item type too…

The item is a number type quantity type angle

if (Netatmo_Wind_Angle.state < 8|°) {
	Netatmo_Winds_Dir.postUpdate(0)    //THIS IS NOT DONE
	logInfo("netatmo", "0")    //THIS COMMENT NEVER SHOWS IN LOG
	}

Thanks, I will try that.
Still I believe this is a silly complication: introducing special characters (for units) in the code looks weird to me and might be dangerous. What if that would be done the same way with currencies for example? ("|$", “|£”, etc.) …mmm minefield.
Why temperatures are different? I do measure in ° as well… :thinking:

Temperatures are in K, °C and °F

Yes Correct. So when we would need to do calculations involving more than one physical unit we will need to do conversion for all of them…
Not sure this is a good path… -> math limitations and errors.
I guess I will need to accept that math, physics an IT are mixing in the same cookie jar.

Mmmmhh… Science Cookies :cookie::man_scientist:

1 Like

When I use these in a rule with several comparisons and checks I use a variable:

var Number Netatmo_Prev_WindDir     //USING A VARIABLE SINCE HAVING MANY IFs
(...)
Netatmo_Prev_WindDir = Netatmoo_Wind_Angle.state as Number
if (Netatmo_Prev_WindDir < 8) {
	Netatmo_Winds_Dir.postUpdate(0)
	logInfo("netatmo", "0")
}

I can’t find proper documentation on these new “special types” and how to deal with them. Do you know where it might be?
Yesterday I spent half a day on this problem, it would be better to avoid others do the same.

I am in the process of updating the docs actually.
The main link is:

But the website is not showing the latest updates yet.

1 Like

I have read your posts again but I am not convinced. Sorry for being boring.:worried:
I tried:

var Number Netatmo_Prev_WindDir     //USING A VARIABLE SINCE HAVING MANY IFs
(..)
Netatmo_Prev_WindDir = Netatmoo_Wind_Angle.state as Number

instead of

var int Netatmo_Prev_WindDir     //USING A VARIABLE SINCE HAVING MANY IFs
(...)
Netatmo_Prev_WindDir = (Netatmo_Wind_Angle.state as Number).intValue

but actually, for some reason, this is working bad: wind angle is 270° but the condition that triggers is (<8)… Lowering that number to 3 it triggers the second condition (<15).
I am not investigating over, there is for sure a good reason, but have no time to clear it out. I am wondering if it really is (or has to be) so complicated.
I guess I’ll stick with my method, that woks well: I am not a PRO but my teacher used to say “always declare variables for what they are!”
Many years have passed thou and things got more comfortable since then, luckily (->auto cast). But still we get problems if new types are introduced. Moreover, these do not give errors, just but wrong results :frowning:

By the way, why do I have the temperature declared like this

Number Netatmo_Indoor_Temp "Temperatura interna (\u00B0C)[%.1f \u00B0C]" <temperature> (Temp) { channel = (..)

and not

Number:Temperature Netatmo_Indoor_Temp "Temperatura interna (\u00B0C)[%.1f \u00B0C]" <temperature> (Temp) { channel =

and it works perfectly fine in the rules as well, without any conversion or special character in the rules code?
Confused.

Sorry for remarking these aspects, but I really see no advantage in units managed as types: please anyone put some positive words in this topic! :rofl:

Do not misunderstand me: I really like and appreciate all the work that is around OpenHAB and all of its bindings!! :+1::+1::+1:

I have the same problem:

my item:

Number   Netatmo_Wind_WindAngle  "Wind angle [%s]"  <wind>  { channel = "netatmo:NAModule2:home:wind:WindAngle" }

I would like to convert the angle into a direction-string, but I can’t access a predictable way in the rule.

I tried:

logInfo("Angle: ", Netatmo_Wind_WindAngle.state.toString)

1. var int angleAsInt = (Netatmo_Wind_WindAngle.state as Number).intValue
2. var int angleAsInt = (Integer.parseInt(Netatmo_Wind_WindAngle.state) as Number).intValue
3. var int angleAsInt = Integer::parseInt(Netatmo_Wind_WindAngle.state)
4. var int angleAsInt = Integer::parseInt(Netatmo_Wind_WindAngle.state.toString)
5. var int angleAsInt = new java.math.BigDecimal(Integer::parseInt(Netatmo_Wind_WindAngle.state)) 

logInfo("AngleAsInt: ", angleAsInt)

The 2nd log output always gives the following error message:

Error during the execution of rule ‘windDirection’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

Does somebody has any idea?

What exactly are you trying to achieve?

Check this out. It is not necessary to use a rule for it. You can use the Scale transformation to archive the same result.

@vzorglub
Hi Vincent, I tried this rule:

rule "Winddirection"
when 
   Item Netatmo_Wind_WindAngle changed
then
   // In case of error, direction is undef
   var direction = "UNDEF";
   var int angle = (Netatmo_Wind_WindAngle.state as Number).intValue

   var directions = 8;
   var degree = 360 / directions;
   angle = angle + degree/2;
        
   if (angle >= 0 * degree && angle < 1 * degree) direction="N";
   if (angle >= 1 * degree && angle < 2 * degree) direction="NE";
   if (angle >= 2 * degree && angle < 3 * degree) direction="E";
   if (angle >= 3 * degree && angle < 4 * degree) direction="SE";
   if (angle >= 4 * degree && angle < 5 * degree) direction="S";
   if (angle >= 5 * degree && angle < 6 * degree) direction="SW";
   if (angle >= 6 * degree && angle < 7 * degree) direction="W";
   if (angle >= 7 * degree && angle < 8 * degree) direction="NW";

   Netatmo_Wind_WindDirection.postUpdate(direction)
end

If I try to convert the state into an integer, angle is null every time.
If I use angle=state.toString, the “angle = angle + degree/2” will be a string concadination.

@cweitkamp
Hi Christoph,

Thank you for this alternative, it works right away. :+1:

But I am still a little dissatisfied because I searched for hours for a solution for the calculation problem.

Hi Jens,

I know what you are meaning. Not sufficient, when you are eager to reach a specific goal and cannot find a proper solution.

Just a guess. Try to replace the [%s] in the label of your item with [%d].

And for your test script try to use parameterized logging. Like this:

logInfo("test", "AngleAsInt: {}", angleAsInt)