Skip to content

Building NUT integration for Home Assistant

Jim Klimov edited this page May 16, 2024 · 9 revisions

Beside the approach detailed below, you may also want to look at:

Originally posted by @DaftHonk at https://github.com/networkupstools/nut/issues/590#issuecomment-966777679

I built my own container for Home Assistant from NUT master branch.

Clone https://github.com/hassio-addons/addon-nut.git into the addons folder and change nut/Dockerfile to:

ARG BUILD_FROM=ghcr.io/hassio-addons/debian-base/amd64:4.2.0
# hadolint ignore=DL3006
FROM ${BUILD_FROM} as builder

# Setup builder
# hadolint ignore=DL3003
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       build-essential \
       git \
       python \
       autoconf \
       automake \
       libtool \
       libneon27-dev \
       libsnmp-dev \
       libusb-dev \
       libltdl-dev

RUN git clone https://github.com/networkupstools/nut.git \
    && cd nut \
    && ./autogen.sh \
    && ./configure \
            --prefix=/usr \
            --libexecdir=/usr/lib/nut \
            --without-wrap \
            --with-user=root \
            --with-group=root \
            --disable-static \
            --with-serial \
            --with-usb \
            --without-avahi \
            --with-snmp \
            --with-neon \
            --without-powerman \
            --without-ipmi \
            --without-freeipmi \
            --with-libltdl \
            --without-cgi \
            --with-drvpath=/usr/lib/nut \
            --datadir=/usr/share/nut \
            --sysconfdir=/etc/nut \
            --with-statepath=/var/run/nut \
            --with-altpidpath=/var/run/nut \
    && make DESTDIR=/app install \
    && make DESTDIR=/app install-conf

FROM ${BUILD_FROM}

# Setup base
# hadolint ignore=DL3003
RUN \
    apt-get update \
    && apt-get install -y --no-install-recommends \
       usbutils \
       libtool \
       openssl \
       libsnmp30 \
       libneon27-gnutls \
       libfreeipmi17 \
       libipmimonitoring6 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Copy root filesystem
COPY rootfs /

COPY --from=builder /app /

# Build arguments
ARG BUILD_ARCH
ARG BUILD_DATE
ARG BUILD_DESCRIPTION
ARG BUILD_NAME
ARG BUILD_REF
ARG BUILD_REPOSITORY
ARG BUILD_VERSION

# Labels
LABEL \
    io.hass.name="${BUILD_NAME}" \
    io.hass.description="${BUILD_DESCRIPTION}" \
    io.hass.arch="${BUILD_ARCH}" \
    io.hass.type="addon" \
    io.hass.version=${BUILD_VERSION} \
    maintainer="Dale Higgs <dale3h@addons.community>" \
    org.opencontainers.image.title="${BUILD_NAME}" \
    org.opencontainers.image.description="${BUILD_DESCRIPTION}" \
    org.opencontainers.image.vendor="Home Assistant Community Add-ons" \
    org.opencontainers.image.authors="Dale Higgs <dale3h@addons.community>" \
    org.opencontainers.image.licenses="MIT" \
    org.opencontainers.image.url="https://addons.community" \
    org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \
    org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \
    org.opencontainers.image.created=${BUILD_DATE} \
    org.opencontainers.image.revision=${BUILD_REF} \
    org.opencontainers.image.version=${BUILD_VERSION}

You can likely update to the latest base image, I haven't gotten around to it yet and it's been working just fine. I haven't changed any other values or labels as I haven't published it anywhere. It should then show up as a local addon and you can build it. You may also need to change it obviously if you are using a different arch.

Overall, you need to create a copy of the nut add-on in your addons folder then replace the Dockerfile. The add-on store should see it the n and you can build it from the store the same way you install a normal add-on.

For further questions, check with HA project -- it has some decent docs on developing addons that should help.

Later discussion in #590 suggested this example Dockerfile for the integration: https://github.com/networkupstools/nut/files/7525735/Dockerfile.txt

Article https://telefoncek.si/2022/09/2022-09-21-priklop-ups-na-homeassistant/ (may need Google Translate) details HA setup to pass notifications about NUT events to the mobile app.

A comment from NUT GitHub discussion details how to get into the container's shell to run (e.g. troubleshoot) NUT programs.

Clone this wiki locally