mampfes / esphome_obis_d0

esphome external component to support meters with OBIS D0 interface
MIT License
45 stars 6 forks source link

ISKRA 2013 M13 1376 - [obis_d0:133]: OBIS value end missing #11

Closed zibous closed 1 year ago

zibous commented 1 year ago

Hi

I get two errors evaluating the telegram (not critical) but I would like to know why:

  1. Device Name /ISk5MT174-0001 --> obis_d0 [W][obis_d0:133]: OBIS value end missing

  2. Current time #0020.9.1(135004)#015 After the meter name, the time is sent with STL. I have to enter the STL code (\x02) in the RegEx, otherwise the time will not be recognized.

  3. Identification ISk5MT174-0001 not found ! Dashes are not supported in IDs, please use underscores instead. obis_d0_id: ISk5MT174-0001

    May 13 10:27:40 esplesekopf system >>> Telegram end: Received Data for esplesekopf
    May 13 10:28:32 esplesekopf system [W][system:789]: >>> Telegram start: Start reading Data for esplesekopf
    May 13 10:28:36 esplesekopf system /ISk5MT174-0001#015
    May 13 10:28:36 esplesekopf obis_d0 [W][obis_d0:161]: Identification ISk5MT174-0001 not found !
    May 13 10:28:36 esplesekopf system #0020.9.1(102824)#015
    May 13 10:28:36 esplesekopf system 0.9.2(0230513)#015
    May 13 10:28:37 esplesekopf system 0.0.0(00339188)#015
    May 13 10:28:37 esplesekopf system 0.2.0(1.03)#015
    May 13 10:28:37 esplesekopf system C.1.6(FDF5)#015
    May 13 10:28:37 esplesekopf system 1.8.1(0018675.062*KWh)#015
    May 13 10:28:37 esplesekopf system 1.8.
    May 13 10:28:39 esplesekopf system 2(0029872.000*KWh)#015
    May 13 10:28:39 esplesekopf system 2.8.1(0022881.100*KWh)#015
    May 13 10:28:39 esplesekopf system 2.8.2(0001415.725*KWh)#015
    May 13 10:28:40 esplesekopf system F.F.0(0000000)#015
    May 13 10:28:40 esplesekopf system !#015
    May 13 10:28:40 esplesekopf system >>> Telegram end: Received Data for esplesekopf

    see: https://wiki.volkszaehler.org/hardware/channels/meters/power/edl-ehz/iskraemeco_mt174

Telegram & Log:


Telegram 
    /ISk5MT174-0001            <--- ERROR
    \x020.9.1(150802)          <---- STL+CODE+VALUE
     0.9.2(1200702)
     0.0.0(00339188)
     0.2.0(1.03)
     C.1.6(FDF5)
     1.8.1(0011400.587*kWh)
     1.8.2(0023806.592*kWh)
     2.8.1(0015608.024*kWh)
     2.8.2(0000900.569*kWh)
     F.F.0(0000000)
    !

May 11 13:52:40 esplesekopf system >>> Start reading data for esplesekopf
May 11 13:52:41 esplesekopf system /ISk5MT174-0001#015
May 11 13:52:41 esplesekopf obis_d0 [W][obis_d0:133]: OBIS value end missing
May 11 13:52:47 esplesekopf system #0020.9.1(135004)#015
May 11 13:52:47 esplesekopf system 0.9.2(1230511)#015
May 11 13:52:47 esplesekopf system 0.0.0(00339188)#015
May 11 13:52:47 esplesekopf system 0.2.0(1.03)#015
May 11 13:52:47 esplesekopf system C.1.6(FDF5)#015
May 11 13:52:47 esplesekopf system 1.8.1(0016832.511*kWh)#015
May 11 13:52:47 esplesekopf system 1.8.2(0029931.830*kWh)#015
May 11 13:52:49 esplesekopf system 2.8.1(0021088.048*kWh)#015
May 11 13:52:49 esplesekopf system 2.8.2(0001249.126*kWh)#015
May 11 13:52:49 esplesekopf system >>> esplesekopf end reading telegram!
May 11 13:52:49 esplesekopf system F.F.0(0000000)#015
May 11 13:52:49 esplesekopf system !#015
May 11 13:52:49 esplesekopf system #0037

