Network Connections Card for Home Assistant
Introduction
Monitoring network activity of a host (or maybe a router that outputs the same data) provides valuable insights into device connectivity, active connections, and traffic flow. The ha_network-connections-card is a custom Lovelace card for Home Assistant that displays real-time network connection data in a structured format.
Yes this is my network…
Why Use a Network Connections Card?
Tracking network connections helps users identify active devices, detect unusual traffic, and monitor bandwidth usage. This card provides:
- Real-time visualization of network connections
- Tracking of active and historical connections
- Filtering by source, destination, and port
Warning
This card was built and tested on a Fedora Linux host. The behavior of network monitoring tools may vary on different operating systems. Users should verify their configurations and adapt the implementation accordingly.
Features of ha_network-connections-card
This custom card provides:
- Dynamic visualization of network connections
- Integration with Home Assistant’s monitoring sensors
- Support for filtering by IP address and port
- Customizable update intervals
- Flexible UI configuration
- Graphical representation using an interactive force-directed graph
Special Graphical Interface
The network connections card represents network activity using an interactive force-directed graph. This visualization style allows:
- Dynamic representation of active network connections
- Nodes representing devices and edges showing active connections
- Live updates as new connections are established or closed
- Clear distinction between internal and external connections
Unlike static tables or lists, this graphical approach makes it easier to identify network traffic patterns and outliers at a glance. The interactive nature enables users to hover over nodes and connections to view detailed information about network activity.
For a table view (auto loaded on the same sensor) see: Netstat Overview Card for Home Assistant plus custom sensor command line netstat
How to Install
To set up this custom card in Home Assistant:
ha_network-connections-card GitHub repository
- Download the Card Clone or download the repository from GitHub:
git clone https://github.com/RoyOltmans/ha_network-connections-card
-
Add the Card to Home Assistant Copy the
ha_network-connections-card
folder into thewww/community/
directory within your Home Assistant configuration. -
Include the Resource in Lovelace Add the following to
ui-lovelace.yaml
:
resources:
- url: /local/community/ha_network-connections-card/ha_network-connections-card.js
type: module
- Sensor Configuration To provide data for the card, set up a sensor that captures network connections. Here’s an example using Home Assistant’s
command_line
sensor:
Here’s the expected format and sensor.network_connections (Viewable in Developer Tools → States):
command_line:
- sensor:
name: Network Connections
command: "netstat -ntu | awk '{if (NR>2) print $4, $5}' | awk -F'[: ]+' '{print $(NF-3), $(NF-2), $(NF-1), $(NF)}' | grep -E '^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+ [0-9]+ [0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+ [0-9]+$' | jq -c -R '[inputs | capture(\"(?<source>[0-9.]+) (?<sport>[0-9]+) (?<target>[0-9.]+) (?<port>[0-9]+)\") | {source, sport: ( .sport | tonumber ), target, port: ( .port | tonumber )}] | {connections: .}'"
value_template: "{{ value_json.connections | length }}"
json_attributes:
- connections
scan_interval: 60
- Card Configuration To add the card to your dashboard, place this in an single card panel and use the following Lovelace configuration:
type: custom:network-connections-card
entity: sensor.my_network_connections
Considerations
This card requires a properly configured network monitoring sensor. Users should confirm their operating system compatibility and ensure the necessary tools (such as netstat
) are installed and functional.
For more information or contributions, visit the project repository: ha_network-connections-card.