birdie1 / victron

Victron bluetooth and serial communication at a python script. With MQTT and HomeAssistant support.
GNU General Public License v3.0
124 stars 16 forks source link

Implementation not working with smart solar / serial #29

Open Henschga opened 6 months ago

Henschga commented 6 months ago

Hi

I recently switched from the bluetooth to serial implementation which works fine for the smarthsunt, but not for the smartsolar products. After triggering the script manual I can see that there are missing dependencies to the library but this should be working (as it works with the smartshunt). Is there any advice that you can give me?

root@raspibus:/opt/victron# python3 victron.py -d 1
/opt/victron/victron.py:237: DeprecationWarning: Callback API version 1 is deprecated, update to latest version
  client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
Exception in thread Thread-1 (read_data_callback):
Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
  File "/opt/victron/victron.py", line 267, in <module>
    victron_thread(1, config, devices_config, q)
  File "/opt/victron/victron.py", line 24, in victron_thread
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    v = Victron(config, vdevice_config, output, args, thread_count, thread_q)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/victron/lib/victron.py", line 40, in __init__
    pid, ser, fw = self.victron_type.get_device_info()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    self._target(*self._args, **self._kwargs)
  File "/opt/victron/lib/victron_serial/victron_serial.py", line 59, in get_device_info
  File "/opt/victron/lib/victron_serial/victron_serial.py", line 18, in read_data_callback
    pid = self.map['PID'][4](data['PID'], self.map['PID'])
    callbackFunction(packet)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/victron/lib/victron_serial/victron_serial.py", line 40, in <lambda>
  File "/opt/victron/lib/helper.py", line 61, in convert_map_out
    callback_wrapper = lambda packet: self.read_data_callback(packet)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return f'{value}: {command[3][value]}'
  File "/opt/victron/lib/victron_serial/victron_serial.py", line 103, in read_data_callback
                       ~~~~~~~~~~^^^^^^^
KeyError: '0xA07D'
    self.process_packet(packet)
  File "/opt/victron/lib/victron_serial/victron_serial.py", line 111, in process_packet
    self.send_out(key, value)
  File "/opt/victron/lib/victron_serial/victron_serial.py", line 119, in send_out
    data = helper_function(value, map_entry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/victron/lib/helper.py", line 61, in convert_map_out
    return f'{value}: {command[3][value]}'
                       ~~~~~~~~~~^^^^^^^
KeyError: '0xA07D'
malocycling commented 4 months ago

Since I ran into the same issue here's how I fixed it. The mappings.py in ./lib seems not to be up-to-date and simply does not contain a representation for some newer devices. In your case you just need to add a line to the PID = {} section containing "0xA07D": "BlueSolar MPPT 75/15 rev3", and the script should be working.