Hi all,
So, what I’m looking to do is set up a dynamic set of Lovelace cards to show the stats of the disks I have installed in my Unraid server. I have a sensor that gives me the disk count as a state and then has attributes for total size, used, free and percentage used
I can pull the individual values out using variations of this template:
{% set list = (state_attr('sensor.unraid_array_disks', 'Size')).split() %}
{{ list[2] }}
The sensor updates if I change the array at all, so I don’t have to go back and change my sensor config if I change the array. I’m looking for the same sort of thing for Lovelace; if I add a disk, I want a new gauge to appear in Lovelace without me needing to change the config.
I found auto-entities on HACS but can’t get my head around it. I also found lovelace-card-templater and Config Template Card but I don’t think they do what I’m after.
If anyone can point me in the right direction, I would appreciate it.
Well, in-case anyone comes along looking for a solution to a similar problem, here is the solution I worked out for myself.
MQTT + Node-Red seems to be the answer.
With Home Assistants MQTT auto-discovery function, I have found it is possible to add and remove entities dynamically. When you send a blank, retained, message to the config topic of an already set-up entity, sensor in this case, it removes the entity from HA straight away.
Through Node-Red it was fairly simple to first count the disks, then have Node-Red retrieve the information for each disk and create or remove sensors as required.
Then it is fairly simple to use the auto-entities card I linked to in the first post to get a dynamic dashboard. Here is what I have right now, just the basics but it works:
If anyone is interested in the Node-Red Flow I’m using, here it is:
EDIT: looks like there is a 32000 character limit it these posts, so I had to put it in a pastebin
EDIT2: New Pastebin
So, the first version of my Node-Red flow broke after a few days, new version should be more stable. Instead of writing a new config for the sensors during each update, it should now only do so if an add or remove action needs to be taken. New version updated in the post above.