Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Energy History to Tesla Fleet #126878

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6b0b084
Add "Grid Status" and "Storm Watch active" values.
JEMcats Sep 14, 2024
fed5846
Adding Sensors For Energy History
JEMcats Sep 15, 2024
ba8400d
Update Naming
JEMcats Sep 15, 2024
3095a24
updated requirements
JEMcats Sep 15, 2024
3d209e9
Do suggested changes.
JEMcats Sep 15, 2024
39af01b
Change sensors from Measurement to Total.
JEMcats Sep 15, 2024
a084f55
Update coordinator.py
JEMcats Sep 16, 2024
1f713e4
Update coordinator.py
JEMcats Sep 16, 2024
7480afb
Update requirements, change formatting, change history update interva…
JEMcats Sep 16, 2024
1b4aff2
Add more details to Energy History.
JEMcats Sep 17, 2024
7c97870
Add Tests
Bre77 Sep 21, 2024
aa72cda
Add snapshot
Bre77 Sep 21, 2024
d8bd6b2
Update coordinator
Bre77 Sep 21, 2024
5b2af99
Change strings
Bre77 Sep 21, 2024
7069dbe
Rework icons
Bre77 Sep 21, 2024
f38ea93
Add sensors
Bre77 Sep 21, 2024
a5a954b
Update snapshot
Bre77 Sep 21, 2024
c73c3f2
Add rate limit test
Bre77 Sep 21, 2024
78e2d74
Add suggested_display_precision back
Bre77 Sep 22, 2024
9f17ac9
Add better polling
Bre77 Oct 5, 2024
fba4d0a
small cleanup
Bre77 Oct 5, 2024
7b7bd58
fix requirements
Bre77 Oct 5, 2024
b8430b9
Fix test
Bre77 Oct 5, 2024
2c05455
Island status review feedback
Bre77 Oct 24, 2024
24088b9
Merge upstream
Bre77 Oct 24, 2024
25a316a
Update snapshots
Bre77 Oct 24, 2024
d91b3ae
Refix Grid status
Bre77 Oct 24, 2024
6d3cb87
Undo snapshot change
Bre77 Oct 24, 2024
26d489f
Merge branch 'dev' into jemcats
Bre77 Nov 7, 2024
08504c5
ruff
Bre77 Nov 14, 2024
f48e19f
Merge branch 'dev' into jemcats
Bre77 Dec 18, 2024
ee468e5
Remove some changes from PR
Bre77 Dec 18, 2024
89601a3
Revert "Remove some changes from PR"
Bre77 Dec 18, 2024
b17fde1
revert unrelated changes
Bre77 Dec 18, 2024
010cc03
update snapshot
Bre77 Dec 18, 2024
649b44e
Revert icons.json
Bre77 Dec 18, 2024
575998a
Fix snapshot with translations
Bre77 Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more details to Energy History.
  • Loading branch information
