RalfZim / venus.dbus-fronius-smartmeter

A service for Venus OS, reading smart meter data from a Fronius system and making the values available on dbus.
MIT License
50 stars 28 forks source link

Adapt this for Tasmota Smart Meter http api? #7

Closed testpaul999 closed 2 years ago

testpaul999 commented 2 years ago

Hello,

no issue! Feature request!

I have a smart meter and do read out with IR-Head and Tasmota. So I can do this http://192.168.2.237/cm?cmnd=status%2010

and get this

{"StatusSNS":{"Time":"2022-03-09T15:39:52","SML":{"DJ_TPWRIN":1708.94,"DJ_TPWROUT":86.36,"DJ_TPWRCURR":145.30,"Meter_number":"0901454d4800009c86bf"},"ESP32":{"Temperature":53.3},"Verbrauch Tag":"2.96","Verbrauch Monat":"1708.94","Verbrauch Jahr":"1708.94","Einspeisung Tag":"0.16","Zählerstand 0:00Uhr":"1705.98","Zählerstand Monatsanfang":"0.00","Zählerstand Jahrenanfang":"0.00","Kosten dieses Jahr":"501.06","TempUnit":"C"}}

Need only DJ_TPWRCURR Is it possible to adapt the .py for this? Regards

testpaul999 commented 2 years ago

Hi, is there anything that I can do to help you? Regards E-mail contact jufranz@outlook.com

Marv2190 commented 2 years ago

I did this with Tasmota and MQTT. Works really well. You can just replace the request section with an mqtt subscribe section. Using the same variables of course. https://community.victronenergy.com/questions/82935/victron-ess-external-meter-mqtt.html?childToView=126665#answer-126665

Just got it working today :)

testpaul999 commented 2 years ago

@Marv2190 Pls can you share this „simple“ script. I‘l by you a coffee 👍🏻 regards

RalfZim commented 2 years ago

I have a smart meter and do read out with IR-Head and Tasmota. So I can do this http://192.168.2.237/cm?cmnd=status%2010

and get this

{"StatusSNS":{"Time":"2022-03-09T15:39:52","SML":{"DJ_TPWRIN":1708.94,"DJ_TPWROUT":86.36,"DJ_TPWRCURR":145.30,"Meter_number":"0901454d4800009c86bf"},"ESP32":{"Temperature":53.3},"Verbrauch Tag":"2.96","Verbrauch Monat":"1708.94","Verbrauch Jahr":"1708.94","Einspeisung Tag":"0.16","Zählerstand 0:00Uhr":"1705.98","Zählerstand Monatsanfang":"0.00","Zählerstand Jahrenanfang":"0.00","Kosten dieses Jahr":"501.06","TempUnit":"C"}}

Need only DJ_TPWRCURR Is it possible to adapt the .py for this? Regards

@testpaul999 You can just change the meter_URL from meter_url = "http://10.194.65.143/solar_api/v1/GetMeterRealtimeData.cgi?"\ "Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData" to meter_url = "http://192.168.2.237/cm?cmnd=status%2010" and then you change meter_consumption = meter_data['Body']['Data']['PowerReal_P_Sum'] to meter_consumption = meter_data['StatusSNS']['SML']['DJ_TPWRCURR']

Please let me know if this works.

testpaul999 commented 2 years ago

Hello,

it shows only one time the sum at start the script but not ongonig.

image

and at the gui is nothing image

the files are at the right place image

the symolic link is there

image

and this

python /data/dbus-fronius-smartmeter/dbus-fronius-smartmete r.py Traceback (most recent call last): File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 118, in main() File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 94, in m ain pvacoutput = DbusDummyService( File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 32, in _init__ self._dbusservice = VeDbusService(servicename) File "/data/dbus-fronius-smartmeter/vedbus.py", line 78, in init self._dbusname = dbus.service.BusName(servicename, self._dbusconn, do_not_qu eue=True) File "/usr/lib/python3.8/site-packages/dbus/service.py", line 144, in new raise NameExistsException(name) dbus.exceptions.NameExistsException: Bus name already exists: com.victronenergy. grid root@raspberrypi2:~#

Marv2190 commented 2 years ago

@Marv2190 Pls can you share this „simple“ script. I‘l by you a coffee 👍🏻 regards

Hi, i forked this project. You can look unter forked and find my Github there :)

Marv2190 commented 2 years ago

Hello,

it shows only one time the sum at start the script but not ongonig.

image

and at the gui is nothing image

the files are at the right place image

the symolic link is there

image

and this

