The following tutorial depicts my adventure in making a Megatec protocol based UPS working on Home Assistant either by compiling NUT from source or using this forked docker image.
I bought a cheap UPS in Portugal from a lesser known brand called "Eurotech", it came with some installation cd with a program called UPSmart which only works when it is plugged to a computer running windows:
I was very happy when i found out about the Network UPS Tools and i could finally connect my UPS to my Raspberry Pi running Home Assistant. But things were not so simple.
After connecting the USB cable, running a simple lsusb
should have given me the information that i needed about the Product Id and Vendor Id:
but the manufacturer didn't bothered to write it's real IDs and we have a bogus "Fry's Electronics MEC0003". After searching some open issues regarding the topic, i noticed that i needed to grab a newer version of NUT (version 2.8) which was not available on package managers. In this readme i provide instructions in how to build NUT from source or use this forked docker image for your purposes. This fork allows to set extra fields like subdriver
, protocol
, product
, langid_fix
and norating
.
I used a pristine version of the Raspberry Pi OS (Bullseye) to build NUT. Other systems may vary.
sudo apt-get update -y
sudo apt-get install -y \
ccache time git \
git python2.7 perl curl \
make autoconf automake libltdl-dev libtool-bin libtool \
valgrind \
cppcheck \
pkg-config \
gcc g++ clang \
libcppunit-dev \
libssl-dev libnss3-dev \
augeas-tools libaugeas-dev augeas-lenses \
libusb-dev libusb-1.0-0-dev \
libi2c-dev \
libmodbus-dev \
libsnmp-dev \
libpowerman0-dev \
libfreeipmi-dev libipmimonitoring-dev \
libavahi-common-dev libavahi-core-dev libavahi-client-dev \
libneon27-gnutls-dev \
libgd-dev \
asciidoc source-highlight python3-pygments dblatex
I downloaded the most recent version of nut when this tutorial was written (2.8.0):
wget https://github.com/networkupstools/nut/releases/download/v2.8.0/nut-2.8.0.tar.gz
tar xzvf nut-2.8.0.tar.gz
cd nut-2.8.0
And used the following command to configure what i wanted:
./configure --with-all --with-user=pi --with-group=pi --sysconfdir=/etc/nut --bindir=/usr/bin --sbindir=/usr/sbin
You can find more information about the selected options here. The command above installs all drivers and files (which may not be needed), sets the user and group (you should use yours if it is not pi) and sets the system directories for the configurations and binaries
Compile and install:
make
sudo make install
Edit the necessary configuration files present on the sysconfdir
sudo nano /etc/nut/ups.conf
The content of the file will be something like this:
maxretry=3
pollinterval=1
[eurotech]
driver = "nutdrv_qx"
subdriver = "hunnox"
protocol = q1
port = "auto"
vendorid = "0001"
productid = "0000"
product = "MEC0003"
norating
novendor
langid_fix = "0x0409"
override.battery.packs = 1
default.battery.voltage.high = "13.8"
default.battery.voltage.low = "12"
pollfreq = 1
Your main challenge will be finding out which combination of configurations will work for you. Mine was a result of checking the open issues and the driver documentation for drivers like blazer_ser, blazer_usb, nut_atcl_usb or nutdrv_qx and checking their subdrivers, protocols and langid_fixes. Don't ask me directly what will work in your UPS, it will be your own adventure.
You can debug your configuration and check if you can read the results of your UPS simply by running:
/usr/bin/nutdrv_qx -a eurotech -DDDDDD
The command needs to call the driver that you are using with the name of the UPS that you configured on
/etc/nut/ups.conf
You can also try to autoscan to help you fill this file and try your luck with the command
nut-scanner -U
but the configurations that i got didn't work. When you find the right configuration you are ready to set your NUT server.
Edit the file:
sudo nano /etc/nut/upsmon.conf
and add:
RUN_AS_USER root
MONITOR eurotech@localhost 1 admin secret master
eurotech
should be the name of your configured UPS, admin
and secret
should be your username and password
Edit the file:
sudo nano /etc/nut/upsd.conf
and add:
LISTEN 0.0.0.0 3493
Edit the file:
sudo nano /etc/nut/nut.conf
and add:
MODE=netserver
Edit the file:
sudo nano /etc/nut/upsd.users
and fill with your username and password:
[monuser]
password = secret
admin master
Create some missing needed folders:
sudo mkdir -p /var/state/ups
sudo chmod 0770 /var/state/ups
sudo chown root:pi /var/state/ups
And enable some services:
sudo systemctl enable nut-server.service
sudo systemctl enable nut-monitor.service
sudo systemctl enable nut-driver-enumerator.service
sudo systemctl enable nut.target
Reboot at the end and test it by running
upsc eurotech@localhost
Simply run the command with your desired options:
docker run -d \
-p 3493:3493 \
-e DESCRIPTION='eurotech' \
-e DRIVER='nutdrv_qx' \
-e SUBDRIVER='hunnox' \
-e PROTOCOL='q1' \
-e PRODUCT='MEC0003' \
-e LANGID_FIX='0x0409' \
-e NORATING='true' \
-e NOVENDOR='true' \
-e OVERRIDE_BATTERY_PACKS='1' \
-e DEFAULT_BATTERY_VOLTAGE_HIGH='13.8' \
-e DEFAULT_BATTERY_VOLTAGE_LOW='12' \
-e VENDORID='0001' \
-e PRODUCTID='0000' \
-e POLLINTERVAL='1' \
-e POLLFREQ='1' \
-e API_USER='admin' \
-e API_PASSWORD='secret' \
--restart always \
--name nut-upsd \
--privileged \
brunoalves/nut-upsd:latest
Add a new integration and select NUT, add the ip of the server where you installed it, the port and the desired username and password. All the information will be available as entities.
The default scan interval is set to 60 seconds. If you go to the integration options you can set it to a minimum of 10 seconds
One way of editing this value directly without the GUI is to edit the file <homeassistant-config-folder>/.storage/core.config_entries
BACKUP THIS FILE FIRST!
Look for the line with the scan_interval
of NUT and set it to 1 (for example)
Kubernetes is hard--or is it? This repo is a collection of multi-platform images and container resource definitions for managing a software-dev organization using Kubernetes. These tools make it easy. Contents:
Directory | Description |
---|---|
ansible | build your own cluster (Kubernetes or Swarm) |
images | images which are published to Docker Hub |
k8s | container resources in kubernetes yaml format |
lib/build | build makefile and tools |
services | non-clustered docker-compose services |
ssl | PKI certificate tools (deprecated by k8s) |
stacks | container resources in docker-compose format |
Find images at docker hub/instantlinux. Each image is scanned by trivy to ensure they contain no known CVE vulnerabilities before promotion to Docker Hub.
Find a lot more details about the Kubernetes bare-metal installer in k8s/README.
The cluster-deployment tools here include helm charts and ansible playbooks to spin up bare-metal or VM master/worker nodes, and a Makefile to add several additional features.
- Direct-attached SSD local storage pools
- Dashboard
- Non-default namespace with its own service account (full permissions within namespace, limited read-only in kube-system namespaces)
- Keycloak for OpenID / OAuth2 user authentication / authorization
- Helm3
- Mozilla sops with encryption (to keep credentials in local git repo)
- Encryption for internal etcd
- MFA using Authelia and Google Authenticator
- Calico or flannel networking
- ingress-nginx
- Local-volume sync
- Pod security policies
- Automatic certificate issuing/renewal with Letsencrypt
- PostgreSQL-operator from CrunchyData
Developer infrastructure
Networking and support
Service | Version | Notes |
---|---|---|
authelia | ** | single-signon multi-factor auth |
cloud | ** | nextcloud, private sync like Apple iCloud |
data-sync | poor-man's SAN for persistent storage | |
duplicati | backups | |
ez-ipupdate | Dynamic DNS client | |
haproxy-keepalived | load balancer | |
guacamole | ** | authenticated remote-desktop server |
logspout | ** | central logging for Docker |
mysqldump | per-database alternative to xtrabackup | |
nagios | Nagios Core v4 for monitoring | |
nagiosql | NagiosQL for configuring Nagios Core v4 | |
nut-upsd | Network UPS Tools | |
openldap | OpenLDAP authentication server | |
restic | ** | backups |
rsyslogd | logger in a 13MB image | |
samba | file server | |
samba-dc | Active-Directory compatible domain controller | |
secondshot | rsnapshot-based backups | |
splunk | ** | the free version |
Entertainment
Thank you to the following contributors!
- Mike Neir
- Chad Hedstrom - personal site
- Sean Mollet
- Juan Manuel Carrillo Moreno - personal site
- nicxvan
- Frank Riley
- Devin Bayer
- Daniel Muller
- Brian Hechinger
Contents created 2017-23 under Apache 2.0 License by Rich Braun.