Integrating HASS.Agent with Open Hardware Monitor

Hello everyone, I hope you are all well.

I’m here to share some scripts I created to send information from Open Hardware Monitor to HASS.Agent and enable PC data telemetry via MQTT. I hope it’s useful.

Project: GitHub - douglasjunior/ohm-to-hass-agent: Here you will found my Power Shell scripts to read sensors from Open Hardware Monitor with HASS.Agent.

Example:

Requirements

  • Open Hardware Monitor
  • HASS.Agent
  • Windows 11
  • PowerShell

Scripts available

  • CPU Temperature
  • CPU Frequency
  • CPU Usage
  • Memory Usage
  • GPU Temperature
  • GPU Frequency
  • GPU Usage
  • GPU VRAM Usage

Open Hardware Monitor

  1. Download Open Hardware Monitor and unzip it.
  2. Run OpenHardwareMonitor.exe as Administrator.
  3. If you want, configure it to startup with Windows. Click on Options menu and then:
    • Start minimized
    • Minimize to Tray
    • Run on Windows startup

HASS.Agent

  1. Download HASS.Agent and install it.
  2. Follow the instructions to connect HASS.Agent to your Home Assistant and MQTT servers (required to send sensors data from PC to Home Assistant).
  3. (Optional) Configure the Satellite Service to allow the HASS.Agent to work when the user is not logged on Windows.
  4. Add Sensors following the Script usage instructions below.

Script usage

  1. Make sure that Open Hardware Monitor is running in background.

  2. Copy or create the .ps1 script as you want.In the script content you need to:

    • Import the read-sensor.ps1 script:
    • Call the Read-Sensor function setting the SensorType and Name respectively.

    Don’t forget to copy the read-sensor.ps1 to the same folder

  3. Test your script pasting the path to the .ps1 file on the PowerShell terminal, ex:

    C:\scripts\gpu-temperature.ps1
    
  4. On HASS.Agent add a new Local Sensor → select PowerShellSensor → and paste the path to the .ps1 file (ex. C:\scripts\gpu-temperature.ps1) in the powershell command or script field.

  5. Save and you are done! :tada:

Notes

Some SensorType and Name are not always the same in Open Hardware Monitor GUI and on PowerShell script.

So, to find the correct sensors available in PowerShell, run the script list-sensors.ps1 on Terminal.

2 Likes

Hey, Douglas!
I tried your project, but entering “C:\scripts\gpu-temperature.ps1” in powershell i get an error:

PS D:\OpenHardwareMonitor\scripts> cpu-load.ps1
cpu-load.ps1 : The term ‘cpu-load.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • cpu-load.ps1
  •   + CategoryInfo          : ObjectNotFound: (cpu-load.ps1:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    
    

Suggestion [3,General]: The command cpu-load.ps1 was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: “.\cpu-load.ps1”. See “get-help about_Command_Precedence” for more details.
PS D:\OpenHardwareMonitor\scripts> .\cpu-load.ps1

I did execute “Set-ExecutionPolicy Unrestricted” , after that running script with “.\gpu-temperature.ps1” as suggested works in powershell, but i have to answer with “R” each time (twice!), but thing doesn’t run in Hass.Agent.

I bet it has something to do with some other permissions… any suggestions?

EDIT: to all those who’ll have the same problem: you must enter this in powershell:

Set-ExecutionPolicy Bypass -Force
** only then things work without confirmation. But note that enabling this can be a security risk!!! (this allows all scripts to be executed without you knowing it!)**

I’m afraid I haven’t gone through this yet, but my guess is that you need to run HASS as an administrator as well.

Thanks for reply! As i wrote above i figured it out - after some digging and searching i found out that these scripts are restricted by default, so they can’t be easily executed until i specifically tell windows that i allow them. After executing above shell command all works like a charm! Thanks for scripts and instructions!

1 Like

Would be nice to have a way to allow only the wanted scripts and not disabling the security for all.

Found it! It’s possible to unblock only desired files. Explained HERE (example 7).

I just have to check if this is permanent or only until reboot…

You could also sign the script

I guess i could, but i’d have to search and learn how…

Thats fair. The other thing you could do would be use GitHub - LibreHardwareMonitor/LibreHardwareMonitor: Libre Hardware Monitor is free software that can monitor the temperature sensors, fan speeds, voltages, load and clock speeds of your computer. (its the maintained/updated fork of Open Hw monitor), enable the webpage, then use the existing integration - Open Hardware Monitor - Home Assistant

I’m not quite sure what the benefit is of running an extra script

Jesus… 121 entities :scream:
Thanks for this info, it works, i’ll test it and see which one is more convenient to me.

One thing i need hass.agent anyway is for it’s media player - i use it for all my announcements on my main wall screen (which runs on windows). And since all parametes i want aren’t available in hass.agent directly i used scripts.

Thanks for this. Not sure how you managed to run the scripts without setting policies because they seem to be restricted in Windows out of the box.

This is what I had to do:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

sets the PowerShell execution policy to Unrestricted for the CurrentUser scope. Unrestricted - All scripts run, but warns about downloaded scripts. You could also set it to Bypass then the step below won’t be necessary.

Bypass Zone.Identifier that Windows adds to files downloaded from the internet. The command below unblocks all files in the folder. You could also unblock file by file:

Get-ChildItem -Path "C:\Users\myUser\Hardware Monitor HASS" -Filter *.ps1 | Unblock-File

Save the new sensor and Store & Activate Sensors. Then click on Sensors again and you’ll see the values. It didn’t until I did this.

Probably I did this, but I don’t remember.

I’m a software developer, so I use scripts and WSL in my windows for a long time.

Unfortunately Windows will block open hardware monitor. It’s an issue with winring. This has already been an issue with HASS Agent itself where it was fixed with the current beta version. Any idea how to resolve this?

OpenHardwareMonitorLib.sys → VulnerableDriver:WinNT/Winring0

I just helped myself by replacing OpenHardwareMonitor with the nvdidia-smi cli command

gpu-temperature.ps1

return [int](& nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits)

Just add a new sensor in the Sensors Configuration in HASS.Agent and paste in the path of the script. No Windows issues like with OpenHardwareMonitor you’ll always have the latest software with Nvidia.

I guess there should be a cli command for AMD cards and other brands. Google/ChatGpt should help you with this.