I have used this rule in OH2 to convert the smart meter value for total energy consumtion.
rule "smartmeter to kWh"
when
Item smartmeter_Wh received update
then
smartmeter_kWh.postUpdate(smartmeter_Wh.state as DecimalType / 1000)
end
I want to do this also in OH3. For this reason I’ve created a new element (item?) below of the smart meter equipment. What is additional needed to get this rule running?
This is my try in OH3.
var item_Wh = itemRegistry.getItem("smartmeter_Wh").state;
var item_kWh = itemRegistry.getItem("smartmeter_kWh");
item_kWh.postUpdate(item_Wh.state / 1000);
You don’t need a rule for this.
If you define your item type as number:Energy you can use the state description metadata to set the correct unit of measurement.
If you want to have both units, just link both items to the same channel and only change the state description.