How to monitor your home Windows PC with Home Assistant & Glances

A common request is to be able to monitor your home computers using Home Assistant. It is easy to monitor basic machine information on the machine that you have installed Home Assistant on (using System Monitor).

A much more powerful way is to use Glances. Glances is a cross-platform system monitoring tool written in Python.

There is already a pre-built addin to make it easy to monitor the machine Home Assistant is running on. However, this doesn’t let you monitor a remote machine (not the same machine your Home Assistant is running on).

I have a Windows PC on my home network (to play games do work on). I would like to monitor this machine from Home Assistant.

Here are the high level steps we will go through.

  • Install Glances on the remote Windows PC with pip
  • Test Glances locally
  • Create a Windows Scheduled Task to run Glances on login
  • Open the Windows Firewall port so Home Assistant can communicate with the local Glances service
  • Add a new Glances Integration in Home Assistant
  • Add new Glances sensors to UI

Install Glances on the remote Windows PC with pip

You will need to install the Glances Python program onto your Windows PC. The easiest way to do this is via the command line. You can easily install the Glances application using the Python package manager called pip.

Follow the instructions on the Glances GitHub page for your platform. Since I am running Windows on the machine I would like to monitor, I can run the following command. Obviously, you must have Python & pip installed on your Windows PC.

NOTE: You must install Glances as Administrator. Open the Windows Powershell command prompt as Administrator.

pip install glances

Test Glances locally

Now that you have installed Glances, we need to ensure it is working. In the same Administrator command prompt you just opened, run the following command to start up Glances manually.

glances -w

This will start the local instance of Glances so you can test it. You should see a window that looks like this.

You can now open a local browser and see the Glances GUI. Navigate to the following URL.

http://localhost:61208

Create a Windows Scheduled Task to run Glances on login

Now that you have installed Glances & tested it, you can create a Windows Scheduled Task to run it. This is needed because you want Glances to always be running in the background, no matter who is logged into the PC.

Open the “Task Scheduler” as Administrator by searching for it on the Start Menu.

In the Task Scheduler GUI, on the right-hand side, click on “Create Task…”

On the General tab, set the Name to “Glances” and set the Configure for to “Windows 10”

On the Trigger tab, click New. Set the Begin the task to “At log on” and set the Delay task for to “15 minutes” (customize as needed). Click OK.

On the Actions tab, click on New. Set the Action to “Start a Program”. The most likely location for Glances to be installed is “C:\Python27\Scripts\glances.exe” (your mileage may vary). Make sure to add the “-w” argument so it starts in “web server” mode. Click OK.

You can set any other settings you want to or your can just click OK to finish. You will now see the “Glances” task in the Task list.

Click on the Run button on the right-hand side of the window to force it to run now. Close the Task Scheduler.

Open the Windows Firewall port so Home Assistant can communicate with the local Glances service

Most likely, you will need to open a Windows Firewall port in order to allow Home Assistant running on another computer (a Raspberry Pi, for instance) to communicate with the locally running instance of Glances.

Open the “Windows Defender Firewall with Advanced Security” as Administrator by searching for it on the Start Menu.

Click on Inbound Rules on the left-hand side of the window. Click on New Rule… on the right-hand side of the window.

Set the Rule Type to “Port”. Click Next.

Set the Protocol to “TCP” and the Specific local ports to “61208”. This will allow incoming requests to be received by your local instance of Glances on this port only. Click Next.

Set the Action to “Allow the connection”. Click Next.

Make sure the Profile is set to only allow Domain and Private, not Public. This is because you don’t want Glances to respond to requests when you are not connected to your home network (since why would a public network (like a coffee shop WiFi) be trying to communicate with your computer over this port. This would most likely be a hacker scanning all available ports to see what responds. Click Next.

Ensure local network is Private (Optional, may not be needed for your network)

An issue I had was my home network was not set to Private for some reason. I was able to fix this by opening the Registry and setting the appropriate network to be Private instead of Public.

Note: there are ways to set this via the Control Panel Network settings, but these GUIs never worked for me. Therefore, I fell back to modifying the Registry. Use at your own risk!!!

Open “Regedit” as Adminstrator and navigate to the following key.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles

Under the Profiles key, click on each one in turn until you find the one that is your home connection (look at the ProfileName key). When you find it, double-click on the Category key and change the value to 1 (meaning Private). Close Regedit.

Give the new Inbound Firewall rule a Name “Glances” and click Finish. Close the Windows Firewall GUI.

Add a new Glances Integration in Home Assistant

Now that we have installed Glances, set it up to run automatically (and forced it to run now) and opened the Windows Firewall, we can set up Home Assistant.

Navigate to your Home Assistant home page and click on Configuration then Integrations.

Click on the orange New button at the bottom-right side of the page.

Search for Glances and click on the item.

Change the Host to the IP Address of your Windows PC (you can get this by running ipconfig from the Windows command line). My local address is blanked out in this screenshot. Click Submit.

Assuming a connection is made, you will see the new Glances integration in the list. Click on it. You will see all the new sensors that have been added to Home Assistant.

Add new Glances sensors to UI

Finally, we need to add these sensors to the Home Assistant UI so we can see the results. I am going to add them as simple badges.

Open up your lovelace YAML file (mine is broken up into different pages per tab) and add the following code.

badges:
  - sensor.glances_containers_active
  - sensor.glances_containers_ram_used
  - sensor.glances_disk_used_percent
  - sensor.glances_swap_used
  - sensor.glances_sleeping
  - sensor.glances_disk_free
  - sensor.glances_running
  - sensor.glances_cpu_load
  - sensor.glances_containers_cpu_used
  - sensor.glances_swap_used_percent
  - sensor.glances_ram_used
  - sensor.glances_total
  - sensor.glances_disk_used
  - sensor.glances_cpu_temp
  - sensor.glances_swap_free
  - sensor.glances_thread
  - sensor.glances_cpu_used
  - sensor.glances_ram_free
  - sensor.glances_ram_used_percent

Refresh your lovelace dashboard and see all your new sensors!