May 11 13:53:40 esplesekopf system >>> Start reading data for esplesekopf
May 11 13:53:41 esplesekopf system /ISk5MT174-0001#015
May 11 13:53:41 esplesekopf obis_d0 [W][obis_d0:133]: OBIS value end missing
May 11 13:53:47 esplesekopf system #0020.9.1(135104)#015
May 11 13:53:47 esplesekopf system 0.9.2(1230511)#015
May 11 13:53:47 esplesekopf system 0.0.0(00339188)#015
May 11 13:53:47 esplesekopf system 0.2.0(1.03)#015
May 11 13:53:47 esplesekopf system C.1.6(FDF5)#015
May 11 13:53:47 esplesekopf system 1.8.1(0016832.511*kWh)#015
May 11 13:53:47 esplesekopf system 1.8.2(0029931.830*kWh)#015
May 11 13:53:49 esplesekopf system 2.8.1(0021088.064*kWh)#015
May 11 13:53:49 esplesekopf system 2.8.2(0001249.126*kWh)#015
May 11 13:53:49 esplesekopf system >>> esplesekopf end reading telegram!
May 11 13:53:49 esplesekopf system F.F.0(0000000)#015
May 11 13:53:49 esplesekopf system !#015
May 11 13:53:49 esplesekopf system #0038

Configuration:

## ---------------------------------------------------------------------------
## ESP LESEKOPF az-delivery-devkit-v4 Gridmeter ISKRA 2013 M13 1376
## Hardware: ESP32 240MHz, 520KB RAM, 4MB Flash
## ---------------------------------------------------------------------------
substitutions:

  ## device settings
  device_name_short: "esplesekopf"
  device_description: "Smartmeter Device ESP32 with Infrared Reader for Gridmeter ISKRA 2013 M13 1376, Drehstromzähler Version OBIS D0"
  project: "ISKRA2013.Gridmeter"
  appversion: "2.1.0"

  ## logger settings
  log_level: "WARN"  # not that logging need memory, so in production mode use "WARN"
  log_obis: "WARN"   # Loglevel for wmbus meters component
  log_baudrate: "0"  # 0 disable uart logger messages

  ## device configuration az-delivery-devkit-v4
  board: "az-delivery-devkit-v4"
  uart_tx_pin: "GPIO17"
  uart_rx_pin: "GPIO16"
  uart_baudrate: "300"
  devicename: "⚐ "

  ## read intervall for the gridmeter
  update_interval: "60s"

## ---------------------------------------------------
## HARDWARE az-delivery-devkit-v4
## ---------------------------------------------------
esp32:
  board: ${board}
  framework:
    type: arduino

## ---------------------------------------------------
## APPLICATION ESPHOME
## ---------------------------------------------------
esphome:
  name: "${device_name_short}"
  comment: "${device_description}"
  project:
    name: ${project}
    version: ${appversion}
  build_path: ./build/${device_name_short}
  on_boot:
    priority: -100.00
    then:
      - globals.set:
          id: boot_counter
          value: !lambda "return id(boot_counter)+=1;"
      - logger.log:
          level: WARN
          format: "BOOTMESSAGE:${device_name_short} API is connected, Device ready!"
      - component.update: bootcounter

  on_shutdown:
    priority: 700
    then:
      - logger.log:
          level: WARN
          format: "${device_name_short} is down!"

## ---------------------------------------------------
## Compoments obis_d0, backup, syslog
## ---------------------------------------------------
external_components:

  ## local component obis reader
  ## https://github.com/mampfes/esphome_obis_d0
  - source:
      type: local
      path: custom_components
    components: [obis_d0]

  ## local component backup
  ## ## https://github.com/zdzichu6969/esphome-component
  - source:
      type: local
      path: custom_components
    components: [backup]

  ## local component syslog
  ## https://github.com/TheStaticTurtle/esphome_syslog
  - source:
      type: local
      path: custom_components
    components: [syslog]

## ---------------------------------------------------
## BACKUP SETTINGS
## ---------------------------------------------------
backup:
  auth:
    username: !secret web_username
    password: !secret web_password
  force_update: false

## ---------------------------------------------------
## SYSLOG SETTINGS
## ---------------------------------------------------
syslog:
  ip_address: !secret syslog_server
  port: !secret syslog_port
  min_level: DEBUG
  enable_logger: true

## ---------------------------------------------------
# Global variables
## ---------------------------------------------------
globals:

  - id: boot_counter
    type: int
    restore_value: yes
    initial_value: "0"

