Reading Raspberry Pi CPU temp with Exec binding

I have successfully used the JavaScript transformation

items file:

Number System_Temperature_CPU "CPU temperatuur [%.1f °C]" <temperature> (System) { exec="<[cat /sys/class/thermal/thermal_zone0/temp:30000:JS(milli.js)]" }

transform file: milli.js

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


Text item=System_Temperature_CPU

Hi digineut!

I would like to ask you to be a bit more precise, because I’ve followed your commands, but I have no value shown on my sitemap. Alltrough, I’m a really beginner, so it could be, that I’ve made a mistake…
For example, where should I put the .js file? I’ve made a new JS file in the transforms folder…



I don’t now exactly what information you are looking for, so pls find a small addition:

  • I added the Number line to my system.items file in the
    items folder
  • I created a new milli.js file in the transform folder and added the
    function line to that
  • I added the Text line to my default.sitemap file.

I suggest you paste some of the contents of your items, js and sitemap
files here, so we can have a look.

Dear digineut,

thank you for your help, now it works! I’m getting more familiar with it. Now, I have to figure out, how to start it on boot.

I have created a page in the wiki to document this use case example: Raspberry Pi System Temperature.

Does these instructions work with OpenHab2 also? I followed the wiki instructions but temperature is not read. Only get “-” in the sitemap.

It should work. I have not tested it yet myself. However, the exec commands depend on your RPi so those should still work. You can test these from a regular command line first. Both transformations should work as well.

If you need help, please post your confit in the forums and I will see what I can do.

For your information. The new Systeminfo binding also supports CPU temperature. I have only tested this binding with my Mac and not yet with the RPi. But this could be a more sustainable implementation.

I tested the new systeminfo binding, it displays 0° as well. I think is related to the RPi & maybe access rights? I’m using a RPi 3 with Jessie.

Both Linux commands $ cat /sys/class/thermal/thermal_zone0/temp and $ /opt/vc/bin/vcgencmd measure_temp are working and I also added the openhab user to the video group.

I am no Linux expert so I’m not sure if I can solve this issue for you.

Have you already tried to run it from OH1 on the same RPi? What were the results?

And. Have you tried warching the event log? I am aware that the new basic UI has issues with refreshing. Refreshing the browser might help. Or try the classic UI.

Could you please copy your item and sitemap definitions in the thread?

@rtvb here are my configs …

Group System_Temperature_Chart (System, Charts) Number System_Temperature_Chart_Period "Periode" (System) Number System_Temperature_CPU "Temperature CPU [%.1f C]" <temperature> (System_Temperature_Chart) { exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000]" }

Text item=System_Temperature_CPU

I removed all the chart and GPU stuff, only display the CPU temperature. For testing I also removed the millis.js transformation.

The first thing I noticed was the missing transformation. As far as I
know, you should Always add one; at least a REGEX that matches the
complete contents.

Please try

Number System_Temperature_CPU "Temperature CPU [%.1f   C]" <temperature> (System_Temperature_Chart) { exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000:REGEX((.*?))]"

I got it working. I switched on debug log for the exec binding and noticed it does not log anything. I uninstalled the binding, restarted OH and installed the binding again. Fixed.

1 Like

Hey, rtvb. I see you got that working. I followed your steps but no success on my rpi temperature displaying. Could you give a clue? I did the exect same thing as you mentioned (using the .js file on tranformation). I also tried the first item config you posted (the one with REGEX). I tried the vcgencmd measure_temp command from Raspian. Don t I have to configure a .thing file? Could you help me?

Any one with hints on this?


You don’t need a thing if you use the exec1 binding.

Are you sure the vcgencmd command is working on the command line?
If so, and it is not working in openHAB, it might be a permissions issue.
The openHAB user (depending on your installation, but probably is openhab.
That user should be a member of the video group (as per my wiki item).
Can you confirm this?

My test:

$ getent group video

Tks for the reply. VCGENCMD command is working on command line - when I type vcgencmd measure_temp I get the following return temp=48.3 C. About the permission, when i type getent group video as you suggested I get the following return video:x:44:openhabian.

$ vcgencmd measure_temp
getent group video

My sitemap file looks like this:

        Frame {
                Text item=CPU_Temp

So far, I`ve tried the following item lines under the CPU_Temp.items file:

Number CPU_Temp "Temperature CPU [%.1f °C]" <temperature> (System_Temperature_Chart) { exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000]" }

String CPU_Temp "Temperature CPU [%.1f °C]" <temperature> (System_Temperature_Chart) { exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000]" }

String CPU_Temp "Temperature CPU [%.1f °C]" <temperature> (System_Temperature_Chart) { exec="<[cat vcgencmd measure_temp" }

Number CPU_Temp "Temperature CPU [%.1f °C]" <temperature> (System_Temperature_Chart) { exec="<[cat vcgencmd measure_temp" }

I`d appreciate if you could give me a hand here. Thanks in advance for your help!

Neither of your item definitions has a transformation included. I don’t think you followed my example. Please try to add a transformation for example.

Number CPU_Temp "Temperature CPU [%.1f °C]" <temperature> (System_Temperature_Chart) { exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000:REGEX((.*?))]" }

rtvb, sorry for my late reply, had some other issues to solve. I still have problemas with my CPU Temperature. But different behavior - now I get “- °C” on sitemap. It follows my files to your evaluation, if possible. Thank you once again!


Number CPU_Temp "Temperature CPU [%.1f °C]" <temperature> { exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000:REGEX((.*?))]" }


Text item=CPU_Temp icon="temperature"

Didn’t paste the milli.js, becaues I am using the REGEX transformation. There is no need for REGEX transofrmsation file?

As I mentioned before, openhab and openhabian are both on video group.

Sorry for some dumb question, I am rookie to programming and Openhab as well.

Hi Community

Unfortunately I have the same problem.
No matter what I adjust I get the CPU temperature from my Raspberry not spent in Openhab.
I have tried different methods but without success.

Number System_Temperature_CPU "CPU temperatuur [%.1f °C]" <temperature> (System)     {exec="<[cat /sys/class/thermal/thermal_zone0/temp:30000:JS(milli.js)]" }
Number System_Temperature_CPU02 "CPU temperatuur [%.1f °C]" <temperature> (System)   {exec="<[cat /sys/class/thermal/thermal_zone0/temp]" }
Number CPU_Temp "Temperature CPU [%.1f °C]" <temperature> (System_Temperature_Chart) {exec="<[cat /sys/class/thermal/thermal_zone0/temp:10000:REGEX((.*?))]" }

Frame label="Raspberry"
                        Text item=System_Temperature_CPU	
                        Text item=System_Temperature_CPU02
                        Text item=CPU_Temp			
milli.js in transform folder

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

Exec Binding 2.0.0 is installed.
How can I test if the exec binding works at all?
This is the output on my sitemap: CPU temperatuur - °C

In the console with “cat /sys/class/thermal/thermal_zone0/temp” the temperature is displayed to me.
I have add the user openhab and openhabian to the video group.

Has anyone a solution for me to solve the problem?