Having issues with UoM, Transformation and Java formatter class syntax

Hello everyone,
im configuring the display of my solar roof plant. I got several NUMBER and STRING typed items with some beeing just pure NUMBER and other beeing NUMBER:ENERGY. Reading the values makes most of them show in Watt which reads a biiiiig number if you are looking up daily production e.g… So i would rather like it to convert to showing in KWh but dont know how…
my original item looks like this:

Number Production "Produktion [%.2s kWh]" <solarplant> (gSolaranlage){channel="solaredge:generic:cb124819:live#production"}

I am totally overwhelmed understanding the Java formatter calss syntax, perhaps someone has a useful link for a self tutorial?

The live#production channel is of type Number:Power, not Number:Energy
Number:Power and Number:Energy have different representations.

See the docs on UoM.
There’s some power stuff here too. (found via the site search, which you should use)

If you have a specific formatting question, just ask directly. It’s almost certainly been done before…

1 Like

Yes, i saw that. But when changing the item to Number:Power
Number:Power Production "Produktion [%.2s %unit%]" <solarplant> (gSolaranlage){channel="solaredge:generic:cb124819:live#production"}

i get an error report of Eclipse SmartHome Designer:

reading carefully your provided links i think i might be missing the " Defining ChannelTypes" but dont know if i have to define them manually (and where) or if it is provided by the channel itsself automatically.

No, but it does depend on your openHAB version. Units were introduced partway through OH2.

That’s obsolete and doesn’t know anything about OH2 or units, so it will not understand Number:Power

i see… didnt touch my openhab in a while now. will change that. suggestions?

oh2 newest

VSCode with openHAB extension is the current file editing tool.

For your original problem, once you’ve got the correct Item type, just give the (appropriate type of) units that you want in the [state presentation] part of the label, e.g. kW, and it will auto convert for display.

thanks for that. i managed the transformation process, not too difficult.
I ran through a problem with the Java formatter class syntax nevertheless. i am unsure what values to use in the [] brackets and cant find out the differences between %s, %f and so on… the help page isnt too useful. And what does number:dimensionless mean?

The java formatter is well documented all over the web. No idea which “help page” you are looking at.

%s is simple enough, “show me the string”. Transformation services always return strings so that’s all you need in this context. If you need to prettily some transform result you need to it in the transform itself.

Number:Dimensionless is a Quantity Type without dimensions. But it does have units. What? Think of ratio or proportions. Commonly we use units of % or db for quantities like that.

thanks for your reply. i was referring to: https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax

Reads way too cryptical for me although i am willing to read into it.

For one that’s one version too old for OH 2.5. Those are the Java 7 docs and you need the Java 8 docs. https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax But I suspect there isn’t anything significantly different between the two in this case, paying attention to that sort of thing will save you a ton of grief in the long run.

As for how to read it, scroll down to the relevant section to find the right flag. Then search the internet for examples using that flag.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.