Get data from APC Smart + Network Management Card via SMTP

This configuration works nice with APC Smart + AP9617 Smart Slot Network Management Card connected to LAN.

Sensor setup:

sensor:
  - platform: snmp
    name: ups_smart_capacity
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.1.0
    accept_errors: true
    unit_of_measurement: '%'
  - platform: snmp
    name: ups_smart_runtime_remaining
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.3.0
    accept_errors: true
    value_template: >-
      {% set time = (value | int) / 100 | 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 -%}
  - platform: snmp
    name: ups_smart_load_percentage
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.4.2.3.0
    accept_errors: true
    unit_of_measurement: '%'
  - platform: snmp
    name: ups_smart_battery_temperature
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.2.0
    accept_errors: true
    unit_of_measurement: '°C'
  - platform: snmp
    name: ups_smart_battery_status
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.4.0
    accept_errors: true
    value_template: >-
      {%if value == '1' %}
        Good
      {% elif value == '2' %}
        Failed
      {% endif %}
  - platform: snmp
    name: ups_smart_type
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.1.1.1.0
    accept_errors: true
  - platform: snmp
    name: ups_smart_input_voltage
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.3.2.1.0
    accept_errors: true
    unit_of_measurement: 'V'
  - platform: snmp
    name: ups_smart_last_transfer_reason
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.3.2.5.0
    accept_errors: true
    value_template: >-
      {%if value == '1' %}
        No events
      {% elif value == '2' %}
        High line voltage
      {% elif value == '3' %}
        Brownout
      {% elif value == '4' %}
        Loss of mains power
      {% elif value == '5' %}
        Small temporary power drop
      {% elif value == '6' %}
        Large temporary power drop
      {% elif value == '7' %}
        Small spike
      {% elif value == '8' %}
        Large spike
      {% elif value == '9' %}
        UPS self test
      {% elif value == '10' %}
        Excessive input voltage fluctuation
      {% endif %}
  - platform: snmp
    name: ups_smart_output_load
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.4.2.3.0
    accept_errors: true
    unit_of_measurement: '%'
  - platform: snmp
    name: ups_smart_output_current
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.4.2.4.0
    accept_errors: true
    unit_of_measurement: 'A'
  - platform: snmp
    name: ups_smart_last_self_test_result
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.7.2.3.0
    accept_errors: true
    value_template: >-
      {%if value == '1' %}
        OK
      {% elif value == '2' %}
        Failed
      {% elif value == '3' %}
        Invalid Test
      {% elif value == '4' %}
        Test In Progress
      {% endif %}
  - platform: snmp
    name: ups_smart_last_self_test_date
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.7.2.4.0
    accept_errors: true
  - platform: snmp
    name: ups_smart_communication_status
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.8.1.0
    accept_errors: true
    value_template: >-
      {%if value == '1' %}
        on
      {% elif value == '2' %}
        off
      {% endif %}
  - platform: snmp
    name: ups_smart_status
    host: SNMP_IP
    baseoid: 1.3.6.1.4.1.318.1.1.1.4.1.1.0
    accept_errors: true
    value_template: >-
      {%if value == '1' %}
        Unknown
      {% elif value == '2' %}
        On Line
      {% elif value == '3' %}
        On Battery
      {% elif value == '4' %}
        On Smart Boost
      {% elif value == '5' %}
        Timed Sleeping
      {% elif value == '6' %}
        Software Bypass
      {% elif value == '7' %}
        Off
      {% elif value == '8' %}
        Rebooting
      {% elif value == '9' %}
        Switched Bypass
      {% elif value == '10' %}
        Hardware Failure Bypass
      {% elif value == '11' %}
        Sleeping Until Power Returns
      {% elif value == '12' %}
        On Smart Trim
      {% endif %}

homeassistant:
  customize:
    sensor.ups_smart_status:
      device_class: connectivity
      friendly_name: Smart-UPS status
    sensor.ups_smart_capacity:
      device_class: battery

11 Likes

Thanks for this. To be clear, if you use this method, do you not need to go the route of the Network UPS Tools add-on and Integration?

Yes, with this method you need nothing else.

Thanks! I’ve chucked it in as a package and it’s working a treat.

Thank you @xbmcnut for recommending this configs - it is working fine.

great job @aqualx for sharing this configs. Great job !!!

Anyway - I have one question - how I will change the temperature from Celsius to F ? I tried and shows the same Celsius value. I checked into my UPS web portal and I have the ups set up to F .

If problem is in display unit, than change everywhere:

    unit_of_measurement: '°C'

to

   unit_of_measurement: '°F'

@aqualx - made the change but still showing the Celsius value even after the HASS restart. (see below snip)

Also it shows me the UPS is on battery - is that normal ? shouldn’t say on power or something ?!

  • “Battery Temperature”: Assume you need change settings for Network Management Card itself:
  • “Model”: remove unit_of_measurement: '%' from sensor definition. I’ve updated config in first post.
  • “UPS status”: While on AC it should show On Line

Thank you @aqualx . I was able to fix the temperature measurement ( I had to updated all the local users in the card to US Customary) and also I removed the % from sensor definition.

