APC UPS and Synology NAS integration for Home assistant

I don’t get it to work somehow, maybe anyone can help me out…

Config:
Home Assistant running on Synology Docker (everything is working, except nuts)
Using separate file for my sensors: sensor.yaml (included in my configuration.yaml)
For testing, I allowed all port 3493 communications in my Synology firewall
Added, in the Synology UPS Control Panel ‘Permitted Diskstation devices’:

  • My computer
  • My Synology LAN2 IP (local LAN 192.168.6.9)
  • My Synology LAN1 IP (WAN)

Added to my sensor.yaml:

  • platform: nut
    name: Synology UPS (NUT)
    host: 192.169.6.9
    port: 3493
    alias: ups
    resources:
    • battery.charge
    • battery.runtime
    • battery.voltage
    • battery.voltage.nominal
    • ups.status

When I use my Linux computer, with command:
upsc [email protected]
I have a output:
Init SSL without certificate database
battery.charge: 100

battery.runtime: 2880

battery.voltage: 27.1
battery.voltage.nominal: 24.0
device.mfr: American Power Conversion
device.model: Smart-UPS 750

ups.status: OL

Even with a telnet command from my computer:
telnet 192.168.6.9 3493
ask for the variables with connected telnet command:
LIST VAR ups
I got output:
VAR ups battery.charge “100”
VAR ups battery.charge.low “10”

VAR ups battery.voltage “27.1”
VAR ups battery.voltage.nominal “24.0”
VAR ups device.mfr "American Power Conversion "
VAR ups device.model “Smart-UPS 750”

VAR ups ups.status “OL”

So, the Synology Home Assistant Docker is somehow not able to connect:
2018-12-15 17:49:35 ERROR (SyncWorker_2) [homeassistant.components.sensor.nut] NUT Sensor has no data, unable to set up
2018-12-15 17:49:35 WARNING (MainThread) [homeassistant.components.sensor] Platform nut not ready yet. Retrying in 180 seconds.

What am I missing here?

EDIT: Found something. When using my Synology WAN IP as host: it is working. Something to do with the Synology Home Assistant Docker. It is communicating on the wrong Ethernet card. When checking in the Docker, I can see two cards setup (ifconfig).
Now I have to figure out how a way to solve this…

Your config is missing your username and password.

thank you all i will try it

No, it is not needed. I found the reason why it was not working…

I have a Synology NAS with two Ethernet cards. The Home assistant is installed on the Synology, using the Synology Docker package. The network configuration of the Home Assistant Docker container is set to host, meaning it will use the NAS Ethernet settings.

The Syno first card settings is set to a ‘WAN’ (kind of WAN inside my LAN) and the second is set to my LAN side. So, normally I have to use the LAN IP-address.

I did some reading and checking, and it appears that in the Syno Docker Package you can’t disable one Ethernet card. If you want to do that you could use the Virtual Manager Manager package but my Syno is not on the applied list, so I can use that.

Eventually I used the IP of my Synology ‘WAN’ side. Also for the Synology UPS NUT server setting and my Syno Firewall settings. Now it is working!

So it seems that the HA Docker NUT component only communicates on one port…

I don’t know how to ‘fix’ it but it will do for now. BTW, no user/password setting is needed in the NUT component. (alias must set to ups)

If anybody has troubles, try to connect with telnet for testing.

finally work with me :grinning::grinning:
i connect the ups to synology and enable the UPS server in synology like in the photo
i put the IP for HA in permitted Diskstation devices

in HA config for sensor is:
- platform: nut
name: NUT UPS
host: 192.168.xxx.xxx
resources:
- ups.model
- ups.status.display
- ups.load
- ups.realpower.nominal
- input.voltage
- battery.runtime

no need for the username and password or the port
HAUPS

my only problem is the NUT UPS battery run time is in second not in minute is there a way to make it in minute ?

thank you i hope it work with you all

1 Like

Did you get to put the time in minutes of the UPS ?, I am trying and I do not see how to do it, any solution ??? Thank you

hi

sorry i was busy only today see your post about put the time in minutes of the UPS i use this code:


  - platform: template
    sensors:  
      nut_ups_runtime_friendly:
        friendly_name: 'NUT UPS Battery Time Remaining'
        value_template: >- 
          {% set time = (states.sensor.nut_ups_battery_runtime.state | int) | int %}
          {% set minutes = ((time % 3600) / 60) | int %}
          {% set hours = ((time % 86400) / 3600) | int %}
          {% set days = (time / 86400) | int %}
        
          {%- if time < 60 -%}
            Less than a minute
            {%- else -%}
            {%- if days > 0 -%}
              {{ days }}d
            {%- endif -%}
            {%- if hours > 0 -%}
              {%- if days > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ hours }}h
            {%- endif -%}
            {%- if minutes > 0 -%}
              {%- if days > 0 or hours > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ minutes }}m
            {%- endif -%}
          {%- endif -%}


you need replace the (states.sensor.nut_ups_battery_runtime.state) with your entity name

i hope it help you.

Thank you very much for the help, I have been in HA for a short time and there are no things that drive me crazy. I did what you told me but there is something that does not work well, create a new sensor and I get this (the one below) the one above is the standard sensor.

Because the code you gave me, I have to put it under the other one in configuration.yaml no? , that’s how I have the code now

