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!