Custom component: EdgeOS

EdgeOS

GitHub | Changelog

Description

Provides an integration between EdgeOS (Ubiquiti) routers to Home Assistant.

How to

Installation

Look for “Integration with EdgeOS (Ubiquiti)” and install

Requirements

  • EdgeRouter with version 1.10 at least
  • EdgeRouter User with ‘Operator’ level access or higher
  • Traffic Analysis set to ‘Enabled’ (both dpi and export enabled under system/traffic-analysis)

Setup

To add integration use Configuration -> Integrations -> Add EdgeOS
Integration supports multiple EdgeOS devices

Fields name Type Required Default Description
Name Textbox + - Represents the integration name
Host Textbox + - Hostname or IP address to access EdgeOS device
Username Textbox + - Username of user with Operator level access or higher, better to create a dedicated user for that integration for faster issues identification
Password Textbox + -
Unit Drop-down + Bytes Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes
EdgeOS Device validation errors
Errors
Cannot reach device (404)
Invalid credentials (403)
General authentication error (when failed to get valid response from device)
Could not retrieve device data from EdgeOS Router
Export (traffic-analysis) configuration is disabled, please enable
Deep Packet Inspection (traffic-analysis) configuration is disabled, please enable

Incompatible version (Required at least v1.10)

Password protection

In latest version new capability added to encrypt password before saving integration settings to .storage

In order to benefit from that capability, please remove and re-add the integration (after restart of HA between actions) for that capability to work,
As long as the password will remain in clear text saved in integration setting, the following warning log message will appear during restart:

EdgeOS password is not encrypted, please remove integration and reintegrate

Options

Configuration -> Integrations -> {Integration} -> Options

Fields name Type Required Default Description
Host Textbox + - Hostname or IP address to access EdgeOS device
Username Textbox + - Username of user with Operator level access or higher, better to create a dedicated user for that integration for faster issues identification
Password Textbox + -
Clear credentials Check-box + Unchecked Will reset username and password (Not being stored under options)
Unit Drop-down + Bytes Unit for sensors, available options are: Bytes, KiloBytes, MegaBytes
Consider away interval Textbox + 180 Consider away interval in seconds
Monitored devices Drop-down + NONE Devices to monitor using binary_sensor and sensor
Monitored interfaces Drop-down + NONE Interfaces to monitor using binary_sensor and sensor,
Track Drop-down + NONE Devices to track using device_trac
Update API Interval Textbox + 60 Number of seconds to update new devices and router settings
Update Entities Interval Textbox + 1 Number of seconds to update entities
Save debug file Check-box + Unchecked Will store debug file, more details below (Not being stored under options)
Log level Drop-down + Default Changes component’s log level (more details below)
Log incoming messages Check-box + Unchecked Whether to log as DEBUG incoming web-socket messages or not
Drop-downs work-around

As workaround for UI not allowing submitting the form without all fields with values,
First option in each drop-down is NONE,
as long as this option is checked,
it will not allow checking other items

Log Level’s drop-down

New feature to set the log level for the component without need to set log_level in customization: and restart or call manually logger.set_level and loose it after restart.

Upon startup or integration’s option update, based on the value chosen, the component will make a service call to logger.set_level for that component with the desired value,

In case Default option is chosen, flow will skip calling the service, after changing from any other option to Default, it will not take place automatically, only after restart

Save debug file

Will store debug data from the component to HA CONFIG path named edgeos_data.log

Components

Default

Name Type State Attributes
{Integration Name} System Status Binary Sensor Connected or not CPU
Memory
Up-time
API Last Update
WS Last Update
{Integration Name} System Uptime Sensor Time since restart in seconds CPU
Memory
Is Alive
API Last Update
WS Last Update
{Integration Name} Unknown Devices Sensor Number of unknown devices Unknown Devices description

Monitored Devices

Name Type State Attributes
{Integration Name} Device {Device Name} Binary Sensor Connected or not IP
MAC
Name
{Unit}Bytes (Sent)
{Unit}Bytes/ps (Sent)
{Unit}Bytes (Received)
{Unit}Bytes/ps (Received)
Last Activity
Last Changed

Monitored Interfaces

Name Type State Attributes
{Integration Name} Interface {Interface Name} Binary Sensor Connected or not Name
Duplex
Link Speed (Mbps)
address
Packets (Received)
Packets (Sent)
Errors (Received)
Errors (Sent)
Dropped packets (Received)
Dropped packets (Sent)
{Unit}Bytes (Received)
{Unit}Bytes (Sent)
{Unit}Bytes/ps (Received)
{Unit}Bytes/ps (Sent)
Multicast
Last Changed

Tracked Devices

Name Type State Attributes
{Integration Name} {Device Name} Device Tracker Home or Away Host
IP
MAC
Name
Last Activity
Connected

Setting up the integration

Setup integration

Edit options

EdgeOS Setup

15 Likes

Just tried to add this to my custom_components folder. Added the example lines to my configuration.yaml, changing the values to match my system but when restarting I get the following in my log

Setup failed for edgeos: Component not found

Along with another couple of similar lines about not being able to find the edgeos Component.

Inside my custom_components folder I created an edgeos folder and inside is the contents of the custom_components folder on the GitHub repo. Have I missed something, everything looks similar to the other custom_components I have working in HASS.

