Source sensor sensor.mains_energy_export has no unit of measurement.
The problem
Hi, This report comes from the logs on my Home Assistant. I created the integration in yaml, not using the user interface at all. Attached is the integration:
- name: Mains Energy Export
unique_id: mains_energy_export
platform: integration
source: sensor.mains_power_export
unit_prefix: k
round: 2
max_sub_interval:
seconds: 5
unit_time: h
method: trapezoidal
What version of Home Assistant Core has the issue?
core-2025.2.1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
integral
Link to integration documentation on our website
https://www.home-assistant.io/integrations/integration/
Diagnostics information
No response
Example YAML snippet
- name: Mains Energy Import
unique_id: mains_energy_import
platform: integration
source: sensor.mains_power_import
unit_prefix: k
round: 2
max_sub_interval:
seconds: 5
unit_time: h
method: trapezoidal
- name: Mains Energy Export
unique_id: mains_energy_export
platform: integration
source: sensor.mains_power_export
unit_prefix: k
round: 2
max_sub_interval:
seconds: 5
unit_time: h
method: trapezoidal
Anything in the logs that might be useful for us?
Logger: homeassistant.components.utility_meter.sensor
Source: components/utility_meter/sensor.py:508
integration: Utility Meter (documentation, issues)
First occurred: 10:48:38 (2 occurrences)
Last logged: 10:50:44
Source sensor sensor.mains_energy_export has no unit of measurement. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+integration%22
Source sensor sensor.mains_energy_import has no unit of measurement. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+integration%22
Additional information
No response
Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration (integration) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of integration can trigger bot actions by commenting:
@home-assistant closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign integrationRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.
(message by CodeOwnersMention)
integration documentation integration source (message by IssueLinks)
Hi, These are the power sensors, also built only in yaml.
- name: Mains Power Total
unique_id: mains_power_total
unit_of_measurement: W
state_class: measurement
device_class: power
state: |
{% set answer = states('sensor.mains_power_channel_a_power') %}
{% if is_number(answer) %}{% set a_power = answer | float %}{% else %}{% set a_power = 0 | float %}{% endif %}
{% set answer = states('sensor.mains_power_channel_b_power') %}
{% if is_number(answer) %}{% set b_power = answer | float %}{% else %}{% set b_power = 0 | float %}{% endif %}
{% set answer = states('sensor.mains_power_channel_c_power') %}
{% if is_number(answer) %}{% set c_power = answer | float %}{% else %}{% set c_power = 0 | float %}{% endif %}
{{ (a_power + b_power + c_power) | float }}
attributes:
attribute: "{{ now() }}"
- name: Mains Power Import
unique_id: mains_power_import
unit_of_measurement: W
state_class: measurement
device_class: power
state: |
{% set answer = states('sensor.mains_power_total') %}
{% if is_number(answer) and answer | float > 0%}{% set a_power = answer | float %}{% else %}{% set a_power = 0 | float %}{% endif %}
{{ (a_power) | float }}
attributes:
attribute: "{{ now() }}"
- name: Mains Power Export
unique_id: mains_power_export
unit_of_measurement: W
state_class: measurement
device_class: power
state: |
{% set answer = states('sensor.mains_power_total') %}
{% if is_number(answer) and answer | float < 0 %}{% set a_power = answer | float %}{% else %}{% set a_power = 0 | float %}{% endif %}
{{ (a_power) | float | abs }}
attributes:
attribute: "{{ now() }}"
and the states in Developer tools shows the correct unit of measurement:
sensor.mains_energy_importMains Energy Import | 0.88 | state_class: total unit_of_measurement: kWh device_class: energy friendly_name: Mains Energy Import source: sensor.mains_power_import
-- | -- | --
[sensor.mains_energy_import](http://homeassistant.local:8123/developer-tools/state#)
Mains Energy Import
0.88 state_class: total
unit_of_measurement: kWh
device_class: energy
friendly_name: Mains Energy Import
source: sensor.mains_power_import
Utility Meter detected that the source sensor had no unit of measurement, so the issue lies in the template not in utility_meter nor integration sensor which simply relay the source unit of measurement.
Eventually this is a race condition where template takes several cycles to propagate the unit
Hey there @phracturedblue, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of template can trigger bot actions by commenting:
@home-assistant closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign templateRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.
(message by CodeOwnersMention)
template documentation template source (message by IssueLinks)
@dgomes the template integration simply assigns the UOM, this isn't a template issue. This is likely elsewhere.
@crayner Please post a screenshot of the source entities in developer tools -> states page showing attributes.
both Riemann and Utility_meter rely on the source UOM, since everything comeback together (from the screenshot the UOM is set) I'm betting on a race condition.
@dgomes the template integration simply assigns the UOM, this isn't a template issue. This is likely elsewhere.
@crayner Please post a screenshot of the source entities in developer tools -> states page showing attributes.
Already provided above....
I believe this may have been a warning during the process of building the integral. To be clear, this is NOT a Utility Meter, but an integral. As stated above, the integral in the development does show the correct unit-of _measurement, but this information was collected hours after the lag warning was noted.
From your logs it shows that it was the utility_meter that detected the issue
From your logs it shows that it was the utility_meter that detected the issue
yes, but it was the integral at fault. Unique Circumstance: The integral and the utility_meter were created at the same time, as they were loaded from yaml on the same restart of HA. Hence, my comment earlier, about the delay in the build process.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.