I have a Thing channel of type number , which receives a voltage from an MQTT state topic. It is typically around 2 to 3.5 volts. This is linked to an Item “B” of category battery.
In OH panel , a widget is linked to the Item "B"and I use the battery icon from “classic set” icons.
Now, the battery icon is just white regardless of the Item “B” value but if i create a new Item, link that to the openhab panel widget , and set that Item value to say 50, the battery icon has a green infill of about 50%, as expected.
So , where can i define the scaling for the icon, because clearly my Item for voltage (around 3V) is not generating any infill of the battery icon.
mmm, well, i suppose I’ll have to do an output transformation on the channel then to scale it up, because min value on the topic will be 1V (1) and max is 3.5V (3.5) so that’s a range 2.5 on a scale of 0.100 (for battery)
See https://www.openhab.org/docs/configuration/items.html#dynamic-icons for a full documentation for how dynamic icons work. If the default settings do not work for you, you can either create proxy Items or transform the value to work with the icons which expect a range between 0 and 100 or you can create a new set of icons with the _<state> parts in the ranges you expect.
The battery icons that come with OH were configured to work with percentages, not voltages.
Apologize to get into a SOLVED topic, but (as a newbie) I do not understand yet the mechanics of the “output” transformation… are we talking of Javascript-ing the labels? Or in the channel? In the latter case is it possible to tranform the output in PaperUI?
You can’t use dynamic icons or value transforms effectively in PaperUI. It’s just an administrators toolbox, not intended for finished user facing display.
What are you trying to do?
In general, transforms can be used in rules, or in displaying item states, or in profiles linking channels to Items,or a great many bindings allow you to apply transforms to incoming or outgoing data.
As expected, dynamic icons cannot be applied, so with a voltage around 2-3V an empty battery icon is shown
So, I decided to use a transformation
(function(i){
var minV = 2.
var percBatt = 0.
percBatt = (parseFloat(i) - minV)*100
return Math.round(percBatt)
})(input)
This should return a percentage (o an integer?) between 0-100 when the V range is between 2 and 3 - according to my experience the voltage range needed for the humidity sensor to work properly
But I get always 100.0 (voltage is reported to be 2.55 → my expectation is to get 55 instead)
Additionally, I get the error below in the log file
2020-02-08 22:04:17.671 [WARN ] [rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state ‘2.55’ on item ‘LivingDining_BatteryCharge’ with pattern ‘JS(v-to-charge.js):%d’: Cannot format state ‘2.55’ to format ‘%d’
I am pretty sure I am missing something trivial, perhaps could you help?
Transformations always return strings.
“2.55” is a four character string here.
It cannot be formatted using %d for decimal number.
You’d want to use string format %s
It’s not going to help any with icons; dynamic icons are selected on the Item’s state.
The Item’s state remains unaltered by transforms applied in the label, which only affect the displayed value.
Does it mean I need either to define another item (and assigning a transformation of the input value) or change the Arduino code I put into the sensors? Or perhaps there is a third way (e.g. transforming the input value) I do not know yet?
Does it mean I need to redefine the Thing in a text file? Up to now I have been very happy to use PaperUI for the initial conf (discovery->linking), then going down with text files for final tuning.
The least intrusive way I can think I could do is to use a proxy item that will source from the original one (defined in the PaperUI) and apply the transformation. I guess I need to use something like shown here
I must be completed off today… I cannot find the transformation option in the channel (Paper UI -> Configuration -> Things -> Configure Channel), see below.
I am sure I have seen this before, at least for another binding.