Beginner needs help -> Smartmeter data to MQTT

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.


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

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;

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

Of course using the path which you have obtained above.

1 Like

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.0255"].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:

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.

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

1 Like

Start by reading this excellent tutorial on MQTT. Then you will understand about MQTT topics. MQTT Essentials - All Core Concepts Explained

1 Like

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

2 Likes

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