Nut Sensor with docker

Using Nut Sensor with docker without --net=host
Can’t get Nut to connect to NUT at localhost since docker has no port out to connect to host I believe.

Any using Nut with docker? How you connecting?
Any work around for this? How allow docker connect service listening on localhost port?

I did verify Nut running and data received when run command from host.

So after several hours of trying to get this integration running for me for the first time I have figured it out. I don’t know if you need a config change for NUT or Home Assistant or Docker, but below is how I have everything configured. Obviously make up your own <user> and <pass> for the config and ensure ups.conf is configured correctly for your UPS.

/etc/nut/nut.conf

MODE=netserver

/etc/nut/upsd.conf
Note: probably can be restricted with a specific IP, but was just trying to eliminate barriers.

LISTEN 0.0.0.0 3493

/etc/nut/upsd.users

[<user>]
  password = <pass>
  upsmon master

/etc/nut/upsmon.conf

MONITOR cyberpower@localhost 1 <user> <pass> master
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5

partial configuration.yaml
Note: the host address below can be found by running ifconfig on the host and looking for the docker0 entry. This is the IP address of the docker host on the default bridge network.

...
sensor:
  - platform: nut
    host: 172.17.0.1
    name: CyberPower 1500VA
    alias: cyberpower
    resources:
      - battery.charge
      - battery.runtime
      - input.voltage
      - ups.load
      - ups.realpower.nominal
      - ups.status.display
...
1 Like

This was issue.

I had both 0.0.0.0 and 127.0.0.1.
with that it only listen at localhost and not allow the external connection

for HA I actually put the host IP address not the docker IP

After set to 0.0.0.0 I can connect from any PC to docker Host IP

I know this is old but I wanted to throw my own “bash-my-head-against-the-wall” experience.

I followed all of the info I could find from here first (before I found this thread):

(NOTE: you will get an error after you install the “nut” package when the service starts because there is no config yet. Just ignore it and continue on with editing the config files.)

then when I finally ran the “upsc myups” command to test it all out I kept getting a “network unreachable” error.

I then came upon this thread and edited the config files as described above (thanks @jdm12989!).

But I still got the same error and I wasn’t able to reach it via HA when setting up the integration in the HA UI either.

Then after googling the error I found this website (in Russian so you’ll need to translate) that said that they needed to restart the nut service:

By running (may need sudo, I did):

service nut-server restart

After I did that and then checked the nut service status:

service nut-server status

The result was that the service was running fine.

Then I was able to enter in the info on the integration UI (using “localhost”) and everything worked. Yay!

1 Like

What docker image do you reccomend for this?