Weird stuff happens. A demo -
// test Items - a non-quantity, a quantity with default, and a quantity without default
Number testN "testing [%.1f kWh]"
Number:Energy testE "testing [%.1f kWh]"
Number:Energy testX "testing"
// test rule
testN.postUpdate("10") // no units
testE.postUpdate("10")
testX.postUpdate("10")
Thread::sleep(1000)
testN.postUpdate("15 Wh")
testE.postUpdate("15 Wh") // unit doesn't match default
testX.postUpdate("15 Wh")
Thread::sleep(1000)
testN.postUpdate("25 kWh")
testE.postUpdate("25 kWh")
testX.postUpdate("25 kWh")
results
2021-12-21 12:40:22.734 [vent.ItemStateChangedEvent] - testN changed from NULL to 10
2021-12-21 12:40:22.735 [vent.ItemStateChangedEvent] - testE changed from NULL to 10.0 kWh
2021-12-21 12:40:22.736 [vent.ItemStateChangedEvent] - testX changed from NULL to 10
Pretty much what you would expect. A unit is assumed for testE when posting just-a-number. testX is just messed up - no unit given, no default either, pretty meaningless.
2021-12-21 12:40:23.750 [vent.ItemStateChangedEvent] - testN changed from 10 to 0.015 kWh
2021-12-21 12:40:23.757 [vent.ItemStateChangedEvent] - testE changed from 10.0 kWh to 0.015 kWh
2021-12-21 12:40:23.759 [vent.ItemStateChangedEvent] - testX changed from 10 to 15 Wh
Woah, that surprised me. The plain Number Item has actually done an auto-conversion to a default unit. I expected that to load with 15Wh. But of course it isa nonsense posting units to a plain Number - this is just exploring.
testE has done what I expected - auto-converted the update to the default unit, good.
And testX (with no default) just accepts what unit it was given.
2021-12-21 12:40:24.754 [vent.ItemStateChangedEvent] - testN changed from 0.015 kWh to 25 kWh
2021-12-21 12:40:24.762 [vent.ItemStateChangedEvent] - testE changed from 0.015 kWh to 25 kWh
2021-12-21 12:40:24.763 [vent.ItemStateChangedEvent] - testX changed from 15 Wh to 25 kWh
This is all as expected.
Of course this is postUpdate from rules, it is not quite the same as channel updates from a binding.
What we’re not sure of here is exactly what the SolarEdge channel is posting to the Item - with or without units?
You could confirm this by creating test plain Number type Items, with no [default] but perhaps just [%s]
, and link those to your SolarEdge channels as well as your regular Items. Not all the channels might be alike here.
What I’m driving at here is that if the channel posts updates with units, I would expect the Item to auto-convert to user-defined default unit, which takes care of all your worries.
Note also that when defining Items from text files OH2 style, the [default] given in a label may not end up in the OH3 metadata ‘pattern’. The test Item acting most like your observations is the one with no default assigned. We might have to check this out on your Items.