APC UPS and Synology NAS integration for Home assistant

Did you connect the usb to the synology box and setup the NUT server in the Synology GUI?

If the above is done, setup the NUT sensor in Home Assistant.

how i setup Synology GUI ? you mean this /
ups

?

Did you click ‘permitted diskstation devices’ and enter the IP of your home assistant device?

yes i did that

Ok so when your UPS detects a power outage it will put the diskstation in safemode and then shutoff the UPS.

You also enabled the UPS server so you can setup the NUT sensor in HA now.

yes
i try this code but not working:

  • platform: nut
    name: UPS Nut
    host: 192.168.xxx.xx
    port: 3493
    alias: ups_name
    resources:
    • ups.load
    • ups.realpower.nominal
    • input.voltage
    • battery.runtime

is his correct ?
do i need username and password ?
if yes how i get them from synology ?

Unless you’ve changed the default config, your alias should be ups. You can get the username and password from /usr/syno/etc/ups/upsd.users. You can the resource names by running upsc ups@localhost over ssh.

hello
i want ask how i get username and password from /usr/syno/etc/ups/upsd.users ? i’m new in Linux and what is the resource names by running upsc ups@localhost over ssh. ???

thank you

Excuse me to barge in.:wink:

If you are in your Synology as admin user by ssh, use this to command:
sudo cat usr/syno/etc/ups/upsd.users

Be aware to set your Synology firewall to accept connections from your HA on port 3493.

EDIT: to check which resources are available you can use this command on your Syno:
upsc ups@localhost

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.