Home Assistant Unofficial Reference 2024.12.1
mix.py
Go to the documentation of this file.
1 """Growatt Sensor definitions for the Mix type."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
6 from homeassistant.const import (
7  PERCENTAGE,
8  UnitOfElectricPotential,
9  UnitOfEnergy,
10  UnitOfPower,
11 )
12 
13 from .sensor_entity_description import GrowattSensorEntityDescription
14 
15 MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
16  # Values from 'mix_info' API call
18  key="mix_statement_of_charge",
19  translation_key="mix_statement_of_charge",
20  api_key="capacity",
21  native_unit_of_measurement=PERCENTAGE,
22  device_class=SensorDeviceClass.BATTERY,
23  ),
25  key="mix_battery_charge_today",
26  translation_key="mix_battery_charge_today",
27  api_key="eBatChargeToday",
28  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
29  device_class=SensorDeviceClass.ENERGY,
30  ),
32  key="mix_battery_charge_lifetime",
33  translation_key="mix_battery_charge_lifetime",
34  api_key="eBatChargeTotal",
35  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
36  device_class=SensorDeviceClass.ENERGY,
37  state_class=SensorStateClass.TOTAL,
38  ),
40  key="mix_battery_discharge_today",
41  translation_key="mix_battery_discharge_today",
42  api_key="eBatDisChargeToday",
43  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
44  device_class=SensorDeviceClass.ENERGY,
45  ),
47  key="mix_battery_discharge_lifetime",
48  translation_key="mix_battery_discharge_lifetime",
49  api_key="eBatDisChargeTotal",
50  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
51  device_class=SensorDeviceClass.ENERGY,
52  state_class=SensorStateClass.TOTAL,
53  ),
55  key="mix_solar_generation_today",
56  translation_key="mix_solar_generation_today",
57  api_key="epvToday",
58  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
59  device_class=SensorDeviceClass.ENERGY,
60  ),
62  key="mix_solar_generation_lifetime",
63  translation_key="mix_solar_generation_lifetime",
64  api_key="epvTotal",
65  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
66  device_class=SensorDeviceClass.ENERGY,
67  state_class=SensorStateClass.TOTAL,
68  ),
70  key="mix_battery_discharge_w",
71  translation_key="mix_battery_discharge_w",
72  api_key="pDischarge1",
73  native_unit_of_measurement=UnitOfPower.WATT,
74  device_class=SensorDeviceClass.POWER,
75  ),
77  key="mix_battery_voltage",
78  translation_key="mix_battery_voltage",
79  api_key="vbat",
80  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
81  device_class=SensorDeviceClass.VOLTAGE,
82  ),
84  key="mix_pv1_voltage",
85  translation_key="mix_pv1_voltage",
86  api_key="vpv1",
87  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
88  device_class=SensorDeviceClass.VOLTAGE,
89  ),
91  key="mix_pv2_voltage",
92  translation_key="mix_pv2_voltage",
93  api_key="vpv2",
94  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
95  device_class=SensorDeviceClass.VOLTAGE,
96  ),
97  # Values from 'mix_totals' API call
99  key="mix_load_consumption_today",
100  translation_key="mix_load_consumption_today",
101  api_key="elocalLoadToday",
102  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
103  device_class=SensorDeviceClass.ENERGY,
104  ),
106  key="mix_load_consumption_lifetime",
107  translation_key="mix_load_consumption_lifetime",
108  api_key="elocalLoadTotal",
109  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
110  device_class=SensorDeviceClass.ENERGY,
111  state_class=SensorStateClass.TOTAL,
112  ),
114  key="mix_export_to_grid_today",
115  translation_key="mix_export_to_grid_today",
116  api_key="etoGridToday",
117  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
118  device_class=SensorDeviceClass.ENERGY,
119  ),
121  key="mix_export_to_grid_lifetime",
122  translation_key="mix_export_to_grid_lifetime",
123  api_key="etogridTotal",
124  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
125  device_class=SensorDeviceClass.ENERGY,
126  state_class=SensorStateClass.TOTAL,
127  ),
128  # Values from 'mix_system_status' API call
130  key="mix_battery_charge",
131  translation_key="mix_battery_charge",
132  api_key="chargePower",
133  native_unit_of_measurement=UnitOfPower.KILO_WATT,
134  device_class=SensorDeviceClass.POWER,
135  ),
137  key="mix_load_consumption",
138  translation_key="mix_load_consumption",
139  api_key="pLocalLoad",
140  native_unit_of_measurement=UnitOfPower.KILO_WATT,
141  device_class=SensorDeviceClass.POWER,
142  ),
144  key="mix_wattage_pv_1",
145  translation_key="mix_wattage_pv_1",
146  api_key="pPv1",
147  native_unit_of_measurement=UnitOfPower.KILO_WATT,
148  device_class=SensorDeviceClass.POWER,
149  ),
151  key="mix_wattage_pv_2",
152  translation_key="mix_wattage_pv_2",
153  api_key="pPv2",
154  native_unit_of_measurement=UnitOfPower.KILO_WATT,
155  device_class=SensorDeviceClass.POWER,
156  ),
158  key="mix_wattage_pv_all",
159  translation_key="mix_wattage_pv_all",
160  api_key="ppv",
161  native_unit_of_measurement=UnitOfPower.KILO_WATT,
162  device_class=SensorDeviceClass.POWER,
163  ),
165  key="mix_export_to_grid",
166  translation_key="mix_export_to_grid",
167  api_key="pactogrid",
168  native_unit_of_measurement=UnitOfPower.KILO_WATT,
169  device_class=SensorDeviceClass.POWER,
170  ),
172  key="mix_import_from_grid",
173  translation_key="mix_import_from_grid",
174  api_key="pactouser",
175  native_unit_of_measurement=UnitOfPower.KILO_WATT,
176  device_class=SensorDeviceClass.POWER,
177  ),
179  key="mix_battery_discharge_kw",
180  translation_key="mix_battery_discharge_kw",
181  api_key="pdisCharge1",
182  native_unit_of_measurement=UnitOfPower.KILO_WATT,
183  device_class=SensorDeviceClass.POWER,
184  ),
186  key="mix_grid_voltage",
187  translation_key="mix_grid_voltage",
188  api_key="vAc1",
189  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
190  device_class=SensorDeviceClass.VOLTAGE,
191  ),
192  # Values from 'mix_detail' API call
194  key="mix_system_production_today",
195  translation_key="mix_system_production_today",
196  api_key="eCharge",
197  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
198  device_class=SensorDeviceClass.ENERGY,
199  ),
201  key="mix_load_consumption_solar_today",
202  translation_key="mix_load_consumption_solar_today",
203  api_key="eChargeToday",
204  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
205  device_class=SensorDeviceClass.ENERGY,
206  ),
208  key="mix_self_consumption_today",
209  translation_key="mix_self_consumption_today",
210  api_key="eChargeToday1",
211  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
212  device_class=SensorDeviceClass.ENERGY,
213  ),
215  key="mix_load_consumption_battery_today",
216  translation_key="mix_load_consumption_battery_today",
217  api_key="echarge1",
218  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
219  device_class=SensorDeviceClass.ENERGY,
220  ),
222  key="mix_import_from_grid_today",
223  translation_key="mix_import_from_grid_today",
224  api_key="etouser",
225  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
226  device_class=SensorDeviceClass.ENERGY,
227  ),
228  # This sensor is manually created using the most recent X-Axis value from the chartData
230  key="mix_last_update",
231  translation_key="mix_last_update",
232  api_key="lastdataupdate",
233  device_class=SensorDeviceClass.TIMESTAMP,
234  ),
235  # Values from 'dashboard_data' API call
237  key="mix_import_from_grid_today_combined",
238  translation_key="mix_import_from_grid_today_combined",
239  api_key="etouser_combined", # This id is not present in the raw API data, it is added by the sensor
240  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
241  device_class=SensorDeviceClass.ENERGY,
242  state_class=SensorStateClass.TOTAL_INCREASING,
243  previous_value_drop_threshold=0.2,
244  ),
245 )