python /data/dbus-fronius-smartmeter/dbus-fronius-smartmete r.py Traceback (most recent call last): File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 118, in main() File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 94, in m ain pvacoutput = DbusDummyService( File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 32, in _init__ self._dbusservice = VeDbusService(servicename) File "/data/dbus-fronius-smartmeter/vedbus.py", line 78, in init self._dbusname = dbus.service.BusName(servicename, self._dbusconn, do_not_qu eue=True) File "/usr/lib/python3.8/site-packages/dbus/service.py", line 144, in new raise NameExistsException(name) dbus.exceptions.NameExistsException: Bus name already exists: com.victronenergy. grid root@raspberrypi2:~#

Is your Meter distrubutin all the Data? Or just that? Mine only shows Current, in and export. In my script I just divide the total /3 and set it in.

testpaul999 commented 2 years ago

@Marv2190 No you must request this web site when you will get new current, So I‘ll try your fork.

Regards

RalfZim commented 2 years ago

it shows only one time the sum at start the script but not ongonig.

Hm, not sure how that would happen. _update() is being called regularly. And in this function, it then calls meter_r = requests.get(url=meter_url) which then updates the values.

and this python /data/dbus-fronius-smartmeter/dbus-fronius-smartmete r.py Traceback (most recent call last): File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 118, in main() File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 94, in m ain pvacoutput = DbusDummyService( File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 32, in _init__ self._dbusservice = VeDbusService(servicename) File "/data/dbus-fronius-smartmeter/vedbus.py", line 78, in init self._dbusname = dbus.service.BusName(servicename, self._dbusconn, do_not_qu eue=True) File "/usr/lib/python3.8/site-packages/dbus/service.py", line 144, in new raise NameExistsException(name) dbus.exceptions.NameExistsException: Bus name already exists: com.victronenergy. grid root@raspberrypi2:~#

This error message means that another script is already running which registered as "com.victronenergy.grid". Therefore the script throwing this error stopped. I am irritated that the error says "com.victronenergy. grid" with a space before "grid". Is there a typo somewhere? There should be no space in the bus name.

Is your Meter distrubutin all the Data? Or just that? Mine only shows Current, in and export. In my script I just divide the total /3 and set it in.

Yes, my Fronius energy meter gives readings for all the values that I am setting in the script, for example: self._dbusservice['/Ac/L3/Current'] = meter_data['Body']['Data']['Current_AC_Phase_3']

testpaul999 commented 2 years ago

@Marv2190 i get this meassage if I try install paho-mqtt root@raspberrypi2:~# python -m ensurepip --upgrade pip install paho-mqtt /usr/bin/python: No module named ensurepip root@raspberrypi2:~#

Have rpi with 2.84 venus os.

@RalfZim

I have only this changed

def _update(self): meter_url = meter_url = "http://192.168.2.237/cm?cmnd=status%2010"\ "Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData" meter_r = requests.get(url=meter_url) # request data from the Fronius PV inverter meter_data = meter_r.json() # convert JSON data meter_consumption = meter_data['StatusSNS']['SML']['DJ_TPWRCURR']

how I must this edit?

MQTT Setup

broker_address = "192.168.2.237" MQTTNAME = "Strom_21F4D0" Zaehlersensorpfad = "tele/Strom_21F4D0/SENSOR/"

testpaul999 commented 2 years ago

@Marv2190 don't see anythig with your script

grafik grafik grafik have change my tasmota ip here

def _update(self): meter_url = ""http://192.168.2.237/cm?cmnd=status%2010"\ "Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData" meter_r = requests.get(url=meter_url) # request data from the Fronius PV inverter meter_data = meter_r.json() # convert JSON data meter_consumption = meter_data['StatusSNS']['SML']['DJ_TPWRCURR']

is this right?

MQTT Setup

broker_address = "192.168.2.237" MQTTNAME = "Strom_21F4D0" Zaehlersensorpfad = "tele/Strom_21F4D0/SENSOR/"

RalfZim commented 2 years ago

have change my tasmota ip here

def _update(self): meter_url = ""http://192.168.2.237/cm?cmnd=status%2010"\ "Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData" meter_r = requests.get(url=meter_url) # request data from the Fronius PV inverter meter_data = meter_r.json() # convert JSON data meter_consumption = meter_data['StatusSNS']['SML']['DJ_TPWRCURR']

You need to delete "\Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData" from your code. Look at what I wrote above! You should only use: meter_url = "http://192.168.2.237/cm?cmnd=status%2010"

testpaul999 commented 2 years ago

Thx, but this will not change the effect. I only see current at start.

RalfZim commented 2 years ago

Thx, but this will not change the effect. I only see current at start.

Lets try to debug this. We want to run the script manually, not as a service. For this, do the following on the command line: Remove the service, so that is does not get started again: rm /service/dbus-fronius-smartmeter Kill the current service: kill $(pgrep -f 'python /data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py') Run the script manually: python /data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py Periodically, you should get the following message: House Consumption: -123 The value should always be what your energy meter reports. Are you seeing any errors or warnings instead?

testpaul999 commented 2 years ago

Hi, here are the output. dbus.log

RalfZim commented 2 years ago

Hi, here are the output. dbus.log

Your log file shows the following error:

  File "/data/dbus-fronius-smartmeter/dbus-fronius-smartmeter.py", line 62, in _update
    self._dbusservice['/Ac/L1/Voltage'] = meter_data['Body']['Data']['Voltage_AC_Phase_1']
KeyError: 'Body'

The lines which use meter_data['Body']['Data']['...'] throw an error, because your energy meter does not provide these values. Change or delete these lines in the code!

testpaul999 commented 2 years ago

:-) Hi works well. Have comment out all lines with „ meter_data['Body']“ in and now i get continues data from the tasmota SmartMeter.

Regards

Marv2190 commented 2 years ago

@Marv2190 don't see anythig with your script

grafik grafik grafik have change my tasmota ip here

def _update(self): meter_url = ""http://192.168.2.237/cm?cmnd=status%2010"\ "Scope=Device&DeviceId=0&DataCollection=MeterRealtimeData" meter_r = requests.get(url=meter_url) # request data from the Fronius PV inverter meter_data = meter_r.json() # convert JSON data meter_consumption = meter_data['StatusSNS']['SML']['DJ_TPWRCURR']

is this right?

MQTT Setup

broker_address = "192.168.2.237" MQTTNAME = "Strom_21F4D0" Zaehlersensorpfad = "tele/Strom_21F4D0/SENSOR/"

Iam a little bit confused. Did you used mine? What is the output if the script if you run it?

Marv2190 commented 2 years ago

You need to run these two Commands seperate. first install pip and with pip you cann install paho

testpaul999 commented 2 years ago

@Marv2190 Ich denke wir könne auch Deutsch schreiben? Ja ich habe Dein Script genutzt, aber wo und wie trage ich den mqtt Server ein? Was muss in welcher der beiden *.py angepasst werden?

ich finde bei mir nur pip3 Weiterhin ist hier Python 3.8 installiert

das hier kommt bei ausführen der .py

root@raspberrypi2:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 33, in from vedbus import VeDbusService ModuleNotFoundError: No module named 'vedbus' root@raspberrypi2:/data/mqtttogrid#

danke

Marv2190 commented 2 years ago

@Marv2190 Ich denke wir könne auch Deutsch schreiben? Ja ich habe Dein Script genutzt, aber wo und wie trage ich den mqtt Server ein? Was muss in welcher der beiden *.py angepasst werden?

ich finde bei mir nur pip3 Weiterhin ist hier Python 3.8 installiert

das hier kommt bei ausführen der .py

root@raspberrypi2:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 33, in from vedbus import VeDbusService ModuleNotFoundError: No module named 'vedbus' root@raspberrypi2:/data/mqtttogrid#

danke

Hi klar, hast du wie in der Anleitung angegeben in den ordner die beiden Dateien hinterlegt? Es scheint das er diese Datei nicht findet. Du lässt das auf einen Raspi mit Venus OS laufen? Sollte aber auch keinen unterschied machen.

Server wird unter : broker_address = "IPADRESS" anstatt IPADRESS eingetragen.

Vielleicht solltest du ein Issue auf meiner Projektseite aufmachen. Damit die zugehörigkeit passt und es von anderen einfacher gefunden werden kann.

testpaul999 commented 2 years ago

Ja mache ich, schreibe weiter in deinem GitHub

Viele Grüße

Jens-Uwe Franz

Am 25.03.2022 um 00:37 schrieb Marvin @.***>:



@Marv2190https://github.com/Marv2190 Ich denke wir könne auch Deutsch schreiben? Ja ich habe Dein Script genutzt, aber wo und wie trage ich den mqtt Server ein? Was muss in welcher der beiden *.py angepasst werden?

ich finde bei mir nur pip3 Weiterhin ist hier Python 3.8 installiert

das hier kommt bei ausführen der .py

@.:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 33, in from vedbus import VeDbusService ModuleNotFoundError: No module named 'vedbus' @.:/data/mqtttogrid#

danke

Hi klar, hast du wie in der Anleitung angegeben in den ordner die beiden Dateien hinterlegt? Es scheint das er diese Datei nicht findet. Du lässt das auf einen Raspi mit Venus OS laufen? Sollte aber auch keinen unterschied machen.

Server wird unter : broker_address = "IPADRESS" anstatt IPADRESS eingetragen.

— Reply to this email directly, view it on GitHubhttps://github.com/RalfZim/venus.dbus-fronius-smartmeter/issues/7#issuecomment-1078485893, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIPS4U3S6KWRVFE2PXYYPKDVBT4CLANCNFSM5QJYHJSQ. You are receiving this because you modified the open/close state.Message ID: @.***>

testpaul999 commented 2 years ago

Hallo Marvin,

Auf Deinem GitHub kann ich keinen issue aufmachen. Fehlt einfach in der Anzeige.

@.:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 195, in client.connect(broker_address) # connect to broker File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 941, in connect return self.reconnect() File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 1075, in reconnect sock = self._create_socket_connection() File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection return socket.create_connection(addr, source_address=source, timeout=self._keepalive) File "/usr/lib/python3.8/socket.py", line 808, in create_connection raise err File "/usr/lib/python3.8/socket.py", line 796, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused @.:/data/mqtttogrid#

habe jetzt das hier drin

MQTT Setup

broker_address = "192.168.2.237" MQTTNAME = "MQTTtoMeter" Zaehlersensorpfad = "Path"

Zaehlersensorpfad = "tele/Strom_21F4D0/SENSOR"

Aber mein Broker hat User und PW! Oder kann/ der tasmota selber abgefragt werden?

Viele Grüße

Jens-Uwe Franz

Am 25.03.2022 um 00:37 schrieb Marvin @.***>:



@Marv2190https://github.com/Marv2190 Ich denke wir könne auch Deutsch schreiben? Ja ich habe Dein Script genutzt, aber wo und wie trage ich den mqtt Server ein? Was muss in welcher der beiden *.py angepasst werden?

ich finde bei mir nur pip3 Weiterhin ist hier Python 3.8 installiert

das hier kommt bei ausführen der .py

@.:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 33, in from vedbus import VeDbusService ModuleNotFoundError: No module named 'vedbus' @.:/data/mqtttogrid#

danke

Hi klar, hast du wie in der Anleitung angegeben in den ordner die beiden Dateien hinterlegt? Es scheint das er diese Datei nicht findet. Du lässt das auf einen Raspi mit Venus OS laufen? Sollte aber auch keinen unterschied machen.

Server wird unter : broker_address = "IPADRESS" anstatt IPADRESS eingetragen.

— Reply to this email directly, view it on GitHubhttps://github.com/RalfZim/venus.dbus-fronius-smartmeter/issues/7#issuecomment-1078485893, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIPS4U3S6KWRVFE2PXYYPKDVBT4CLANCNFSM5QJYHJSQ. You are receiving this because you modified the open/close state.Message ID: @.***>

Marv2190 commented 2 years ago

Hallo Marvin, Auf Deinem GitHub kann ich keinen issue aufmachen. Fehlt einfach in der Anzeige. @.:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 195, in client.connect(broker_address) # connect to broker File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 941, in connect return self.reconnect() File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 1075, in reconnect sock = self._create_socket_connection() File "/usr/lib/python3.8/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection return socket.create_connection(addr, source_address=source, timeout=self._keepalive) File "/usr/lib/python3.8/socket.py", line 808, in create_connection raise err File "/usr/lib/python3.8/socket.py", line 796, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused @.:/data/mqtttogrid# habe jetzt das hier drin # MQTT Setup broker_address = "192.168.2.237" MQTTNAME = "MQTTtoMeter" Zaehlersensorpfad = "Path" #Zaehlersensorpfad = "tele/Strom_21F4D0/SENSOR" Aber mein Broker hat User und PW! Oder kann/ der tasmota selber abgefragt werden? Viele Grüße Jens-Uwe Franz Am 25.03.2022 um 00:37 schrieb Marvin @.>:  @Marv2190https://github.com/Marv2190 Ich denke wir könne auch Deutsch schreiben? Ja ich habe Dein Script genutzt, aber wo und wie trage ich den mqtt Server ein? Was muss in welcher der beiden .py angepasst werden? ich finde bei mir nur pip3 Weiterhin ist hier Python 3.8 installiert das hier kommt bei ausführen der .py **@.:/data/mqtttogrid# python MQTTtoGridMeter.py Traceback (most recent call last): File "MQTTtoGridMeter.py", line 33, in from vedbus import VeDbusService ModuleNotFoundError: No module named 'vedbus' @.:/data/mqtttogrid# danke Hi klar, hast du wie in der Anleitung angegeben in den ordner die beiden Dateien hinterlegt? Es scheint das er diese Datei nicht findet. Du lässt das auf einen Raspi mit Venus OS laufen? Sollte aber auch keinen unterschied machen. Server wird unter : broker_address = "IPADRESS" anstatt IPADRESS eingetragen. — Reply to this email directly, view it on GitHub<#7 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIPS4U3S6KWRVFE2PXYYPKDVBT4CLANCNFSM5QJYHJSQ. You are receiving this because you modified the open/close state.Message ID: @.***>

Nein, mein Script sieht vor, bei einem Broker zu subscriben. Für Name und Passwort hab ich es nicht programmiert, da ich es nur intern nutze. Kannst aber gerne ein Pullrequest dazu machen.