[SOLVED] Create first item on a new installation with config files

  • Platform information:
    • Hardware: Raspberry Pi 4 ARMv8/4GB RAM/32GB SD card
    • OS: Raspbian Lite 2019-07-10
    • Java Runtime Environment: openjdk-8-jre-headless:armhf 8u212-b01-1+rpi1
    • openHAB version: openhab2 2.4.0-1
  • Issue of the topic: please be detailed explaining your issue
    On a new installation, I try to read the CPU temp of the raspberry pi into an openhab item, using only configuration files. After creating the configuration files and watching their effects in the log viewer, I use PaperUI control to inspect the temperature value. It shows me that the latest value is minus not-a-number (-NaN), but it should be around 40 degrees (or 40000 millidegrees).

in the exec binding, I initially used the command

sed -e 's/\(.*\)\(...\)$/\1.\2/' /sys/class/thermal/thermal_zone0/temp

to convert from millidegrees to degrees, but then changed to the cat command that you see in the .things file below because I escaped the backslashes to double backslashes in the .things file and did not know if this is correct.

  • Please post configurations (if applicable):
    • Items configuration related to the issue
      cat /etc/openhab2/items/raspberry_pi.items

      Number RaspberryOpenhabTemperatureValue “[%.1f C]” (All) {channel=“exec:command:RaspberryOpenhabTemperature:output”}

cat /etc/openhab2/things/raspberry_pi.things

Thing exec:command:RaspberryOpenhabTemperature [command="cat /sys/class/thermal/thermal_zone0/temp", interval=15, timeout=5, autorun=false]
  • Sitemap configuration related to the issue

  • Rules code related to the issue

  • Services configuration related to the issue
    grep -v ^# /etc/openhab2/services/addons.cfg | uniq

    binding = exec
    transformation = regex

  • If logs where generated please post these here using code fences:

tail -f /var/log/openhab2/openhab.log /var/log/openhab2/events.log

2019-07-14 23:11:53.948 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2019-07-14 23:12:06.901 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.178.36:8080
2019-07-14 23:12:06.904 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.178.36:8443
2019-07-14 23:54:02.920 [thome.event.ExtensionEvent] - Extension 'package-standard' has been installed.
2019-07-14 23:54:08.780 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2019-07-14 23:54:08.879 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2019-07-14 23:54:09.255 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-07-14 23:54:09.286 [thome.event.ExtensionEvent] - Extension 'ui-homebuilder' has been installed.
2019-07-14 23:54:09.289 [thome.event.ExtensionEvent] - Extension 'ui-basic' has been installed.
2019-07-14 23:54:09.293 [thome.event.ExtensionEvent] - Extension 'ui-habpanel' has been installed.
2019-07-14 23:54:09.294 [thome.event.ExtensionEvent] - Extension 'ui-paper' has been installed.
2019-07-16 11:15:36.827 [INFO ] [basic.internal.servlet.WebAppServlet] - Stopped Basic UI
2019-07-16 11:15:43.485 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Stopped Paper UI
2019-07-16 11:15:43.509 [INFO ] [panel.internal.HABPanelDashboardTile] - Stopped HABPanel
2019-07-16 11:15:43.517 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Stopped Home Builder
2019-07-16 11:15:43.562 [INFO ] [.dashboard.internal.DashboardService] - Stopped Dashboard
2019-07-16 11:15:52.735 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2019-07-16 11:15:52.866 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2019-07-16 11:15:59.076 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2019-07-16 11:16:00.138 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.178.36:8080
2019-07-16 11:16:00.141 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.178.36:8443
2019-07-16 11:16:00.419 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-07-16 11:17:54.017 [thome.event.ExtensionEvent] - Extension 'binding-exec' has been installed.
2019-07-16 11:33:59.172 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'raspberry_pi.things'
2019-07-16 11:33:59.318 [hingStatusInfoChangedEvent] - 'exec:command:RaspberryOpenhabTemperature' changed from UNINITIALIZED to INITIALIZING
2019-07-16 11:33:59.331 [hingStatusInfoChangedEvent] - 'exec:command:RaspberryOpenhabTemperature' changed from INITIALIZING to ONLINE
2019-07-16 11:33:59.359 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable
2019-07-16 11:34:00.363 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'raspberry_pi.things'
2019-07-16 11:34:14.418 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable
2019-07-16 11:34:29.443 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable
2019-07-16 11:34:44.469 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable
... Repeats until ...
2019-07-16 11:54:31.355 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable
2019-07-16 11:54:31.409 [thome.event.ExtensionEvent] - Extension 'transformation-regex' has been installed.
2019-07-16 12:06:09.855 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'raspberry_pi.items'
2019-07-16 12:06:09.932 [.ItemChannelLinkAddedEvent] - Link 'RaspberryOpenhabTemperatureValue-exec:command:RaspberryOpenhabTemperature:output' has been added.
2019-07-16 12:06:10.952 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'raspberry_pi.items'
2019-07-16 12:20:58.311 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'raspberry_pi.things'
2019-07-16 12:20:58.357 [me.event.ThingUpdatedEvent] - Thing 'exec:command:RaspberryOpenhabTemperature' has been updated.

This is an installable service, not built in. PaperUI > Add ons > transformation

Welcome to the openHAB Forum!

Besides the missing RegEx Transformation, you could have used the SystemInfo binding IOT get exactly that information.

Yes I googled the REGEX warning after seeing it in the log I have added

transformation = regex

to addons.cfg already as shown in the addons.cfg content that I posted, and as it shows up in the logs further down. The warning is fixed. Still, the value that I see in the item is -NaN. How can I debug this?

What I have done to debug this:
edited /etc/passwd and set shell of user openhab from /bin/false to /bin/bash so that I can sudo su openhab and test that the command

openhab@pi4:/root$ cat /sys/class/thermal/thermal_zone0/temp

38946

also works for user openhab. It does.

How can I do more debugging to see why the 38946 is converted to -NaN?

I have googled how to get the CPU temperature of the Raspberry into openHAB before I tried it and found this info in https://community.openhab.org/t/solved-cpu-temperature/30041:

SysInfo doesn’t work:

Hi, Eduardo, I am sorry, but the binding currently doesn’t return values for CPU temperature of Raspberry Pis. …

Exec should work:

Are you saying this is fixed? If so, what are the things and items definitions that I need to add to the config files?

To debug this further, I changed the item type from Number to String, like this in /etc/openhab2/items/raspberry_pi.items

String RaspberryOpenhabTemperatureValue "[%s]" (All) {channel="exec:command:RaspberryOpenhabTemperature:output"}

After doing this, I see in the log

2019-07-16 13:59:16.621 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'raspberry_pi.items'
2019-07-16 13:59:16.654 [ome.event.ItemUpdatedEvent] - Item 'RaspberryOpenhabTemperatureValue' has been updated.
2019-07-16 13:59:21.264 [vent.ItemStateChangedEvent] - RaspberryOpenhabTemperatureValue changed from NULL to 39920
2019-07-16 13:59:36.271 [vent.ItemStateChangedEvent] - RaspberryOpenhabTemperatureValue changed from 39920 to 38459
...

PaperUI control shows the received value string. So I thought maybe the unit C is the problem in the Number item definition and changed it back to number but as

Number RaspberryOpenhabTemperatureValue "[%.1f]" (All) {channel="exec:command:RaspberryOpenhabTemperature:output"}

The log for this change is

2019-07-16 14:02:28.806 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'raspberry_pi.items'
2019-07-16 14:02:28.843 [.ItemChannelLinkAddedEvent] - Link 'RaspberryOpenhabTemperatureValue-exec:command:RaspberryOpenhabTemperature:output' has been added.

After that, no value changed logs are displaying, and the PaperUI control display of the item is back to -NaN.

What is wrong with the Number item line?

Funny, I’m using Systeminfo on my Raspi3

That’s a two year old post. It’s probably fixed.

1 Like

Thanks for the suggestion. I have done these changes to my config files:

  • Removed the only openhab item and thing by saving my /etc/openhab2/items/raspberry.items and /etc/openhab2/things/raspberry.things as empty files.
  • Edited /etc/openhab2/services/addons.cfg. Removed the exec binding and the regex transformation. Inserted the systeminfo binding.
  • Checked the effect of the previous edits in the logs. Looks ok.
  • add entry to /etc/openhab2/things/raspberry.things: systeminfo:computer:raspberry [interval_high=7, interval_medium=80]
  • add entry to /etc/openhab2/items/raspberry.items:
    Number Sensor_CPUTemp “CPU Temperature” { channel=“systeminfo:computer:raspberry:sensors#cpuTemp” }

With these changes, the CPU temperature is finally available in openHAB as a number item. Thanks for the helpful replies.