Smart Meter | Conversion of energy value

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);

Does someone have a hint for me?

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.

This looks easy. number:Energy was already set. But how can I divide by 1000 using the pattern?

Add metadata → state description → add the following as pattern: %s kWh

1 Like

Crazy … That it is!! Many thanks. I’m new to OH3 and have a lot to learn.

btw… I’ve modified the pattern to %.2f kWh

1 Like