[SOLVED] Formatting problem with unit on sitemap (Item has dimension 'one')

openHAB 2.4.0 on Raspberry Pi 3

I read out the room humidity with a DHT22 sensor via a python script (from this thread: How can I get data of DHT22 that connected to GPIO on Raspberry running Openhab)
This works fine, the script is executed by a rule where the item gets its value.

Item definition:

Number:Dimensionless hum_ist “Luftfeuchtigkeit im Raum”

The rule looks like this:

rule "DHT22 Sensor auslesen"
when
	Time cron "0 */5 * * * ?"
then
	val TEMP = executeCommandLine("python /etc/openhab2/scripts/DHT22_temp.py", 5000)
	if (TEMP.toString().length <= 5) temp_ist.postUpdate(TEMP)
	Thread::sleep(5000)
	val HUMID = executeCommandLine("python /etc/openhab2/scripts/DHT22_hum.py", 5000)
	if (HUMID.toString().length <= 5) hum_ist.postUpdate(HUMID)
	logInfo("DHT22 Sensorwerte:", "Temperatur: " + TEMP.toString() + "°C, Feuchte: " + HUMID.toString() + "%")
end

In the log everything looks fine:

[home.model.script.DHT22 Sensorwerte:] - Temperatur: 22.50°C, Feuchte: 46.10%

and finally in the Sitemap:

Text item=hum_ist label=“Luftfeuchtigkeit innen [%.1f %unit%]” icon=“humidity”

Now this results in:

Luftfeuchtigkeit innen 47.2 one

If I set the format to Luftfeuchtigkeit innen [%.1f %%] it will result in 4720 %

I can’t find a way to get rid of the “one” dimension and just get a percentage sign without the x100 conversion?

Some help would be really appreciated. Thanks!

Try specifying this in the ITEM label definition, giving OH a chance to figure out units before using them

or

Try[%.1f %%%] , so far as I can make out that is %unit% of % type.

For myself I have
Number:Dimensionless CurrentHumidity "humidity [%d %unit%]" <humidity> { channel="openweathermap:weather-and-forecast:api:foss:current#humidity" }
but that is using input from a UoM aware binding, not a script.

Default humidity.png icon set works with it :slight_smile:

Thanks for the leads. Unfortunately specifying this in the ITEM label definition will result in the Factor 100 conversion.

[%.1f %%%] results in an Err on the Sitemap.

A dirty workaround would be to divide the value by 100 prior to the usage. However I use the value directly from the item for another thing (through the REST API where I need it without a dimension). There I could potentially do the next dirty workaround and multiply it by 100 again … but quite frankly this would be a shame :slight_smile:

The thing that bothers me is that I collect a second humidity value also from openweathermap.
I set it up exactly as you also described and everything works perfectly fine, but not with the humidity value that I get from my DHT22 sensor.

Maybe the fix should go in your rule, to make the Item understand it is being fed a percentage not a simple number.
From your logInfo, HUMID has a value of 46.10 and I think it will be a string “46.10” as it is the result of an exececuteCommandLine.
postUpdate likes to be fed strings, so we just add the UoM indicator to the string
hum_ist.postUpdate(HUMID + "|%")

1 Like

This should do the job:

Text item=hum_ist label="Luftfeuchtigkeit innen [%.1f %]" icon="humidity"

image

Thank you so much, kind stranger :wink:

Your problem stemmed from your item definition:
It should have been:

Number:Dimensionless hum_ist "Luftfeuchtigkeit innen [%.1f %%]" <humidity>

And your sitemap:

Text item=hum_ist

The item definition label formatting would then instruct the UoM than we are using percents

I advise you to put your labels and formatting and icons ALL in the item definition and keep the sitemap as simple as possible.
This way there is only one file to maintain

1 Like

Thanks for the advice. I redid the definitions in the items-file and it looks way more organized now.

1 Like