home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.55k stars 30.35k forks source link

Attributes aren't carried across with some utility_meter entities. #93770

Closed jyavenard closed 11 months ago

jyavenard commented 1 year ago

The problem

When creating a utility_meter to account for tariffs, such as:

daily_purchased_energy:
  source: sensor.eagle_200_total_meter_energy_delivered
  name: Daily Purchased Energy
  unique_id: daily_purchased_energy
  cycle: daily
  tariffs:
    - peak
    - offpeak

three entities will be created: select.daily_purchased_energy sensor.daily_purchased_energy_peak sensor.daily_purchased_energy_offpeak

and we can see that both the peak and offpeak entities carry the attributes from the source sensor: sensor.eagle_200_total_meter_energy_delivered

state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
friendly_name: Eagle-200 Total Meter Energy

and sensor.daily_purchased_energy_peak:

state_class: total_increasing
source: sensor.eagle_200_total_meter_energy_delivered
status: paused
last_period: '24.615000'
last_valid_state: None
meter_period: daily
cron pattern: 0 0 * * *
tariff: peak
last_reset: '2023-05-29T14:00:00.080861+00:00'
unit_of_measurement: kWh
device_class: energy
icon: mdi:transmission-tower-import
friendly_name: Daily Purchased Energy peak

in particular, unit_of_measurement, device_class and state_class are carried across.

However, if you define a simple utility_meter for measuring daily values:

daily_exported_energy:
  source: sensor.eagle_200_total_meter_energy_received
  name: Daily Exported Energy
  unique_id: daily_exported_energy
  cycle: daily

the created sensor sensor.daily_exported_energy will not carried the attribute across:

state_class: total_increasing
source: sensor.eagle_200_total_meter_energy_received
status: collecting
last_period: '4.081000'
last_valid_state: '2441.241000'
meter_period: daily
cron pattern: 0 0 * * *
last_reset: '2023-05-29T14:00:00.028049+00:00'
icon: mdi:transmission-tower-export
friendly_name: Daily Exported Energy

unit_of_measurement, device_class aren't passed to the generated sensors.

This is inconsistent.

It should carry the attributes from the original source sensor even if no tariffs are defined.

What version of Home Assistant Core has the issue?

core-2023.5.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

utility_meter

Link to integration documentation on our website

https://www.home-assistant.io/integrations/utility_meter/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration (utility_meter) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `utility_meter` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign utility_meter` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


utility_meter documentation utility_meter source (message by IssueLinks)

alexeiw123 commented 1 year ago

I also have this.

I have an existing entry

  source: sensor.grid_import_energy
  name: Daily Import Meter
  cycle: daily
  tariffs:
    - offpeak
    - shoulder
    - peak
    - superoffpeak

I recently added the superoffpeak tariff and it is created OK but doens't have the unit of kWh, so can't be added to energy dashboard.

jyavenard commented 1 year ago

I recently added the superoffpeak tariff and it is created OK but doens't have the unit of kWh, so can't be added to energy dashboard.

when used with tariff it works just fine, this isn't the same bug as I listed above. However, you need to let the system populate the new entity, it won't have a unit until then

alexeiw123 commented 1 year ago

when used with tariff it works just fine, this isn't the same bug as I listed above. However, you need to let the system populate the new entity, it won't have a unit until then

Maybe not exactly the same but seems somewhat related with both unit_of_measurement and device_class not appearing in newly created entities. of the four tariffs I listed above, the first three which were existing are working fine. The 4th one which I recently added is not working as expected.

Mine have been created now for over 24 hours, and have accumulated energy.

Ih8rain2 commented 1 year ago

Hi,

I have more or less the same issue and perhaps even stranger. I have one source sensor for the watts, which I use in an integration to give me the kWh. After that I use the Utility Meter integration on 4 levels: hourly, daily, monthly and yearly cycle. The monthly and yearly give device_class: energy and unit_of_measurement: 'kWh', exactly as expected. The other 2, hourly and daily don't do that. The numeric value though is correct for all of them..

state_class: total_increasing
source: sensor.cum_kwh_heat_pump
status: collecting
last_period: 0
last_valid_state: 0.040
meter_period: monthly
cron pattern: 0 0 1 * *
last_reset: 2023-07-05T21:46:05.274063+00:00
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: kWh Heat Pump MTD

vs

state_class: total_increasing
source: sensor.cum_kwh_heat_pump
status: collecting
last_period: 0
last_valid_state: 0.040
meter_period: daily
cron pattern: 0 0 * * *
last_reset: 2023-07-07T23:00:00.046418+00:00
icon: mdi:flash
friendly_name: Heat Pump Energy

I have multiple set-ups for other 'consumers' working flawlessly. I can't find any typo's, I have searched and searched, modified and tried but so far no results.. I have no clue.

alexeiw123 commented 1 year ago

Hi,

I have more or less the same issue and perhaps even stranger. I have one source sensor for the watts, which I use in an integration to give me the kWh. After that I use the Utility Meter integration on 4 levels: hourly, daily, monthly and yearly cycle. The monthly and yearly give device_class: energy and unit_of_measurement: 'kWh', exactly as expected. The other 2, hourly and daily don't do that. The numeric value though is correct for all of them..

state_class: total_increasing
source: sensor.cum_kwh_heat_pump
status: collecting
last_period: 0
last_valid_state: 0.040
meter_period: monthly
cron pattern: 0 0 1 * *
last_reset: 2023-07-05T21:46:05.274063+00:00
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: kWh Heat Pump MTD

vs

state_class: total_increasing
source: sensor.cum_kwh_heat_pump
status: collecting
last_period: 0
last_valid_state: 0.040
meter_period: daily
cron pattern: 0 0 * * *
last_reset: 2023-07-07T23:00:00.046418+00:00
icon: mdi:flash
friendly_name: Heat Pump Energy

I have multiple set-ups for other 'consumers' working flawlessly. I can't find any typo's, I have searched and searched, modified and tried but so far no results.. I have no clue.

This is the same issue I found (all coming from one energy sensor), it can only be a bug. You can add the device class and unit in customise.yaml just note that you'll also need to hit the fix issue button in you developer > statistics area after a reboot to correct the mismatching units.

vincenzoca69 commented 1 year ago

if I create it with a certain name it gives me the unit of measurement as I change the name it disappears and in any case the problem is with daily

issue-triage-workflows[bot] commented 11 months ago

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.