Using SNMP sensor on Windows clients to track uptime and status

Continuing the discussion from Windows 10 PC always shows as not_home in device tracker:

I thought I had solved this in post #5 by setting up IIS and using NMap but it turned out to be a failed project. This method replaces that and I thought I’d do a step by step for others hoping to do the same thing.

This involves installing SNMP on your WIndows client, setting up the proper community settings and then using the SNMP Sensor in HA and a specific Host OID to check the status.

While the examples are from a Win10 PC, the procedure is almost identical in Win8 and Win7. Theoretically, the OID I am using is in the host.mib so it could be adapted for other OS as well. This tutorial assumes you already have a basic understanding of what SNMP is (and not much more is needed) but if you don’t or if you’re just curious, this is a great place to start: http://www.snmplink.org/articles/abeginnersguide/

#Step one: Installing SNMP agent in Windows

Open Programs and Features in Windows and click on the left hand section labeled “Turn Windows Features on or off”

In the resulting dialog box, choose "Simple Network Management Protocol (SNMP) and allow it to complete the installation. It will take just a minute or so and does not require a reboot.

#Step Two: SNMP Settings

Go to your Windows Services in Computer Management and locate the SNMP Service. Right click on it and choose “Properties”. It should be set to start up automatically and should already be running. Click on the tab marked “Traps”.

We next have to create a ‘community name’ or a group to share the SNMP trap messages with. HA’s SNMP sensor uses the default ‘public’, so we’ll use that. Type public (lower case) in the Community name blank and click on the button Add to list.

Next, click on the Security tab. Under Accepted community names, click on the “Add” button. Leave the default rights at READ ONLY and add public (lower case) in the blank for the community name. Click “Add” to save this information. Below that you should see “Accept SNMP packets from these hosts” with the entry localhost already added. We need to add in the IP/hostname of our HA machine to this list. Click the “Add” button and enter in the appropriate info. (I chose the IP of my RPi HA host in this example.)

Click OK and we’re done on the Windows side.

#Step Three: Setting up the SNMP Sensor and template sensor on the HA side

The SNMP sensor requires the following information to create a sensor instance:

  • The IP address of the host system being monitored

  • The Base OID to be monitored. SNMP has Object Identifiers (OIDs) that define each thing that can be monitored for the manager and agents. SNMP Object Identifiers (OIDs) point to network objects stored in a database called the Management Information Base, often referred to as the “MIB”.

  • Name is optional but I included it here to make things easier when setting it up

First one is easy and pretty self explanatory. The second was a little harder to figure out. There are literally thousands of MIBS available to monitor in Windows and you can use a great little command line tool called SNMPWalk to show them all.

The OID I chose from the HOST.MIB was the one that displays the host’s name because this makes it easy when creating the templates and also because it is common to all Windows versions. That OID is: 1.3.6.1.2.1.1.5.0

First we need to create the SNMP sensors themselves:

-  platform: snmp
   host: 192.168.1.152
   name: zen_snmp
   baseoid: 1.3.6.1.2.1.1.5.0

-  platform: snmp
   host: 192.168.1.170
   name: satori_snmp
   baseoid: 1.3.6.1.2.1.1.5.0

This give us two sensors; one sensor named zen_snmp, which will give the value “ZEN” (upper case) when the host is up and one named satori_snmp, which gives the value “SATORI” when the host is up. Obviously, these are the names of my hosts and your names will be different.

Next, because I wanted sensors that showed custom values of “System Up” or “System Offline” instead of just showing the host name, I created two template sensors that I actually use to display the status in my card along with the other devices I am tracking with device_tracker/NMap. Those sensors are created like so:

-  platform: template
   sensors:
     satori:
       value_template: "{% if is_state('sensor.satori_snmp', 'SATORI') %}System Up{% else %}System Offline{% endif %}"
     zen:
       value_template: "{% if is_state('sensor.zen_snmp', 'ZEN') %}System Up{% else %}System Offline{% endif %}"

These are the sensors I will actually use to display the state in my UI.

#Step Four: Formatting and displaying the results

You can just add the two template sensors we created in a card to display them, or if you want to get fancy, you can use customize and assign a proper icon to them and give them a descriptive name. I used mdi: desktop-tower for mine. They end up looking like this:

The other devices you see here are the result of using the same formula of templating but with device_tracker entities instead of SNMP. Templates allowed me to change output from home/not_home values to values that made more sense for the things I was monitoring.

I hope this helps someone, please ask if anything needs clarification!

8 Likes

Hi

Tanks for a great guide. It works fine for me until the clients go offline. Then it seems like the SNMP crashes in HA. Have you hade any issues with this? If I restart HA i works fin and the clients gets Offline status. But if I don’t restart the clients is stuck in Online status.

So far I haven’t had any issues that I noticed, but I’ll have to test it later on and see.

I’ve had devices go off line, but I restart HA often when changing things so I can’t really say until I try to duplicate your situation.

I’ll let you know here.

So I’m trying to replicate this tutorial (thanks btw) because it seems like I can’t find any other way to get HA to recognize wired Ethernet devices. But I can’t figure out how to use the snmpwalk.exe command line tool. Mind expanding on it’s use?

Before that, have you tried the ping sensor? It’s working great for some of my more troublesome stuff.

Huh, yeah I set it up and pointed it at the IP’s of my main desktop and my Plex Server and while they both showed up in my known devices yaml. they would only say ‘not_home’ or in the case of my sensor template ‘offline’. Idk why, seems like the config created the device but nothing seems to recognize it afterwards.

Really wish it worked though idk what I could have done wrong… That’d be much simpler.

Here’s the guide I used for snmpwalk; it should help you.

Thanks I’ll give this a shot.

This is awesome! So far I’ve got the computer’s status working. I was wondering what you used to determine whether the bridge and extender is transmitting.

They are both seen in device tracker so I just modified a template sensor to check the state ‘home’ and re formatted the response:

 acurite_wx:
       value_template: "{% if is_state('device_tracker.acurite', 'home') %}transmitting{% else %}down{% endif %}"
 ex3700:
       value_template: "{% if is_state('device_tracker.ex3700fiosrouterhome', 'home') %}TX/RX Up{% else %}down{% endif %}"
1 Like

@Svartbacken did you ever solve the issue you were facing? I’m coming to the snmp party late, and facing the same problem. status of sensor is accurate on HASS startup, but does not then change until after a restart.

Hi. Haven’t tested any more. I bought a new router (Microtik) and uses that to know if clients are online.
Sorry.

@Svartbacken thanks for the response. I’ve fixed the problem of the template sensor not working by using the ‘accept_errors’ parameter in the primary snmp sensor; setting it to true allows the change to an undefined value, so the template sensor can work.
@rpitera thanks for such an easy-to-follow guide!

Hi,

Sorry i have this problem.

Maybe someone had the same problem before and can help me?

https://community.home-assistant.io/t/snmp-values-read-by-ha-not-correspond-with-value-sended-by-device/51789/9

thanks

I was not able to follow the first step in the original post since SNMP was not an option in the “Turn Windows features on or off”. However, I followed the steps in this article and the rest of the guide worked perfectly after that!

Thanks for sharing! This was the only sensor I was missing from my dashboard dedicated to my gamign machine. The rest all came from the very simple integration with OpenHardwareMonitor.