P1 smart meter mttq parsing

I have built a Wemos D1 mini base Tasmota Smart data reader to monitor power consumption and generation. D1 mini sends data in every 10 second and it is available on Mosquito Mttq server.

11:55:48.039 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"0-0:96.1.0(9902758328)\r"}
11:55:48.052 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"0-0:96.14.0(0001)\r"}
11:55:48.065 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"0-0:96.50.68(ON)\r"}
11:55:48.079 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"0-0:17.0.0(90.000*kW)\r"}
11:55:48.093 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:1.8.0(001540.369*kWh)\r"}
11:55:48.107 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:1.8.1(000695.519*kWh)\r"}
11:55:48.121 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:1.8.2(000844.850*kWh)\r"}
11:55:48.137 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:1.8.3(000000.000*kWh)\r"}
11:55:48.151 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:1.8.4(000000.000*kWh)\r"}
11:55:48.165 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:2.8.0(005431.496*kWh)\r"}
11:55:48.179 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:2.8.1(003888.665*kWh)\r"}
11:55:48.193 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:2.8.2(001542.831*kWh)\r"}
11:55:48.207 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:2.8.3(000000.000*kWh)\r"}
11:55:48.222 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:2.8.4(000000.000*kWh)\r"}
11:55:48.238 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:3.8.0(000274.046*kvarh)\r"}
11:55:48.253 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:4.8.0(000732.779*kvarh)\r"}
11:55:48.267 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:5.8.0(000154.115*kvarh)\r"}
11:55:48.281 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:6.8.0(000119.931*kvarh)\r"}
11:55:48.296 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:7.8.0(000248.954*kvarh)\r"}
11:55:48.309 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:8.8.0(000483.825*kvarh)\r"}
11:55:48.321 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:15.8.0(006971.872*kWh)\r"}
11:55:48.333 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:32.7.0(234.0*V)\r"}
11:55:48.342 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:52.7.0(232.4*V)\r"}
11:55:48.351 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:72.7.0(229.9*V)\r"}
11:55:48.359 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:31.7.0(000*A)\r"}
11:55:48.370 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:51.7.0(000*A)\r"}
11:55:48.379 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:71.7.0(000*A)\r"}
11:55:48.388 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:13.7.0(0.992)\r"}
11:55:48.396 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:33.7.0(0.781)\r"}
11:55:48.404 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:53.7.0(0.989)\r"}
11:55:48.413 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:73.7.0(0.646)\r"}
11:55:48.423 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:14.7.0(50.02*Hz)\r"}
11:55:48.433 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:1.7.0(00.000*kW)\r"}
11:55:48.442 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:2.7.0(00.256*kW)\r"}
11:55:48.450 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:5.7.0(00.000*kvar)\r"}
11:55:48.464 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:6.7.0(00.051*kvar)\r"}
11:55:48.476 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:7.7.0(00.083*kvar)\r"}
11:55:48.490 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"1-0:8.7.0(00.000*kvar)\r"}
11:55:48.558 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"0-0:98.1.0(221001000000S)(001522.200*kWh)(000694.331*kWh)(000827.869*kWh)(005400.112*kWh)(003880.377*kWh)(001519.735*kWh)(000272.325*kvarh)(000722.372*kvarh)(000153.011*kvarh)(000119.314*kvarh)(000246.253*kvarh)(000476.119*kvarh)(006922.318*kWh)(03.968*kW)(03.968*kW)(02.676*kW)(04.960*kW)(04.960*kW)(04.304*kW)\r"}
11:55:49.393 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":")\r"}
11:55:49.403 MQT: tele/tasmota_5A9AE8/RESULT = {"SerialReceived":"!75B4\r"}

All are these lines comes to mttq one-by-one and all line are diferent parameter. I try to search how should I parse this information and it seems I need to use value_template

Based on other similar topic I tried to add one of the parameter as senson to my HA configuration

mqtt:
  sensor:
    - name: "P1-Import_Energy"
      state_topic: "tele/tasmota_5A9AE8/RESULT"
      value_template: >
        {% set found = value_json.SerialReceived | regex_findall_index("1-0:1.8.1(\(\d+.\d+\*kWh\))") %}
        {{ found | first | replace('(','') | replace('*kWh)','') }}
      unit_of_measurement: kWh

However the configuration is valid, but I have got error.

Logger: homeassistant.helpers.template
Source: helpers/template.py:582
First occurred: 1:09:05 PM (1 occurrences)
Last logged: 1:09:05 PM

Template variable error: ‘value_json’ is undefined when rendering ‘{% set found = value_json.SerialReceived | regex_findall_index(“1-0:1.8.1((\d+.\d+*kWh))”) %} {{ found | first | replace(’(‘,’‘) | replace(’*kWh)‘,’‘) }}’

I’v check the mttq values and all looks JSON to me. Can Anybody help me to extract data and assign its to sensons?

tele/tasmota_5A9AE8/RESULT are not sent to mqtt I think.

Check with mqtt explorer.

You may need to use “tasmota sml”:

https://tasmota.github.io/docs/Smart-Meter-Interface/

tele/tasmota_5A9AE8/RESULT are sent to Mosquito mttq broker, I’ve seen it in mttq explorer. The only interesting thing is, it comes line-by-line in every 10 seconds (as the smart meter send data on serial port), so it is a series of JSONs.

Yesterday I’ve sent hours to recompile Tasmota firmware with specific Smart meter interface parameters without any success. However was able to recomplie it, but the scrip (described here) not worked to me, I got so many Unknow Command line.

So… I’m still looking for how to parse original {"SerialReceived":"0-0:96.1.0(9902758328)\r"} lines, but will look after the scripting fix on Tasmota side to get better mttq messages.

Finally I’ve manage to read the data with ESPHome DSMR reader
However not all the OBIS code are parsed, but have all important so happy with that solution.

1 Like