How To Monitor Remote CPU Temp (Windows)

I run openHAB on a Pi3, which is all well and good until you wish to remotely probe a Windows device, for say CPU temp.

I started off exploring SNMP as a possibility, but the Windows & SNMP route for monitoring CPU temps all seemed to rely on an ageing version of SpeedFan and a 3rd party plugin/overlay to connect to SNMP. Which I couldn’t get to work.

I installed most “CPU Monitoring” programs during this trial and error period, as above, most products are old/discontinued.

Just as I was about to give up, I found HWinfo - which is not only free, but actually seems to get updated still!

Installing and running HWinfo, is simple, it’s a portable app, so simply download, unzip, and run. Upon running you’ll get a few prompts/windows. Do what you want with these. Explained below, is how I have configured HWinfo to record (and write) my CPU temp, and display this in openHAB. If nothing else, this “tutorial” is being written by me, for me. As I’ve no doubt I’ll forget how I’ve gone about doing this in the days/weeks/months down the line.

Also, I’m by no means an expert at coding/programming, so my methodology may suck… But, it works, for me!

Within HWinfo, browse the sensors. Find the sensor you wish to “record”/display in openHAB – assuming here this is CPU Temp (I’ve opted for the CPU temp being read via the Motherboard, another option would have been CPU Package – an average combination of all cores, read from the CPU itself). Right click on it, and select Alert Settings.

In “Alert Settings”, select;

  • Enable alerting, if value >= 1
  • Run a program (defaults to cmd.exe)
  • Add argument – /c del “\fqdn\path\to\openhab2\config\html\CPU_Temperature.txt” /f /s /q && echo %v >> “\fqdn\path\to\openhab2\config\html\CPU_Temperature.txt”
  • Define your own time/frequency (mine is set to 5 minutes)

The argument here deletes the previously written “CPU_Temperature.txt” and then echo’s the current CPU temp into “CPU_Temperature.txt”… Why? Honest truth, I couldn’t find how to have openHAB read the last line/latest CPU temp from an array. So I just decided to delete the previous “log” and write again. The result is a text file with one entry, thus only one entry for openHAB to read.

Equally, because I want to store this in persistence (rr4dj), by deleting the log files, I’m not duplicating what will possibly become a sizeable text file.

Then, within openHAB. Create a STRING item, called CPUTemperature & a NUMBER item called CPUTemperatureNumber.

Within openHAB rules, define the following;

rule "Get CPU Temperature data"
when
     Time cron "0 */5 * * * ?" //Every 5 minutes
then
    val String cpuTemp = sendHttpGetRequest("http://localhost:8080/static/CPU_Temperature.txt")
	logInfo("EXTRA", "CPU Temperature is currently "+CPUTemperature.state)
	CPUTemperature.postUpdate(cpuTemp)
end

rule "CPU Temp String to Number"
when
    Item CPUTemperature changed
then
    CPUTemperatureNumber.postUpdate(Float::parseFloat(String::format("%s",CPUTemperature.state).replace(' ','')))
	logInfo("EXTRA", "CPUTemperatureNumber is currently "+CPUTemperatureNum.state)	
end

(http://localhost:8080/static/ is the web accessible path to your HTML folder)

I then added this to my Sitemap, using

Text		 item=CPUTemperature label="CPU Temp [%s]" icon="temperature"

and added CPUTemperatureNumber to my RRD4J.

3 Likes

Thanks for sharing…

but i found another workaround… its a little overkill, but can give you a lot more options for that windows PC, and once you have it you will use it :slight_smile:

  1. install OH on that windows PC
  2. install systeminfo bidning
  3. send to main OH by REST/MQTT

Hi - thanks!

Last time I explored MQTT, you needed to utilise a 3rd party broker… Which is kind of why I shied away from MQTT this time around.

Do you have an end to end tutorial on doing the above?

Regarding my solution above, I’ve just realised (found out the hard way) you cannot RRD4J a string… so need to work out how to switch my collection to Number (simply changing String for Number in my rule/item, left me with NULL :()

If @rlkoshak or @vzorglub are floating around, could you quickly advise how I could get this working as a number? I’ve read the forum from top to bottom and I’ve gone code blind :frowning:

My above “solution” was primarily made up of advise offered by @vzorglub (here) and (here).

My CPUTemperature.txt simply consists of one line, with a 2 char “number” (56, as an example). No decimals etc…

MQTT is an essential part of my automation system…(i think for the Majority of users here)

deploying a broker is simple, free ,easy , and light wight
but you do need to understand how MQTT works…

i will give you a little direction but its hardly all you need to know

  1. install a broker https://www.youtube.com/watch?v=n0l5xNOH4Dk(you can find tones of vids online)
  2. install node-red
    this will give you an MQTT clinet , and a debug tool
    once you will have node red talking to the broker ,the sky is the limit

this channel is great , watch it … i have leaned MQTT with try and error in node red

1 Like

The magic word is parse - search “parse number text” or suchlike

Searching “parse file” is how I ended up “this close”… I seemingly just need to parse as a number instead of string.

1 Like

This seems to work…

rule "Get CPU Temperature data"
when
     Time cron "0 */1 * * * ?" //Every 5 minutes
then
    val String cpuTemp = sendHttpGetRequest("http://localhost:8080/static/CPU_Temperature.txt")
	logInfo("EXTRA", "CPU Temperature is currently "+CPUTemperature.state)
	CPUTemperature.postUpdate(cpuTemp)
end

rule "CPU Temp String to Number"
when
    Item CPUTemperature changed
then
    CPUTemperatureNum.postUpdate(Float::parseFloat(String::format("%s",CPUTemperature.state).replace(' ','')))
	logInfo("EXTRA", "CPUTemperatureNum is currently "+CPUTemperatureNum.state)	
end
1 Like