Ubiquiti UniFi power consumption and switch stats

Hi,

Since Home Assistent is focussing more and more on energy with the new energy dashboard.
Would it be possible to add the power consumption sensors for PoE devices (which are already present in UniFi UI itself).

Also switches, gateways, AP’s,… provide some stats regarding CPU and RAM usage in UniFi UI. wouldn’t be nice to have your whole UniFi network show on your wall tablet, PC dashboard,… so you don’t always have to open the Unifi UI.

Best regards,
Quinten

In the meantime you can get this data into Home Assistant with SNMP sensors. As described in my repo here.

2 Likes

Funnily enough, I set this up this week :

It could probably be adapted to pull the PoE power stats too

1 Like

Thanks, will definitly have a look to it.

This looks promising, it provides part of the stats that I want.

I’m modifying the Appdaemon app I did in the post above to get switch info, and that includes poe power and voltage

This Appdaemon app will pull any POE power and voltage from configured switches (add the names and MAC addresses in target_macs:

from pyunifi.controller import Controller
import json
import re
import hassapi as hass
import datetime
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

class UnifiSwitch(hass.Hass):

    def initialize(self):
        self.log("Unifi Switches Started")
        self.run_in(self.update, 0)
        self.run_every(self.update, datetime.datetime.now(), 600)

    def update(self, kwargs):
        self.log("Update Started")
        username = 'USERNAME'
        password = 'PASSWORD'
        target_macs = {'workshop_switch': 'XX:XX:XX:XX:XX:XX', 'loft_switch': 'XX:XX:XX:XX:XX:XX'}
        for key in target_macs:
            entity = "sensor.unifi_" + (key)
            client = Controller('192.168.1.1', username, password, 443, 'UDMP-unifiOS', site_id='default', ssl_verify=False)
            devs = client.get_device_stat(target_macs[key])
            model = devs['model']
            self.log('Switch Model: ' + model)
            for x in range(len(devs['port_table'])):
                port_poe = devs['port_table'][x]['port_poe']
                if port_poe == True:
                    port_name = devs['port_table'][x]['name']
                    poe_power = round(float(devs['port_table'][x]['poe_power']), 1)
                    poe_voltage = round(float(devs['port_table'][x]['poe_voltage']))
                    self.log(str(key) + ' Port ' + str(x+1) + ': ' + str(poe_power) + 'W' + ' ' + str(poe_voltage) + 'V')
                    self.set_state(entity + "_port" + str(x+1) + "_power", state = poe_power, attributes = {"friendly_name": port_name, "device_class": "power", "unit_of_measurement": "W", "model": model})
                    self.set_state(entity + "_port" + str(x+1) + "_voltage", state = poe_voltage, attributes = {"friendly_name": port_name, "device_class": "voltage", "unit_of_measurement": "V", "model": model})
                else:
                    self.log(str(key) + ' Port ' + str(x+1) + ": NOT POE")  
1 Like

@Holdestmade @Quinten94B

Have you all been able to pull in the power for the Unifi devices themselves (not PoE ports)? The Unifi Network integration doesn’t appear to have those sensors and I don’t see those parameters in the Unifi app or on my UDM SE’s Overview? How did you do it?

1 Like

No, not seen power of the devices themselves, only the POE port power.

This part of my Appdaemon app is redundant now as the latest version of the Unifi Integration has POE power sensors (and controls) built in

Are there no temperature sensors in the UDM? I feel like previous versions had them but this integration isnt showing them,… I’ll tinker with it this weekend but figured I would ask to see if anyone knew.

Thanks
-John

1 Like