keshavdv / victron-hacs

Home Assistant plug-in for Victron Instant Readout compatible devices
46 stars 16 forks source link

Missing External Device Load (A) entity for SmartSolar MPPT 100/20 48v #90

Open nikakoy131 opened 1 year ago

nikakoy131 commented 1 year ago

Version of the custom_component

Latest from HACS Home Assistant 2023.6.3 Supervisor 2023.06.4 Operating System 10.2 Frontend 20230608.0 - latest

Configuration

# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

Describe the bug

image

All other entities are displayed and work well, only EXTERNAL_DEVICE_LOAD is missing

Debug log


This error originated from a custom integration.

Logger: custom_components.victron_ble
Source: custom_components/victron_ble/sensor.py:154
Integration: Victron BLE (documentation, issues)
First occurred: July 4, 2023 at 21:22:21 (46475 occurrences)
Last logged: 10:25:26

Unexpected error updating SmartSolar HQ22114FJ3F data: (<VictronSensor.EXTERNAL_DEVICE_LOAD: 'external_device_load'>, <Units.ELECTRIC_CURRENT_AMPERE: 'A'>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_processor.py", line 278, in async_handle_update
    new_data = self.update_method(update)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/victron_ble/sensor.py", line 151, in sensor_update_to_bluetooth_data_update
    entity_descriptions={
                        ^
  File "/config/custom_components/victron_ble/sensor.py", line 154, in <dictcomp>
    ): SENSOR_DESCRIPTIONS[
       ^^^^^^^^^^^^^^^^^^^^
KeyError: (<VictronSensor.EXTERNAL_DEVICE_LOAD: 'external_device_load'>, <Units.ELECTRIC_CURRENT_AMPERE: 'A'>)
nikakoy131 commented 12 months ago

Finally, I get this working. Nothing helps me until I ask chatGPT for help )) He says to me -

The code you provided appears to be mostly correct. However, there is one issue that may be causing the KeyError you encountered.

In the sensor_update_to_bluetooth_data_update function, when creating the entity_descriptions dictionary, you're using the description.native_unit_of_measurement as part of the key to access SENSOR_DESCRIPTIONS. However, in the SENSOR_DESCRIPTIONS dictionary, some of the keys have a value of None for the native unit of measurement.

To fix the issue, you can modify the code as follows:

entity_descriptions = {
    PassiveBluetoothEntityKey(
        device_key.key, device_key.device_id
    ): SENSOR_DESCRIPTIONS.get(
        (description.device_key.key, description.native_unit_of_measurement),
        SENSOR_DESCRIPTIONS.get((description.device_key.key, None))
    )
    for device_key, description in sensor_update.entity_descriptions.items()
    if description.device_key
}

This change allows the code to first try accessing SENSOR_DESCRIPTIONS with both the device key and the native unit of measurement. If that key is not found, it falls back to using the device key and None as the unit of measurement.

This modification should help resolve the KeyError you encountered. Let me know if you need further assistance!

It helped me. Currently, the integration works fine, and shows me missing entity :-) Maybe this helps someone PS: I'm totally not familiar with Python, so I totally don't know what's going on, so use this at your own risk

wmichael3 commented 8 months ago

I had the exact same problem with the SmartSolar controller and this solution fixed it for me. Thanks much!

promofu commented 8 months ago

I see a very similar issue here when activating the "midpoint_voltage" function on the SmartShunt:

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.victron_ble
Source: components/bluetooth/passive_update_processor.py:585
Integration: Victron BLE (documentation, issues)
First occurred: 09:41:21 (4343 occurrences)
Last logged: 22:58:36

Unexpected error updating SmartShunt HQ2209R7EDE data: (<VictronSensor.MIDPOINT_VOLTAGE: 'midpoint_voltage'>, <Units.ELECTRIC_POTENTIAL_VOLT: 'V'>)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_processor.py", line 585, in async_handle_update
    new_data = self.update_method(update)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/victron_ble/sensor.py", line 151, in sensor_update_to_bluetooth_data_update
    entity_descriptions={
                        ^
  File "/config/custom_components/victron_ble/sensor.py", line 154, in <dictcomp>
    ): SENSOR_DESCRIPTIONS[
       ^^^^^^^^^^^^^^^^^^^^
KeyError: (<VictronSensor.MIDPOINT_VOLTAGE: 'midpoint_voltage'>, <Units.ELECTRIC_POTENTIAL_VOLT: 'V'>)

and the above fix worked for me as well.

promofu commented 8 months ago

... of course this does not add the reading of the midpoint voltage into HA it seems ... but at least the Device is correctly queried and does not fail as a whole.

alwien commented 2 months ago

Found this while troubleshooting why my vehicle based Victron Battery Sense was picked up 100% when I arrive home but my Smart Solar was not auto-connecting and would only get a few data points in after I'd reset the integration manually before hanging again.

After making the code change my External Device Load sensor exits and the device seems to function well.

Thanks for the fix. This is a fantastic integration overall so I'm happy to have it working with both devices.

patman15 commented 3 weeks ago

Has anyone done a PR for this issue? I just ran into it as well.