1 """Definitions for DSMR Reader sensors added to MQTT."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from typing
import Final
11 SensorEntityDescription,
16 UnitOfElectricCurrent,
17 UnitOfElectricPotential,
24 PRICE_EUR_KWH: Final = f
"EUR/{UnitOfEnergy.KILO_WATT_HOUR}"
25 PRICE_EUR_M3: Final = f
"EUR/{UnitOfVolume.CUBIC_METERS}"
29 """Transform DSMR version value to right format."""
31 return float(value) / 10
36 """Transform tariff from number to description."""
42 @dataclass(frozen=True)
45 """Sensor entity description for DSMR Reader."""
47 state: Callable |
None =
None
50 SENSORS: tuple[DSMRReaderSensorEntityDescription, ...] = (
52 key=
"dsmr/reading/electricity_delivered_1",
53 translation_key=
"low_tariff_usage",
54 device_class=SensorDeviceClass.ENERGY,
55 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
56 state_class=SensorStateClass.TOTAL_INCREASING,
59 key=
"dsmr/reading/electricity_returned_1",
60 translation_key=
"low_tariff_returned",
61 device_class=SensorDeviceClass.ENERGY,
62 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
63 state_class=SensorStateClass.TOTAL_INCREASING,
66 key=
"dsmr/reading/electricity_delivered_2",
67 translation_key=
"high_tariff_usage",
68 device_class=SensorDeviceClass.ENERGY,
69 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
70 state_class=SensorStateClass.TOTAL_INCREASING,
73 key=
"dsmr/reading/electricity_returned_2",
74 translation_key=
"high_tariff_returned",
75 device_class=SensorDeviceClass.ENERGY,
76 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
77 state_class=SensorStateClass.TOTAL_INCREASING,
80 key=
"dsmr/reading/electricity_currently_delivered",
81 translation_key=
"current_power_usage",
82 device_class=SensorDeviceClass.POWER,
83 native_unit_of_measurement=UnitOfPower.KILO_WATT,
84 state_class=SensorStateClass.MEASUREMENT,
87 key=
"dsmr/reading/electricity_currently_returned",
88 translation_key=
"current_power_return",
89 device_class=SensorDeviceClass.POWER,
90 native_unit_of_measurement=UnitOfPower.KILO_WATT,
91 state_class=SensorStateClass.MEASUREMENT,
94 key=
"dsmr/reading/phase_currently_delivered_l1",
95 translation_key=
"current_power_usage_l1",
96 entity_registry_enabled_default=
False,
97 device_class=SensorDeviceClass.POWER,
98 native_unit_of_measurement=UnitOfPower.KILO_WATT,
99 state_class=SensorStateClass.MEASUREMENT,
102 key=
"dsmr/reading/phase_currently_delivered_l2",
103 translation_key=
"current_power_usage_l2",
104 entity_registry_enabled_default=
False,
105 device_class=SensorDeviceClass.POWER,
106 native_unit_of_measurement=UnitOfPower.KILO_WATT,
107 state_class=SensorStateClass.MEASUREMENT,
110 key=
"dsmr/reading/phase_currently_delivered_l3",
111 translation_key=
"current_power_usage_l3",
112 entity_registry_enabled_default=
False,
113 device_class=SensorDeviceClass.POWER,
114 native_unit_of_measurement=UnitOfPower.KILO_WATT,
115 state_class=SensorStateClass.MEASUREMENT,
118 key=
"dsmr/reading/phase_currently_returned_l1",
119 translation_key=
"current_power_return_l1",
120 entity_registry_enabled_default=
False,
121 device_class=SensorDeviceClass.POWER,
122 native_unit_of_measurement=UnitOfPower.KILO_WATT,
123 state_class=SensorStateClass.MEASUREMENT,
126 key=
"dsmr/reading/phase_currently_returned_l2",
127 translation_key=
"current_power_return_l2",
128 entity_registry_enabled_default=
False,
129 device_class=SensorDeviceClass.POWER,
130 native_unit_of_measurement=UnitOfPower.KILO_WATT,
131 state_class=SensorStateClass.MEASUREMENT,
134 key=
"dsmr/reading/phase_currently_returned_l3",
135 translation_key=
"current_power_return_l3",
136 entity_registry_enabled_default=
False,
137 device_class=SensorDeviceClass.POWER,
138 native_unit_of_measurement=UnitOfPower.KILO_WATT,
139 state_class=SensorStateClass.MEASUREMENT,
142 key=
"dsmr/reading/extra_device_delivered",
143 translation_key=
"gas_meter_usage",
144 entity_registry_enabled_default=
False,
145 device_class=SensorDeviceClass.GAS,
146 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
147 state_class=SensorStateClass.TOTAL_INCREASING,
150 key=
"dsmr/reading/phase_voltage_l1",
151 translation_key=
"current_voltage_l1",
152 entity_registry_enabled_default=
False,
153 device_class=SensorDeviceClass.VOLTAGE,
154 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
155 state_class=SensorStateClass.MEASUREMENT,
158 key=
"dsmr/reading/phase_voltage_l2",
159 translation_key=
"current_voltage_l2",
160 entity_registry_enabled_default=
False,
161 device_class=SensorDeviceClass.VOLTAGE,
162 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
163 state_class=SensorStateClass.MEASUREMENT,
166 key=
"dsmr/reading/phase_voltage_l3",
167 translation_key=
"current_voltage_l3",
168 entity_registry_enabled_default=
False,
169 device_class=SensorDeviceClass.VOLTAGE,
170 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
171 state_class=SensorStateClass.MEASUREMENT,
174 key=
"dsmr/reading/phase_power_current_l1",
175 translation_key=
"phase_power_current_l1",
176 entity_registry_enabled_default=
False,
177 device_class=SensorDeviceClass.CURRENT,
178 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
179 state_class=SensorStateClass.MEASUREMENT,
182 key=
"dsmr/reading/phase_power_current_l2",
183 translation_key=
"phase_power_current_l2",
184 entity_registry_enabled_default=
False,
185 device_class=SensorDeviceClass.CURRENT,
186 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
187 state_class=SensorStateClass.MEASUREMENT,
190 key=
"dsmr/reading/phase_power_current_l3",
191 translation_key=
"phase_power_current_l3",
192 entity_registry_enabled_default=
False,
193 device_class=SensorDeviceClass.CURRENT,
194 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
195 state_class=SensorStateClass.MEASUREMENT,
198 key=
"dsmr/reading/timestamp",
199 translation_key=
"telegram_timestamp",
200 entity_registry_enabled_default=
False,
201 device_class=SensorDeviceClass.TIMESTAMP,
202 state=dt_util.parse_datetime,
205 key=
"dsmr/consumption/gas/delivered",
206 translation_key=
"gas_usage",
207 device_class=SensorDeviceClass.GAS,
208 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
209 state_class=SensorStateClass.TOTAL_INCREASING,
212 key=
"dsmr/consumption/gas/currently_delivered",
213 translation_key=
"current_gas_usage",
214 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
215 state_class=SensorStateClass.MEASUREMENT,
218 key=
"dsmr/consumption/gas/read_at",
219 translation_key=
"gas_meter_read",
220 entity_registry_enabled_default=
False,
221 device_class=SensorDeviceClass.TIMESTAMP,
222 state=dt_util.parse_datetime,
225 key=
"dsmr/day-consumption/electricity1",
226 translation_key=
"daily_low_tariff_usage",
227 device_class=SensorDeviceClass.ENERGY,
228 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
229 state_class=SensorStateClass.TOTAL_INCREASING,
232 key=
"dsmr/day-consumption/electricity2",
233 translation_key=
"daily_high_tariff_usage",
234 device_class=SensorDeviceClass.ENERGY,
235 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
236 state_class=SensorStateClass.TOTAL_INCREASING,
239 key=
"dsmr/day-consumption/electricity1_returned",
240 translation_key=
"daily_low_tariff_return",
241 device_class=SensorDeviceClass.ENERGY,
242 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
243 state_class=SensorStateClass.TOTAL_INCREASING,
246 key=
"dsmr/day-consumption/electricity2_returned",
247 translation_key=
"daily_high_tariff_return",
248 device_class=SensorDeviceClass.ENERGY,
249 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
250 state_class=SensorStateClass.TOTAL_INCREASING,
253 key=
"dsmr/day-consumption/electricity_merged",
254 translation_key=
"daily_power_usage_total",
255 device_class=SensorDeviceClass.ENERGY,
256 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
257 state_class=SensorStateClass.TOTAL_INCREASING,
260 key=
"dsmr/day-consumption/electricity_returned_merged",
261 translation_key=
"daily_power_return_total",
262 device_class=SensorDeviceClass.ENERGY,
263 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
264 state_class=SensorStateClass.TOTAL_INCREASING,
267 key=
"dsmr/day-consumption/electricity1_cost",
268 translation_key=
"daily_low_tariff_cost",
269 native_unit_of_measurement=CURRENCY_EURO,
272 key=
"dsmr/day-consumption/electricity2_cost",
273 translation_key=
"daily_high_tariff_cost",
274 native_unit_of_measurement=CURRENCY_EURO,
277 key=
"dsmr/day-consumption/electricity_cost_merged",
278 translation_key=
"daily_power_total_cost",
279 native_unit_of_measurement=CURRENCY_EURO,
282 key=
"dsmr/day-consumption/gas",
283 translation_key=
"daily_gas_usage",
284 device_class=SensorDeviceClass.GAS,
285 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
288 key=
"dsmr/day-consumption/gas_cost",
289 translation_key=
"gas_cost",
290 native_unit_of_measurement=CURRENCY_EURO,
293 key=
"dsmr/day-consumption/total_cost",
294 translation_key=
"total_cost",
295 native_unit_of_measurement=CURRENCY_EURO,
298 key=
"dsmr/day-consumption/energy_supplier_price_electricity_delivered_1",
299 translation_key=
"low_tariff_delivered_price",
300 native_unit_of_measurement=PRICE_EUR_KWH,
303 key=
"dsmr/day-consumption/energy_supplier_price_electricity_delivered_2",
304 translation_key=
"high_tariff_delivered_price",
305 native_unit_of_measurement=PRICE_EUR_KWH,
308 key=
"dsmr/day-consumption/energy_supplier_price_electricity_returned_1",
309 translation_key=
"low_tariff_returned_price",
310 native_unit_of_measurement=PRICE_EUR_KWH,
313 key=
"dsmr/day-consumption/energy_supplier_price_electricity_returned_2",
314 translation_key=
"high_tariff_returned_price",
315 native_unit_of_measurement=PRICE_EUR_KWH,
318 key=
"dsmr/day-consumption/energy_supplier_price_gas",
319 translation_key=
"gas_price",
320 native_unit_of_measurement=PRICE_EUR_M3,
323 key=
"dsmr/day-consumption/fixed_cost",
324 translation_key=
"current_day_fixed_cost",
325 native_unit_of_measurement=CURRENCY_EURO,
328 key=
"dsmr/meter-stats/dsmr_version",
329 translation_key=
"dsmr_version",
330 entity_registry_enabled_default=
False,
331 state=dsmr_transform,
334 key=
"dsmr/meter-stats/electricity_tariff",
335 translation_key=
"electricity_tariff",
336 device_class=SensorDeviceClass.ENUM,
337 options=[
"low",
"high"],
338 state=tariff_transform,
341 key=
"dsmr/meter-stats/power_failure_count",
342 translation_key=
"power_failure_count",
343 entity_registry_enabled_default=
False,
346 key=
"dsmr/meter-stats/long_power_failure_count",
347 translation_key=
"long_power_failure_count",
348 entity_registry_enabled_default=
False,
351 key=
"dsmr/meter-stats/voltage_sag_count_l1",
352 translation_key=
"voltage_sag_l1",
353 entity_registry_enabled_default=
False,
356 key=
"dsmr/meter-stats/voltage_sag_count_l2",
357 translation_key=
"voltage_sag_l2",
358 entity_registry_enabled_default=
False,
361 key=
"dsmr/meter-stats/voltage_sag_count_l3",
362 translation_key=
"voltage_sag_l3",
363 entity_registry_enabled_default=
False,
366 key=
"dsmr/meter-stats/voltage_swell_count_l1",
367 translation_key=
"voltage_swell_l1",
368 entity_registry_enabled_default=
False,
371 key=
"dsmr/meter-stats/voltage_swell_count_l2",
372 translation_key=
"voltage_swell_l2",
373 entity_registry_enabled_default=
False,
376 key=
"dsmr/meter-stats/voltage_swell_count_l3",
377 translation_key=
"voltage_swell_l3",
378 entity_registry_enabled_default=
False,
381 key=
"dsmr/meter-stats/rejected_telegrams",
382 translation_key=
"rejected_telegrams",
383 entity_registry_enabled_default=
False,
386 key=
"dsmr/current-month/electricity1",
387 translation_key=
"current_month_low_tariff_usage",
388 device_class=SensorDeviceClass.ENERGY,
389 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
392 key=
"dsmr/current-month/electricity2",
393 translation_key=
"current_month_high_tariff_usage",
394 device_class=SensorDeviceClass.ENERGY,
395 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
398 key=
"dsmr/current-month/electricity1_returned",
399 translation_key=
"current_month_low_tariff_returned",
400 device_class=SensorDeviceClass.ENERGY,
401 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
404 key=
"dsmr/current-month/electricity2_returned",
405 translation_key=
"current_month_high_tariff_returned",
406 device_class=SensorDeviceClass.ENERGY,
407 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
410 key=
"dsmr/current-month/electricity_merged",
411 translation_key=
"current_month_power_usage_total",
412 device_class=SensorDeviceClass.ENERGY,
413 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
416 key=
"dsmr/current-month/electricity_returned_merged",
417 translation_key=
"current_month_power_return_total",
418 device_class=SensorDeviceClass.ENERGY,
419 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
422 key=
"dsmr/current-month/electricity1_cost",
423 translation_key=
"current_month_low_tariff_cost",
424 native_unit_of_measurement=CURRENCY_EURO,
427 key=
"dsmr/current-month/electricity2_cost",
428 translation_key=
"current_month_high_tariff_cost",
429 native_unit_of_measurement=CURRENCY_EURO,
432 key=
"dsmr/current-month/electricity_cost_merged",
433 translation_key=
"current_month_power_total_cost",
434 native_unit_of_measurement=CURRENCY_EURO,
437 key=
"dsmr/current-month/gas",
438 translation_key=
"current_month_gas_usage",
439 device_class=SensorDeviceClass.GAS,
440 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
443 key=
"dsmr/current-month/gas_cost",
444 translation_key=
"current_month_gas_cost",
445 native_unit_of_measurement=CURRENCY_EURO,
448 key=
"dsmr/current-month/fixed_cost",
449 translation_key=
"current_month_fixed_cost",
450 native_unit_of_measurement=CURRENCY_EURO,
453 key=
"dsmr/current-month/total_cost",
454 translation_key=
"current_month_total_cost",
455 native_unit_of_measurement=CURRENCY_EURO,
458 key=
"dsmr/current-year/electricity1",
459 translation_key=
"current_year_low_tariff_usage",
460 device_class=SensorDeviceClass.ENERGY,
461 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
464 key=
"dsmr/current-year/electricity2",
465 translation_key=
"current_year_high_tariff_usage",
466 device_class=SensorDeviceClass.ENERGY,
467 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
470 key=
"dsmr/current-year/electricity1_returned",
471 translation_key=
"current_year_low_tariff_returned",
472 device_class=SensorDeviceClass.ENERGY,
473 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
476 key=
"dsmr/current-year/electricity2_returned",
477 translation_key=
"current_year_high_tariff_returned",
478 device_class=SensorDeviceClass.ENERGY,
479 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
482 key=
"dsmr/current-year/electricity_merged",
483 translation_key=
"current_year_power_usage_total",
484 device_class=SensorDeviceClass.ENERGY,
485 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
488 key=
"dsmr/current-year/electricity_returned_merged",
489 translation_key=
"current_year_power_returned_total",
490 device_class=SensorDeviceClass.ENERGY,
491 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
494 key=
"dsmr/current-year/electricity1_cost",
495 translation_key=
"current_year_low_tariff_cost",
496 native_unit_of_measurement=CURRENCY_EURO,
499 key=
"dsmr/current-year/electricity2_cost",
500 translation_key=
"current_year_high_tariff_cost",
501 native_unit_of_measurement=CURRENCY_EURO,
504 key=
"dsmr/current-year/electricity_cost_merged",
505 translation_key=
"current_year_power_total_cost",
506 native_unit_of_measurement=CURRENCY_EURO,
509 key=
"dsmr/current-year/gas",
510 translation_key=
"current_year_gas_usage",
511 device_class=SensorDeviceClass.GAS,
512 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
515 key=
"dsmr/current-year/gas_cost",
516 translation_key=
"current_year_gas_cost",
517 native_unit_of_measurement=CURRENCY_EURO,
520 key=
"dsmr/current-year/fixed_cost",
521 translation_key=
"current_year_fixed_cost",
522 native_unit_of_measurement=CURRENCY_EURO,
525 key=
"dsmr/current-year/total_cost",
526 translation_key=
"current_year_total_cost",
527 native_unit_of_measurement=CURRENCY_EURO,
530 key=
"dsmr/consumption/quarter-hour-peak-electricity/average_delivered",
531 translation_key=
"previous_quarter_hour_peak_usage",
532 device_class=SensorDeviceClass.POWER,
533 native_unit_of_measurement=UnitOfPower.KILO_WATT,
536 key=
"dsmr/consumption/quarter-hour-peak-electricity/read_at_start",
537 translation_key=
"quarter_hour_peak_start_time",
538 entity_registry_enabled_default=
False,
539 device_class=SensorDeviceClass.TIMESTAMP,
540 state=dt_util.parse_datetime,
543 key=
"dsmr/consumption/quarter-hour-peak-electricity/read_at_end",
544 translation_key=
"quarter_hour_peak_end_time",
545 entity_registry_enabled_default=
False,
546 device_class=SensorDeviceClass.TIMESTAMP,
547 state=dt_util.parse_datetime,
float|str dsmr_transform(str value)
str tariff_transform(str value)