Sometimes it’s important to know when devices are online or offline on the network. There’s the Network binding and various add-ons and scripts and such that work with various routers and gateways. But I just tumbled upon this self-hosted service which could be an option for some.
Why I bring this up here is because it has an MQTT plugin that speaks the Home Assistant standard meaning once up and running it can scan your network and report online/offline status among other things. So OH can just discover the Things when using the Home Assistant add-on. If that’s too heavy weight for you, there’s also a webhook plugin that can let NetAlertX to update OH Items directly.
It seems pretty good at following devices even if they change IP address or MAC address. It has plugins to pull info from PiHole, AdGuard, and lots of other services and gateways.
I’m not usually an advocate for using OH as a network monitoring service but often there are good reasons to know the online status of devices in OH. For example, I send a notification if one tries to activate the garage door opener but for some reason the controller is offline.
I don’t have time for a proper tutorial right now. I hope to come back. But I can post enough to get you started. Ask questions as necessary.
Installation
See the NetAlertX docs for details. I used Docker and I use Ansible. Here’s my playbook.
---
- name: Create the netalertx user and group
ansible.builtin.import_role:
name: create-user
vars:
uid: "{{ netalertx_uid }}"
gid: "{{ netalertx_uid }}"
user_name: netalertx
create_home: false
service: netalertx
- name: Create the netalertx folder
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: netalertx
group: netalertx
mode: u=rwx,g=rwx,o=rx
loop:
- "{{ netalertx_home }}"
- "{{ netalertx_home }}/tmp"
become: true
- name: "Bring up the netalertx server"
community.docker.docker_container:
capabilities:
- NET_RAW
- NET_ADMIN
- NET_BIND_SERVICE
detach: true
env:
PUID: "{{ netalertx_uid }}"
PGID: "{{ netalertx_uid }}"
PORT: "{{ netalertx_port }}"
GRAPHQL_PORT: "{{ netalertx_api_port }}"
image: ghcr.io/jokob-sk/netalertx:latest
log_driver: "{{ docker_log_driver }}"
log_options:
max-size: "10m"
max-file: "3"
name: netalertx
network_mode: host
pull: true
read_only: true
restart_policy: always
volumes:
- "{{ netalertx_home }}:/data"
- "{{ netalertx_home }}/tmp:/tmp"
- "/etc/localtime:/etc/localtime"
Note: the NetAlertX docs have you put /tmp on a tmpfs file system. I didn’t want to do it that way right off so I could learn from the logs but will be doing that later to minimize writes (I’ve deployed this temporarily to an RPi 4).
Configuration
Under Settings → Enabled Settings you’ll want to set the following:
- Time Zone
- Networks to Scan: put in your subnet and which interface used to scan. For example
10.10.1.0/24 --interface=wlan0; add one for each subnet you have - Loaded Plugins: choose any additional plugins you may want to use. For the Home Assisntant discovery I mentioned above you need add at least MQTT. Leave the default plugins enabled. Hit save if you changed the plugins to get the configuration fields for the new ones.
- MQTT: You’ll find this at the bottom under “Publishers”, fill in all the relevant connection info. You can get those from your MQTT Broker Thing if you’ve forgotten them. Leave everything else default in terms of root topic and stuff like that.
- Configure any other plugins you’ve configured. I have AdAware so I added that. There doesn’t appear to be an opnsense plugin but plugins are supposed to be easy to create so maybe I’ll make one if this service proves to be useful to keep running.
openHAB Integration
If you’ve installed the HomeAssistant add-on and created an MQTT Broker Thing, Things should start to appear in your inbox. The hostname will be part of the Thing name so you should be able to figure out which Thing goes with which device.
There appears to be two Things discovered per device for me. I’m not yet certain what the difference is.
Initial discovery does take a little time so be patient. There is a little status badge at the top of NetAlertX’s page telling you if it’s doing something.
There are a lot of information and lots of potential for alerts and presence tracking and such. I’ve only scratched the surface myself and I mainly installed this to help understand and correct a weird networking problem I’m seeing.
If you don’t have a gateway/router that OH will integrate with directly, this could be an alternative approach that’s easier and/or more capable than the Network binding.