Energymeter with Gosund-SP111 and node-red2influx

node-red flow

Starting with the flow…

Prerequisits:

I assume that you´ve already installed node-red and connected it with your influxdb.
You should also have installed tasmota on your device. I´ve a Tuya device flashed with a actual Tasmota version by tuya-convert

I´ve used a Gosund SP111 for this, but you can basicaly use it with every device giving you SENSOR data. So it doesn´t matter whether you want to monitor temperature, gas, energy or other. You´ve just adapt where i used the $..ENERGY by chosing what ever your sensor provides. Other examples i use are „$..Illuminance“, „$..Pressure“, „$..Pressure“ and „$..Temperature“

Used elements:

  • MQTT in

With the MQTT in i subscribe to tele/+/SENSOR which is the default topic of tasmota for sensor values, here i make no selection what sensor values i will use so it gets every sensor type you have in your mqtt network

Here i use the JSONPath expression „$..ENERGY“ to filter only on JSON messages which includes ENERGY as a element.

  • Switch

I use the switch element to identifiy whether the supplyed element from JSONPath is empty or not.

  • Function

The function is where i add the source name within the JSON String to have that information afterwards available also in the influx measurements.

  • InfluxDB

After all i write the whole string in the influxDB in my statisitcs database in a measuremnt called „energy1“

  • DebugMsg

The DebugMsg element is to controll the output of the chain. In my environemnt this is a typical output:

[{„TotalStartTime“:“2020-05-21T19:09:01″,“Total“:1.591,“Yesterday“:0.208,“Today“:0.054,“Period“:0,“Power“:0,“ApparentPower“:17,“ReactivePower“:17,“Factor“:0.02,“Voltage“:228,“Current“:0.073″,“Name“:“energy2″}]

As you see there is the NAME added at the end of the object.

CODE:

[
{
„id“: „3a60f610.f66632“,
„type“: „jsonpath“,
„z“: „2c0c97dc.300d7“,
„expression“: „$..ENERGY“,
„split“: false,
„name“: „“,
„x“: 630,
„y“: 2080,
„wires“: [
[
„d5a418c2.d9bda8“
]
]
},
{
„id“: „d5a418c2.d9bda8“,
„type“: „switch“,
„z“: „2c0c97dc.300d7“,
„name“: „“,
„property“: „payload“,
„propertyType“: „msg“,
„rules“: [
{
„t“: „nempty“
},
{
„t“: „cont“,
„v“: „topic“,
„vt“: „msg“
},
{
„t“: „else“
}
],
„checkall“: „true“,
„repair“: false,
„outputs“: 3,
„x“: 790,
„y“: 2080,
„wires“: [
[
„e78d6b7c.6767c“
],
[],
[]
]
},
{
„id“: „e78d6b7c.6767c“,
„type“: „function“,
„z“: „2c0c97dc.300d7“,
„name“: „add name“,
„func“: „msg.payload[0].emname = msg.topic.split(\“/\“)[1];\nmsg.payload[0].Name = msg.topic.split(\“/\“)[1];\n\nreturn msg;“,
„outputs“: 1,
„noerr“: 0,
„x“: 940,
„y“: 2080,
„wires“: [
[
„76d65968.6c1568“,
„a78d055d.d1ea3“
]
]
},
{
„id“: „76d65968.6c1568“,
„type“: „influxdb out“,
„z“: „2c0c97dc.300d7“,
„influxdb“: „306f62ed.836df6“,
„name“: „Statistics“,
„measurement“: „energy1“,
„precision“: „“,
„retentionPolicy“: „“,
„x“: 1140,
„y“: 2080,
„wires“: []
},
{
„id“: „a78d055d.d1ea3“,
„type“: „debug“,
„z“: „2c0c97dc.300d7“,
„name“: „energy.raw“,
„active“: false,
„tosidebar“: true,
„console“: false,
„tostatus“: false,
„complete“: „true“,
„targetType“: „full“,
„x“: 1150,
„y“: 2040,
„wires“: []
},
{
„id“: „306f62ed.836df6“,
„type“: „influxdb“,
„z“: „“,
„hostname“: „influxdb“,
„port“: „8086“,
„protocol“: „http“,
„database“: „statistics“,
„name“: „“,
„usetls“: false,
„tls“: „“
}
]