- platform: nut
    name: APC Pro RS900G
    host: 192.168.2.250
    resources:
      - ups.status.display
      - ups.load
      - input.voltage
      - output.voltage
      - battery.charge
      - battery.runtime   
      - ups.realpower.nominal
      - output.current
      - output.frequency
      - ups.power
      - ups.realpower
  - platform: template
    sensors:  
      nut_ups_runtime_friendly:
        friendly_name: 'NUT UPS Battery Time Remaining'
        value_template: >- 
          {% set time = (states.sensor.apc_pro_rs900g_battery_runtime | int) | int %}
          {% set minutes = ((time % 3600) / 60) | int %}
          {% set hours = ((time % 86400) / 3600) | int %}
          {% set days = (time / 86400) | int %}
        
          {%- if time < 60 -%}
            Less than a minute
            {%- else -%}
            {%- if days > 0 -%}
              {{ days }}d
            {%- endif -%}
            {%- if hours > 0 -%}
              {%- if days > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ hours }}h
            {%- endif -%}
            {%- if minutes > 0 -%}
              {%- if days > 0 or hours > 0 -%}
                {{ ' ' }}
              {%- endif -%}
              {{ minutes }}m
            {%- endif -%}
          {%- endif -%}  

Let’s see if I get this to work, thank you very much for your time

1 Like
{% set time = (states.sensor.apc_pro_rs900g_battery_runtime | int) | int %}

This is wrong… should be

{% set time = states('sensor.apc_pro_rs900g_battery_runtime') | int %}
1 Like

Thank you!!! I didn’t see it! Now it works

1 Like

Welcome i happy it work for you, i don’t why the :

{% set time = (states.sensor.apc_pro_rs900g_battery_runtime | int) | int %}

don’t work for you, i use it and work fine for me.

I don’t know how that ever worked for you. That will always return 0, no matter what. You’re casting a state object as an int. Then you you it again. This is a state object, it is not the ‘state’. That syntax in all versions of home assistant is invalid. It only would have have worked if you added .state at the end.

{% set time = states.sensor.apc_pro_rs900g_battery_runtime.state | int %}
                                                             ^
                                                             ^
                                                             ^

OK, thank you for your info.

using a slightly different technique to get the time in a “readable format”:

- platform: template
  sensors:
    desktop_ups_battery_runtime_hhmmss:
      value_template: "{{ states('sensor.desktop_ups_battery_runtime')|int | timestamp_custom('%H:%M:%S',false) }}"

For anyone interested, I’ve got my setup working with my APC Smart-UPS plugged in to HA and then Synology as the slave, rather than the other way around.

This configuration approach should also work when connecting to any other NUT.

Here are my configs with an example IP address:

First install NUT via Hassio Add-On Store: https://github.com/hassio-addons/addon-nut

NUT: (Synology requires the name “ups”, and defaults to “monuser”)

users:
  - username: monuser
    password: apcups123
    instcmds:
      - all
    actions: []
devices:
  - name: ups
    driver: usbhid-ups
    port: auto
    config:
      - vendorid = 051d
mode: netserver
shutdown_host: 'true'

Make sure you add host port 3493 under “Network”.

Then SSH in to your DiskStation and then in /usr/syno/etc/ups:

Edit upsd.users, changing master to slave and set the password to match the config above:

[monuser]
                password = apcups123
                upsman slave

Edit upsd.conf and add your HA IP Address. Eg:

LISTEN 192.168.1.95

Then set your HA IP address in the Synology UPS interface:

Synology UPS Settings

9 Likes

Does anyone know how to get the NUT UPS Device Info into a sensor so that I can display it in lovelace? I have the NUT integration configure and while I see it on the NUT devices page as shown below, i just dont have it in a sensor for display elsewhere. I was wondering if I should manually add NUT and then specifiy all the attributes you can pull from NUT in the manual config if that woul do it? Any help would be appreciated.
Screen Shot 2022-03-02 at 12.09.29 AM

Are you sure the entities are not disabled? Also make sure that in the Synology DSM you have enabled access for HASS to the NAS.

image

I was able to set up my HA as a slave connected to my Synology master UPS server which is connected to my APC via USB. Once you add your HA device IP to the Permitted Synology NAS Devices, you can configure HA NUT as follows:

devices:
  - config: []
    driver: usbhid-ups
    name: ups
    port: auto
mode: netclient
shutdown_host: 'true'
users:
  - actions: []
    instcmds:
      - all
    password: <synology ups password>
    username: <synology ups user>
    upsmon: slave
remote_ups_name: ups
remote_ups_host: <synology IP>
remote_ups_user: <synology ups user>
remote_ups_password: <synology ups password>

You can set your UPS user and password in your Synology /usr/syno/etc/ups/upsd.users, something like this:

[monuser]
                password = secret
                upsmon master

Hello,
could you please explain differences between remote_ups_name and remote_ups_user fields?
are both “master” as of your example?

Login on UPS [[email protected] failed - got [ERR ACCESS-DENIED]

Hi, does not work for me…

43.383353 UPS [[email protected]]: connect failed: Connection failure: No route to host
48.383604 [D1] Trying to connect to UPS [[email protected]]

I’m pretty sure my configuration is ok