Closed elad-bar closed 1 week ago
That's not 100% accurate. There are multiple "ways" to get Today's consumption. One would be get today's hourly and then calculate the total, other would be to get a daily (resolution=3) readings (from IEC API) and get Today/Yesterdays totals, as provided by IEC API. Currently, the way it works is the latter.
You can confirm this by checking IEC site for the same data and see the same discrepencies.
I'm sure it can be done using aggregation, but the result in my component is that there is huge gap, when comparing the sensor with data from iec portal, If more data is need will provide it
Make sure you compare the data from IEC portal - looking at daily usage, not hourly
Sure, the comparison was shared when I opened the ticket, including yesterday's data in IEC portal and the sensors
Can you try to replicate this test yourself (use this). Compare the values with resolution=1 and resolution=3 from today. And see if this correlates to either IEC site or what you see in HA
Will try to do that later or tomorrow and will share the result, thanks
Check that issue and found based on the logs that for today, it requests date for 2 date 04/11 (today) + 02/11 (2 days ago), looking at those 2 days with 2 resolutions provides intresting finding.
Before diving into details, I based my requests on the logs from HA:
2024-11-04 08:49:25.290 DEBUG (MainThread) [iec_api.commons] HTTP Content POST: b'{"meterSerialNumber":"***","meterCode":"***","lastInvoiceDate":"2024-11-02","fromDate":"2024-11-02","resolution":1}'
2024-11-04 08:49:23.839 DEBUG (MainThread) [iec_api.commons] HTTP Content POST: b'{"meterSerialNumber":"***","meterCode":"***","lastInvoiceDate":"2024-11-04","fromDate":"2024-11-04","resolution":1}'
Below are the requests and responses, including my findings.
for 02/11 - result is the same with resolution 1 & 3 Request - Resolution 1:
{
"meterSerialNumber": "{{device_id}}",
"meterCode": "{{device_code}}",
"lastInvoiceDate": "2024-11-02",
"fromDate": "2024-11-02",
"resolution": 1
}
Response - Resolution 1:
{
"status": 0,
"futureConsumptionInfo": {
"lastInvoiceDate": null,
"currentDate": "2024-11-03",
"futureConsumption": 53.63,
"totalImport": 36828.962,
"totalImportDate": "2024-11-03"
},
"fromDate": "2024-11-02",
"toDate": "2024-11-02",
"totalConsumptionForPeriod": 45.888,
"totalImportDateForPeriod": "2024-11-02",
"meterStartDate": "2023-06-16",
"totalImport": 36783.074,
"data": [
{
"status": 0,
"date": "2024-11-02T00:00:00.000000",
"value": 0.562
},
{
"status": 0,
"date": "2024-11-02T00:15:00.000000",
"value": 0.455
},
{
"status": 0,
"date": "2024-11-02T00:30:00.000000",
"value": 0.434
},
{
"status": 0,
"date": "2024-11-02T00:45:00.000000",
"value": 0.413
},
{
"status": 0,
"date": "2024-11-02T01:00:00.000000",
"value": 0.554
},
{
"status": 0,
"date": "2024-11-02T01:15:00.000000",
"value": 0.377
},
{
"status": 0,
"date": "2024-11-02T01:30:00.000000",
"value": 0.427
},
{
"status": 0,
"date": "2024-11-02T01:45:00.000000",
"value": 0.368
},
{
"status": 0,
"date": "2024-11-02T02:00:00.000000",
"value": 0.361
},
{
"status": 0,
"date": "2024-11-02T02:15:00.000000",
"value": 0.332
},
{
"status": 0,
"date": "2024-11-02T02:30:00.000000",
"value": 0.463
},
{
"status": 0,
"date": "2024-11-02T02:45:00.000000",
"value": 0.492
},
{
"status": 0,
"date": "2024-11-02T03:00:00.000000",
"value": 0.325
},
{
"status": 0,
"date": "2024-11-02T03:15:00.000000",
"value": 0.314
},
{
"status": 0,
"date": "2024-11-02T03:30:00.000000",
"value": 0.274
},
{
"status": 0,
"date": "2024-11-02T03:45:00.000000",
"value": 0.387
},
{
"status": 0,
"date": "2024-11-02T04:00:00.000000",
"value": 0.36
},
{
"status": 0,
"date": "2024-11-02T04:15:00.000000",
"value": 0.759
},
{
"status": 0,
"date": "2024-11-02T04:30:00.000000",
"value": 0.336
},
{
"status": 0,
"date": "2024-11-02T04:45:00.000000",
"value": 0.332
},
{
"status": 0,
"date": "2024-11-02T05:00:00.000000",
"value": 0.379
},
{
"status": 0,
"date": "2024-11-02T05:15:00.000000",
"value": 0.458
},
{
"status": 0,
"date": "2024-11-02T05:30:00.000000",
"value": 0.443
},
{
"status": 0,
"date": "2024-11-02T05:45:00.000000",
"value": 0.331
},
{
"status": 0,
"date": "2024-11-02T06:00:00.000000",
"value": 0.29
},
{
"status": 0,
"date": "2024-11-02T06:15:00.000000",
"value": 0.224
},
{
"status": 0,
"date": "2024-11-02T06:30:00.000000",
"value": 0.264
},
{
"status": 0,
"date": "2024-11-02T06:45:00.000000",
"value": 0.016
},
{
"status": 0,
"date": "2024-11-02T07:00:00.000000",
"value": 0
},
{
"status": 1024,
"date": "2024-11-02T07:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T07:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T07:45:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T08:00:00.000000",
"value": 0.063
},
{
"status": 0,
"date": "2024-11-02T08:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T08:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T08:45:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T09:00:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T09:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T09:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T09:45:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T10:00:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T10:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T10:30:00.000000",
"value": 0.03
},
{
"status": 0,
"date": "2024-11-02T10:45:00.000000",
"value": 0.01
},
{
"status": 0,
"date": "2024-11-02T11:00:00.000000",
"value": 0.083
},
{
"status": 0,
"date": "2024-11-02T11:15:00.000000",
"value": 0.292
},
{
"status": 0,
"date": "2024-11-02T11:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T11:45:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T12:00:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T12:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T12:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T12:45:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T13:00:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T13:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T13:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T13:45:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T14:00:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T14:15:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T14:30:00.000000",
"value": 0
},
{
"status": 0,
"date": "2024-11-02T14:45:00.000000",
"value": 0.007
},
{
"status": 0,
"date": "2024-11-02T15:00:00.000000",
"value": 0.061
},
{
"status": 0,
"date": "2024-11-02T15:15:00.000000",
"value": 0.151
},
{
"status": 0,
"date": "2024-11-02T15:30:00.000000",
"value": 0.233
},
{
"status": 0,
"date": "2024-11-02T15:45:00.000000",
"value": 0.373
},
{
"status": 0,
"date": "2024-11-02T16:00:00.000000",
"value": 1.203
},
{
"status": 0,
"date": "2024-11-02T16:15:00.000000",
"value": 1.768
},
{
"status": 0,
"date": "2024-11-02T16:30:00.000000",
"value": 1.105
},
{
"status": 0,
"date": "2024-11-02T16:45:00.000000",
"value": 1.114
},
{
"status": 0,
"date": "2024-11-02T17:00:00.000000",
"value": 1.029
},
{
"status": 0,
"date": "2024-11-02T17:15:00.000000",
"value": 0.687
},
{
"status": 0,
"date": "2024-11-02T17:30:00.000000",
"value": 0.725
},
{
"status": 0,
"date": "2024-11-02T17:45:00.000000",
"value": 0.874
},
{
"status": 0,
"date": "2024-11-02T18:00:00.000000",
"value": 1.102
},
{
"status": 0,
"date": "2024-11-02T18:15:00.000000",
"value": 0.902
},
{
"status": 0,
"date": "2024-11-02T18:30:00.000000",
"value": 1.092
},
{
"status": 0,
"date": "2024-11-02T18:45:00.000000",
"value": 0.998
},
{
"status": 0,
"date": "2024-11-02T19:00:00.000000",
"value": 1.228
},
{
"status": 0,
"date": "2024-11-02T19:15:00.000000",
"value": 0.913
},
{
"status": 0,
"date": "2024-11-02T19:30:00.000000",
"value": 1.006
},
{
"status": 0,
"date": "2024-11-02T19:45:00.000000",
"value": 0.898
},
{
"status": 0,
"date": "2024-11-02T20:00:00.000000",
"value": 1.832
},
{
"status": 0,
"date": "2024-11-02T20:15:00.000000",
"value": 1.36
},
{
"status": 0,
"date": "2024-11-02T20:30:00.000000",
"value": 0.965
},
{
"status": 0,
"date": "2024-11-02T20:45:00.000000",
"value": 1.019
},
{
"status": 0,
"date": "2024-11-02T21:00:00.000000",
"value": 2.145
},
{
"status": 0,
"date": "2024-11-02T21:15:00.000000",
"value": 1.301
},
{
"status": 0,
"date": "2024-11-02T21:30:00.000000",
"value": 1.004
},
{
"status": 0,
"date": "2024-11-02T21:45:00.000000",
"value": 1.176
},
{
"status": 0,
"date": "2024-11-02T22:00:00.000000",
"value": 1.193
},
{
"status": 0,
"date": "2024-11-02T22:15:00.000000",
"value": 1.03
},
{
"status": 0,
"date": "2024-11-02T22:30:00.000000",
"value": 0.987
},
{
"status": 0,
"date": "2024-11-02T22:45:00.000000",
"value": 1.053
},
{
"status": 0,
"date": "2024-11-02T23:00:00.000000",
"value": 0.563
},
{
"status": 0,
"date": "2024-11-02T23:15:00.000000",
"value": 0.563
},
{
"status": 0,
"date": "2024-11-02T23:30:00.000000",
"value": 0.585
},
{
"status": 0,
"date": "2024-11-02T23:45:00.000000",
"value": 0.435
}
]
}
Request - Resolution 3:
{
"meterSerialNumber": "{{device_id}}",
"meterCode": "{{device_code}}",
"lastInvoiceDate": "2024-11-02",
"fromDate": "2024-11-02",
"resolution": 3
}
Response - Resolution 3:
{
"status": 0,
"futureConsumptionInfo": {
"lastInvoiceDate": null,
"currentDate": "2024-11-04",
"futureConsumption": 133.964,
"totalImport": 36899.279,
"totalImportDate": "2024-11-04"
},
"fromDate": "2024-11-01",
"toDate": "2024-11-04",
"totalConsumptionForPeriod": 162.459,
"totalImportDateForPeriod": "2024-11-04",
"meterStartDate": "2023-06-16",
"totalImport": 36899.279,
"data": [
{
"status": 1024,
"date": "2024-11-01T00:00:00.000000",
"value": 28.495
},
{
"status": 1024,
"date": "2024-11-02T00:00:00.000000",
"value": 45.888
},
{
"status": 1024,
"date": "2024-11-03T00:00:00.000000",
"value": 70.317
},
{
"status": 0,
"date": "2024-11-04T00:00:00.000000",
"value": 17.759
}
]
}
for 04/11 - result with resolution 3, is like in IEC portal, with resolution 1, it's empty Request - Resolution 1:
{
"meterSerialNumber": "{{device_id}}",
"meterCode": "{{device_code}}",
"lastInvoiceDate": "2024-11-04",
"fromDate": "2024-11-04",
"resolution": 1
}
Response - Resolution 1:
{
"status": 0,
"futureConsumptionInfo": {
"lastInvoiceDate": null,
"currentDate": "2024-11-03",
"futureConsumption": null,
"totalImport": 36828.962,
"totalImportDate": "2024-11-03"
},
"fromDate": "2024-11-04",
"toDate": "2024-11-04",
"totalConsumptionForPeriod": null,
"totalImportDateForPeriod": "2024-11-03",
"meterStartDate": "2023-06-16",
"totalImport": 36828.962,
"data": []
}
Request - Resolution 3:
{
"meterSerialNumber": "{{device_id}}",
"meterCode": "{{device_code}}",
"lastInvoiceDate": "2024-11-04",
"fromDate": "2024-11-04",
"resolution": 3
}
Response - Resolution 3:
{
"status": 0,
"futureConsumptionInfo": {
"lastInvoiceDate": null,
"currentDate": "2024-11-04",
"futureConsumption": 17.759,
"totalImport": 36899.279,
"totalImportDate": "2024-11-04"
},
"fromDate": "2024-11-01",
"toDate": "2024-11-04",
"totalConsumptionForPeriod": 162.459,
"totalImportDateForPeriod": "2024-11-04",
"meterStartDate": "2023-06-16",
"totalImport": 36899.279,
"data": [
{
"status": 1024,
"date": "2024-11-01T00:00:00.000000",
"value": 28.495
},
{
"status": 1024,
"date": "2024-11-02T00:00:00.000000",
"value": 45.888
},
{
"status": 1024,
"date": "2024-11-03T00:00:00.000000",
"value": 70.317
},
{
"status": 0,
"date": "2024-11-04T00:00:00.000000",
"value": 17.759
}
]
}
reason for that is for resolution 1 - the data that available is only for yesterday - totalImportDateForPeriod=2024-11-03, for resolution 3 - the data is available for today - totalImportDateForPeriod=2024-11-04.
of course there are multiple ways to calculate daily if you have different resolutions, but if you already have it in the specific resolution the sensor should represent why to make the software do more things, offload it to IEC API and get the same results as in their portal.
I have the log and can share it over an email if you would like to see it
to sum it up, when using resolution level 1 - futureConsumptionInfo.currentDate
and futureConsumptionInfo.totalImportDate
are one day before, as opposed to resolution 3 (daily) which is up to date for today.
in addition, the yesterday based in HA on 2 days ago, not yesterday.
my suggestion is to collect data using single API call with resolution 3 - today is always the last item in data
, while the one to the end is yesterday (of course it can be verified with python function of today, and date delta of one day back)
Thanks for the details and the summary. I'll check it further
I switched to use Monthly with today's date for the "Today Usage" sensors. Please confirm with version 0.0.38
Log details (ERROR) This error originated from a custom integration. Logger: custom_components.iec.coordinator Source: helpers/update_coordinator.py:354 integration: Israel Electric Corporation (IEC) (documentation, issues) First occurred: 8:11:20 PM (1 occurrences) Last logged: 8:11:20 PM
Unexpected error fetching Iec data Traceback (most recent call last): File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.homeassistant/custom_components/iec/coordinator.py", line 501, in _async_update_data await self._verify_daily_readings_exist( File "/root/.homeassistant/custom_components/iec/coordinator.py", line 324, in _verify_daily_readings_exist filter( TypeError: 'RemoteReadingResponse' object is not iterable
Woah.... so strange, it seems my changes to coordinator
weren't added.
Fixing in 0.0.38.1
Looks great! Thanks
Another issue, based on the function name I assume it's relatedת after restart it was solved.
Logger: custom_components.iec.coordinator
Source: helpers/update_coordinator.py:354
integration: Israel Electric Corporation (IEC) ([documentation](https://github.com/guykh/iec-custom-component), [issues](https://github.com/guykh/iec-custom-component/issues))
First occurred: 12:28:13 AM (9 occurrences)
Last logged: 8:29:15 AM
Unexpected error fetching Iec data
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.homeassistant/custom_components/iec/coordinator.py", line 503, in _async_update_data
await self._verify_daily_readings_exist(
File "/root/.homeassistant/custom_components/iec/coordinator.py", line 330, in _verify_daily_readings_exist
if desired_date_reading.value <= 0:
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'value'
Fix is on the way
@elad-bar give 0.0.38.2
a shot
with v0.0.38.2:
Logger: custom_components.iec.coordinator
Source: helpers/update_coordinator.py:354
integration: Israel Electric Corporation (IEC) ([documentation](https://github.com/guykh/iec-custom-component), [issues](https://github.com/guykh/iec-custom-component/issues))
First occurred: 11:20:40 AM (1 occurrences)
Last logged: 11:20:40 AM
Unexpected error fetching Iec data
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.homeassistant/custom_components/iec/coordinator.py", line 472, in _async_update_data
daily_readings[device.device_number] = remote_reading.data
^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'data'
@elad-bar We're already at 0.0.40.4. Can you retry with that?
After you wrote it, i was actually with 40.3, upgraded and will update, thanks!
it cannot get loaded
Logger: custom_components.iec.coordinator
Source: custom_components/iec/coordinator.py:181
integration: Israel Electric Corporation (IEC) ([documentation](https://github.com/guykh/iec-custom-component), [issues](https://github.com/guykh/iec-custom-component/issues))
First occurred: 12:21:05 PM (3 occurrences)
Last logged: 12:31:39 PM
Bad logger message: Failed fetching kWh Tariff ((IECError('(Code -1): Failed to communicate with IEC API due to time out: ()'),))
Logger: homeassistant.config_entries
Source: config_entries.py:594
First occurred: 12:24:56 PM (2 occurrences)
Last logged: 12:33:45 PM
Error setting up entry IEC Account (***) for iec
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/config_entries.py", line 594, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.homeassistant/custom_components/iec/__init__.py", line 21, in async_setup_entry
await iec_coordinator.async_config_entry_first_refresh()
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 281, in async_config_entry_first_refresh
await self._async_refresh(
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.homeassistant/custom_components/iec/coordinator.py", line 580, in _async_update_data
) = await self._estimate_bill(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.homeassistant/custom_components/iec/coordinator.py", line 916, in _estimate_bill
distribution_tariff = await self._get_distribution_tariff(phase_count)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.homeassistant/custom_components/iec/coordinator.py", line 210, in _get_distribution_tariff
distribution_tariff = await self.api.get_distribution_tariff(phase)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/iec_api/iec_client.py", line 490, in get_distribution_tariff
return await static_data.get_distribution_tariff(self._session, phase_count)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/iec_api/static_data.py", line 73, in get_distribution_tariff
await _get_tariffs(session)
File "/srv/homeassistant/lib/python3.12/site-packages/iec_api/static_data.py", line 42, in _get_tariffs
response = await commons.send_get_request(session=session, url=GET_KWH_TARIFF_URL)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/iec_api/commons.py", line 116, in send_get_request
resp = await session.get(url=url, headers=headers, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/aiohttp/client.py", line 686, in _request
await resp.start(conn)
File "/srv/homeassistant/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1022, in start
message, payload = await protocol.read() # type: ignore[union-attr]
^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/aiohttp/streams.py", line 643, in read
await self._waiter
asyncio.exceptions.CancelledError: Global task timeout
but i think it's not related to the component, timeout also takes place in IEC portal, will check later
Yeah. Timeouts aren't coming from logic, but from FREAKING BAD API (sorry... a bit frustrated)
System Health details
System Information
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 | 1445 Downloaded Repositories | 47Home 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 | okDashboards
dashboards | 4 -- | -- resources | 19 views | 17 mode | storageRecorder
oldest_recorder_run | October 12, 2024 at 9:17 AM -- | -- current_recorder_run | October 14, 2024 at 4:04 PM estimated_db_size | 2209.73 MiB database_engine | mysql database_version | 11.3.2Spotify
api_endpoint_reachable | ok -- | --Checklist
Describe the issue
I mentioned October 13rd to make sure there is no delay in data so yesterday is the day before
Response of
https://iecapi.iec.co.il/api/Consumption/RemoteReadingRange/{{contract_id}}
with parameters from IEC portal (lastInvoiceDate, fromDate, resolution)Request parameters:
Response:
Data in HA:
Reproduction steps
Debug logs
Diagnostics dump
No response