Hello,
I am preparing on my Raspberry 4 (Openhabian 3.4.5) the update from 3.4.5 to 4.x and have unfortunately set some of the number items to “kWh” instead of “Wh” in the *.items files. As a result, some values were calculated incorrectly.
But now I have corrected the unit - nevertheless the unit remains in “kWh”.
How can I force the new unit in the system?
A restart of the openhab.service did not solve the problem.
unit metadata that fixes the unit for a given Item. This unit is assumed if a value with no unit is sent to the Item and the same unit is used when data is persisted.
From that I understand your issue comes from wherever you get the power value from is a unitless source, and you tell it to assign Wh to this number, even if it is something else. So, rather you should assign the correct unit (probably kWh), and handle the conversion to Wh downstream, as display unit, and in the rule via something like .state.toUnit("Wh").doubleValue or so (not sure that casting syntax is correct, I am guessing from my understanding of the docs)
If the data is coming from fronius binding, it provides the unit already.
@J-N-K is the summary at the top of this github issue still applies to the current state of the codebase? If that’s the case then it should be perfectly fine to define an item like this:
The value is still going to be correct, just converted to the specified unit, e.g. the source sends 5000 Wh, the item will hold the value 5 kWh and not 5000 kWh because the incoming unit is not stripped.
This would affect persistence though, right?
If the source sends 5000 Wh and no unit has been specified → persist the value 5000
If the source sends 5000 Wh and unit=“kWh” → persist the value 5.0
Ok, even if the binding brings the unit, the unit is currently wrong for the value.
Wh are interpreted as kWh.
How do I solve this ?
Edit:
For now, I am back to my previously created backup. Here you can see that the channel “Real Energy Consumed” does not provide a unit in the “smart meter” although the channels in the “inverter” have units:
It is as I have said:
The channel of the item “IBBM_Consumed” does not have a unit. I accidentally assigned the wrong unit in my configuration (kWh) and I can’t get back (Wh).
For example here is a channel from the inverter with a delivered unit
The correct documentation can be found here. The default unit for energy is kWh, so without setting unit a value of 5000 Wh is converted to 5 kWh for the item’s internal state and that is persisted (as 5). If you want to persist a value of 5000, change the item’s unit to Wh.
… btw… I restarted the openhab service - not the whole raspi, but this should be enough (?)
EDIT:
But ok, as I said, I’ve restored the backup and let the system continue to run with it. I will correct all the units that do not correspond to the standard and then re-install the changes tomorrow.