I am planning to add the secondary UPS card - by adding UPS02 to the name string - hope will work.

Great work again !!!

adding multiple UPSs is working as well - I was able to add the second UPS by changing the host IP and name for identification.
Great job !!!

1 Like

i added to lovelace but i got “unknown”

I don’t understand how to configure please explain to me where the text should be put?

config.yaml or other?
in the board / ups setup I have to do something
thanks

If all your configuration is in configuration.yaml, than put it there.
You will need replace SNMP_IP with real address of your APC.

I did as you told me but nothing
immagine

Solved
immagine

set SNMPv1
Community Name : public
Hostname : 0.0.0.0
Access Type: Read

perfect work

This is an excellent post, however, the Home Assistant NUT tools provide a very easy way to configure the UPS via SNMP and provide automatic shutdown:

Install the Hassio NUT add-in via the Supervisor: https://github.com/hassio-addons/addon-nut

Configure it - here is my config. Just set the host to the IP address of your UPS network address and set your own username and password for the HA integration.

Make sure the UPS access control for SNMP v1 is in a profile called public and is accessible (E.g. 0.0.0.0)

users:
  - username: username
    password: password
    instcmds:
      - all
    actions: []
devices:
  - name: ups
    driver: snmp-ups
    port: 192.168.1.???
    config: []
mode: netserver
shutdown_host: 'true'

Then install the NUT integration as per the instructions: https://www.home-assistant.io/integrations/nut/

3 Likes

I just tried setting this up with my UPS, but Nut complains it doesn’t know what to do with the MIB that was found:

No matching MIB found for sysOID ‘.1.3.6.1.4.1.318.1.3.27’!
Please report it to NUT developers, with an ‘upsc’ output for your device.
Going back to the classic MIB detection method.

But when I ssl into HA, I try the upsc command, and it says upsc isn’t found.

I am using an APC SRT 8000 (which BTW I picked up on a craigslist sale for $300!)

EDIT: Sorry, I figured out I needed to stick a port number in the network config below so the integration would actually work. Things seem ok now!

Where did you stick that port number? And what port was NUT looking for? I have the same issue here.

@fdlou147 I had to add 3493 in the Network section of the config page, down at the bottom. Once I did that, the UPS info updated just fine.

1 Like

Just use one line for the runtime. You don’t need that bunch of code with lots of ifs ifs ifs )))

value_template: "{{((value | int) / 100)|timestamp_custom('%-H hours %-M min', false)}}"

It’s also convenient to use device_class: battery for batt capacity and the system will automatically detect the icon and change it depending on the state.

Also use a unique_id for each sensor, this will allow you to change their names and icons directly in UI
unique_id: apc2200_smart_battery_voltage

My code:

# APC 2200 snmp    
  - platform: snmp
    name: apc2200_smart_type
    unique_id: apc2200_smart_type
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.1.1.1.0
    accept_errors: true
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_status
    unique_id: apc2200_smart_status
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.4.1.1.0
    accept_errors: true
    value_template: >-
      {%if value == '1' %}
        Unknown
      {% elif value == '2' %}
        Online
      {% elif value == '3' %}
        On Battery
      {% elif value == '4' %}
        On Smart Boost
      {% elif value == '5' %}
        Timed Sleeping
      {% elif value == '6' %}
        Software Bypass
      {% elif value == '7' %}
        Off
      {% elif value == '8' %}
        Rebooting
      {% elif value == '9' %}
        Switched Bypass
      {% elif value == '10' %}
        Hardware Failure Bypass
      {% elif value == '11' %}
        Sleeping Until Power Returns
      {% elif value == '12' %}
        On Smart Trim
      {% endif %}
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_battery_voltage
    unique_id: apc2200_smart_battery_voltage
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.3.4.0
    device_class: voltage
    unit_of_measurement: "V"
    accept_errors: true
    value_template: "{{((value | int) / 10)}}"
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_battery_capacity
    unique_id: apc2200_smart_battery_capacity
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.1.0
    device_class: battery
    unit_of_measurement: "%"
    accept_errors: true
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_input_voltage
    unique_id: apc2200_smart_input_voltage
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.3.2.1.0
    device_class: voltage
    unit_of_measurement: "V"
    accept_errors: true
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_output_frequency
    unique_id: apc2200_smart_output_frequency
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.3.3.4.0
    accept_errors: true
    value_template: "{{((value | int) / 10)}}"
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_load
    unique_id: apc2200_smart_load
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.4.3.3.0
    unit_of_measurement: "%"
    accept_errors: true
    value_template: "{{((value | int) / 10)}}"
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_ups_temperature
    unique_id: apc2200_smart_ups_temperature
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.2.0
    device_class: temperature
    unit_of_measurement: "°C"
    accept_errors: true
  - platform: snmp
    scan_interval: 10
    name: apc2200_smart_runtime
    unique_id: apc2200_smart_runtime
    host: 192.168.1.50
    baseoid: 1.3.6.1.4.1.318.1.1.1.2.2.3.0
    accept_errors: true
    value_template: "{{((value | int) / 100)|timestamp_custom('%-H год %-M хв', false)}}"

1 Like