question

tozz avatar image
tozz asked

Victron ESS - External meter MQTT

Hi


I'm building an ESS. I have 10 kWh of batteries, Victron Cerbo GX, MultiPlus, etc, etc. So far so good. What I'm missing is the AC-meter.

I already have grid meters in my house, which are fed into MQTT. It would be pretty useless to buy a EM24 Ethernet meter just for the Cerbo, while I already have the data available.


My question is simple: Can I write (publish) meter values (such as grid consumption and grid feed-in) to the Cerbo's CX MQTT broker? And will this work as ESS AC meter in the ESS Assistant?

I tried setting eg. N/X/system/0/Ac/Grid/L1/Power, but this gets overwritten quickly.

Any help is appreciated!


ESSgridMQTT
2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

sviwowa avatar image sviwowa commented ·

This is an intesting topic. Have you made any progress?

0 Likes 0 ·
tenacioustech avatar image tenacioustech commented ·

Keen to follow this also. Using Shelly EM for grid monitoring and i too would like to be able to push the grid power usage to the GX device via MQTT

0 Likes 0 ·
15 Answers
mr-manuel avatar image
mr-manuel answered ·

For all interested I wrote a driver for that, which is well documented. You can find it here: https://github.com/mr-manuel/venus-os_dbus-mqtt-grid

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

bonitos avatar image bonitos commented ·
Works great, thanks! The EM24 broke last evening. A bit of NodeRed to feed from a Fronius meter to MQTT and your service saved my day.
1 Like 1 ·
marv21 avatar image
marv21 answered ·

That would be so nice to have, as my Smartmeter published every 5 sec to Mqtt and we coult spare that EM24...

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marv21 avatar image
marv21 answered ·

So, after writing here, I tried to implement it.My meter from the network operator is read out via Tasmota (a modified Tasmota which sends data every 2 seconds via MQTT to the broker).This is done simply via the D0 interface and infrared.

A script on the Cerbo then puts this into the DBUS and the rest works quite well.

Since my meter only outputs "import" "export" and "current consumption", I had to let the script L1 L2 L3 divide by 3.
Therefore the numbers between L1 to L3 are always the same.

This has the nice side effect that my 3 Victrons are now finally loaded with the same load. This is unfortunately not possible with the counter from Victron Energy (EM24). Why, I have not figured out and it is also demanded by many here in the forum - but this is another topic :)


20210819-013136.jpg

20210819-144334.jpg


rc1.jpg

rc2.jpg

rc3.jpgrcpages.jpg

scriptruns.jpg


