OH2: CPU temperature from systeminfo

Hello,
I try to read the system temperature of my Raspberry via the systeminfo binding.
I was able to install the binding itself, I also installed the GPIO binding and defined the following item:

Number RaspberryCPUTemp    "Temperatur RPi2 [%.1f °C]"                             { channel="systeminfo:computer:rpi2_openhab:sensors#cpuTemp" }

But the field stays empty on my sitemap.

When I try the change the interval of the channel, I get the following log message:

22:32:12.601 [ERROR] [platform.linux.LinuxCentralProcessor] - Couldn't find physical processor count. Assuming 1.
22:32:12.898 [ERROR] [platform.linux.LinuxCentralProcessor] - Unable to parse /proc/77/stat

Is this information is not available on a raspberry - or do I face a permission problem - or what’s wrong?
Currently, I use a script being executed to get the system temperature, but I’d prefer to use the systeminfo binding in order to reduce unnecessary scripts etc.

[Update]: Seems to be a rights problem:

-r--r--r-- 1 root root 0 Okt  4 20:51 stat

The quesiton is: How can I grant the user openhab to read this file?

Thank you,
Boby

Those permissions show that anyone can read that file. No one can write to it or execute it.

Can’t help with your real problem but read permissions on that file is not it.

Stupid me, thank’s - you’re completely right!
The root cause of the problem is somewhere else.

I’ll increase the loglevel - maybe I get more information then.

@ThomDietrich, in the meantime I switched to openHABian (btw. it’s great!), but the problem here is exactly the same:
I cannot read the CPU temperature via sysinfo binding; the temperature stays 0 - and in the logfile I get the follwing hint (even with DEBUG loglevel, I only get this):

13:14:28.705 [ERROR] [platform.linux.LinuxCentralProcessor] - Unable to parse /proc/77/stat

All other values (e.g. available memory etc.) work flawless.

Have you ever managed to get the CPU temperature via sysinfo? I have a different way as workaround, but executing scripts is not as neat as to read it directly from a binding :slight_smile:
Thank you!

As you can see, almost every information available has values - except the CPU temperature:

I don’t think temperature is obtainable through the systeminfo binding for the RPi*. (If that’s correct it might be something worth sending an issue for)

An item that correctly obtains the system temperature in degrees Celsius using exec binding and javascript transformation:

Number    RPi_Temp    "System Temperature [%.1f °C]"    {exec="<[cat /sys/class/thermal/thermal_zone0/temp:60000:JS(milli.js)]"}

Where millli.js in your transform folder contains the following to scale:

(function(i){ return i / 1000; })(input)

Hmmm…when it’s that simple to get the temperature (simple cat), then I don’t understand why it isn’t supported by the sysinfo binding. I’ll wait a while - and if nobody tells me that it’s definetely not possible for a RPi at all, I’ll go for an issue and let’s see, what the developers say about it.

Thank you, @Benjy!

For further reference:
https://github.com/openhab/openhab2-addons/issues/1324

On my RPI I also get the Couldn’t find physical processor count. Assuming 1 error, but I don’t get the second error. (But I also have no values on CPU temp or voltage)

I think the first error is a problem of the oshi component that openhab is using: https://github.com/oshi/oshi/blob/master/oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessor.java

The code tries to read the sysctl kern.sched.topology_spec which is not available on the RPI. Has anyone found a solution for this yet?

@Benjy
I tried to use your approach using OH2 but there is something wrong with the transformation.
I am receiving:

2017-04-26 07:57:11.090 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(milli.js), response=54230]
org.openhab.core.transform.TransformationException: An error occured while loading script.
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:63)[189:org.openhab.core.compat1x:2.0.0]
	at org.openhab.binding.exec.internal.ExecBinding.transformResponse(ExecBinding.java:159)[185:org.openhab.binding.exec:1.9.0]
	at org.openhab.binding.exec.internal.ExecBinding.execute(ExecBinding.java:128)[185:org.openhab.binding.exec:1.9.0]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[189:org.openhab.core.compat1x:2.0.0]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173)[189:org.openhab.core.compat1x:2.0.0]

Hi Martin,

two silly questions, just to check the initial situation:

  1. Did you install the Javascript Transformation Service?

  2. Did you create the milli.js file an put in into the transform/ folder?

I assume the Exec Binding returns a String, so maybe the value in the JavaScript file should be parsed before deviding by 1000.

(function(i) {
    return parseFloat(i) / 1000;
})(input)

Thanks for asking.
Meanwhile I could resolve the problem.
I created the milli.js file by copying your previous post.
In this post there was one “l” too much therefore OH did not find the file.
Error message did not help to spot the bug immediately.

Anyway problem solved and thanks for your solution.

1 Like

Sounds good. You’re welcome.

Even if the solution was posted by someone else. :wink:

1 Like

Hello!
I’m testing OH2 with EXEC2…

.things

Thing exec:command:temp_rpi [command="cat /sys/class/thermal/thermal_zone0/temp", interval=15, timeout=5, transform="JS((function(i) {return i / 1000;})(input))"]

.items

Number  Temp_RPI "RPi Temp [%.1f °C]" { channel="exec:command:temp_rpi:output" }

The LOG:

2018-03-22 12:34:05.972 [ERROR] [hab.binding.exec.handler.ExecHandler]
An exception occurred while transforming '48312' with
'JS((function(i) {return i / 1000;})(input))' :
'An error occurred while loading script.'

I’ve not found reference for transform JS with exec2 :roll_eyes:
Thank you!

If you are interested in the CPU-temperature, why not use the systeminfo binding?

The systeminfo binding should be working now.

But for fun:

Oh!.. thank you!

Thank you!

Another extremely simple solution without going through a transformation script
my items:

String Raspi (All) {channel="exec:command:apc:output"}
Number Raspi_CPU "Temperature CPU [%s °C]" <temperature>

my things:

Thing exec:command:apc [command="cat /sys/class/thermal/thermal_zone0/temp", interval=60, timeout=5, autorun=false]

my rules :

rule "temp Celsius"
when
    Item Raspi received update
then
    var String temp = Raspi.state.toString
    var String temp2 = (temp.substring(0,2)) + "." + (temp.substring(2,3))
    Raspi_CPU.postUpdate( temp2)
end

Which Transformation would be needed using the binding?