I’m trying to get system status from my Unifi Security Gateway and Unifi Switch by creating a Python script that logs in to the device and gives me temperature, uptime, free memory, cpu usage.
Now I don’t want to login to the device too many times and instead i want to use one script that gives me all of the information with one run.
Getting the script to work I will manage myself but I am having trouble finding information how to implement this in Home Assistant.
To use Python scripts it seems that command_line platform should be used.
But having something like in the documentation would only result in one sensor with one value?
sensor:
- platform: command_line
name: getdata
command: "python3 /path/to/script/getdata.py"
- platform: template
sensors:
firstvalue:
value_template: "{% set list = states.sensor.getdata.state.split(':') %} {{ list[0] }}"
friendly_name: 'First'
secondvalue:
value_template: "{% set list = states.sensor.getdata.state.split(':') %} {{ list[1] }}"
friendly_name: 'Second'
thirdvalue:
value_template: "{% set list = states.sensor.getdata.state.split(':') %} {{ list[2] }}"
friendly_name: 'Third'
*note… I found that template sensor names cannot be capitalized
Now you will have three sensors that you can reference for other automatons. I’m sure this is not the only way to do this or the best way but it’s a quick hack to at your solution.
Hi,
Thank you for your reply.
I ended up making a cronjob which ssh:ed to my router and saved the information i wanted to a file and then i added sensors which got the information from the file: