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
71.15k stars 29.83k forks source link

Tesla Fleet Needs device_class type Energy #124671

Open eddy-r opened 2 weeks ago

eddy-r commented 2 weeks ago

The problem

When configuring the Energy tab, adding a Grid Consumption sensor does not list any sensor from the Tesla Fleet sensors. Following the help link (https://www.home-assistant.io/docs/energy/faq/#troubleshooting-missing-entities) explains that power is measured in Watts and energy in kiloWatt-hour.

Tesla Fleet provides sensors for grid_power, load_power, solar_power, and battery_power with a unit of measure of kW and a device_class of power.

In order to use the information from these sensors in the Energy tab, the device_class needs to be energy. The state_class must be total or total_increasing. The unit_of_measure should be kWh.

These sensors cannot currently be used in the Energy tab as they are.

What version of Home Assistant Core has the issue?

core-2024.8.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

Tesla Fleet

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

To reproduce, simply add a Tesla account with a solar system and attempt to add the consumption information.

home-assistant[bot] commented 2 weeks ago

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

Code owner commands Code owners of `tesla_fleet` 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 tesla_fleet` 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)


tesla_fleet documentation tesla_fleet source (message by IssueLinks)

Bre77 commented 2 weeks ago

@eddy-r the information provided by Tesla is power, not energy. Changing the device_class will make it show up in the energy dashboard, but the information will be incorrect.

You need to create an integration helper to estimate the energy value from the power. https://www.home-assistant.io/integrations/integration/#energy

eddy-r commented 1 week ago

@Bre77 exactly right, the information provided by Tesla is power, but a full integration for Home Assistant should provide the data points for useful features within Home Assistant. If this have been posted under feature request, please feel free to move it.

I have it working and showing data in the Energy tab, but it took some delving into the inner workings of the system. For instance, Tesla Fleet provides power as a single number, with a positive number meaning flow of power away from the given source (whether it's the grid, battery, or panels), and a negative value being power flowing towards the source of the reading. Taking this and producing a straight-forward integration helper that also shows positive and negative kWh is not what the Energy tab expects. First, I had to split the data from the grid and battery power into positive-only values.

For example, grid_power in the positive value became grid_import_kw. grid_power in the negative became a positive value for grid_export_kw. grid_import_kw and grid_export_kw then have to be used in the integration template to create grid_input_kwh and grid_export_kwh.

To extract the positive value from grid_power I wound up using {{ [ states('sensor.my_home_grid_power')|float(0), 0.0 ] | max }}, which because I am not fluent in the language used, I had to adapt from a search result. The method to convert a negative value into a positive value I wound up using was {{ [ ( -1 * states('sensor.my_home_grid_power')|float(0)), 0.0 ] | max }}.

Rinse and repeat for the battery, and create an integration helper for the solar panels, and it was done, but only after trial and error. After setting the Device section to the Tesla Fleet device name ("My Home" by default), all of these show up as entities and sensors for the device.

Isn't it possible to set this up programmatically so that users don't each have to go hunting for how to do those steps?

Bre77 commented 1 week ago

Isn't it possible to set this up programmatically so that users don't each have to go hunting for how to do those steps?

It sure is, but as far as I am aware Home Assistant has rules against me doing it in the integration itself. I've asked the question on Discord because if I am allowed to then I defintely will for Tessie, Teslemetry, and Tesla Fleet.

stromdriver commented 1 week ago

update: there was a communication issue with gateway seems to be functioning but the kwh data sensor isn't reporting any data even though the fleet sensor shows it

i thought i had this setup properly last night but because it was night i assumed thats why solar value was 0. i'm getting the energy from grid sensor just fine but still no solar readout, so it seems its properly portioned just not getting solar info? (complete newb to HA, just installed green box yesterday)

sensor:

stromdriver commented 1 week ago

Screenshot 2024-09-07 at 10-19-59 Settings – Home Assistant Screenshot 2024-09-07 at 09-39-31 File editor – Home Assistant

stromdriver commented 1 week ago

config_entry-tesla_fleet-01J75NBXQM6108JTF7QV3APRQ0.json

jeegnesh-patel commented 2 days ago

Hey - so total novice first time user of HA which I primarily purchased for energy tracking to start with. I have the Tesla Fleet connected and obviously ran into the same problem as I was trying to setup the energy dashboard. I really tried my best to understand what was done in this thread but honestly getting nowhere. Would it be too much to ask for steps to create these sensors so I could use them in the energy dashboard? Thanks.

Bre77 commented 2 days ago

Hey - so total novice first time user of HA which I primarily purchased for energy tracking to start with. I have the Tesla Fleet connected and obviously ran into the same problem as I was trying to setup the energy dashboard. I really tried my best to understand what was done in this thread but honestly getting nowhere. Would it be too much to ask for steps to create these sensors so I could use them in the energy dashboard? Thanks.

No that's a really good idea, I'll add a section to the documentation.

jeegnesh-patel commented 1 day ago

That would be so awesome and maybe stop me returning my HA green box

So for the silly, does that mean I will find it at the bottom of https://www.home-assistant.io/integrations/tesla_fleet once you add it? (Please write for the stupid)