1111import logging
1212
1313import paho .mqtt .client as mqtt
14- #import paho
1514
1615lastValues = {}
1716logger = logging .getLogger ()
@@ -28,18 +27,17 @@ def on_message(client, userdata, message):
2827
2928 topicmap = userdata ['topicmap' ]
3029 if message .topic == f"userdata['topic']/status" :
31- logger .info (f"status: { message .payload } " )
3230 if message .payload .decode ("utf-8" ) == "online" :
3331 logger .debug (f"Status is online" )
3432 else :
35- logger .debug (f"Status is not online, cleaning buffer" )
36- lastValues .clear ()
33+ logger .debug (f"Status is not online, setting power vlaues to 0" )
34+ lastValues ["power_active" ] = 0
35+ lastValues ["l1_power_active" ] = 0
36+ lastValues ["l1_current" ] = 0
3737 elif message .topic in topicmap :
38- if (isinstance (topicmap [message .topic ], str )):
39- lastValues [topicmap [message .topic ]] = float (message .payload )
40- else :
41- for key in topicmap [message .topic ]:
42- lastValues [key ] = float (message .payload )
38+ logger .debug (f"message { message .topic } is in map" )
39+ for entry in topicmap [message .topic ]:
40+ lastValues [entry ] = float (message .payload )
4341 else :
4442 logger .debug (f"MQTT ignored unknown topic { message .topic } " )
4543
@@ -73,18 +71,21 @@ def device(config):
7371 keepalive = config .getint ("keepalive" , fallback = 60 )
7472 topic = config .get ("topic" , fallback = "deye" )
7573
74+ """ The topicmap is used for mapping the Deye names to the one within the proxy.
75+ Per MQTT topic an array of proxy keys has to be given. The array entries are arrays again.
76+ The first value of the array is the name within the proxy, the second vlaue is a scaling
77+ factor. Set it to -1 to invert something. Currently not really needed, but who knows.
78+ """
7679 userdata = {
7780 "host" : host ,
7881 "port" : port ,
7982 "topic" : topic ,
8083 "topicmap" : {
81- f"{ topic } /total_energy" : "energy_active" ,
82- f"{ topic } /ac/active_power" : "power_active" ,
83- f"{ topic } /l1/power_active" : "l1_power_active" ,
84- f"{ topic } /l1/voltage" : ["voltage_ln" , "l1n_voltage" ],
85- f"{ topic } /ac/freq" : "frequency" ,
86- f"{ topic } /total_energy" : ["l1_energy_active" , "l1_export_energy_active" ],
87- f"{ topic } /l1/current" : "l1_current" ,
84+ f"{ topic } /ac/active_power" : [ "power_active" , "l1_power_active" , "power_apparent" ],
85+ f"{ topic } /ac/freq" : [ "frequency" ],
86+ f"{ topic } /ac/l1/current" : [ "l1_current" ],
87+ f"{ topic } /ac/l1/voltage" : [ "voltage_ln" , "l1n_voltage" ],
88+ f"{ topic } /total_energy" : [ "energy_active" , "l1_energy_active" , "import_energy_active" , "l1_import_energy_active" ],
8889 }
8990 }
9091
0 commit comments