im quite new to open Hab and now i have a simple problem… I use V3.0.1 on a raspberry Pi4.
I created a channel which receives a JSON String. Then i added a couple of Items to this channel with a JSONPath Expression to filter the values i want. All Items are of type number. Everything works fine and i get the values i want to display, but its not possible to use the state formatter in the adcanced setting to add a unit. If i use anything else than the standard %s expression, for example %.3f or %.1f it doesnt work anymore… How do i use this State formatter ?
I used the GUI to add the channel and the Iems.
Do i have to create a own channel for each value i want to display and add the JSON Patch expression there ? Because if i use the Unit of measurement there i can display the units…
best regards
I think the state formatter here formats the value before it’s passed to the profile. You need to specify this as the state description in the item configuration.
Thank you thats it! But even in the state description its not possible to use %0.3f
only %s is allowed which i dont understand a the Items type is defined as number…
Is there some reason you are not using the units parameter provided by MQTT binding on number type channels? You would then link to a Number:ElectricPotential (or whatever appropriate) Item type.
yes, because then i have to create an own channel for every value in the JSON string. I thought it would be a better workflow to add one channel, get the whole JSON String and then do the transformation for every Item indidual. My Json string has parameters for voltage, current, power and energy.
That is the conventional way to do it. This becomes more meaningful when you have outgoing commands, so you’ll probably end up working this way for at least some devices.
I couldn’t say if transforming in channel is more efficient than a profile, but I suspect so.
Ok good to know. For this special purpose all data is read only, but you’re right, i guess it would be unhandy to change a parameter in the jason string with only one channel containing the whole string…