GuyKh / iec-custom-component

HomeAssistant Custom Component for IEC
MIT License
128 stars 5 forks source link

Failed to fetch data from devices_by_id, falling back to Masa API #184

Open elad-bar opened 4 days ago

elad-bar commented 4 days ago

System Health details

System Information

version core-2024.10.2
installation_type Home Assistant Core
dev false
hassio false
docker false
user root
virtualenv true
python_version 3.12.3
os_name Linux
os_version 6.8.12-1-pve
arch x86_64
timezone Asia/Jerusalem
config_dir /root/.homeassistant
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.1 Stage | running Available Repositories | 1441 Downloaded Repositories | 47
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | March 17, 2025 at 2:00 AM relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | true remote_server | eu-central-1-15.ui.nabu.casa certificate_status | ready instance_id | --- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 4 -- | -- resources | 19 views | 17 mode | storage
Recorder oldest_recorder_run | October 11, 2024 at 11:11 AM -- | -- current_recorder_run | October 13, 2024 at 9:01 AM estimated_db_size | 1551.14 MiB database_engine | mysql database_version | 11.3.2
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

Error is being logged every HA restart

Reproduction steps

  1. Restart HA

Debug logs

2024-10-13 09:16:16.904 
 2024-10-13 09:16:16.903 DEBUG (MainThread) [iec_api.commons] HTTP GET Response <200>: {"pageSize":10,"pageNumber":1,"moreRecords":false,"totalRecords":1,"pageCookie":0,"items":[{"accountId":""***","accountType":279830001,"accountName":"בר אלעד חביב","addressId":""***","areaId":""***","regionId":""***","fullAddress":""***","siteId":"***","iec_ContractNumber":""***","siteType":16,"activeConnections":1,"connections":[{"connectionId":""***","connectionNumber":""***","hasOpenOrders":false,"shovalOpenOrder":null,"powerConnectionSize":279830009,"isLowVolte":true,"isCanIncrease":false,"meterId":""***","meterNumber":""***","voltType":279830001,"currentReader":"27.71","currentAmpere":null,"currentVoltLevel":{"id":null,"name":null}}],"possible2ShiftBit":true,"building":{"id":""***","name":"masaapi","hasSAOrders":null,"shovalSAOrder":null,"multiResidentialBuilding":false,"isMaxPublicSitesSum":false,"isResidentialBuilding":false,"numOfRelatedSitesInt":1},"backuplineOrder":null,"hasBackuplineOrders":false}]}

2024-10-13 09:16:15.885 
 2024-10-13 09:16:15.883 DEBUG (MainThread) [iec_api.commons] HTTP GET: https://masaapi-wa.azurewebsites.net/equipments/get?accountId=***&pageNumber=1&pageSize=10
2024-10-13 09:16:15.885 
 2024-10-13 09:16:15.882 DEBUG (MainThread) [iec_api.commons] HTTP GET Response <200>: {"regions":[{"regionId":"909a5d57-d7db-ea11-a813-000d3aabca53","name":"חיפה והצפון","code":7},{"regionId":"32d0f7a8-d7db-ea11-a813-000d3aabca53","name":"ירושלים והנגב","code":9},{"regionId":"788f411f-756e-e811-8101-1458d043c6c0","name":"דן והחוף","code":8},{"regionId":"26d3dc4f-756e-e811-8101-1458d043c6c0","name":"מחוז דרום","code":3},{"regionId":"e3693c7a-756e-e811-8101-1458d043c6c0","name":"מחוז חיפה","code":1},{"regionId":"dec95d9e-756e-e811-8101-1458d043c6c0","name":"מחוז ירושלים","code":6},{"regionId":"3a4e6dc2-756e-e811-8101-1458d043c6c0","name":"מחוז צפון","code":2}],"connectionSizeTypes":[{"id":"7ddab873-671f-e911-a961-000d3a29f1fd","name":"6","sizeType":279830001,"voltType":279830001,"code":"Z01","description":"חד פאזי 6 אמפר (1X6)","index":1,"isEnlargeable":true,"isAllowResidence":false},{"id":"81dab873-671f-e911-a961-000d3a29f1fd","name":"16","sizeType":279830002,"voltType":279830001,"code":"Z02","description":"חד פאזי 16 אמפר (1X16)","index":2,"isEnlargeable":true,"isAllowResidence":false},{"id":"82dab873-671f-e911-a961-000d3a29f1fd","name":"25","sizeType":279830003,"voltType":279830001,"code":"Z03","description":"חד פאזי 25 אמפר (1X25)","index":3,"isEnlargeable":false,"isAllowResidence":null},{"id":"83dab873-671f-e911-a961-000d3a29f1fd","name":"35","sizeType":279830004,"voltType":279830001,"code":"Z04","description":"חד פאזי 35 אמפר (1X35)","index":4,"isEnlargeable":false,"isAllowResidence":null},{"id":"84dab873-671f-e911-a961-000d3a29f1fd","name":"40","sizeType":279830005,"voltType":279830001,"code":"Z05","description":"חד פאזי 40 אמפר (1X40)","index":5,"isEnlargeable":true,"isAllowResidence":true},{"id":"85dab873-671f-e911-a961-000d3a29f1fd","name":"3X25","sizeType":279830006,"voltType":279830001,"code":"Z06","description":"תלת פאזי 25 אמפר (3X25)","index":6,"isEnlargeable":true,"isAllowResidence":true},{"id":"86dab873-671f-e911-a961-000d3a29f1fd","name":"3X26","sizeType":279830007,"voltType":279830001,"code":"Z07","description":"תלת פאזי 26 אמפר (3X26)","index":7,"isEnlargeable":false,"isAllowResidence":null},{"id":"87dab873-671f-e911-a961-000d3a29f1fd","name":"3X35","sizeType":279830008,"voltType":279830001,"code":"Z08","description":"תלת פאזי 35 אמפר (3X35)","index":8,"isEnlargeable":false,"isAllowResidence":null},{"id":"88dab873-671f-e911-a961-000d3a29f1fd","name":"3X40","sizeType":279830009,"voltType":279830001,"code":"Z09","description":"תלת פאזי 40 אמפר (3X40)","index":9,"isEnlargeable":true,"isAllowResidence":true},{"id":"89dab873-671f-e911-a961-000d3a29f1fd","name":"3X50","sizeType":279830010,"voltType":279830001,"code":"Z10","description":"תלת פאזי 50 אמפר (3X50)","index":10,"isEnlargeable":false,"isAllowResidence":null},{"id":"8adab873-671f-e911-a961-000d3a29f1fd","name":"3X63","sizeType":279830011,"voltType":279830001,"code":"Z11","description":"תלת פאזי 63 אמפר (3X63)","index":11,"isEnlargeable":true,"isAllowResidence":true},{"id":"8bdab873-671f-e911-a961-000d3a29f1fd","name":"3X80","sizeType":279830012,"voltType":279830001,"code":"Z12","description":"תלת פאזי 80 אמפר (3X80)","index":12,"isEnlargeable":true,"isAllowResidence":true},{"id":"8cdab873-671f-e911-a961-000d3a29f1fd","name":"3X100","sizeType":279830013,"voltType":279830001,"code":"Z13","description":"תלת פאזי 100 אמפר (3X100)","index":13,"isEnlargeable":true,"isAllowResidence":true},{"id":"8ddab873-671f-e911-a961-000d3a29f1fd","name":"3X125","sizeType":279830014,"voltType":279830001,"code":"Z14","description":"תלת פאזי 125 אמפר (3X125)","index":14,"isEnlargeable":true,"isAllowResidence":true},{"id":"8edab873-671f-e911-a961-000d3a29f1fd","name":"3X160","sizeType":279830015,"voltType":279830001,"code":"Z15","description":"תלת פאזי 160 אמפר (3X160)","index":15,"isEnlargeable":true,"isAllowResidence":true},{"id":"90dab873-671f-e911-a961-000d3a29f1fd","name":"3X200","sizeType":279830016,"voltType":279830001,"code":"Z16","description":"תלת פאזי 200 אמפר (3X200)","index":16,"isEnlargeable":true,"isAllowResidence":true},{"id":"91dab873-671f-e911-a961-000d3a29f1fd","name":"3X250","sizeType":279830017,"voltType":279830001,"code":"Z17","description":"תלת פאזי 250 אמפר (3X250)","index":17,"isEnlargeable":true,"isAllowResidence":true},{"id":"92dab873-671f-e911-a961-000d3a29f1fd","name":"3X315","sizeType":279830018,"voltType":279830001,"code":"Z18","description":"תלת פאזי 315 אמפר (3X315)","index":18,"isEnlargeable":true,"isAllowResidence":true},{"id":"94dab873-671f-e911-a961-000d3a29f1fd","name":"3X350","sizeType":279830019,"voltType":279830001,"code":"Z19","description":"תלת פאזי 350 אמפר (3X350)","index":19,"isEnlargeable":false,"isAllowResidence":null},{"id":"96dab873-671f-e911-a961-000d3a29f1fd","name":"3X400","sizeType":279830020,"voltType":279830001,"code":"Z20","description":"תלת פאזי 400 אמפר (3X400)","index":20,"isEnlargeable":true,"isAllowResidence":false},{"id":"97dab873-671f-e911-a961-000d3a29f1fd","name":"3X500","sizeType":279830021,"voltType":279830001,"code":"Z21","description":"תלת פאזי 500 אמפר (3X500)","index":21,"isEnlargeable":true,"isAllowResidence":false},{"id":"98dab873-671f-e911-a961-000d3a29f1fd","name":"3X630","sizeType":279830022,"voltType":279830001,"code":"Z22","description":"תלת פאזי 630 אמפר (3X630)","index":22,"isEnlargeable":true,"isAllowResidence":false},{"id":"99dab873-671f-e911-a961-000d3a29f1fd","name":"3X800","sizeType":279830023,"voltType":279830001,"code":"Z23","description":"תלת פאזי 800 אמפר (3X800)","index":23,"isEnlargeable":true,"isAllowResidence":false},{"id":"9adab873-671f-e911-a961-000d3a29f1fd","name":"3X910","sizeType":279830024,"voltType":279830001,"code":"Z24","description":"תלת פאזי 910 אמפר (3X910)","index":24,"isEnlargeable":true,"isAllowResidence":false},{"id":"9bdab873-671f-e911-a961-000d3a29f1fd","name":"3X1000","sizeType":279830025,"voltType":279830001,"code":"Z25","description":"תלת פאזי 1000 אמפר (3X1000)","index":25,"isEnlargeable":false,"isAllowResidence":null},{"id":"9cdab873-671f-e911-a961-000d3a29f1fd","name":"3X1030","sizeType":279830026,"voltType":279830001,"code":"Z26","description":"תלת פאזי 1030 אמפר (3X1030)","index":26,"isEnlargeable":false,"isAllowResidence":null},{"id":"9ddab873-671f-e911-a961-000d3a29f1fd","name":"3X1130","sizeType":279830027,"voltType":279830001,"code":"Z27","description":"תלת פאזי 1130 אמפר (3X1130)","index":27,"isEnlargeable":false,"isAllowResidence":null},{"id":"9edab873-671f-e911-a961-000d3a29f1fd","name":"3X1200","sizeType":279830028,"voltType":279830001,"code":"Z28","description":"תלת פאזי 1200 אמפר (3X1200)","index":28,"isEnlargeable":false,"isAllowResidence":null},{"id":"9fdab873-671f-e911-a961-000d3a29f1fd","name":"3X1250","sizeType":279830029,"voltType":279830001,"code":"Z29","description":"תלת פאזי 1250 אמפר (3X1250)","index":29,"isEnlargeable":false,"isAllowResidence":null},{"id":"a0dab873-671f-e911-a961-000d3a29f1fd","name":"3X1260","sizeType":279830030,"voltType":279830001,"code":"Z30","description":"תלת פאזי 1260 אמפר (3X1260)","index":30,"isEnlargeable":false,"isAllowResidence":null},{"id":"a1dab873-671f-e911-a961-000d3a29f1fd","name":"3X1280","sizeType":279830031,"voltType":279830001,"code":"Z31","description":"תלת פאזי 1280 אמפר (3X1280)","index":31,"isEnlargeable":false,"isAllowResidence":null},{"id":"a2dab873-671f-e911-a961-000d3a29f1fd","name":"3X1310","sizeType":279830032,"voltType":279830001,"code":"Z32","description":"תלת פאזי 1310 אמפר (3X1310)","index":32,"isEnlargeable":false,"isAllowResidence":null},{"id":"a3dab873-671f-e911-a961-000d3a29f1fd","name":"3X1400","sizeType":279830033,"voltType":27983
2024-10-13 09:16:14.765 
 2024-10-13 09:16:14.764 DEBUG (MainThread) [iec_api.commons] HTTP GET: https://masaapi-wa.azurewebsites.net/lookup/all
2024-10-13 09:16:14.765 
 2024-10-13 09:16:14.764 DEBUG (MainThread) [iec_api.commons] HTTP GET Response <200>: {"data":[{"accountNumber":"***","accountType":***,"id":"***","email":null,"telephone":null,"governmentNumber":"***","name":"***","viewTypeCode":1}],"reponseDescriptor":{"isSuccess":true,"code":"0","description":""}}
2024-10-13 09:16:14.664 
 2024-10-13 09:16:14.662 DEBUG (MainThread) [iec_api.commons] HTTP GET: https://iecapi.iec.co.il/api/outages/accounts
2024-10-13 09:16:14.663 
 2024-10-13 09:16:14.662 DEBUG (MainThread) [custom_components.iec.coordinator] Last Reading for contract ***, Meter ***: MeterReading(reading=32203, reading_code='25', reading_date=datetime.datetime(2024, 8, 21, 0, 0, tzinfo=<DstTzInfo 'Asia/Jerusalem' IDT+3:00:00 DST>), usage='1533', serial_number=None)
2024-10-13 09:16:14.663 
 2024-10-13 09:16:14.662 DEBUG (MainThread) [custom_components.iec.coordinator] Last Reading for contract ***, Meter ***: MeterReading(reading=123382, reading_code='01', reading_date=datetime.datetime(2023, 6, 15, 0, 0, tzinfo=<DstTzInfo 'Asia/Jerusalem' IDT+3:00:00 DST>), usage='3453', serial_number=None)
2024-10-13 09:16:14.663 
 2024-10-13 09:16:14.661 DEBUG (MainThread) [iec_api.commons] HTTP GET Response <200>: {"data":{"contractAccount":"***","lastMeters":[{"meterReadings":[{"reading":123382,"readingCode":"01","readingDate":"2023-06-15T00:00:00","usage":"3453","serialNumber":null},{"reading":119929,"readingCode":"01","readingDate":"2023-05-04T00:00:00","usage":"2461","serialNumber":null},{"reading":117468,"readingCode":"01","readingDate":"2023-02-27T00:00:00","usage":"3113","serialNumber":null},{"reading":114355,"readingCode":"11","readingDate":"2022-12-29T00:00:00","usage":"2541","serialNumber":null},{"reading":111814,"readingCode":"11","readingDate":"2022-10-30T00:00:00","usage":"4017","serialNumber":null}],"serialNumber":"***","materialNumber":"***","registerNumber":"000000000000000001"},{"meterReadings":[{"reading":32203,"readingCode":"25","readingDate":"2024-08-21T00:00:00","usage":"1533","serialNumber":null},{"reading":28056,"readingCode":"25","readingDate":"2024-06-24T00:00:00","usage":"1296","serialNumber":null},{"reading":26760,"readingCode":"01","readingDate":"2024-05-31T00:00:00","usage":"2907","serialNumber":null},{"reading":26375,"readingCode":"01","readingDate":"2024-05-21T00:00:00","usage":"2907","serialNumber":null},{"reading":23853,"readingCode":"25","readingDate":"2024-04-19T00:00:00","usage":"2475","serialNumber":null},{"reading":21378,"readingCode":"25","readingDate":"2024-02-21T00:00:00","usage":"3338","serialNumber":null},{"reading":18040,"readingCode":"25","readingDate":"2023-12-21T00:00:00","usage":"3294","serialNumber":null},{"reading":14746,"readingCode":"25","readingDate":"2023-10-24T00:00:00","usage":"5491","serialNumber":null},{"reading":9255,"readingCode":"25","readingDate":"2023-08-31T00:00:00","usage":"1241","serialNumber":null},{"reading":8014,"readingCode":"25","readingDate":"2023-08-21T00:00:00","usage":"7860","serialNumber":null},{"reading":154,"readingCode":"03","readingDate":"2023-06-21T00:00:00","usage":"154","serialNumber":null}],"serialNumber":"***","materialNumber":"***","registerNumber":"000000000000000001"}]},"reponseDescriptor":{"isSuccess":true,"code":"00","description":""}}
2024-10-13 09:16:13.371 
 2024-10-13 09:16:13.370 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform solaredgeoptimizers is taking over 10 seconds.
2024-10-13 09:16:10.856 
 2024-10-13 09:16:10.852 DEBUG (MainThread) [iec_api.commons] HTTP GET: https://iecapi.iec.co.il/api/Device/LastMeterReading/***/***
2024-10-13 09:16:10.856 
 2024-10-13 09:16:10.852 DEBUG (MainThread) [custom_components.iec.coordinator] DevicesById Response: Devices(counter_devices=None, mr_type='00')
2024-10-13 09:16:10.856 
 Arguments: (TypeError("'NoneType' object is not subscriptable"),)
2024-10-13 09:16:10.856 
 Message: 'Failed to fetch data from devices_by_id, falling back to Masa API'
2024-10-13 09:16:10.856 
     self.emit(record)
2024-10-13 09:16:10.856 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/util/logging.py", line 41, in handle
2024-10-13 09:16:10.856 
     hdlr.handle(record)
2024-10-13 09:16:10.856 
   File "/usr/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
2024-10-13 09:16:10.856 
     self.callHandlers(record)
2024-10-13 09:16:10.856 
   File "/usr/lib/python3.12/logging/__init__.py", line 1700, in handle
2024-10-13 09:16:10.856 
     self.handle(record)
2024-10-13 09:16:10.856 
   File "/usr/lib/python3.12/logging/__init__.py", line 1684, in _log
2024-10-13 09:16:10.856 
     self._log(WARNING, msg, args, **kwargs)
2024-10-13 09:16:10.856 
   File "/usr/lib/python3.12/logging/__init__.py", line 1551, in warning
2024-10-13 09:16:10.856 
     _LOGGER.warning("Failed to fetch data from devices_by_id, falling back to Masa API", e)
2024-10-13 09:16:10.856 
   File "/root/.homeassistant/custom_components/iec/coordinator.py", line 638, in _estimate_bill
2024-10-13 09:16:10.856 
     total_kva_price, estimated_kwh_consumption = await self._estimate_bill(contract_id, device.device_number,
2024-10-13 09:16:10.856 
   File "/root/.homeassistant/custom_components/iec/coordinator.py", line 423, in _async_update_data
2024-10-13 09:16:10.856 
     self.data = await self._async_update_data()
2024-10-13 09:16:10.856 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
2024-10-13 09:16:10.856 
     await self._async_refresh(
2024-10-13 09:16:10.856 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 281, in async_config_entry_first_refresh
2024-10-13 09:16:10.856 
     await iec_coordinator.async_config_entry_first_refresh()
2024-10-13 09:16:10.856 
   File "/root/.homeassistant/custom_components/iec/__init__.py", line 18, in async_setup_entry
2024-10-13 09:16:10.856 
     result = await component.async_setup_entry(hass, self)
2024-10-13 09:16:10.853 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/config_entries.py", line 594, in async_setup
2024-10-13 09:16:10.853 
     await self.async_setup(hass, integration=integration)
2024-10-13 09:16:10.853 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/config_entries.py", line 742, in async_setup_locked
2024-10-13 09:16:10.853 
     self._context.run(self._callback, *self._args)
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/asyncio/events.py", line 88, in _run
2024-10-13 09:16:10.853 
     handle._run()
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/asyncio/base_events.py", line 1987, in _run_once
2024-10-13 09:16:10.853 
     self._run_once()
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
2024-10-13 09:16:10.853 
     self.run_forever()
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
2024-10-13 09:16:10.853 
     return loop.run_until_complete(setup_and_run_hass(runtime_config))
2024-10-13 09:16:10.853 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/runner.py", line 189, in run
2024-10-13 09:16:10.853 
     exit_code = runner.run(runtime_conf)
2024-10-13 09:16:10.853 
   File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/__main__.py", line 209, in main
2024-10-13 09:16:10.853 
     sys.exit(main())
2024-10-13 09:16:10.853 
   File "/srv/homeassistant/bin/hass", line 8, in <module>
2024-10-13 09:16:10.853 
 Call stack:
2024-10-13 09:16:10.853 
 TypeError: not all arguments converted during string formatting
2024-10-13 09:16:10.853 
           ~~~~^~~~~~~~~~~
2024-10-13 09:16:10.853 
     msg = msg % self.args
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/logging/__init__.py", line 392, in getMessage
2024-10-13 09:16:10.853 
                      ^^^^^^^^^^^^^^^^^^^
2024-10-13 09:16:10.853 
     record.message = record.getMessage()
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/logging/__init__.py", line 703, in format
2024-10-13 09:16:10.853 
            ^^^^^^^^^^^^^^^^^^
2024-10-13 09:16:10.853 
     return fmt.format(record)
2024-10-13 09:16:10.853 
   File "/usr/lib/python3.12/logging/__init__.py", line 999, in format
2024-10-13 09:16:10.852 
           ^^^^^^^^^^^^^^^^^^^
2024-10-13 09:16:10.852 
     msg = self.format(record)
2024-10-13 09:16:10.852 
   File "/usr/lib/python3.12/logging/handlers.py", line 1475, in prepare
2024-10-13 09:16:10.852 
                  ^^^^^^^^^^^^^^^^^^^^
2024-10-13 09:16:10.852 
     self.enqueue(self.prepare(record))
2024-10-13 09:16:10.852 
   File "/usr/lib/python3.12/logging/handlers.py", line 1493, in emit
2024-10-13 09:16:10.852 
 Traceback (most recent call last):
2024-10-13 09:16:10.852 
 During handling of the above exception, another exception occurred:
2024-10-13 09:16:10.852 
 TypeError: 'NoneType' object is not subscriptable
2024-10-13 09:16:10.852 
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
2024-10-13 09:16:10.852 
     last_meter_read = int(devices_by_id.counter_devices[0].last_mr)
2024-10-13 09:16:10.852 
   File "/root/.homeassistant/custom_components/iec/coordinator.py", line 632, in _estimate_bill
2024-10-13 09:16:10.851 
 Traceback (most recent call last):
2024-10-13 09:16:10.851 
 2024-10-13 09:16:10.850 DEBUG (MainThread) [iec_api.commons] HTTP GET Response <200>: {"data":{"counterDevices":null,"mrType":"00"},"reponseDescriptor":{"isSuccess":false,"code":"08","description":"No authorization for this product: PV Product"}}
2024-10-13 09:16:10.851 
 --- Logging error ---
2024-10-13 09:16:09.810 
 2024-10-13 09:16:09.809 DEBUG (MainThread) [iec_api.commons] HTTP GET: https://iecapi.iec.co.il/api/Device/***/***
2024-10-13 09:16:09.810 
 2024-10-13 09:16:09.807 DEBUG (MainThread) [iec_api.commons] HTTP POST Response <200>: {"status":0,"futureConsumptionInfo":{"lastInvoiceDate":null,"currentDate":"2024-10-12","futureConsumption":53.847,"totalImport":35842.651,"totalImportDate":"2024-10-12"},"fromDate":"2024-10-11","toDate":"2024-10-11","totalConsumptionForPeriod":43.373,"totalImportDateForPeriod":"2024-10-11","meterStartDate":"2023-06-16","totalImport":35799.278,"data":[{"status":0,"date":"2024-10-11T00:00:00.000000","value":1.653},{"status":0,"date":"2024-10-11T00:15:00.000000","value":0.567},{"status":0,"date":"2024-10-11T00:30:00.000000","value":0.527},{"status":0,"date":"2024-10-11T00:45:00.000000","value":0.587},{"status":0,"date":"2024-10-11T01:00:00.000000","value":0.544},{"status":0,"date":"2024-10-11T01:15:00.000000","value":0.7},{"status":0,"date":"2024-10-11T01:30:00.000000","value":0.553},{"status":0,"date":"2024-10-11T01:45:00.000000","value":0.574},{"status":0,"date":"2024-10-11T02:00:00.000000","value":0.475},{"status":0,"date":"2024-10-11T02:15:00.000000","value":0.474},{"status":0,"date":"2024-10-11T02:30:00.000000","value":0.494},{"status":0,"date":"2024-10-11T02:45:00.000000","value":0.621},{"status":0,"date":"2024-10-11T03:00:00.000000","value":0.526},{"status":0,"date":"2024-10-11T03:15:00.000000","value":0.469},{"status":0,"date":"2024-10-11T03:30:00.000000","value":0.486},{"status":0,"date":"2024-10-11T03:45:00.000000","value":0.457},{"status":0,"date":"2024-10-11T04:00:00.000000","value":0.49},{"status":0,"date":"2024-10-11T04:15:00.000000","value":0.632},{"status":0,"date":"2024-10-11T04:30:00.000000","value":0.538},{"status":0,"date":"2024-10-11T04:45:00.000000","value":0.49},{"status":0,"date":"2024-10-11T05:00:00.000000","value":0.47},{"status":0,"date":"2024-10-11T05:15:00.000000","value":0.497},{"status":0,"date":"2024-10-11T05:30:00.000000","value":0.496},{"status":0,"date":"2024-10-11T05:45:00.000000","value":0.461},{"status":0,"date":"2024-10-11T06:00:00.000000","value":0.466},{"status":0,"date":"2024-10-11T06:15:00.000000","value":0.658},{"status":0,"date":"2024-10-11T06:30:00.000000","value":0.495},{"status":0,"date":"2024-10-11T06:45:00.000000","value":0.454},{"status":0,"date":"2024-10-11T07:00:00.000000","value":0.328},{"status":0,"date":"2024-10-11T07:15:00.000000","value":0.386},{"status":0,"date":"2024-10-11T07:30:00.000000","value":0.257},{"status":0,"date":"2024-10-11T07:45:00.000000","value":0.386},{"status":0,"date":"2024-10-11T08:00:00.000000","value":0.928},{"status":0,"date":"2024-10-11T08:15:00.000000","value":0.749},{"status":0,"date":"2024-10-11T08:30:00.000000","value":0.288},{"status":0,"date":"2024-10-11T08:45:00.000000","value":0},{"status":0,"date":"2024-10-11T09:00:00.000000","value":0},{"status":0,"date":"2024-10-11T09:15:00.000000","value":0},{"status":0,"date":"2024-10-11T09:30:00.000000","value":0.047},{"status":0,"date":"2024-10-11T09:45:00.000000","value":0},{"status":0,"date":"2024-10-11T10:00:00.000000","value":0},{"status":0,"date":"2024-10-11T10:15:00.000000","value":0},{"status":0,"date":"2024-10-11T10:30:00.000000","value":0},{"status":0,"date":"2024-10-11T10:45:00.000000","value":0},{"status":0,"date":"2024-10-11T11:00:00.000000","value":0},{"status":0,"date":"2024-10-11T11:15:00.000000","value":0},{"status":0,"date":"2024-10-11T11:30:00.000000","value":0},{"status":0,"date":"2024-10-11T11:45:00.000000","value":0},{"status":0,"date":"2024-10-11T12:00:00.000000","value":0},{"status":0,"date":"2024-10-11T12:15:00.000000","value":0},{"status":0,"date":"2024-10-11T12:30:00.000000","value":0},{"status":0,"date":"2024-10-11T12:45:00.000000","value":0},{"status":0,"date":"2024-10-11T13:00:00.000000","value":0},{"status":0,"date":"2024-10-11T13:15:00.000000","value":0},{"status":0,"date":"2024-10-11T13:30:00.000000","value":0},{"status":0,"date":"2024-10-11T13:45:00.000000","value":0},{"status":0,"date":"2024-10-11T14:00:00.000000","value":0},{"status":0,"date":"2024-10-11T14:15:00.000000","value":0},{"status":0,"date":"2024-10-11T14:30:00.000000","value":0},{"status":0,"date":"2024-10-11T14:45:00.000000","value":0},{"status":0,"date":"2024-10-11T15:00:00.000000","value":0},{"status":0,"date":"2024-10-11T15:15:00.000000","value":0.007},{"status":0,"date":"2024-10-11T15:30:00.000000","value":0.037},{"status":0,"date":"2024-10-11T15:45:00.000000","value":0.245},{"status":0,"date":"2024-10-11T16:00:00.000000","value":0.256},{"status":0,"date":"2024-10-11T16:15:00.000000","value":0.243},{"status":0,"date":"2024-10-11T16:30:00.000000","value":0.557},{"status":0,"date":"2024-10-11T16:45:00.000000","value":0.501},{"status":0,"date":"2024-10-11T17:00:00.000000","value":0.557},{"status":0,"date":"2024-10-11T17:15:00.000000","value":0.811},{"status":0,"date":"2024-10-11T17:30:00.000000","value":1.007},{"status":0,"date":"2024-10-11T17:45:00.000000","value":1.391},{"status":0,"date":"2024-10-11T18:00:00.000000","value":0.751},{"status":0,"date":"2024-10-11T18:15:00.000000","value":0.628},{"status":0,"date":"2024-10-11T18:30:00.000000","value":0.515},{"status":0,"date":"2024-10-11T18:45:00.000000","value":0.438},{"status":0,"date":"2024-10-11T19:00:00.000000","value":0.364},{"status":0,"date":"2024-10-11T19:15:00.000000","value":0.61},{"status":0,"date":"2024-10-11T19:30:00.000000","value":0.399},{"status":0,"date":"2024-10-11T19:45:00.000000","value":0.36},{"status":0,"date":"2024-10-11T20:00:00.000000","value":0.344},{"status":0,"date":"2024-10-11T20:15:00.000000","value":0.366},{"status":0,"date":"2024-10-11T20:30:00.000000","value":0.597},{"status":0,"date":"2024-10-11T20:45:00.000000","value":1.35},{"status":0,"date":"2024-10-11T21:00:00.000000","value":1.185},{"status":0,"date":"2024-10-11T21:15:00.000000","value":0.98},{"status":0,"date":"2024-10-11T21:30:00.000000","value":0.95},{"status":0,"date":"2024-10-11T21:45:00.000000","value":1.752},{"status":0,"date":"2024-10-11T22:00:00.000000","value":1.241},{"status":0,"date":"2024-10-11T22:15:00.000000","value":0.818},{"status":0,"date":"2024-10-11T22:30:00.000000","value":0.91},{"status":0,"date":"2024-10-11T22:45:00.000000","value":0.747},{"status":0,"date":"2024-10-11T23:00:00.000000","value":1.058},{"status":0,"date":"2024-10-11T23:15:00.000000","value":1.023},{"status":0,"date":"2024-10-11T23:30:00.000000","value":0.663},{"status":0,"date":"2024-10-11T23:45:00.000000","value":0.489}]}

Diagnostics dump

No response

GuyKh commented 4 days ago

@elad-bar is this a WARN or an ERROR?

Also - this looks the IEC API doesn't consider your account as a private producer . Can you check the response of contracts? specifically fromPrivateProducer field (in the response it's fromPativteProducer 🤦🏻 )

elad-bar commented 4 days ago

an assumption why it happens, I have PV panels and i'm producing on top of consuming on the same meter, maybe bill estimation is not supported for PV Products device type (3) as there is no isolation between incoming and outgoing support by IEC.

more details about the questions: it looks like unhandled error, weird thing about this error is - it is not available in the regular log of HA, it is being catch as system error (sent to my Syslog Server), I can see that the function that it happens in is _estimate_bill line 632 but there is an issue logging it as states in the exception:

File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/util/logging.py", line 41, in handle

the root cause is this line:

last_meter_read = int(devices_by_id.counter_devices[0].last_mr)

the response of devices by devices id is:

{
    "data": {
        "counterDevices": null,
        "mrType": "00"
    },
    "reponseDescriptor": {
        "isSuccess": false,
        "code": "08",
        "description": "No authorization for this product: PV Product"
    }
}

which makes extracting the last_mr of the first device to fail (it is null / None as stated in the error), according to the error in the description of the request - No authorization for this product: PV Product.

regarding the second question - fromPativteProducer is false

Response of contract:

{
    "data": {
        "contracts": [
            {
                "address": "***",
                "contractId": "***",
                "dueDate": "1900-01-01",
                "totalDebt": 0.0,
                "frequency": 2,
                "status": 1,
                "fromPativteProducer": false,
                "cityCode": "***",
                "cityName": "***",
                "streetCode": "***",
                "streetName": "***",
                "houseNumber": "***",
                "debtForInvoicesDueDateNotPassed": 0.0,
                "isTouz": false,
                "smartMeter": true,
                "producerType": 2,
                "isDomestic": true
            }
        ],
        "contractAmount": 1,
        "totalToPay": 0.0
    },
    "reponseDescriptor": {
        "isSuccess": true,
        "code": "0",
        "description": ""
    }
}
GuyKh commented 3 days ago

This is indeed a full and correct analysis.

The reason device_by_device_id is needed is for last meter reading, i wonder if I could get this from a different api.

GuyKh commented 3 days ago

Also, @elad-bar - any idea what's producerType:2 - I only saw 1 so far. Is it PV producer?

elad-bar commented 3 days ago

looked over the api/translation files couldn't find what is producer type enums values, found an article about IEC: image

https://www.lnrg.technology/2024/08/07/overview-of-the-israeli-electricity-market-2024/

maybe values are IEC, P2IEC, P2P I'm have PV panels so i'm producer and consumer

tried to find over the api some indication for the estmations, but it's not available so I guess for my consumer type, which is ok, but the code should not allow those entities and claculation for producerType == 2

GuyKh commented 3 days ago

I agree, but I want to cover more ground here. For example - I want to get few questions answered -

  1. Is this your only contract (from API)? Only Account? (I'm assuming you're using just a single customer).
  2. Using GET https://iecapi.iec.co.il/api/Device/{{contract_id}}/{{device_id}} - can you get last meter (consumption) reading?
  3. In IEC API - do you see your current consumption details, if so - (using Network tab in DevTools) - can you find from which API?
elad-bar commented 3 days ago

I have 1 contract in the array of contracts (from Postman), I have 1 device although in the website of IEC I have 2 devices (1 was available up until 1.5 years ago, so I guess it's just for reviewing historical data).

I can see the current consumption and wanted to open another issue for that, I see today's consumption in 1 day lag, meaning, in the result i can see today's consumption, but the data that available in the integration is for yesterday (compared to IEC portal).

Endpoint: https://iecapi.iec.co.il/api/Consumption/RemoteReadingRange/{{contract_id}}

in the following endpoint I can see both devices: https://iecapi.iec.co.il/api/Device/LastMeterReading/{{contract_id}}/{{bp_number}}

If you would like me to check it though Postman you created I think it would be much faster, I can also change the code locally according to your suggestion and test it.

GuyKh commented 3 days ago

Thanks. Ill keep you posted on this thread with check requests.

Which sensor/state do you see in 1 day delay?

elad-bar commented 3 days ago

Today's consumption, Thanks a lot for the integration and the super quick response

GuyKh commented 2 days ago

TodayConsumption is fetched by trying to get (and sum) today's hourly readings. Often you'll see in IEC site discrepancy between hourly view and daily view etc. I think this is what causes this

elad-bar commented 2 days ago

is fetched by trying to get (and sum) today's hourly read

opened another issue about it, there are huge gaps and suggested solution following what is being done in IEC portal (different resolution, no need to aggregate / calculate)

GuyKh commented 1 day ago

@elad-bar - correct, only the data is usually behind the hourly check so this is a mitigation for get a (latest) data