Creating nodes (sensors) dynamically?

Hi all,

I am trying to build a basic monitoring for my Proxmox Host with Node-Red.
I am able to access the API from Proxmox and get a list of all available containers and their information...

These information will be returned as an Array (for each container) - and each Array does contain an Object with the different information related to the container.

# and more...

Since the API would allow to create or delete containers on proxmox, I can't be sure how many machines will be returned back - so, I don't know, how long the array would be.

Since I want to forward the information to another client (homeAssistant), I need to create sensors for each entity that I want to monitor.
In my case, I need an "sensor" at least for each container included in the message.

Now, I can do this "manually":

With this method, I could simply collect the information and will have each device available as a Sensor in HomeAssistant.

But: Is there a way to create the sensors dynamically?
something like that?

in this case, the sensor would work as a template - which will be created for each container that is within the return message...

Unless the HA team provided a node that permits this dynamic nature you might have to change the means of communication. Can you use MQTT to transmit information to HA?

Note: I have zero working knowledge of HA (same as most folk here) so you may have more luck asking on the HA forum.

I've already tried asking in the HA forum... unfortunately, it seems that there isn't a way to generate this dynamically in HA...

But yes, I could use MQTT, too... or - I just create the sensors manually (for now)... in theory there shouldn't be a change in the amount of containers in a high frequency...

just struggling with splitting the return message and switch them to different outputs... isn't working as expected atm...

You can do this dynamically with Node-RED dashboard, but without HA.

But with HA, I am not sure if there is an easy way.
If you know the upper limit, then you can pre-define all the sensors and connect them to HA, and only send message to the sensor when you detect that the sensor exists from the array. If the sensor does not exist, you may send null message, or use a gate node to block the message.
This is not an elegant solution, but works if the upper limit number of sensors is not a big number.

thanks a lot!
I have now managed to get these things done... with creating the sensors manually...

But... one short further question:
Can someone pls. help me to convert the "uptime" attribute into (days, hours....)


"uptime":189062 ==> the output should be something like: 3d, 13h, 45m

so, the msg should be then:

{"state":"running","attributes":{"maxmem":16000221184,"netin":299918419,"template":"","maxswap":16000221184,"cpu":0.000211577817977571,"uptime":"3d 13h, 45m","maxdisk":"52777418752","disk":"4223741952","status":"running","vmid":"101","netout":428287283,"type":"lxc","diskread":1995493376,"name":"emby-server","cpus":4,"mem":360140800,"diskwrite":28351791104,"swap":0,"pid":"2821"}}

Thanks a lot and with best regards,

Quick google search shows this;

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.