rc1.jpg (52.4 KiB)
rc2.jpg (49.7 KiB)
rc3.jpg (53.8 KiB)
rcpages.jpg (62.8 KiB)
scriptruns.jpg (148.1 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Paul Test avatar image
Paul Test answered ·

@Marv21

thats looks good pls can you share this little script?

and one other question, may you can have a look at this question from me?

https://community.victronenergy.com/questions/126558/absolutes-verstandnis-problem-multiplus-im-ess-mod.html

regards

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

gone-sailing avatar image
gone-sailing answered ·

I’d like to see the script too. If I can see what dbus paths and settings you are using I can probably add them to my generic dbus-Mqtt-devices driver.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marv21 avatar image marv21 commented ·

https://github.com/Marv2190/venus.dbus-MqttToGridMeter

Its in the MQTTtoGridMeter.py .

self._dbusservice['/Ac/Power'] = powercurr # positive: consumption, negative: feed into grid

self._dbusservice['/Ac/L1/Voltage'] = "230"

self._dbusservice['/Ac/L2/Voltage'] = "230"

self._dbusservice['/Ac/L3/Voltage'] = "230"

self._dbusservice['/Ac/L1/Current'] = "1"

self._dbusservice['/Ac/L2/Current'] = "1"

self._dbusservice['/Ac/L3/Current'] = "1"

self._dbusservice['/Ac/L1/Power'] = powercurr/3

self._dbusservice['/Ac/L2/Power'] = powercurr/3

self._dbusservice['/Ac/L3/Power'] = powercurr/3


self._dbusservice['/Ac/Energy/Forward'] = totalin

self._dbusservice['/Ac/Energy/Reverse'] =

0 Likes 0 ·
sailorm avatar image
sailorm answered ·

Please share your script.

I am also trying to connect an foreign meter with the cerbo and mqtt.

What values do I have to write?

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

para756 avatar image
para756 answered ·

I am currently messing around with your script @Marv21

I also added a fake charger for my GPU miner and a Shelly used to measure my PV output.

It works nicely now. Only problem i have that AC Input power sum is not shown on VRM Portal. Do you have any Idea what the reason could be?

By the way: I can get power values from all three phases with tasmora+SML with the script below. So no need for calulation. Maybe this works with your grid meter too. I also added energy out meter calculation from my NodeRed instance. But still getting no

@SailorM You ca find anything you need on the github page @Marv21 linked above in response to @gone-sailing.

The documentation by Victron was handy (https://github.com/victronenergy/venus/wiki/dbus) but coud be a bit more talking about every specific datapoint.

(Python script is getting a bit messy.)

>D

>B

=>sensor53 r 

>M 1 
+1,1,s,16,9600,MT175
1,77070100010800ff@1000,Verbrauch,KWh,Total_in,1
1,77070100020800ff@1000,Netzeinspeisung,KWh,Total_out,0
1,77070100100700ff@1,Leistung,W,Power_curr,16
1,77070100240700ff@1,Wirkleistung L1,W,Power_p1,1
1,77070100380700ff@1,Wirkleistung L2,W,Power_p2,1
1,770701004c0700ff@1,Wirkleistung L3,W,Power_p3,1
#
def on_message(client, userdata, msg):
    try:
        global powercurr, powercurr_p1, powercurr_p2, powercurr_p3, totalin, totalout
        if msg.topic == Zaehlersensorpfad:   # JSON String vom Zaehler Sensor auslesen
            if msg.payload != '{"value": null}' and msg.payload != b'{"value": null}':
                jsonpayload = json.loads(msg.payload)
                if "Power_curr" in jsonpayload["MT175"]:
                        powercurr = float(jsonpayload["MT175"]["Power_curr"])
                        print("Power from MQTT:" + f'{powercurr:.2f}')
                if "Power_p1" in jsonpayload["MT175"]:
                        powercurr_p1 = float(jsonpayload["MT175"]["Power_p1"])
                if "Power_p2" in jsonpayload["MT175"]:
                        powercurr_p2 = float(jsonpayload["MT175"]["Power_p2"])
                if "Power_p3" in jsonpayload["MT175"]:
                        powercurr_p3 = float(jsonpayload["MT175"]["Power_p3"])
                if "Total_in" in jsonpayload["MT175"]:
                        totalin = float(jsonpayload["MT175"]["Total_in"])
                        print("Energy_in from MQTT:" + f'{totalin:.2f}')
                #if "Total_out" in jsonpayload["MT175"]:
                #        totalout = float(jsonpayload["MT175"]["Total_out"])
            else:
                print("Antwort vom MQTT war Null und wurde ignoriert")
        if msg.topic == "nodered/grid/energy_out":
           totalout = float(msg.payload);
           print("Energy_out from MQTT:" + f'{totalout:.2f}')

    except Exception as e:
        logging.exception("Programm MQTTtoMeter ist abgestuerzt. (on message Funkion)")
        print(e)
        print("Im MQTTtoMeter Programm ist etwas beim auslesen der Nachrichten schief gegangen")


1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marv21 avatar image marv21 commented ·

Hi, sorry for the messy Python Script :D

As iam not a programmer myself sometimes its trial and error


I tried your Tasmota Script. Sadly the single Phasesoutput is 0.



0 Likes 0 ·
Guido Schneider avatar image
Guido Schneider answered ·

@Marv21

I have a system similar to yours. A bi-directional counter from Iskra and the reading head from Hichi. Then i transferred to IoBroker with a Wemos D1 using Tasmota.

I downloaded your script because it's actually exactly what I'm looking for. Unfortunately, I can't cope with it because my Python knowledge is zero. But I am in the process of learning and once wrote a first script which reads the MQTT data from the IoBroker and displays it on the screen.


Unfortunately I have no idea how to put it in your script.

iobroker now makes this data available via mqtt


1652098114880.png


Übersetzungsergebnisse


star_border


1652098114880.png (33.0 KiB)
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marv21 avatar image marv21 commented ·

Hi,

you have to install it directly on your GX device.

You can setup the Script MQTT

# MQTT Setup

broker_address = "IPADRESS"

MQTTNAME = "MQTTtoMeter"

Zaehlersensorpfad = "Path"


broker adress should be your IObroker with the right path.


Maybe you have to edit the:


def on_message(client, userdata, msg):

try:


global powercurr, totalin, totalout

if msg.topic == Zaehlersensorpfad: # JSON String vom Zaehler Sensor auslesen

if msg.payload != '{"value": null}' and msg.payload != b'{"value": null}':

jsonpayload = json.loads(msg.payload)

powercurr = float(jsonpayload["Zaehler"]["Power_curr"])

totalin = float(jsonpayload["Zaehler"]["Total_in"])

totalout = float(jsonpayload["Zaehler"]["Total_out"])


to match your Outputs from IoBroker.


0 Likes 0 ·
Guido Schneider avatar image
Guido Schneider answered ·

Thanks, I got it.

What would be interesting is a script with which I could emulate a PV inverter. Actually, you should be able to take this script, adjust the settings and set it as a PV inverter. I just don't know how to address the inverter.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

flubber avatar image
flubber answered ·

@Marv21

First of all thanks for the script, it is exactly what I am looking for!

Unfortunately I have some problems to getting it to run.

On GitHub you say that you have to run Pah Client on your GXDevice.

I tried to execute "python -m ensurepip --upgrade pip install paho-mqtt" on my Cerbo GX but always get the error "No module named ensurepip".
I tried several thinks but without success.

I think that's the reason why your script always crashes on my CerboGX...?

Many thanks in advance!

Kai

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marv21 avatar image marv21 commented ·

try

python -m ensurepip --upgrade

and then

pip install paho-mqtt


0 Likes 0 ·
flubber avatar image
flubber answered ·

root@einstein:~# python -m ensurepip --upgrade

/usr/bin/python: No module named ensurepip


:-(

Any other ideas?


5 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

flubber avatar image flubber commented ·

Ok, I made a little progress.


The problem was that the image of my cerbo gx was corrupt.

I made a factory reset via an usb-stick and then I was able to install ensurepip.


But know I have another problem.

root@einstein:/data/mqtttogrid# python /data/mqtttogrid/MQTTtoGridMeter.py

192.168.178.154

/SmartHome/Energie/Bezug/state

Traceback (most recent call last):

File "/data/mqtttogrid/MQTTtoGridMeter.py", line 194, in <module>

client.connect(broker_address) # connect to broker

File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 939, in connect

self.connect_async(host, port, keepalive,

File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 1005, in connect_async

raise ValueError('Invalid host.')

ValueError: Invalid host.

root@einstein:/data/mqtttogrid#

I guess it has something to do with the Path.

May I ask you for your help again @Marv21 ?



0 Likes 0 ·
marv21 avatar image marv21 flubber commented ·

Hard to tell. Something is wrong with your IP Adress i would think.

I guess your guess is right, bur from here without your script i cant tell exactly.

0 Likes 0 ·
flubber avatar image flubber marv21 commented ·

# MQTT Setup

broker_address = input("192.168.178.154")

MQTTNAME = "Bezug"

Zaehlersensorpfad = input("/SmartHome/Energie/Bezug/state")

0 Likes 0 ·
flubber avatar image flubber flubber commented ·

Ok, step by step... :-)

Seems like you have to enter the IP address and path like this.

# MQTT Setup

broker_address = '192.168.178.154'

MQTTNAME = 'Bezug'

Zaehlersensorpfad = '/SmartHome/Energie/Bezug/state'


The script still seems to crash but I hope I can fix a solution for this too.


INFO:root:House Consumption: 0


EDIT:


ERROR:root:Programm MQTTtoMeter ist abgestuerzt. (on message Funkion)

Traceback (most recent call last):

File "/data/mqtttogrid/MQTTtoGridMeter.py", line 89, in on_message

powercurr = float(jsonpayload["Zaehler"]["Power_curr"])

TypeError: 'int' object is not subscriptable

'int' object is not subscriptable

Im MQTTtoMeter Programm ist etwas beim auslesen der Nachrichten schief gegangen



0 Likes 0 ·
flubber avatar image flubber flubber commented ·

Does anyone else have any ideas? :-(

0 Likes 0 ·
elko avatar image
elko answered ·

Good evening,

There is a ready-made project on GitHub for exactly this. I also used this in conjunction with MQTT/ioBroker - Works quite well.

https://github.com/stormmurdoc/victron_sdm630_bridge

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

flubber avatar image flubber commented ·
Thanks for the info but I want to get marv21 version running first. :-)


0 Likes 0 ·
maxi-fpv avatar image
maxi-fpv answered ·

Good evening,

I got the script running thanks for the script in the first place but i only get zero Consumtion.

The wierd Thing is in Homeassistant i recive Messages fome the exact same Topic. Also im using the Mosquitto mqtt broke



Victon Console

INFO:root:House Consumption: 0

INFO:root:House Consumption: 0

INFO:root:House Consumption: 0

INFO:root:House Consumption: 0


Here is my python configuration the rest is default


# MQTT Setup

broker_address = "192.168.178.12"

MQTTNAME = "MQTTtoMeter"

Zaehlersensorpfad = "sonoff/0/StromVerbrauch"


Homeassistant MQtt messages


sonoff/0/StromVerbrauch/Power_curr


Nachricht 71 empfangen auf sonoff/0/StromVerbrauch/Power_curr um 20:26:

475

QoS: 0 - Retain: false

Nachricht 70 empfangen auf sonoff/0/StromVerbrauch/Power_curr um 20:26:

473

QoS: 0 - Retain: false


The Mosquitto Log also shows that the device is connected

1661453157: New connection from 192.168.178.95:57377 on port 1883.
1661453157: New client connected from 192.168.178.95:57377 as Victron (p2, c1, k60).

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marv21 avatar image marv21 commented ·
Are you getting these per Phase? Or only Power_curr? Try to devide it with 3 and set it on each Phase.
0 Likes 0 ·
maxi-fpv avatar image maxi-fpv marv21 commented ·

Im getting 0 per Phase and 0 on Power_curr. In The console it also shows 0 (INFO:root:House Consumption: 0 )

If you mean if I send 3 Phases over mqtt no just the current, total in and out

0 Likes 0 ·
aikawa24 avatar image aikawa24 maxi-fpv commented ·

Hi I have had the same problems at first but after some trying it works

# Variblen setzen
verbunden = 0
durchlauf = 0
maxcellvoltage = 3.0
powercurr = 0
powerp1 = 0
powerp2 = 0
powerp3 = 0
totalin = 0
totalout = 0


def on_message(client, userdata, msg):
    try:

        global powercurr, powerp1, powerp2, powerp3,  totalin, totalout
        if msg.topic == Zaehlersensorpfad:   # JSON String vom Zaehler Sensor auslesen
            if msg.payload != '{"value": null}' and msg.payload != b'{"value": null}':
                jsonpayload = json.loads(msg.payload)
                powercurr = float(jsonpayload["StatusSNS"]["mt681"]["Power_cur"])
                powerp1 = float(jsonpayload["StatusSNS"]["mt681"]["Power_p1"])
                powerp2 = float(jsonpayload["StatusSNS"]["mt681"]["Power_p2"])
                powerp3 = float(jsonpayload["StatusSNS"]["mt681"]["Power_p3"])
                totalin = float(jsonpayload["StatusSNS"]["mt681"]["Total_in"])
                totalout = float(jsonpayload["StatusSNS"]["mt681"]["Total_out"])
            else:
                print("Antwort vom MQTT war Null und wurde ignoriert")


def _update(self):
    self._dbusservice['/Ac/Power'] =  powercurr # positive: consumption, negative: feed into grid
    self._dbusservice['/Ac/L1/Voltage'] = 230
    self._dbusservice['/Ac/L2/Voltage'] = 230
    self._dbusservice['/Ac/L3/Voltage'] = 230
    self._dbusservice['/Ac/L1/Current'] = round(powerp1 / 230 ,2)
    self._dbusservice['/Ac/L2/Current'] = round(powerp2 / 230 ,2)
    self._dbusservice['/Ac/L3/Current'] = round(powerp3 / 230 ,2)
    self._dbusservice['/Ac/L1/Power'] = powerp1
    self._dbusservice['/Ac/L2/Power'] = powerp2
    self._dbusservice['/Ac/L3/Power'] = powerp3


the two applications

https://jsonpathfinder.com/

and

http://mqtt-explorer.com/

helped me to find the correct path for jsonpayload

mt681-tasmota-script.png

mt681-on-cerbogx.png

mt681-on-cerbogx-detail.png

mt681-jsonpath.png

mt681-mqttexplorer.png


0 Likes 0 ·
energykonnex avatar image
energykonnex answered ·


Hi there Victron experts,

I have been trying to follow this tutorial, but I can get this to work. It's my python knowledge. Can some one point mi in the right direction? I think that the script is running but my mqtt data isn't comming through?

mqtt-v1.jpg


mqtt-setup.jpgnode-red-mqtt-topic.jpg


mqtt-v1.jpg (49.2 KiB)
mqtt-setup.jpg (10.4 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

mkohler avatar image
mkohler answered ·

Hi Flubber,

could you explain to me how to install ensurepip? I get the same error, even if

Python 3.8.13 is installed on my MP2.

/usr/bin/python3: No module named ensurepip

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources