Hi all, I’ve spend the past two days trying to figure out why an integration sensor isn’t working for tracking kWh’s consumed in the energy dashboard. Essentially, I have two sensors and templates set up almost identically for tracking kWh consumed, one works fine, the other refuses to update.
Summary of what I’m doing:
I’m trying to create an energy sensor in Home Assistant that tracks my UPS’s total load (in kWh) using the integration
platform.
I have a template sensor called sensor.ups_total_load
(in Watts) based on UPS load percentage × nominal output power. This is data collected from the APC UPS Daemon, which gathers data from my Windows desktop running Apcupsd and connecting to my UPS over USB. Below is the sensor template from my templates.yaml
file.
Sensor in templates.yaml
- sensor:
- name: "UPS Total Load"
unique_id: ups1500_total_load
unit_of_measurement: W
device_class: power
state_class: measurement
availability: >
{% set load = states('sensor.justinspcv8_load') %}
{% set nominal_power = states('sensor.justinspcv8_nominal_output_power') %}
{{ load is number or load not in ['unknown', 'unavailable', None] and nominal_power is number or nominal_power not in ['unknown', 'unavailable', None] }}
state: >
{% set load = states('sensor.justinspcv8_load') | float(0) %}
{% set nominal_power = states('sensor.justinspcv8_nominal_output_power') | float(0) %}
{% if load > 0 and nominal_power > 0 %}
{{ (load / 100) * nominal_power }}
{% else %}
0
{% endif %}
I set up an integration
sensor to accumulate energy from it, but it stays stuck at “unknown”. I’ve also tried manually updating the sensor.ups_total_load_energy_kwh
entity state in dev tools to a value like 0.1 to see if that would trigger it to start working, but no it never updates. Below is my integration sensor from configuration.yaml
,
Sensor from configuration.yaml
sensor:
- platform: integration
unique_id: ups_total_load_energy_kwh
source: sensor.ups1500_total_load
name: "UPS Total Load Energy (kWh)"
unit_prefix: k
unit_time: h
round: 2
In Developer Tools->Statistics, I noticed the unit of measurement is blank for the integration sensor, even though I set unit_prefix: k
and unit_time: h
. Not sure if this has something to do with it?
I also tried adding an availability:
condition to my template sensor to make sure it’s not unknown or unavailable at any time, but it still doesn’t work.
Below is my config from another sensor also using similar inputs that just tracks the power usage from my desktop computer only (Server and Desktop are connected to the same UPS). This sensor and integration is working perfectly!
templates.yaml
- sensor:
- name: "Justins Desktop Wattage"
# Subtracts the server wattage sourced from iDRAC from the total UPS power draw
unique_id: justins_desktop_wattage
unit_of_measurement: W
device_class: power
state_class: measurement
state: >
{% set ups_wattage = states('sensor.justinspcv8_load') | float(0) / 100 * (states('sensor.justinspcv8_nominal_output_power') | float(0)) %}
{% set server_wattage = states('sensor.server_power') | float(0) %}
{% if ups_wattage not in ['unknown', 'unavailable', None] and server_wattage not in ['unknown', 'unavailable', None] %}
{{ [ups_wattage - server_wattage, 0] | max }}
{% else %}
0
{% endif %}
configuration.yaml
sensor:
- platform: integration
unique_id: justins_desktop_energy_kwh
source: sensor.justins_desktop_wattage
name: "Justins Desktop Energy (kWh)"
unit_prefix: k
unit_time: h
round: 2
Hopefully, someone can help me figure out what is going on, thanks!