Card to show network devices that are online, must be dynamic

Hi, I very new to HASS, but i do have some experience in software programming and the like…

But i cannot figure out how to make this: I want to show a card on the dashboard - lets call it “Local Network” - that will contain a colored dot for every IP/ Hostname that are online. I plan to build this discovery in powershell, and publish the statuses via MQTT, so the MQTT format is rather flexible, but im thinking something in the line of :
topic:Automation/LocalNetwork with a payload in json format like:

{
	"network": [
	  {
			"name": "device a",
			"ip": "123.123.123.123",
			"state": "up",
			"LastSeen": "2021.07.28 11:13:27"
		},
		{
			"name": "device b",
			"ip": "123.123.123.124",
			"state": "up",
			"LastSeen": "2021.07.28 11:13:27"
		}
	]
}

or perhaps like this:

{
	"device a": {
		"ip": "123.123.123.123",
		"state": "up",
		"LastSeen": "2021.07.28 11:13:27"
	},
	"device b": {
		"ip": "123.123.123.124",
		"state": "up",
		"LastSeen": "2021.07.28 11:13:27"
	}
}

But to be honest, i dont know where to start, have tried to build it like a sensor, but that only shown “known” devices, but i want this to be dynamic, so i dont need to add devices every time i add some new device to the network, or if a device changes ip.

Hope someone can point me in the right direction…

A couple of days ago I stumbled on IOTLink
From what I understood you can do what you want it to do.

But ofc there are easier ways; f.e.
binary sensor with active/in-active icon that checks ping?

binary_sensor:
  - platform: ping
    host: 192.168.1.1
    name: Server ping
    count: 1
    scan_interval: 600

and then a template sensor for binary_sensor to control the icons:

template:
  - binary_sensor:
      - name: Online
        state: >
          {{ is_state("binary_sensor.server_ping", "connected") }}
        icon: >
          {% if is_state("binary_sensor.server_ping", "connected") %}
            mdi-server-network
          {% else %}
            mdi-server-network-off
          {% endif %}

Or something like that :stuck_out_tongue:

If you’re programmer enough to make sense of GitHub - custom-cards/boilerplate-card: A community driven blueprint for best practices, you could create a custom card of your liking, which would take any output.

Thanks for the IOTlink suggestion - will have to look deeper into that, but at first glance that seems very complicated for what i want to do…

About the binary sensor, that was exactly what i wanted to avoid, having to configure every network device into HASS. But perhaps im able to build a “generator” that will generate each sensor every day or something… hmm - have to think about that.

Thanks for the link to the boiler plate template - will dig into that - do you know of a simple working example that uses this boiler template, perhaps one that reads from mqtt so i dont have to start from almost scratch?

The simple example is the boilerplate card :wink:
The card will read the state/attributes of an entity, so just create a MQTT sensor with the content above (in an attribute, states are limited to 255 chars), that you will pass to the card.

thanks - now i just have to figure out how to “import” this into hass. :slight_smile:

A suggestion that might get you further down your path, here is what I have done, ymmv:
Make an entry in crontab-e on a network device, I use the node-red server host;
* * * * * nmap -vv -sn 192.168.0.1-255 > textip.txt
in Node-red use “file” node to pull each line (use \n to get .msg per newline)
Use “switch” and “change” nodes to make each string message look like you want, then write them with “file” node to a new file like online.txt, one line per message. Before you write them add an “MQTT node-out” and you can send each message to your broker, if you can use that.
Use crontab -e on the system running HA to copy the file from the node-red machine(if different)
* * * * * scp [user@[node-red server IP]:[path to online.txt} [local path to save file/online.txt]
Note: I have secure keys set-up to allow use of scp with no password entry.
In HA make a command line sensor like:

sensor:
  - platform: command_line
    name: "Online"
    command: "cat \n /home/[user]/online.txt"

Display this sensor in a markdown card, and you have a list of what machines are online. This can be as dynamic as you want if you overwrite the files in node-red at suitable intervals, so they regenerate.
I can share exact code if needed, but this is outline off top of my head. Sorry, no green dots…let me know if you try this, and get further. I am sure this can be streamlined…I plan to work on adding host names, but that’s for another day.
image

1 Like

Yes, something along these lines, i realize that you could properly write a html file and then “import” with the cat command… however, it seems odd to have to do this ina temp file, with data from a mqtt…

My goal is to try and create a real card from the boiler plate, just need more time to figure it out - and time is getting less these days, as im back in the office, after 8 month at home from covid… but i will get there… :slight_smile: