turbokongen / hass-AMS

Custom component reading AMS through MBus adapter into HomeAssistant
42 stars 10 forks source link

Error adding entities for domain sensor with platform ams #48

Closed JLFN closed 3 years ago

JLFN commented 3 years ago

Sensors are not being created Iam running with ser2net on another raspberry pi and and on home assistant server its with socat mounted the serialport it would be nice to add SERIAL TCP support in the future so i dont need to use socat.

I tried to remove and reinstall same issue. Running version: v1.4.2 Same issue with Home Assistant 2021.5.4 and homeassistant 2021.6.4 core_config_entries

                "domain": "ams",
                "title": "Norwegian AMS",
                "data": {
                    "serial_port": "/tmp/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0",
                    "meter_manufacturer": "kamstrup",
                    "parity": "N"
2021-06-14 17:37:30 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.hacs
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams] data read from port=[126, 160, 226, 43, 33, 19, 35, 154, 230, 231, 0, 15, 0, 0, 0, 0, 12, 7, 229, 6, 14, 1, 17, 37, 30, 255, 128, 0, 128, 2, 25, 10, 14, 75, 97, 109, 115, 116, 114, 117, 112, 95, 86, 48, 48, 48, 49, 9, 6, 1, 1, 0, 0, 5, 255, 10, 16, 53, 55, 48, 54, 53, 54, 55, 50, 55, 53, 57, 52, 48, 56, 52, 49, 9, 6, 1, 1, 96, 1, 1, 255, 10, 18, 54, 56, 52, 49, 49, 51, 56, 65, 78, 50, 52, 51, 49, 48, 49, 48, 57, 48, 9, 6, 1, 1, 1, 7, 0, 255, 6, 0, 0, 4, 178, 9, 6, 1, 1, 2, 7, 0, 255, 6, 0, 0, 0, 0, 9, 6, 1, 1, 3, 7, 0, 255, 6, 0, 0, 0, 32, 9, 6, 1, 1, 4, 7, 0, 255, 6, 0, 0, 0, 223, 9, 6, 1, 1, 31, 7, 0, 255, 6, 0, 0, 0, 142, 9, 6, 1, 1, 51, 7, 0, 255, 6, 0, 0, 1, 159, 9, 6, 1, 1, 71, 7, 0, 255, 6, 0, 0, 0, 73, 9, 6, 1, 1, 32, 7, 0, 255, 18, 0, 236, 9, 6, 1, 1, 52, 7, 0, 255, 18, 0, 237, 9, 6, 1, 1, 72, 7, 0, 255, 18, 0, 240, 81, 53, 126]
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] list_type is 25
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] meter_serial, OBIS:[1, 1, 0, 0, 5, 255], Index:(49, 55), Type:10 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type 10: SECRETID, Index:(57, 73)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] meter_type, OBIS:[1, 1, 96, 1, 1, 255], Index:(75, 81), Type:10 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type 10: None, Index:(83, 101)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_active_power_import, OBIS:[1, 1, 1, 7, 0, 255], Index:(103, 109), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 1202, Index:(110, 114)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_active_power_export, OBIS:[1, 1, 2, 7, 0, 255], Index:(116, 122), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 0, Index:(123, 127)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_reactive_power_import, OBIS:[1, 1, 3, 7, 0, 255], Index:(129, 135), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 32, Index:(136, 140)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_reactive_power_export, OBIS:[1, 1, 4, 7, 0, 255], Index:(142, 148), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 223, Index:(149, 153)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_current_l1, OBIS:[1, 1, 31, 7, 0, 255], Index:(155, 161), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 1.42, Index:(162, 166)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_current_l2, OBIS:[1, 1, 51, 7, 0, 255], Index:(168, 174), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 4.15, Index:(175, 179)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_current_l3, OBIS:[1, 1, 71, 7, 0, 255], Index:(181, 187), Type:6 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  6: 0.73, Index:(188, 192)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_voltage_l1, OBIS:[1, 1, 32, 7, 0, 255], Index:(194, 200), Type:18 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  16/18: 236, Index:(201, 203)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_voltage_l2, OBIS:[1, 1, 52, 7, 0, 255], Index:(205, 211), Type:18 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  16/18: 237, Index:(212, 214)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] ams_voltage_l3, OBIS:[1, 1, 72, 7, 0, 255], Index:(216, 222), Type:18 Double OBIS
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams.parsers.kamstrup] Value double OBIS type  16/18: 240, Index:(223, 225)
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams] Got 10 new devices from the serial
2021-06-14 17:37:31 DEBUG (Thread-3) [custom_components.ams] DUMP {'ams_active_power_import': {'state': 1202, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.1.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'W', 'icon': 'mdi:gauge'}}, 'ams_active_power_export': {'state': 0, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.2.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'W', 'icon': 'mdi:gauge'}}, 'ams_reactive_power_import': {'state': 32, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.3.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'VAr', 'icon': 'mdi:gauge'}}, 'ams_reactive_power_export': {'state': 223, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.4.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'VAr', 'icon': 'mdi:gauge'}}, 'ams_current_l1': {'state': 1.42, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.31.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'A', 'icon': 'mdi:current-ac'}}, 'ams_current_l2': {'state': 4.15, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.51.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'A', 'icon': 'mdi:current-ac'}}, 'ams_current_l3': {'state': 0.73, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.71.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'A', 'icon': 'mdi:current-ac'}}, 'ams_voltage_l1': {'state': 236, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.32.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'V', 'icon': 'mdi:flash'}}, 'ams_voltage_l2': {'state': 237, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.52.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'V', 'icon': 'mdi:flash'}}, 'ams_voltage_l3': {'state': 240, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.72.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'V', 'icon': 'mdi:flash'}}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_active_power_import
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_active_power_import DUMP sensor_states {'name': 'ams_active_power_import', 'state': 1202, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.1.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'W', 'icon': 'mdi:gauge'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_active_power_export
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_active_power_export DUMP sensor_states {'name': 'ams_active_power_export', 'state': 0, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.2.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'W', 'icon': 'mdi:gauge'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_reactive_power_import
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_reactive_power_import DUMP sensor_states {'name': 'ams_reactive_power_import', 'state': 32, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.3.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'VAr', 'icon': 'mdi:gauge'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_reactive_power_export
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_reactive_power_export DUMP sensor_states {'name': 'ams_reactive_power_export', 'state': 223, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.4.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'VAr', 'icon': 'mdi:gauge'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_current_l1
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_current_l1 DUMP sensor_states {'name': 'ams_current_l1', 'state': 1.42, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.31.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'A', 'icon': 'mdi:current-ac'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_current_l2
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_current_l2 DUMP sensor_states {'name': 'ams_current_l2', 'state': 4.15, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.51.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'A', 'icon': 'mdi:current-ac'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_current_l3
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_current_l3 DUMP sensor_states {'name': 'ams_current_l3', 'state': 0.73, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.71.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'A', 'icon': 'mdi:current-ac'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_voltage_l1
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_voltage_l1 DUMP sensor_states {'name': 'ams_voltage_l1', 'state': 236, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.32.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'V', 'icon': 'mdi:flash'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_voltage_l2
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_voltage_l2 DUMP sensor_states {'name': 'ams_voltage_l2', 'state': 237, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.52.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'V', 'icon': 'mdi:flash'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Updating sensor ams_voltage_l3
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_voltage_l3 DUMP sensor_states {'name': 'ams_voltage_l3', 'state': 240, 'attributes': {'meter_manufacturer': 'Kamstrup_V0001', 'meter_type': None, 'obis_code': '1.1.72.7.0.255', 'meter_serial': 'SECRETID', 'unit_of_measurement': 'V', 'icon': 'mdi:flash'}}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Hourly sensor ams_active_energy_import added so we can attempt to restore state
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_active_energy_import DUMP sensor_states {'name': 'ams_active_energy_import', 'state': None, 'attributes': None}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Hourly sensor ams_active_energy_export added so we can attempt to restore state
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_active_energy_export DUMP sensor_states {'name': 'ams_active_energy_export', 'state': None, 'attributes': None}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Hourly sensor ams_reactive_energy_import added so we can attempt to restore state
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_reactive_energy_import DUMP sensor_states {'name': 'ams_reactive_energy_import', 'state': None, 'attributes': None}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Hourly sensor ams_reactive_energy_export added so we can attempt to restore state
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Init ams_reactive_energy_export DUMP sensor_states {'name': 'ams_reactive_energy_export', 'state': None, 'attributes': None}
2021-06-14 17:37:31 DEBUG (MainThread) [custom_components.ams.sensor] Trying to add 14 sensors
2021-06-14 17:37:31 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform ams
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 458, in _async_add_entity
    device_info = entity.device_info
  File "/home/homeassistant/.homeassistant/custom_components/ams/sensor.py", line 137, in device_info
    "model": self.ams.meter_type,
  File "/home/homeassistant/.homeassistant/custom_components/ams/__init__.py", line 139, in meter_type
    return self._attrs[const.HAN_METER_TYPE]
KeyError: 'meter_type'
turbokongen commented 3 years ago

Fixed by 5325a094e4e7902df3623b0fc7e558f03f0ed70e in release v1.4.3