Any help appreciated, this Component sounds great.

Realised that I needed to copy everything from the custom_components folder of the Github Repo straight to my custom_components folder. So it should contain the edgeos.py file and the device_tracker folder.

Looking at it now that was obvious, it’s late and confused me because the other custom components I have are under sensor or media_center folders.

The next issue I have is around the cert config line, I left it blank and threw an error, removed the whole line from my configuration.yaml and now I get:

Invalid config for [edgeos]: string value is None for dictionary value @ data['edgeos']['cert_file']. Got None. (See /config/configuration.yaml, line 404). Please check the docs at https://home-assistant.io/components/edgeos/

Do I have to use a certificate on my ERL-3, I said False to SSL in the config of this component. I think I may need to wait until some documentation is written, I’m obviously missing something.

I tried this path for the cert file “/etc/lighttpd/server.pem” but keeps coming back with verify failed:

2019-02-08 10:31:23 ERROR (SyncWorker_15) [custom_components.edgeos] Failed to perform heartbeat, Error: HTTPSConnectionPool(host=‘192.168.1.1’, port=443): Max retries exceeded with url: /api/edge/heartbeat.json?t=1549593083 (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)’),))
2019-02-08 10:31:23 ERROR (SyncWorker_15) [custom_components.edgeos] Failed to load static-devices, Error: HTTPSConnectionPool(host=‘192.168.1.1’, port=443): Max retries exceeded with url: /api/edge/get.json (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)’),))

I added configuration file with details about each settings, your configuration is missing path to the full chain certificate,
Later today i’ll change it to avoid checking the certificate, hopefully it will solve that issue,
Alternatively, you can create full chain certificate (combine cert with key to one file)

Hi @grantc, the path you entered probably is just the certificate, as written in previous post - it requires the full chain

Hi bar, thanks for the reply - any idea how to get that information? Thanks

openssl s_client -showcerts -connect 192.168.1.1:443

not sure what part of the output is the full chain :slight_smile:

I’ll find later the article I used to create it, basically you create pem file consisted with the content of:

  1. Key
  2. Intermediate certificate
  3. Certificate

Creating a .pem with the Private Key and Entire Trust Chain:
https://www.digicert.com/ssl-support/pem-ssl-creation.htm

-----BEGIN RSA PRIVATE KEY-----
(Your Private Key: your_domain_name.key)
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
(Your Primary SSL certificate: your_domain_name.crt)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(Your Intermediate certificate: DigiCertCA.crt)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(Your Root certificate: TrustedRoot.crt)
-----END CERTIFICATE-----

Updated the component, no SSL verification for HTTPS requests,
please try and let me know if now it works for you

Confused now, so no .pem file path is required

Sorry for that :slight_smile:

I updated it once again (removed the SSL verification from login request as well),
Now you don’t need to fill in the cert_file

No longer getting complaint regarding the certificate, instead now get these 2 which are less friendly error messages.

error from callback <bound method EdgeOSWebSocket.on_error of <custom_components.edgeos.EdgeOSWebSocket object at 0x7fc82b824c18>>: on_error() takes 2 positional arguments but 3 were given
error from callback <bound method EdgeOSWebSocket.on_close of <custom_components.edgeos.EdgeOSWebSocket object at 0x7fc82b824c18>>: on_close() takes 1 positional argument but 2 were given

Thanks

found out that it can be caused due to incompetible version of websocket-client,
just to be sure, can you run the following command and let me know which version installed in your system (if you are running python virtual environment, please run it from within it):
pip freeze | grep lxml

Mine is 0.54.0, according to forums, it can be caused when it lower than 0.53.0

thanks

sorry, wrong past, should be:
pip freeze | grep websocket-client

Anyway, I pushed another fix, added the requirements of websocket-client,
If it’s not working, please post the version of your websocket-client

thanks

Unfortunately still not working and I run hass.io, which is a docker container. pip isn’t installed, so can’t use that command to get the version.

I imagine lots of other people will have similar issues with more and more people using using hass.io now.

Any other idea who to check the version without pip?

in both docker and hass.io pip installed, that’s the way it installs python packages,
you can create a command line sensor that you will get the value into its state:
sensor:

  • platform: command_line
    command: ‘pip freeze | grep websocket-client’

@stevenhorner, any progress with the version / issue?

thanks

Sorry away for the weekend, will try on Monday.
Thanks for the help.

Hi bar,

Couple of errors in the log trying to get this up and running;

  1. 2019-02-11 08:44:13 ERROR (MainThread) [homeassistant.config] Invalid config for [edgeos]: string value is None for dictionary value @ data[‘edgeos’][‘cert_file’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 134). Please check the docs at https://home-assistant.io/components/edgeos/
    2019-02-11 08:44:13 ERROR (MainThread) [homeassistant.setup] Setup failed for edgeos: Invalid config.

I added the cert_file line back in (with no value) and then comment the line out still get the same error. I thought you removed this pre-req?

  1. 2019-02-11 08:44:15 ERROR (SyncWorker_13) [custom_components.device_tracker.edgeos] Failed to initialize EdgeOS Scanner, Error: ‘edgeos_ham’, Line: 37
    2019-02-11 08:44:15 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform edgeos

Thanks