Last active
June 18, 2026 22:44
-
-
Save brettinternet/8dabcd07188d4479c7e3bcc34043cb9b to your computer and use it in GitHub Desktop.
Windows sensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $tcp = [System.Net.Sockets.TcpClient]::new() | |
| $tcp.ReceiveTimeout = 10000 | |
| $tcp.Connect("127.0.0.1", 5200) | |
| try { | |
| $reader = [System.IO.StreamReader]::new($tcp.GetStream(), [System.Text.Encoding]::UTF8) | |
| $json = $null | |
| for ($i = 0; $i -lt 10; $i++) { | |
| $line = $reader.ReadLine() | |
| if ([string]::IsNullOrWhiteSpace($line)) { | |
| continue | |
| } | |
| try { | |
| $json = $line | ConvertFrom-Json -ErrorAction Stop | |
| break | |
| } catch { | |
| continue | |
| } | |
| } | |
| if (-not $json) { | |
| throw "No valid JSON received from Core Temp Remote Server." | |
| } | |
| # Core Temp exposes per-core temps in fTemp. | |
| # Use max core temp as the CPU temperature sensor. | |
| $maxTemp = $json.CpuInfo.fTemp | | |
| Measure-Object -Maximum | | |
| Select-Object -ExpandProperty Maximum | |
| [math]::Round([double]$maxTemp, 1) | |
| } | |
| finally { | |
| if ($reader) { $reader.Close() } | |
| $tcp.Close() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # $Smi = (Get-Command nvidia-smi -ErrorAction Stop).Source | |
| # More reliable for HASS.Agent: | |
| $Smi = "C:\Windows\System32\nvidia-smi.exe" | |
| $value = & $Smi --query-gpu=utilization.gpu --format=csv,noheader,nounits | |
| # If multiple GPUs exist, take the first line. | |
| ($value | Select-Object -First 1).Trim() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # $Smi = (Get-Command nvidia-smi -ErrorAction Stop).Source | |
| # More reliable for HASS.Agent: | |
| $Smi = "C:\Windows\System32\nvidia-smi.exe" | |
| $value = & $Smi --query-gpu=temperature.gpu --format=csv,noheader,nounits | |
| # If multiple GPUs exist, take the first line. | |
| ($value | Select-Object -First 1).Trim() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment