We wrote a custom component, that is fetching the data from Sonnen Battery API and putting it on the grid. I realized, that when the values are fetched, they have 2 decimal places. So let’s say I’m fetching them as “1999,98” but that is being displayed as “2000”. The channel definition is as follows: Doc.of(OpenemsType.DOUBLE).unit(Unit.WATT).
Where else am I supposed to change the values for Double? How to display the data in the “1999.98” format, without the rounding?
All the best,
is this the
ActivePower-Channel that you try to display in OpenEMS UI? Or where are you displaying the value?
Where possible OpenEMS tries to round values to Integer format, because there are several places where we check if a value changed (e.g.
onChange-Listener on Channels), which is just more reliable with Integer values than Float/Double. Instead if higher precision is required, we usually still use
OpenemsType.INTEGER but apply a scalefactor in the modbus reading and define the unit e.g. as
By the way: Sonnen Battery API sounds like a very interesting addon for OpenEMS. Are you planning to open-source it?
Hi Stefan, thanks for your answer! I implemented my own channel that belongs to the component written by me… Next, I’m fetching the values in the UI component, and displaying it over there. Here is the code of the component: openEMS_/io.openems.edge.controller.sonnenbattery at main · ktomaszewska97/openEMS_ · GitHub, and the UI part: openEMS_/ui/src/app/edge/live/sonnenbattery at main · ktomaszewska97/openEMS_ · GitHub.
I cannot figure out, where the precision changed…
Thanks for sharing the links. I cannot see any obvious problems in the code - but again, I have not used Doubles a lot. It would surely work if you could switch to INTEGER with Watt unit (the precision should be sufficient for most cases).
I would have to check myself why this does not work with DOUBLE. Seems strange.
thanks for the answer. The thing is that on the backend I have the required precision, so double, but once I’m sending the values to the UI, they are being fetched as INT. So they have to be cast to INT somewhere in the UI, and I’m not sure where exactly it is happening.
Do you know the place, where it might be happening?