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.35k stars 30.28k forks source link

Utility Meter device class missing #127809

Open plug-it-in opened 2 days ago

plug-it-in commented 2 days ago

The problem

When you create a new Utility Meter it ALWAYS has the device class missing. There is no easy way to add this post event. Although people have supplied links to customizing the Helper these do not work, and you cannot simply add this. I have seen this issue reported many times and closed without any fix to the base. For a newbie like me this is a nightmare. I have use the State view and done a set to try and add this and sometimes that works and sometimes it doesn't.

Infact Im sure this example Im submitting will not work at all with just that brief YAML. It seems its doesn't inherit from the underlying devices

This means I cannot add it to for example the Energy Dashboard 2024-10-07_13-05-00 2024-10-07_13-05-40 2024-10-07_13-06-59

What version of Home Assistant Core has the issue?

System Information version | core-2024.10.1 -- | -- installation_type | Home Assistant OS dev | false hassio | true docker | true user | root virtualenv | false python_version | 3.12.4 os_name | Linux os_version | 6.6.31-haos-raspi arch | aarch64 timezone | Europe/London config_dir | /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.1 Stage | running Available Repositories | 1429 Downloaded Repositories | 5
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 13.1 -- | -- update_channel | stable supervisor_version | supervisor-2024.09.1 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 116.8 GB disk_used | 16.7 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | rpi5-64 supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.4.1), Studio Code Server (5.17.1), Get HACS (1.3.1), Frigate (Full Access) (0.14.1), Advanced SSH & Web Terminal (19.0.0), File editor (5.8.0), Terminal & SSH (9.15.0), GivTCP-BETA (3.0.4)
Dashboards dashboards | 7 -- | -- resources | 2 views | 5 mode | storage
Recorder oldest_recorder_run | 29 September 2024 at 20:58 -- | -- current_recorder_run | 5 October 2024 at 16:14 estimated_db_size | 260.27 MiB database_engine | sqlite database_version | 3.45.3

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

Utility Meter

Link to integration documentation on our website

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

Diagnostics information

System Information

version core-2024.10.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.31-haos-raspi
arch aarch64
timezone Europe/London
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.1 Stage | running Available Repositories | 1429 Downloaded Repositories | 5
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 13.1 -- | -- update_channel | stable supervisor_version | supervisor-2024.09.1 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 116.8 GB disk_used | 16.7 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | rpi5-64 supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.4.1), Studio Code Server (5.17.1), Get HACS (1.3.1), Frigate (Full Access) (0.14.1), Advanced SSH & Web Terminal (19.0.0), File editor (5.8.0), Terminal & SSH (9.15.0), GivTCP-BETA (3.0.4)
Dashboards dashboards | 7 -- | -- resources | 2 views | 5 mode | storage
Recorder oldest_recorder_run | 29 September 2024 at 20:58 -- | -- current_recorder_run | 5 October 2024 at 16:14 estimated_db_size | 260.27 MiB database_engine | sqlite database_version | 3.45.3

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

After some more digging this is the actual YAML produced for the final Utility Meter state_class: total_increasing status: paused last_period: "0" last_valid_state: None tariff: offpeak last_reset: "2024-10-07T11:48:39.394395+00:00" next_reset: "2024-10-08T00:00:00+01:00" unit_of_measurement: kWh friendly_name: Grid Import offpeak

I have now added the line through State and setting . I then have to reboot HA for it to be implemented and I now have

state_class: total_increasing status: paused last_period: "0" last_valid_state: None tariff: offpeak last_reset: "2024-10-07T11:48:39.394395+00:00" next_reset: "2024-10-08T00:00:00+01:00" unit_of_measurement: kWh device_class: energy friendly_name: Grid Import offpeak

With device_class as it should be

home-assistant[bot] commented 2 days 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


utility_meter documentation utility_meter source (message by IssueLinks)

dgomes commented 2 days ago

can you share the state of your source_sensor ?

plug-it-in commented 2 days ago

I presume this is what you mean [image: image.png] Kind regards

Pete Rawlings

On Mon, 7 Oct 2024 at 14:29, Diogo Gomes @.***> wrote:

can you share the state of your source_sensor ?

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/127809#issuecomment-2396939859, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEGGW2BDJSAFZ42AKWB4FWTZ2KED5AVCNFSM6AAAAABPPZG6KKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJWHEZTSOBVHE . You are receiving this because you authored the thread.Message ID: @.***>

plug-it-in commented 2 days ago

As that didnt work from email heres a video showing the state you asked for followed by me creating the Utility Meter and it failing to add the device_class . Hope this is more helpful

https://github.com/user-attachments/assets/8de29707-cf84-4453-b7dd-9a5778bb2f61

dgomes commented 2 days ago

You source does not have a device class....

The issue is in your source device

plug-it-in commented 2 days ago

I do not understand Im looking at the screen at the start of the video which is the Source Device and it clearly shows device_class: energy and copy and pasting from the source device it says

state_class: total unit_of_measurement: kWh device_class: energy friendly_name: GivTCP Energy Battery Discharge Energy Today kWh

dgomes commented 2 days ago

Sorry, very difficult to see your video (would be best to have screenshot or textual copies)

But from this part at the end of the video I seen that the source has yet to communicate any new state to the utility meter, so there is no chance for the utility_meter to know the device_class

Screenshot 2024-10-07 at 21 58 33
plug-it-in commented 2 days ago

So are you saying ONCE new data is received in the source and sent to this new meter THEN the device_class will be set? I dont understand why you do not inherit it immediately from the Source this would at least make it available to be added to things like the Energy Dashboard. You cannot do this while it does not have a device_class.

Update: I checked after I knew the Utility Meter Helper sensor should have data and it now has the device_class. Can you please document this as a warning or inherit on creation . I've spent(wasted) days trying to figure out why I could not add to the Energy Dashboard.