You could do it using a Proxy item which gets updated by rule. The rule should be triggered by each update of your item and should do a postupdate to the Proxy item with the corrected value.
This Proxy item would be used for the Display on UIs, persistence etc.
Thanks Opus but I don’t understand your suggestion. I am not old with Openhab yet.
You direct me to rules I thought maybe I can execute an arithmetical operation somewhere in a simple way…
Because it is just and adjustment of an existing value!
(function(i) {
if(isNaN(i)) return "NA";
var days = Math.floor(i/24);
var hours = i%24;
var pad = "00";
return days+":"+(pad+hours).slice(-pad.length)+":00:00";
})(input)
In your case, you will want to the transform on the mqtt binding, not just the label. This also means you will have to extract the JSON value inside the JS which I know is possible but you have to google to find out how. I don’t know off the top of my head.
My Sonoff switches report their uptime (i.e. the amount of time they have been running without a restart or losing power) in number of hours. I use the JS to convert the hours to DD:HH:MM:SS format to match the uptime of my other devices. I only need this for my sitemap so it only applies to the label.
Follow the link on my posting which takes you to the docus for the JS transform.
Hi Rich
Very interesting this Transformation chapter. I like the connection that it can make between numbers and concrete understandable things.
Just one thing as I am not a Javascrpt advanced coder…
I did this :
Number SoffSC_DWST “Temperature [JS(CompSoFF.js):%.1f °C]” {mqtt="<[broker:tele/SonoffSC/SENSOR:state:JSONPATH($.Temperature)]"}
and the function that is located in transformation folder…
(function(i) {
//var res = i;
var degrees = Math.floor(i - 2);
return +degrees;
})(input)