This repository adds support for smart meters with OBIS D0 interface to ESPHome.
This component can be easily added as an external component to ESPHome.
Communication with the smart meter is done using UART, so you need to configure the UART bus.
external_components:
- source: github://mampfes/esphome_obis_d0
uart:
id: my_uart
rx_pin: GPIO16
baud_rate: 9600
data_bits: 7
parity: EVEN
stop_bits: 1
obis_d0:
id: my_sm
uart_id: my_uart
on_telegram:
then:
- logger.log: "telegram received"
sensor:
- platform: obis_d0
name: "Consumed Energy"
obis_d0_id: my_sm
obis_code: "1-0:1.8.0*255"
unit_of_measurement: kWh
accuracy_decimals: 4
state_class: total_increasing
device_class: energy
value_regex: "\\d{6}\\.\\d{8}\\*kWh"
text_sensor:
- platform: obis_d0
name: "Device Identification"
obis_d0_id: my_sm
obis_code: "1-0:96.1.0*255"
entity_category: diagnostic
value_regex: "\\w{14}"
- platform: obis_d0
name: "Manufacturer ID"
obis_d0_id: my_sm
obis_code: "id"
entity_category: diagnostic
value_regex: "\\w+"
- id (Optional, ID): Manually specify the ID used for code generation.
- uart_id (Optional, ID): ID of the UART Component if you want to use multiple UART buses.
- obis_code (Required, string): Specify the OBIS code you want to retrieve data for from the device.
- obis_d0_id (Optional, ID): ID of the OBIS D0 Component if you want to manage multiple smart meters.
- value_regex (Optional, string): Regular expression to check the validity of the OBIS value. If received value does't match the regular expression, it will be discarded.
- format (Optional, string): Format of the OBIS value. Possible choices:
float
,hex
. Defaults tofloat
. - timeout (Optional, Time): Timeout after which value will be invalidated. Defaults to
5s
. - All other options form Sensor.
- obis_code (Required, string): Specify the OBIS code you want to retrieve data for from the device.
- All other options from Text Sensor.
NOTE: There is one special OBIS code for text sensors:
id
returns the manufacturer identification at the beginning of an OBIS telegram (see example above).
- on_telegram (Optional, Automation): An automation to perform after a complete telegram (consisting of manufacturer identification and OBIS records) has been received.
A infrared reader is required to attach to the smart meter.
I am using the "IR-Lese-Schreibkopf" from Hicham Belmadani:
This device is sold on ebay.
NOTE: I'm not responsible or anyhow associated with this offering!
This section lists supported smart meters:
Device | Status |
---|---|
eBZ DD3 Drehstromzähler | Supported |
ISKRA MT174 | Supported |
Logarex LK11 / LK13 | Supported |
EasyMeter Q3D | Supported |
ACE 3000 Type 260 | Supported |
The OBIS D0 data format is a textual format based on ASCII characters without error detection and correction mechanisms except the parity bit. Parity errors are detected by the underlying UART layer, but in case of an error the characters are simply omitted - without further notifications to the application. This leads to corrupt readings being read which completely messes the statistics in Home Assistant. Therefore you can specify the expected format for each using regular expressions. If the received data doesn't match the regular expression (e.g. in case of parity error), the data will be discarded.
If anyone knows how to get a notification from the UART layer in case of an error - please let me know!
The default implementation uses to much flash space (>512k) to be used on an ESP-01. If you want to use an ESP-01, this is possible by using a limited implementation of the regex library. You may activate it by adding optimize_size: true
to the obis_d0
component.
obis_d0:
id: my_sm
uart_id: my_uart
optimize_size: true
This smaller implementation of regex comes with some caveats. They are described in the following section.
The tiny-regex-c library is used to reduce the size of the resulting executable. This comes with some caveats regarding the regex capabilities.
The library was somewhat extended and should include most required cases. Also error logs were added if the regex contains unsupported features.
()
any grouping mechanisms are not supported|
branching is not supported- Additionally the regex must match the entire value, partial matches are detected as an error.
as if they are surrounded with^
and$