Hi there, is there a code that I could add to my sitemap that can convert my WeMo Insight Switch stats from Wh to Kwh, and seconds to minutes, as per screenshot? Thanks.
Paging @hmerk .
No, there is no code available, but feel free to open a feature request at
Hmmm bugger. Thanks anyway.
In the meantime, you could achieve this with a rule and some “dummy” items.
Trigger the rule when total energy consumption changes, read state of the item, do a recalculation and write the result to the dummy item. Your sitemap should then display the dummy item only.
Is there a link to instructions on how to do this please? Thanks.
Have a look in here: http://docs.openhab.org/tutorials/beginner/rules.html
Unfortunately it doesn’t give any examples to the code I want to achieve in there.
It isn’t that complicated
rule "Convert Wh to KWh"
when
Item "WeMo_Energy" received update
then
EnergyDummy.postUpdate((WeMo_Energy.state as DecimalType) / 1000)
end
Just out of mind without any quarantee
Using the search function, you will find many examples for writing rules.
What ItemType should the EnergyDummy be in the sitemap and Items file?
Same type as the original was.
Ok, so now in my wemo.items file I have a new listing called “Number EnergyDummy”.
In my sitemap, I have “Number item=EnergyDummy”
In my WeMo.rules I have your rule “Convert Wh to KWh” and I replaced “WeMo_Energy” to whatever my name was. Does that look correct?
Nearly, your sitemap should show the dummy item, which represents the converted value.
This is part of my site map:
Group item=Insight
{
Switch item=Toggle_WeMo_Insight_Switch icon="poweroutlet"
Text item=CurrentPower_WeMo_Insight_Switch icon="heating"
Text item=EnergyToday_WeMo_Insight_Switch icon="chart"
Text item=EnergyTotal_WeMo_Insight_Switch icon="chart"
Number item=EnergyDummy
Text item=OnToday_WeMo_Insight_Switch icon="line"
Text item=OnTotal_WeMo_Insight_Switch icon="line"
Text item=LastOnFor_WeMo_Insight_Switch icon="wind"
Text item=LastChangedAt_WeMo_Insight_Switch icon="energy"
}
This is my WeMo items file:
//WeMo Insight Switch
Switch Toggle_WeMo_Insight_Switch "WeMo Insight Switch" { channel="wemo:insight:Insight-1_0-221608K1200BAC:state" }
Number CurrentPower_WeMo_Insight_Switch "Current Power Consumption:" { channel="wemo:insight:Insight-1_0-221608K1200BAC:currentPower" }
Number AveragePower_WeMo_Insight_Switch "WeMo Insight Switch Average Power" { channel="wemo:insight:Insight-1_0-221608K1200BAC:averagePower" }
Number EnergyToday_WeMo_Insight_Switch "Today's Energy Consumption:" { channel="wemo:insight:Insight-1_0-221608K1200BAC:energyToday" }
Number EnergyTotal_WeMo_Insight_Switch "Energy Consumption since Reset:" { channel="wemo:insight:Insight-1_0-221608K1200BAC:energyTotal" }
Number LastOnFor_WeMo_Insight_Switch "Switch Last On For:" { channel="wemo:insight:Insight-1_0-221608K1200BAC:lastOnFor" }
Number OnToday_WeMo_Insight_Switch "Today's Usage Time:" { channel="wemo:insight:Insight-1_0-221608K1200BAC:onToday" }
Number OnTotal_WeMo_Insight_Switch "Usage Time since Reset:" { channel="wemo:insight:Insight-1_0-221608K1200BAC:onTotal" }
Number OnTotal_Timespan_WeMo_Insight_Switch "WeMo Insight Switch OnTotal Timespan" { channel="wemo:insight:Insight-1_0-221608K1200BAC:timespan" }
DateTime LastChangedAt_WeMo_Insight_Switch "Switch Last Changed At: [%1$tH:%1$tM]" { channel="wemo:insight:Insight-1_0-221608K1200BAC:lastChangedAt" }
Number EnergyDummy
And this is my Rules file:
rule "Convert Wh to KWh"
when
Item "EnergyTotal_WeMo_Insight_Switch" received update
then
EnergyDummy.postUpdate((EnergyTotal_WeMo_Insight_Switch.state as DecimalType) / 1000)
end
Sorry, did not read your last post carefully enough.
Your items file shoule contain the Number item “EnergyDummy” and in your sitemap file you need
Text item=EnergyDummy
You will have to wait until the first change triggers your rule.
The “Energy Consumption since Reset” has changed since the last post, but the EnergyDummy is still blank.
What do you see in your logs then ???