## ---------------------------------------------------
## WIFI Settings
## ---------------------------------------------------
wifi:
  networks:
    - ssid: !secret ssid3_name
      password: !secret ssid3_pswd
      priority: 0
    - ssid: !secret ssid1_name
      password: !secret ssid1_pswd
      priority: 1
    - ssid: !secret ssid2_name
      password: !secret ssid2_pswd
      priority: 2
  domain: !secret domain

## ---------------------------------------------------
## WEBSERVER COMPONENT
## ---------------------------------------------------
web_server:
  port: 80
  version: 2
  local: true

## ---------------------------------------------------
## OTA COMPONENT
## ---------------------------------------------------
ota:
  password: !secret ota_pswd
  on_error:
    then:
      - logger.log:
          level: INFO
          tag: "system"
          format: "OTA update error %d"
          args: ["x"]

## ---------------------------------------------------
## Home Assistant API COMPONENT
## ---------------------------------------------------
api:
  id: espapi_lesekopf
  port: 6053
  reboot_timeout: 0s

## ---------------------------------------------------
## LOGGER COMPONENT
## ---------------------------------------------------
logger:
  id: appslogger
  level: ${log_level}
  baud_rate: ${log_baudrate}
  logs:
    obis_d0: ${log_obis}

## ---------------------------------------------------
## SNTP COMPONENT
## Change this to your timezone and ntp server
## ---------------------------------------------------
time:
  - platform: sntp
    id: time_sntp
    timezone: Europe/Berlin
    servers:
      - fritz.box
      - 0.at.pool.ntp.org
      - 0.pool.ntp.org
    on_time_sync:
      then:
        - logger.log:
            level: WARN
            tag: "system"
            format: "Synchronized sntp clock"

## ---------------------------------------------------
## SCRIPTS COMPONENT
## ---------------------------------------------------
script:
  # id(post_device_state).execute();
  - id: syslogMessage
    parameters:
      message: string
    then:
      - logger.log:
          level: WARN
          tag: "system"
          format: "%s"
          args: ["message"]

## ------------------------------------------------------------------
## Serial interface uart az-delivery-devkit-v4 to Lesekopf
## ------------------------------------------------------------------
##
##
##                                                               o 1 (3.3V)
##                                                               |
##   ╭――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――o―╮
##   |                                                             |
##   |                                                             |
## - | 5v               az-delivery-devkit-v4                      | -- ANT
##   |                                                             |
##   |                      16  17                                 |
##   ╰――x――x――x――x――x――x――x――o――0――x――x――x――x――x――x――x――x――x――x――o―╯
##                           |  |                                |
##                           |  |                                ╰-o - 2 (GND)
##                           RX TX
## ------------------------------------------------------------------
uart:
  id: my_uart
  tx_pin: GPIO17  # White  D0
  rx_pin: GPIO16  # Orange A0
  baud_rate: 300
  data_bits: 7
  parity: EVEN
  stop_bits: 1
  rx_buffer_size: 1024
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\r\n"
    sequence:
      - lambda: |-
          UARTDebug::log_string(direction, bytes);  //Still log the data
          std::string str(bytes.begin(), bytes.end());
          ESP_LOGW("system", "%s",str.c_str());

## ---------------------------------------------------
## OPBIS Settings
## ---------------------------------------------------
obis_d0:
  - id: my_sm
    uart_id: my_uart
    on_telegram:
      # end telegram reading
      then:
        - syslog.log:
            level: 7
            tag: "system"
            payload: ">>> Telegram end: Received Data for ${device_name_short}"

## ---------------------------------------------------
## the device need to be triggered to sending data.
## We can use the integrated "interval" component
## send the command: 2F3F210D0A
## see: https://github.com/jplitza/esphome_components
## ---------------------------------------------------
interval:
  - interval: ${update_interval}
    then:
      - logger.log:
          level: WARN
          tag: "system"
          format: "Start reading data for ${device_name_short}"
      - uart.write:
          id: my_uart
          data: [0x2F, 0x3F, 0x21, 0x0D, 0x0A]

## ---------------------------------------------------
## SWITCHES
## ---------------------------------------------------
switch:
  # reset boot counter value
  - platform: template
    name: "${devicename} Device Boot Counter reset"
    turn_on_action:
      then:
        - lambda: |-
            id(boot_counter) = 0;
            id(bootcounter).publish_state(id(boot_counter));
        - logger.log:
            level: INFO
            tag: "system"
            format: "${device_name_short} reset boot counter o.k!"
        # - component.update: bootcounter

  # manual start reading telegram
  - platform: template
    name: "Lesekopf Datenlesen starten"
    turn_on_action:
      then:
        - logger.log:
            level: INFO
            tag: "system"
            format: "Start reading from Gridmeter ISKRA 2013 M13 1376"
        - uart.write:
            id: my_uart
            data: [0x2F, 0x3F, 0x21, 0x0D, 0x0A]

  # restart device
  - platform: restart
    name: "${devicename} Device restart"
    id: restart_switch

  # save device boot (develop only)
  - platform: safe_mode
    name: "${devicename} Device restart safemode"

  # reset the device to factory reset (develop only)
  - platform: factory_reset
    name: "${devicename} Device factory reset"

# ---------------------------------------------------
# ALL SENSORS
# # ---------------------------------------------------
#
# Telegram:
# 'ISk5MT174-0001\r\n'
# '\x020.9.1(150802)\r\n'
# '0.9.2(1200702)\r\n'
# '0.0.0(00339188)\r\n'
# '0.2.0(1.03)\r\n'
# 'C.1.6(FDF5)\r\n'
# '1.8.1(0011400.587*kWh)\r\n'
# '1.8.2(0023806.592*kWh)\r\n'
# '2.8.1(0015608.024*kWh)\r\n'
# '2.8.2(0000900.569*kWh)\r\n'
# 'F.F.0(0000000)\r\n'
# ---------------------------------------------------
sensor:
  # ---------------------------------------------------------------------
  # 1.8.1(0011404.409*KWh) Positive active energy (A+) in tariff HT [KWh]
  # ---------------------------------------------------------------------
  - platform: obis_d0
    name: "Energie Verbrauch HT"
    id: mt174ht
    obis_code: "1.8.1"
    obis_d0_id: my_sm
    unit_of_measurement: "kWh"
    accuracy_decimals: 3
    device_class: energy
    state_class: total_increasing
    # value_regex: "(\\d{7}\\.\\d{3}\\*KWh)"
    value_regex: "(\\d{7}\\.\\d{3}\\*\\w{3})"
    on_value:
      then:
        # end start telegram Positive active energy
        - logger.log:
            level: WARN
            tag: "obis_d0"
            format: "Tarif HT: %.3f kWh"
            args: ["x"]

  # ---------------------------------------------------------------------
  # 1.8.2(0023813.725*KWh) Positive active energy (A+) in tariff NT [KWh]
  # ---------------------------------------------------------------------
  - platform: obis_d0
    name: "Energie Verbrauch NT"
    id: mt174nt
    obis_code: "1.8.2"
    obis_d0_id: my_sm
    unit_of_measurement: "kWh"
    accuracy_decimals: 3
    device_class: energy
    state_class: total_increasing
    # value_regex: "\\d{7}\\.\\d{3}\\*KWh"
    value_regex: "(\\d{7}\\.\\d{3}\\*\\w{3})"
    on_value:
      then:
        - logger.log:
            level: WARN
            tag: "obis_d0"
            format: "Tarif NT: %.3f kWh"
            args: ["x"]

  # ---------------------------------------------------------------------
  # 2.8.1(0015608.962*KWh) Negative active energy (A-) in tariff T1 [KWh]
  # ---------------------------------------------------------------------
  - platform: obis_d0
    name: "Energie Einspeisung HT"
    id: mt174t1
    obis_code: "2.8.1"
    obis_d0_id: my_sm
    unit_of_measurement: "kWh"
    accuracy_decimals: 3
    device_class: energy
    state_class: total_increasing
    # value_regex: "\\d{7}\\.\\d{3}\\*KWh"
    value_regex: "(\\d{7}\\.\\d{3}\\*\\w{3})"
    on_value:
      then:
         - logger.log:
            level: WARN
            tag: "obis_d0"
            format: "Tarif HT (T1): %.3f kWh"
            args: ["x"]

  # ---------------------------------------------------------------------
  # 2.8.2(0000900.569*KWh)  Negative active energy (A-) in tariff T2 [KWh]
  # ---------------------------------------------------------------------
  - platform: obis_d0
    name: "Energie Einspeisung NT"
    id: mt174t2
    obis_code: "2.8.2"
    obis_d0_id: my_sm
    unit_of_measurement: "kWh"
    accuracy_decimals: 3
    device_class: energy
    state_class: total_increasing
    # value_regex: "\\d{7}\\.\\d{3}\\*KWh"
    value_regex: "(\\d{7}\\.\\d{3}\\*\\w{3})"
    # end telegram Negative active energy
    on_value:
      then:
        - logger.log:
            level: WARN
            tag: "obis_d0"
            format: "Tarif NT (T2): %.3f kWh"
            args: ["x"]
        - text_sensor.template.publish:
            id: data_timestamp
            state: !lambda return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z");

  # number of boots
  - platform: template
    name: "${devicename} Boot Counter"
    id: bootcounter
    accuracy_decimals: 0
    entity_category: "diagnostic"
    state_class: "measurement"
    lambda: return (id(boot_counter));

# ---------------------------------------------------
# Text sensors
# ---------------------------------------------------
text_sensor:

  # timestamp from telegram
  - platform: template
    name: "Lesekopf Messzeit"
    id: data_timestamp
    entity_category: "diagnostic"

  # ----------------------------------------------------
  # 0.9.1(130203)  Current time (hh:mm:ss) telegram time
  # ----------------------------------------------------
  - platform: obis_d0
    name: "Lesekopf Zeit"
    id: mt174time
    disabled_by_default: true
    obis_d0_id: my_sm
    obis_code: "\x020.9.1"
    value_regex: "\\d{6}"
    on_value:
      then:
        - lambda: |-
            if(id(mt174time).has_state()) {
              std::string t = id(mt174time).state.substr(0,2) + ":" + id(mt174time).state.substr(2,2) + ":" + id(mt174time).state.substr(4,2);
              id(thetime).publish_state(t);
            }else{
              ESP_LOGE("obis_d0", "0.9.1: Time not found!");
            }

  # -------------------------------------------------
  # 0.9.2(0230223) Date (1YY.MM.DD) telegram date
  # -------------------------------------------------
  - platform: obis_d0
    name: "Lesekopf Datum"
    id: mt174date
    disabled_by_default: true
    obis_d0_id: my_sm
    obis_code: "0.9.2"
    value_regex: "\\d{7}"
    on_value:
      then:
        # 2023-05-08T13:02:45
        - lambda: |-
            if(id(mt174date).has_state()) {
              std::string d = id(time_sntp).now().strftime("%Y") + "-"+  x.substr(3,2) + "-" + x.substr(5,2);
              std::string t = id(mt174time).state.substr(0,2) + ":" + id(mt174time).state.substr(2,2) + ":" + id(mt174time).state.substr(4,2);
              id(thedate).publish_state((d + "T" + t));
            }else{
              ESP_LOGE("obis_d0", "0.9.2: Date not found!");
            }

  # timestamp from telegram
  - platform: template
    name: "Lesekopf Messdatum"
    id: thedate
    entity_category: "diagnostic"

  # timestamp from telegram
  - platform: template
    name: "Lesekopf Messzeit"
    id: thetime
    entity_category: "diagnostic"
zibous commented 1 year ago

3. Identification ISk5MT174-0001 not found !

Solved, tricky regex:

 # ----------------------------------------------------
  # obis_code: id returns the manufacturer 
  # at identification the beginning of an OBIS telegram 
  # ISk5MT174-0001
  # ----------------------------------------------------
  - platform: obis_d0
    name: "Smartmeter ID"
    obis_d0_id: my_gridmeter
    obis_code: "id"
    entity_category: diagnostic
    value_regex: "\\w{3}\\d\\w{2}\\d{3}\\-\\d{4}"
    on_value:
      then:
        - logger.log:
            level: WARN
            tag: "obis_d0"
            format: "Smartmeter ID: %s"
            args: ["x.c_str()"]

\x020.9.1(150802) <---- STL+CODE+VALUE

Can't find how to fix it, only workaround with regex ?

mampfes commented 1 year ago

According to the documentation on volkszaehler.org, the MT174 sends a STX and an ETX character. They are responsible for the issue with the Current Time (because it is the first OBIS ID right after the STX) and probably also for the OBIS value end missing message. I have to think about how to get rid of them (because we don't need them).

Regarding the regex for identification: The identification is not a critical value, e.g. it doesn't show up in Home Assistant statistics. Therefore I would simply omit the regex.

mampfes commented 1 year ago

Hi, I created a fix in branch remove_stx_etx. Could you please try this out?

You just have to add the branch name to the external component repo (in case you are using this variant to include an external component):

external_components:
  - source: github://mampfes/esphome_obis_d0@remove_stx_etx
zibous commented 1 year ago

Hi, I created a fix in branch remove_stx_etx. Could you please try this out?

Hi Steffen,

Thanks is working now. 💯

Bildschirmfoto 2023-05-17 um 18 04 12