Display MQTT data from electricity meters

Hello dear community,

I am not so familiar with the Home Assistant as I come from the IoBroker world.
Basically, I understand how the HA works, but there are still a few things I need to understand

I currently have a problem understanding the data I receive via MQTT.
I am currently trying to integrate my IM350 electricity meter from my network operator Kelag (Austria) into HA via MQTT.
I have also received a reader from the operator as well as a key for decrypting the data.

The connection between MQTT and the meter is established and I can see the data stream via the MQTT Explorer in the HA.

Now my understanding is beginning to crumble.
I can see the stream in the MQTT Explorer, but how can I process the stream I receive from the meter?
The stream I get from the counter looks like this:

30.01.2024 22:17​
{"0-0:96.1.1":{"value":"2221202135132"},"0-0:96.13.0":{"value":""},"0-0:96.13.1":{"value":""},"0-0:1.0.0":{"value":0,"time":1706649453},"1-0:1.8.0":{"value":1024614,"time":1706649453},"1-0:2.8.0":{"value":0,"time":1706649453},"1-0:3.8.0":{"value":386,"time":1706649453},"1-0:4.8.0":{"value":541771,"time":1706649453},"1-0:1.7.0":{"value":393,"time":1706649453},"1-0:2.7.0":{"value":0,"time":1706649453},"0-0:2.0.0":{"value":6470,"time":0},"api_version":"v1","name":"2221202135132","sma_time":6493}	true

Here I would like to permanently retrieve the value from 1.7.0 (current watt consumption) and then display the values cumulated in daily, weekly, monthly and possibly also store my kilowatt price so that I know how much electricity I am consuming.

Unfortunately, I don’t have the experience or the idea of how to implement this in the HA.
I assume I will have to enter something in the YAML so that I get an entity at all (which is currently not the case).
Can someone here help me and give me a tip on how I could best implement my plans and which direction I should continue to research.

Thank you very much for your help and tips.

LG
mandragora

configuration.yaml

mqtt:
  sensor:
    - name: "Your sensor name here"
      state_topic: "sma"
      value_template: "{{ value_json['1-0:1.7.0'].value }}"

Other options for the sensor are documented here:

Hello tom_I

Thank you for your hint
When i use your code for yaml i get this error in last line

bad indentation of a mapping entry (50:40)

47 | … r:
48 | … e: “Kelag SMA”
49 | … te_topic: “sma”
50 | … ue_template: “{{ value_json [“1-0:1.7.0”] .value }}”
-----------------------------------------^

do you have an idea whats wrong ?
i did not copy the code but typed it in to avoid any errors.

thank you for your help and understanding for my beginner questions
mandragora

It appears you have put spaces in the value template where I do not have them. Also the indentation is important in YAML. It must be exactly the same as mine.

Hello again

I have now copied exactly your code.
Up to the last line it fits

From here the error starts when I enter the 1

value_template: “{{ value-json[”

Please share your config formatted for the forum like this: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

And the full error you are receiving.

Hi again

Heres my configuration yaml file


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homematic:
  interfaces:
    Funk:
      host: 10.0.0.xx
      port: 2001
      resolvenames: json
      username: xx
      password: xx
    HMIP:
      host: 10.0.0.xx
      port: 2010
      resolvenames: json
      username: xx
      password: xx
    Wired:
      host: 10.0.0.xx
      port: 2000
      resolvenames: json
      username: xx
      password: xx
    groups:
      host: 10.0.0.xx
      port: 9292
      resolvenames: json
      username: xx
      password: xx
      path: /groups
  hosts:
    ccu3:
      host: 10.0.0.xx
      username: xx
      password: xx

mqtt:
  sensor:
    - name: "Your sensor name here"
      state_topic: "sma"
      value_template: "{{ value_json["1-0:1.7.0"].value }}"

and i get this error message when i click on the ! for checking the code

bad indentation of a mapping entry (50:39)

 47 |  ... :
 48 |  ... me: "Your sensor name here"
 49 |  ... ate_topic: "sma"
 50 |  ... lue_template: "{{ value_json["1-0:1.7.0"].value }}"
-----------------------------------------^
 51 |  ... 

thank you very much for helping me.

best regards
mandragora

I beleive the issue is because there are a set of double quotes within another set of double quotes.

1 Like

Ah. Thanks. Well spotted. Should be:

mqtt:
  sensor:
    - name: "Your sensor name here"
      state_topic: "sma"
      value_template: "{{ value_json['1-0:1.7.0'].value }}"

I also edited my original post to reflect this change.

Thank you for the information and tips. I will try this soon and give you feedback on whether it worked.

Thank you very much
Best regards
mandragora

I have now entered and tested everything and it works perfectly.

Thank you very much again for your help.

Best regards
Christian

1 Like