Problems regarding item initialization and rules

Hi there,

I am running the latest version of OH2 on an RPI 2 (openhabian) an I am having some issues related to virtual items and rules.

For one of my Projects, I am in need of an virtual item, where I can store the last value of another item (which actually has a channel).

My item Definition is:

Number PowerMeterCounter "Powermeter eCounter" <energy> {channel="mqtt:topic:4239b1d7:eCounter"} 
Number PowerMeterCounterLast "Powermeter eCounter last" <energy>

To initialize the virtual item, I constructed a rule which I am trying to activate manually:

rule "Testrule"
when Item TestSwitch changed from ON to OFF
     PowerMeterCounterLast.sendCommand(PowerMeterCounter.state as Number))

TestSwitch is of Course another virtual item. When I set the switch from ON to OFF, the rule gets executed (according to the log/tail) but the value isn’t showing up in the sitemap (while the value of PowerMeterCounter is shown.

I think I allready had the Problem once and solved it by creating a MQTT-Dummy Item without a channes which then was displayed correctly. But I dont think this may be the best solution?!

What am I doing wrong?

Thanks in Advance,


I think you have an extra bracket at the tail end of your sendCommand.

Hi rpwong - thanks for your Reply - I allready changed this one and updated my request as I now found out the Item to be updated correctly (log/tail) but not to be shown on sitemap.

Ah yes, I must have read that right before you edited. What do your sitemap entries for both items look like?

Hehe, again solving the Problem… But dont know why…


		Text item=PowerMeterCounter label="eCounter"
		Text item=PowerMeterCounterLast label="eCounterLast [%.0f]"

I just added the [%.0f]" and boom it shows the value. But why do i Need to put the placeholder while the other (nonvirtual) item is displayed correctly?

I thought it might be along these lines, but I would have thought you need the optional state representation on both items.

I would guess that a virtual item doesn’t display its state on a sitemap unless you include the optional state representation to tell it to do so. Otherwise, anyone who uses a virtual switch would see its “On” or “Off” value right next to the toggle. So, your virtual number item needs the state representation, but your non-virtual number item defaults to showing it.

But that’s just a guess. Glad you got it working!

Thanks for your thoughts. It seems indeed to work very well now )ist a power consumption measurement unit). I will crosscheck in the next days :slight_smile: