# Beginner needs help -\> Smartmeter data to MQTT

**URL:** <https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445>\
**Category:** General\
**Created:** [29 November 2021 10:56 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445 "2021-11-29T10:56:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klobrille](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Klobrille](https://discourse.nodered.org/u/Klobrille)\
**Post date:** [29 November 2021 10:56 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/1 "2021-11-29T10:56:43Z")

</div>

Hello,

I hope you can help me. I am an absolut beginner with Raspberry PI, Linux and especially Node Red.

**My situation:**  
I have an Raspberry PI 4 with Raspberry OS, running "Home Assistant" with mosquitto (MQTT), influxdb and Grafana.  
What I want is to log my electricity usage from my whole house and get the data to Home Assistant / InfluxDB / MQTT.

So I bought an IR-Diode (Optokopf by weidmann) to read the SML-Data from my Smartmeter at the basement.

The last few days I tryed a lot and nothing works, so "finaly" discovered "node red".  
I installed the "Optokopf" at my Raspberry and installed Node Red.  
I tried now to get the data to MQTT or alternatively to influxdb.  
At Node Red i installed the addon "node-red-contrib-smartmeter".

I managed to get the data from the smartmeter to Node Red.  
As you can see, the data I need is shown at the right side (marked yellow).

**My first question:**  
I get a lot of error messages between the data-logs from the smart meter.  
What can I do, to solve this problem?

**My second and more important question:**  
What have I to do, to get the data to my MQTT-Server?

I googled at lot and I think I have to put an "function" between the Smartmeter-Input- and MQTT-Output field, to get the yellow marked numbers.

As you can see, I already try it with an MQTT-Out and it says "connected". So this looks good in my opinion. But what I have to set as "message" (2. Screenshot).

Sorry for my bad english, I hope you get, what I want to do.  
Thank you in advance.

 ![Screenshot 2021-11-29 114928](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d7abb58b2046c8ca5cc64a538aedab6a8528d126.jpeg)  
 ![Screenshot 2021-11-29 115258](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38622f5a4d51d59e35e3682980e58e6b282201bd.jpeg)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [29 November 2021 13:13 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/2 "2021-11-29T13:13:15Z")

</div>

To obtain that value, if you look to the right hand side of the debug panel, alongside `value:` which you have highlighted in yellow, click the 'Copy path' button

![path](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/03627019d1ff963e077f6988ee4d83abdfa681d0.jpeg)

and then and paste it into a `change node`, so that you are changing the payload to the path of the value.  
In my example, it would be `msg.payload.volume`

If you want to filter out the errors, you could use a function node, and insert something like the following;

```auto
if (msg.payload.volume !== undefined) {
    msg.payload = msg.payload.volume
    return msg
}

```

Of course using the path which you have obtained above.

---

<div class="post-metadata">

**Author:** ![Klobrille](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Klobrille](https://discourse.nodered.org/u/Klobrille)\
**Post date:** [29 November 2021 14:07 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/3 "2021-11-29T14:07:05Z")

</div>

Thank you very much for your reply!!!  
The change node works very well. Now I get the values i wanted. Thank you!

Unfortunatelly the "function node" doesn't work to filter out the errors.

My first value "Counter\_total" has the path: payload["1-0:1.8.0_255"].values[0].value  
The second value "Watts" has the path: payload["1-0:16.7.0_255"].values[0].value

The function for "Watts" is:

```auto
if (msg.payload["1-0:16.7.0*255"].values[0].value !== undefined) {
    msg.payload = msg.payload["1-0:16.7.0*255"].values[0].value
    return msg
}

```

Is that what you meant? As you can see at the screenshot, I am getting a a lot of error messages. No change without the function node.

At my MQTT-Database there are no messages from node-red. It says "connected", so I think, the login/password/IP are correct.

I am not sure if the problem is at node red or "home assistant" / MQTT-Broker.

 ![Screenshot 2021-11-29 150317](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7cafa8442b20e455dc39ba341a63867b512f955d.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 November 2021 21:23 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/4 "2021-11-29T21:23:49Z")

</div>

The error you have highlighted is coming from the smartmeter-obis package, which I assume is pulled in the smartmeter contrib node. See [SML message parsing errors - githubmemory](https://githubmemory.com/repo/Apollon77/smartmeter-obis/issues/124)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 November 2021 21:39 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/5 "2021-11-29T21:39:26Z")

</div>

> [@Klobrille](#):
>
> What have I to do, to get the data to my MQTT-Server?

Start by reading this excellent tutorial on MQTT. Then you will understand about MQTT topics. [MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt-essentials/)

---

<div class="post-metadata">

**Author:** ![Klobrille](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Klobrille](https://discourse.nodered.org/u/Klobrille)\
**Post date:** [30 November 2021 19:15 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/6 "2021-11-30T19:15:20Z")

</div>

Thank you Colin for your help.  
I now get perfect MQTT Messages to my MQTT-Server.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 December 2021 19:15 UTC](https://discourse.nodered.org/t/beginner-needs-help-smartmeter-data-to-mqtt/54445/7 "2021-12-14T19:15:20Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
