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.