JEMcats authored and Bre77 committed Oct 5, 2024
commit 1b4aff20255d1973ec0a44a4a759de39d31c325d
78 changes: 62 additions & 16 deletions homeassistant/components/tesla_fleet/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,33 +220,79 @@ async def _async_update_data(self) -> dict[str, Any]:
raise UpdateFailed(e.message) from e
self.updated_once = True
formatted_data = {
"grid_in": 0,
"grid_out": 0,
"total_grid_import": 0,
"total_grid_export": 0,
"solar_production": 0,
"battery_in": 0,
"battery_out": 0,
"total_battery_import": 0,
"total_battery_export": 0,
"total_generator_production": 0,
"total_home_usage": 0,
"grid_export_from_solar": 0,
"grid_export_from_generator": 0,
"grid_export_from_battery": 0,
"battery_import_from_solar": 0,
"battery_import_from_grid": 0,
"battery_import_from_generator": 0,
"home_usage_from_grid": 0,
"home_usage_from_solar": 0,
"home_usage_from_battery": 0,
"home_usage_from_generator": 0,
}
for time_entity in data["time_series"]:
formatted_data["grid_in"] += time_entity["grid_energy_imported"]
formatted_data["grid_out"] += (
formatted_data["total_grid_import"] += time_entity["grid_energy_imported"]
formatted_data["total_grid_export"] += (
time_entity["grid_energy_exported_from_solar"]
+ time_entity["grid_energy_exported_from_generator"]
+ time_entity["grid_energy_exported_from_battery"]
)
formatted_data["solar_production"] = (
formatted_data["solar_production"]
+ time_entity["solar_energy_exported"]
)
formatted_data["battery_in"] = (
formatted_data["battery_in"]
+ time_entity["battery_energy_imported_from_grid"]
formatted_data["solar_production"] += time_entity["solar_energy_exported"]
formatted_data["total_battery_import"] += (
time_entity["battery_energy_imported_from_grid"]
+ time_entity["battery_energy_imported_from_solar"]
+ time_entity["battery_energy_imported_from_generator"]
)
formatted_data["battery_out"] = (
formatted_data["battery_out"] + time_entity["battery_energy_exported"]
formatted_data["total_battery_export"] += time_entity[
"battery_energy_exported"
]
formatted_data["total_generator_production"] += time_entity[
"generator_energy_exported"
]
formatted_data["total_home_usage"] += (
time_entity["consumer_energy_imported_from_grid"]
+ time_entity["consumer_energy_imported_from_solar"]
+ time_entity["consumer_energy_imported_from_battery"]
+ time_entity["consumer_energy_imported_from_generator"]
)

formatted_data["grid_export_from_solar"] += time_entity[
"grid_energy_exported_from_solar"
]
formatted_data["grid_export_from_generator"] += time_entity[
"grid_energy_exported_from_generator"
]
formatted_data["grid_export_from_battery"] += time_entity[
"grid_energy_exported_from_battery"
]
formatted_data["battery_import_from_solar"] += time_entity[
"battery_energy_imported_from_solar"
]
formatted_data["battery_import_from_grid"] += time_entity[
"battery_energy_imported_from_grid"
]
formatted_data["battery_import_from_generator"] += time_entity[
"battery_energy_imported_from_generator"
]
formatted_data["home_usage_from_grid"] += time_entity[
"consumer_energy_imported_from_grid"
]
formatted_data["home_usage_from_solar"] += time_entity[
"consumer_energy_imported_from_solar"
]
formatted_data["home_usage_from_battery"] += time_entity[
"consumer_energy_imported_from_battery"
]
formatted_data["home_usage_from_generator"] += time_entity[
"consumer_energy_imported_from_generator"
]
return formatted_data


Expand Down
49 changes: 44 additions & 5 deletions homeassistant/components/tesla_fleet/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,68 @@
"wall_connector_state": {
"default": "mdi:ev-station"
},
"grid_in": {
"total_grid_import": {
"default": "mdi:transmission-tower-import"
},
"grid_out": {
"total_grid_export": {
"default": "mdi:transmission-tower-export"
},
"solar_production": {
"default": "mdi:solar-power-variant"
},
"battery_in": {
"total_battery_import": {
"default": "mdi:battery-arrow-up"
},
"battery_out": {
"total_battery_export": {
"default": "mdi:battery-arrow-down"
},
"storm_mode_active": {
"default": "mdi:weather-lightning"
},
"island_status": {
"default": "mdi:help-circle",
"state": {
"on_grid": "mdi:transmission-tower",
"off_grid": "mdi:transmission-tower-off"
"off_grid": "mdi:transmission-tower-off",
"island_status_unknown": "mdi:help-circle",
"off_grid_intentional": "mdi:account-cancel"
}
},
"total_generator_production": {
"default": "mdi:generator-stationary"
},
"total_home_usage": {
"default": "mdi:home-lightning-bolt"
},
"grid_export_from_solar": {
"default": "mdi:transmission-tower-export"
},
"grid_export_from_generator": {
"default": "mdi:transmission-tower-export"
},
"grid_export_from_battery": {
"default": "mdi:transmission-tower-export"
},
"battery_import_from_solar": {
"default": "mdi:battery-arrow-up"
},
"battery_import_from_grid": {
"default": "mdi:battery-arrow-up"
},
"battery_import_from_generator": {
"default": "mdi:battery-arrow-up"
},
"home_usage_from_grid": {
"default": "mdi:home-lightning-bolt"
},
"home_usage_from_solar": {
"default": "mdi:home-lightning-bolt"
},
"home_usage_from_battery": {
"default": "mdi:home-lightning-bolt"
},
"home_usage_from_generator": {
"default": "mdi:home-lightning-bolt"
}
},
"switch": {
Expand Down
108 changes: 104 additions & 4 deletions homeassistant/components/tesla_fleet/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ class TeslaFleetTimeEntityDescription(SensorEntityDescription):

ENERGY_HISTORY_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="grid_in",
key="total_grid_import",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="grid_out",
key="total_grid_export",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
Expand All @@ -439,21 +439,121 @@ class TeslaFleetTimeEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="battery_in",
key="total_battery_import",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="battery_out",
key="total_battery_export",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="total_generator_production",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="total_home_usage",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="grid_export_from_solar",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="grid_export_from_generator",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="grid_export_from_battery",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="battery_import_from_solar",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="battery_import_from_grid",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="battery_import_from_generator",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="home_usage_from_grid",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="home_usage_from_solar",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="home_usage_from_battery",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="home_usage_from_generator",
state_class=SensorStateClass.TOTAL,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
device_class=SensorDeviceClass.ENERGY,
entity_registry_enabled_default=False,
),
)

ENERGY_INFO_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
Expand Down
Loading