Kimzer
(Kimzer)
January 31, 2020, 9:12am
1
Ubuntu 19.10 running openhab.
I have a power meter setup, wich sends the total kwh used in MQTT wich is read and posted on my sitemap. Thing is, the numbers look like this 12227297 KWh and i would really like to format it into something more readable, like 12.23MWh.
I know i can adjust the number of decimals, but formatting this i am completely unsure of how to go about. Did not find much on google to help me out either, so i hope someone here can assist me
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
January 31, 2020, 10:11am
2
Hi
I had a similar situation with an energy monitor.
In the end I created another Item and used a rule to do the math and post the new valve into the new Item.
It works quite well, as now I can show
kWh and Wh in the same UI.
csi_oh
(Christian)
January 31, 2020, 10:12am
3
Hi,
do you have the chance to convert before sending to MQTT?
rossko57
(Rossko57)
January 31, 2020, 10:25am
4
To process an Item state value for display, without altering the state itself,use a transform in Item or sitemap label format (the [part]).
A transformation can multiply, round etc. as you wish.
Kimzer
(Kimzer)
February 1, 2020, 8:39pm
5
Text item=AMS_Malerstand label=âMĂ„lerstand [%.0f KWh]â
This is how my item looks now, wich works. But again i would like to divide the number by 1000 to get Mwh instead. Im not sure i quite understand how to apply a transformation here.
ljsquare
(Laurens Jan Merkx)
February 1, 2020, 10:29pm
6
How is your item defined? As a UoM (Unit of Measurement) Energy
? Then you can easy convert to Mwh just by using [%.0f MWh]
in your sitemap.
rossko57
(Rossko57)
February 1, 2020, 10:52pm
7
This thread is about using transforms in [labels] to modify displayed Item states.
Evening,
I currently display total runtime of a device in minutes in the following item on sitemap.
Number MyDevice3_Time_Day "Total Runtime Today [%d]"
If would be nice if I could convert minutes into hours. What`s the best way to achieve it ? Can anyone suggest solution please.
Kimzer
(Kimzer)
February 3, 2020, 9:18am
8
Have been reading thru that thread for a while now, and others. And i cant get it to work.
This is where i am at:
Text item=AMS_Malerstand âMĂ„lerstand [JS(kwh-to-mwh.js):%.2f]â
JS file:
(function(i) {
return parseFloat(i) / 1000;
})(input)
rossko57
(Rossko57)
February 3, 2020, 10:03am
9
So, what happens, or doesnât happen? What does openhab.log
have to say about it, if anything? Have you installed the JS transformation service? What is your Item type?
Kimzer
(Kimzer)
February 3, 2020, 10:07am
10
Get this error, js transformation service is installed yes.
2020-02-03 09:10:40.372 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model âdefault.sitemapâ has errors, therefore ignoring it: [24,27]: extraneous input ââMĂ„lerstand [JS(kwh-to-mwh.js):%.2f]ââ expecting â}â
rossko57
(Rossko57)
February 3, 2020, 10:21am
11
Okay, something wrong with the sitemap, not the transform (yet).
The Ă„ makes me think of character encoding, perhaps.
Or maybe the wrong kind of quotemarks, cannot tell without use of code fences in posts.
Kimzer
(Kimzer)
February 3, 2020, 11:55am
12
This is how it looks in my sitemap, even changing out the Ă„. Made no difference.
Error message is:
==> /var/log/openhab2/openhab.log <==
2020-02-03 11:54:44.118 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configu ration model âdefault.sitemapâ has errors, therefore ignoring it: [100,27]: mism atched input ââMaaalerstand [JS(kwh-to-mwh.js):%.2f]ââ expecting â}â
[103,1]: extraneous input â}â expecting EOF
Frame label="AMS" {
Text item=AMS_Effekt label="Watt [%.1f W]"
Text item=AMS_Volt label="Volt [%.1f V]"
Text item=AMS_Strom label="Ampere [%.2f A]"
Text item=AMS_Malerstand "Malerstand [JS(kwh-to-mwh.js):%.2f]"
Webview url="/static/HideHeader.html" icon="none"
}
rossko57
(Rossko57)
February 3, 2020, 12:17pm
13
Compare to
Unless thatâs a copy-paste error, thereâs still a strange character in there
Kimzer
(Kimzer)
February 3, 2020, 12:25pm
14
I just tried changing between a few ways of writing it, copy paste error indeed. But what are u referring to when u say strange character? the quotation marks appear that way when i paste it here for some reason, they are " in the sitemap
rossko57
(Rossko57)
February 3, 2020, 1:03pm
15
What I mean is that you showed us an error with Maaalerstand in it and a sitemap line with Malerstand . Obviously,not the same. We can only work on what you tell us when you say âI have this, and get that errorâ.
Take the whole line out; does your sitemap still have an error?
If not, add it back piece by piece.
If it does, itâs probably a layout problem about { } braces.
Kimzer
(Kimzer)
February 3, 2020, 1:51pm
16
Right, that was just a copy paste error on my end. The error message was the same as Malerstand . So that can be ignored.
If i take the whole line out, i have no errors.
With it in i get this:
2020-02-03 13:49:09.255 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model âdefault.sitemapâ has errors, therefore ignoring it: [100,27]: mismatched input ââMalerstand [JS(kwh-to-mwh.js):%.2f]ââ expecting â}â
[103,1]: extraneous input â}â expecting EOF
I do think you might be right about a layout problem.
Therefore, here is the entire sitemap. I cant spot the error, but maybe you can
sitemap default label="MustachePalace" {
Frame label="" {
Text item=Date icon="calendar"
Text item=Time icon="time"
}
Frame label="" {
Switch item=gLights label="Alle lys"
Text item=OpenHabServer_Cpu_Load label="Server Stats" {
Text item=OpenHabServer_Network_IPAddress label="IP [%s]"
Text item=OpenHabServer_Cpu_Load label="CPU Bruk [%s]"
Text item=OpenHabServer_Storage_Available label="Lagringsplass [%sMB]"
Text item=OpenHabServer_Memory_Available label="Ledig Minne [%sMB]"
Text item=OpenHabServer_Memory_Total label="Totalt Minne [%sMB]"
Text item=SpeedtestResultDown
Text item=SpeedtestResultUp
Text item=SpeedtestResultPing
Text item=SpeedtestResultDate
Text item=SpeedtestRunning label="Speedtest [%s]" visibility=[SpeedtestRunning != "-"]
Switch item=SpeedtestRerun mappings=[ON="Start"]
}
}
Frame label="Lys" {
Switch item=TrippelLampe_onoff label="StÄ Lampe"
Slider item=TrippelLampe1_Brightness label="Dimmer"
Switch item=SofaLys_OnOff1 label="Sofakrok"
Slider item=SofaHjoRne1_Brightness label="Dimmer"
Switch item=MasterBedroom_onoff label="Master Bedroom"
Slider item=MasterBedroom_Dimmer label="Dimmer"
Switch item=Kontor_OnOff label="Kontor"
Slider item=KontorTaklys_Brightness label="Dimmer"
Switch item=Lys_Bod label="Bod"
}
Frame label="Utelys" {
Switch item=gLightsOutside label="Alle utelys"
Switch item=Utelys_Bod label="Bod"
Switch item=UtelysHovedinngang1_onoff label="InngangsdĂžr" icon="switch"
Slider item=UtelysHovedinngang1_Brightness label="InngangsdĂžr" icon="LightBulb"
Switch item=UtelysMellomHus_onoff label="Mellom Hus" icon="switch"
Slider item=UtelysMellomHus_Dimmer label="Mellom Hus" icon="LightBulb"
}
Frame label="VĂŠr og Vind" {
Text item=localCurrentCondition
Text item=localCurrentWindSpeed
Text item=localCurrentRainVolume icon="rain"
Text item=localCurrentSnowVolume icon="snow"
Text item=localDailyForecastTomorrowCondition
}
Frame label="Temperatur" {
Text item=Bod_Temp label="Bod [%.1f °C]" icon="temperature" {
Image refresh=30000 url="http://192.168.10.166:3000/render/d-solo/TSYZ1TtWz/temperatur?panelId=2&width=700&height=350&from=now-48h&to=now"
}
Text item=Outside_Temp label="Ute [%.1f °C]" icon="temperature" {
Image refresh=30000 url="http://192.168.10.166:3000/render/d-solo/TSYZ1TtWz/temperatur?panelId=2&width=700&height=350&from=now-48h&to=now"
}
Text item=localDailyForecastTomorrowMinTemperature
Text item=localDailyForecastTomorrowMaxTemperature
}
Frame label="TV" {
Slider item=TV_Volume label="Volum"
Switch item=TV_Mute label="Mute"
Text item=TV_SourceName label="HDMI [%s]" icon="hdmi"
Text item=TV_ProgramTitle label="Program: [%s]"
Switch item=TV_Power label="StrĂžmbryter"
Switch item=TV_ArtMode label="Art Mode"
}
Frame label="Kontor Vegg" {
Switch item=KontorVegg_OnOff label="Lysbryter"
Slider item=KontorVegg_Dimmer label="Dimmer"
Colorpicker item=KontorVegg_ColorTemperature label="Farge" icon="colorwheel"
}
Frame label="MagicMirror" {
Switch item=MagicMirror_OnOff label="Lysbryter"
Slider item=MagicMirror_Color label="Dimmer"
Colorpicker item=MagicMirror_ColorTemperature label="Farge" icon="colorwheel"
}
Frame label="Bod" {
Switch item=Bod_Relay label="Varmeovn"
Text item=DoorSensor_Bod label="DĂžr [MAP(no.map):%s]" icon="Door"
}
Frame label="Pi Hole"{
Switch item=PiHole_Disable label="Disable Pi-Hole"
Text item=PiHole_DomainsBeingBlocked
Text item=PiHole_AdsBlockedToday
Text item=PiHole_Disable label="Pi-Hole Stats" {
Text item=PiHole_DnsQueriesToday
Text item=PiHole_AdsPercentageToday
Text item=PiHole_UniqueDomains
Text item=PiHole_QueriesForwarded
Text item=PiHole_QueriesCached
Text item=PiHole_ClientsEverSeen
Text item=PiHole_UniqueClients
Text item=PiHole_DnsQueriesAllTypes
}
}
Frame label="AMS" {
Text item=AMS_Effekt label="Watt [%.1f W]"
Text item=AMS_Volt label="Volt [%.1f V]"
Text item=AMS_Strom label="Ampere [%.2f A]"
Text item=AMS_Malerstand "Malerstand [JS(kwh-to-mwh.js):%.2f]"
Webview url="/static/HideHeader.html" icon="none"
}
}
opus
(JĂŒrgen Baginski)
February 3, 2020, 3:01pm
17
If you canât spot any false character, you might try to completely retype the whole line (retype not copy and paste!) . Such could get rid of any hidden/unseen character.
rossko57
(Rossko57)
February 3, 2020, 3:14pm
18
You forgot the label= part
Kimzer
(Kimzer)
February 3, 2020, 5:40pm
19
Correct, i swear sometimes i think i am going blind by looking at this. That was indeed the problem, and thank you for pointing it out.