Network UPS Tools (NUT) UPS view

Just thought I’d share this “card” (collection of cards) which read data from the Network UPS Tools (NUT) integration. It’s nothing special but I made this because I could not find a card or collection of cards which provided a nice view of UPS info, hopefully this is a useful starting point for others wanting to make a UPS view. It should just work if you rename the device created by the NUT integration to ’ UPS ', this should rename the entities correctly.

Requires following components to be installed from HACS:

Lovelace YAML:

type: custom:stack-in-card
title: UPS Info
mode: vertical
background: true
cards:
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        color_type: card
        entity: sensor.ups_status
        show_state: true
        show_name: false
        color: red
        icon: fas:power-off
        state:
          - value: Online Bypass Active
            color: none
            icon: fas:plug
          - value: Online
            color: none
            icon: mdi:connection
          - value: On Battery
            color: red
            icon: fas:battery-full
            styles:
              card:
                - animation: blink 2s ease infinite
                - '--keep-background': 'true'
      - type: gauge
        entity: sensor.ups_load
        min: 0
        max: 100
        severity:
          green: 0
          yellow: 60
          red: 80
        name: Load
      - type: gauge
        entity: sensor.ups_ups_temperature
        min: 10
        max: 80
        severity:
          green: 0
          yellow: 40
          red: 60
        name: Temperature
  - type: horizontal-stack
    cards:
      - type: custom:apexcharts-card
        apex_config:
          chart:
            height: 250px
        header:
          show: true
          show_states: true
          colorize_states: true
        all_series_config:
          stroke_width: 3
          opacity: 0.3
          type: area
          color: white
          group_by:
            func: last
            duration: 5min
          show:
            extremas: true
        series:
          - entity: sensor.ups_input_voltage
            name: Input Voltage
      - type: custom:apexcharts-card
        apex_config:
          chart:
            height: 250px
        header:
          show: true
          show_states: true
          colorize_states: true
        all_series_config:
          stroke_width: 3
          opacity: 0.3
          type: area
          color: white
          group_by:
            func: last
            duration: 5min
          show:
            extremas: true
        series:
          - entity: sensor.ups_output_voltage
            name: Output Voltage
  - type: vertical-stack
    cards:
      - type: custom:bar-card
        name: Battery Charge
        entity: sensor.ups_battery_charge
        severity:
          - from: '0'
            to: '40'
            color: Red
            icon: fas:empty
          - from: '41'
            to: '60'
            color: Orange
            icon: fas:battery-half
          - from: '61'
            color: Blue
            to: '80'
            icon: fas:battery-three-quarters
          - from: '81'
            to: '100'
            color: Green
            icon: fas:battery-full
      - type: custom:bar-card
        name: Battery Voltage
        entities:
          - entity: sensor.ups_battery_voltage
        max: '86'
        target: '82'
        decimal: '1'
        min: '50'
        positions:
          minmax: inside
          value: inside
        severity:
          - from: '0'
            to: '64'
            color: Red
            icon: fas:empty
          - from: '65'
            to: '73'
            color: Orange
            icon: fas:battery-half
          - from: '74'
            color: Blue
            to: '79'
            icon: fas:battery-three-quarters
          - from: '80'
            to: '86'
            color: Green
            icon: fas:battery-full

Pictures:

8 Likes

thank you :slight_smile:

1 Like

This is amazing! Love it.

I have just a little (logic) question – your bottom bar - of the Battery Voltage - is from 50V-86V (currently at 75.6V in your example.

Where are the thresholds come from?
My UPS’s battery data is:
** Battery Type & Number : 12V / 9Ah **

So which values is it recommended for me to enter there?

Thanks, Glad its helpful!

If you mean why i choose 50v as low and 86v high as thresholds on the bar graph, I just based it upon my guess that the batteries won’t ever go down to 50v ( my UPS uses 6x 12v 9Ah batteries), so i would allow a range of 9v to 14v per battery your UPS uses (assuming your UPS uses them in series). 9v is very low per battery voltage btw, i wouldn’t ever really expect it to be below 10v realistic.

I would recommend setting up the NUT addon and integration first with your UPS and seeing what voltage it produces then working out form that how many 12v batteries it uses.

Thanks for your detailed explanation.

Currently I see this through NUT:

battery.charge: 100
battery.voltage: 13.50
battery.voltage.high: 13.00
battery.voltage.low: 10.40
battery.voltage.nominal: 12.0

I think I’ll take your advice and set the bars between 10 and 15

1 Like

Sharing my view, inspired by this one - thank you :slight_smile:

4 Likes

That’s an awesome view, shows a ton of detail!
Would you mind sharing the yaml?

First I have a bunch of template sensors defined in configuration.yaml to catch all the various status entities and pull out the various notices - e.g. OL, OB, RB, CHRG, etc. Not totally sure yet whether some of them are actually produced by my UPS, so that is work in progress still (e.g. not sure if my Eaton 5SX actually will generate a REPLBATT message through NUT, which would show as a status of ‘RB’), but I’ve defined most of the status options to be sure.

The last sensor, net_runtime, takes the remaining runtime and estimates how many minutes remain until the low battery trigger point will shut everything down - i.e. the actual minutes runtime left, not runtime to 0% which the UPS reports.

template:
  - sensor:
      - name: eaton_5sx_power
        unique_id: 2452716747653
        device_class: power
        unit_of_measurement: W
        state_class: measurement
        state: >
          {% if 'OL' in states('sensor.eaton5sx_status_data') -%}
            {{ (states('sensor.eaton5sx_load') | float) / 100 * (states('sensor.eaton5sx_nominal_real_power') | float) }}
          {%- else -%}
            0
          {%- endif %}

  - sensor:
      - name: eaton_5sx_runtime_mins
        unique_id: 2452716747657
        device_class: duration
        unit_of_measurement: min
        state: >
          {{ (states('sensor.eaton5sx_battery_runtime') | float / 60) | round(0) }}

  - sensor:
      - name: eaton_5sx_status_mains
        unique_id: 2452716747661
        state: >
          {% if 'OL' in states('sensor.eaton5sx_status_data') %}
            on_mains
          {% elif 'OB' in states('sensor.eaton5sx_status_data') %}
            on_battery
          {% elif 'OFF' in states('sensor.eaton5sx_status_data') %}
            off
          {% else %}
            unknown
          {% endif %}

  - sensor:
      - name: eaton_5sx_status_charging
        unique_id: 2452716747663
        state: >
          {% if 'CHRG' in states('sensor.eaton5sx_status_data') and 'DISCHRG' not in states('sensor.eaton5sx_status_data') %}
            charging
          {% elif 'DISCHRG' in states('sensor.eaton5sx_status_data') %}
            discharging
          {% elif 'BYPASS' in states('sensor.eaton5sx_status_data') %}
            bypass
          {% else %}
            unknown
          {% endif %}

  - sensor:
      - name: eaton_5sx_status_battery_replace
        unique_id: 2452716747665
        state: >
          {% if 'RB' in states('sensor.eaton5sx_status_data') %}
            battery_replace
          {% else %}
            battery_ok
          {% endif %}

  - sensor:
      - name: eaton_5sx_status_fsd
        unique_id: 2452716747667
        state: >
          {% if 'FSD' in states('sensor.eaton5sx_status_data') %}
            fsd
          {% else %}
            not_fsd
          {% endif %}

  - sensor:
      - name: eaton_5sx_status_battery_low_high
        unique_id: 2452716747669
        state: >
          {% if 'LB' in states('sensor.eaton5sx_status_data') %}
            low_battery
          {% elif 'HB' in states('sensor.eaton5sx_status_data') %}
            high_battery
          {% else %}
            normal
          {% endif %}

  - sensor:
      - name: eaton_5sx_status_overload
        unique_id: 2452716747671
        state: >
          {% if 'OVER' in states('sensor.eaton5sx_status_data') %}
            overload
          {% else %}
            load_ok
          {% endif %}

  - sensor:
      - name: eaton_5sx_status_buck_boost
        unique_id: 2452716747673
        state: >
          {% if 'TRIM' in states('sensor.eaton5sx_status_data') %}
            buck
          {% elif 'BOOST' in states('sensor.eaton5sx_status_data') %}
            boost
          {% else %}
            normal
          {% endif %}

  - sensor:
      - name: eaton_5sx_net_runtime
        unique_id: 2452716747675
        device_class: duration
        unit_of_measurement: min
        state: >-
            {{ ((states('sensor.eaton5sx_battery_runtime') | float / states('sensor.eaton5sx_battery_charge') | float)
               * ((states('sensor.eaton5sx_battery_charge') | float) - (states('sensor.eaton5sx_low_battery_setpoint') | float)) / 60) | round(0)
            }}

I also have this sensor defined so I can add the rack/UPS to the Energy dashboard.

sensor:
## Eaton UPS consumed power
  - platform: integration
    name: Rack Energy
    source: sensor.eaton_5sx_power
    unit_prefix: k
    unique_id: 2452716747655

That also needs a “customize”:

homeassistant:
  customize:
    sensor.rack_energy:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: total_increasing

Then the dashboard is as follows (it’s a YAML edited one, not GUI edited, bear that in mind):

  - type: horizontal-stack
    cards:
      - type: 'custom:button-card'
        template: card_title
        name: Eaton UPS Status
  - type: custom:stack-in-card
    cards:
      - type: horizontal-stack
        cards:
          - type: custom:button-card
            entity: sensor.eaton_5sx_status_mains
            show_name: true
            state:
              - value: on_mains
                name: On mains
                color: green
                icon: mdi:power-plug
              - value: on_battery
                name: On battery
                color: red
                icon: mdi:battery
              - value: 'off'
                name: UPS off
                color: red
                icon: mdi:power-off
          - type: custom:button-card
            entity: sensor.eaton_5sx_status_battery_replace
            show_name: name
            state:
              - value: battery_ok
                name: Healthy
                color: green
                icon: mdi:battery
              - value: battery_replace
                name: Replace!
                color: red
                icon: mdi:battery-charging-10
          - type: custom:button-card
            entity: sensor.eaton_5sx_status_charging
            show_name: true
            state:
              - value: charging
                name: Charging
                color: green
                icon: mdi:power-plug
              - value: discharging
                name: Discharging
                color: red
                icon: mdi:power-plug-off
              - value: bypass
                name: On bypass
                color: red
                icon: mdi:power-plug-off
      - type: horizontal-stack
        cards:
          - type: custom:button-card
            entity: sensor.eaton_5sx_status_battery_low_high
            show_name: true
            state:
              - value: low_battery
                name: Low V
                color: red
                icon: mdi:battery-10
              - value: normal
                name: Normal V
                color: green
                icon: mdi:battery
              - value: high_battery
                name: High V
                color: yellow
                icon: mdi:battery
          - type: custom:button-card
            entity: sensor.eaton_5sx_status_buck_boost
            show_name: true
            state:
              - value: buck
                name: V in high
                color: yellow
                icon: mdi:electric-switch
              - value: normal
                name: No alarm
                color: green
                icon: mdi:electric-switch
              - value: boost
                name: V in low
                color: yellow
                icon: mdi:electric-switch
          - type: entity
            entity: sensor.eaton5sx_low_battery_setpoint
            name: Off trigger
      - type: horizontal-stack
        cards:
          - type: gauge
            entity: sensor.eaton5sx_load
            min: 0
            max: 110
            severity:
              green: 0
              yellow: 50
              red: 90
            name: Load %
          - type: gauge
            entity: sensor.eaton5sx_battery_charge
            min: 0
            max: 100
            severity:
              red: 0
              yellow: 35
              green: 70
            name: Battery charge
      - type: horizontal-stack
        cards:
          - type: gauge
            entity: sensor.eaton_5sx_runtime_mins
            min: 0
            max: 100
            severity:
              red: 0
              yellow: 25
              green: 45
            name: Runtime to 0%
          - type: gauge
            entity: sensor.eaton_5sx_net_runtime
            min: 0
            max: 70
            severity:
              red: 0
              yellow: 15
              green: 30
            name: Runtime to trigger
      - type: horizontal-stack
        cards:
          - type: custom:apexcharts-card
            apex_config:
              chart:
                height: 250px
            header:
              show: true
              show_states: true
              colorize_states: true
            all_series_config:
              stroke_width: 3
              opacity: 0.3
              type: area
              color: orange
              group_by:
                func: last
                duration: 5min
              show:
                extremas: true
            series:
              - entity: sensor.eaton_5sx_power
                name: Input power
          - type: custom:apexcharts-card
            apex_config:
              chart:
                height: 250px
            header:
              show: true
              show_states: true
              colorize_states: true
            all_series_config:
              stroke_width: 3
              opacity: 0.3
              type: area
              color: purple
              group_by:
                func: last
                duration: 5min
              show:
                extremas: true
            series:
              - entity: sensor.eaton5sx_current_real_power
                name: Out real power
      - type: horizontal-stack
        cards:
          - type: custom:apexcharts-card
            apex_config:
              chart:
                height: 250px
            header:
              show: true
              show_states: true
              colorize_states: true
            all_series_config:
              stroke_width: 3
              opacity: 0.3
              type: area
              color: green
              group_by:
                func: last
                duration: 5min
              show:
                extremas: true
            series:
              - entity: sensor.eaton5sx_input_voltage
                name: Input Voltage
          - type: custom:apexcharts-card
            apex_config:
              chart:
                height: 250px
            header:
              show: true
              show_states: true
              colorize_states: true
            all_series_config:
              stroke_width: 3
              opacity: 0.3
              type: area
              color: blue
              group_by:
                func: last
                duration: 5min
              show:
                extremas: true
            series:
              - entity: sensor.eaton5sx_output_voltage
                name: Output Voltage
3 Likes