PiotrMachowski / Home-Assistant-custom-components-Tauron-AMIplus

This sensor uses unofficial API to get energy usage and generation data from https://elicznik.tauron-dystrybucja.pl.
MIT License
138 stars 34 forks source link

Polling frequency #38

Closed GregoryKowalik closed 2 years ago

GregoryKowalik commented 2 years ago

Hi Piotr,

how often the integration does poll for data on eLicznik? Can I modify the frequency by my own? It appears that scan_interval parameter in YAML config is not working.

Thanks Greg

rodaman commented 2 years ago

I have exactly the same problem. My Tauron account is blocked every day becouse too often poll. Message is "Przekroczono maksymalną ilość logowań na dobę". Is it possible to poll once a day for exemple? Where is "scan_interval" config?

GregoryKowalik commented 2 years ago

I found something interesting in const.py file located in the integration directory. Lines: 27,29,36,43,50,57,64. There is "timedelta(hours=n)" line in the code. I'm curious what it does... Speaking of the errors in the log I found 21 occurrences of them within only 2 hours which is odd.

PiotrMachowski commented 2 years ago

@GregoryKowalik These are values that are used to limit calls to eLicznik. scan_interval should work if it's set to value greater then 6h.

Which errors are you talking about?

GregoryKowalik commented 2 years ago

Thanks Piotr, good to know. There are errors like this:

Logger: homeassistant.helpers.entity
Source: custom_components/tauron_amiplus/sensor.py:165
Integration: Tauron AMIplus (documentation, issues)
First occurred: 10:48:23 (28 occurrences)
Last logged: 13:48:41
Update for sensor.tauron_amiplus_consumption_monthly fails
Update for sensor.tauron_amiplus_consumption_yearly fails
Update for sensor.tauron_amiplus_generation_daily fails
Update for sensor.tauron_amiplus_generation_monthly fails
Update for sensor.tauron_amiplus_generation_yearly fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 468, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 658, in async_device_update
    raise exc
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 277, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/tauron_amiplus/sensor.py", line 222, in _update
    self.update_configuration()
  File "/config/custom_components/tauron_amiplus/sensor.py", line 258, in update_configuration
    config = TauronAmiplusSensor.calculate_configuration(self.username, self.password, self.meter_id,
  File "/config/custom_components/tauron_amiplus/sensor.py", line 165, in calculate_configuration
    json_data = response.json()
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

And eLicznik encounters some issues now with data. I don't have data since 3 days in eLicznik.

PiotrMachowski commented 2 years ago

How many sensors from this integration do you have? (on the same account)

GregoryKowalik commented 2 years ago

There are 7 sensors created (3 for consumption, 3 for generation and 1 for zone)

PiotrMachowski commented 2 years ago

The problem with current implementation of this integration is that every sensor is updated separately -> each one has to log in, which creates a burst of 6 attempts to log in every 6 hour. I have to implement mechanism to use 1 session for all sensors. It is not hard, but I don't have enough time right now.

GregoryKowalik commented 2 years ago

Sounds like a plan. Many thanks Piotr and we will be awaiting new version of the very handy integration :)

pbabilas commented 2 years ago

Hi, I'd like to refresh this issue. Why integration pools data every 6 hours? can it be set to hour by hour? I've tried it, by changing const with sensors but no luck.

GregoryKowalik commented 2 years ago

Fair point, nevertheless more important change would be to have all polls under one login session. Currently if you have 6 sensors the integration authenticates in eLicznik on every sensor update which very fast leads to daily logins limit breach. That's why the integration polling interval is every 6 hours as far as I understand it. So we keep our fingers crossed for that change to make happen :)

PiotrMachowski commented 2 years ago

@pbabilas data on elicznik page is refreshed only ~2-3 times a day, so increasing poll interval doesn't make much sense anyway

GregoryKowalik commented 2 years ago

Good point Piotr, nevertheless it would be great if the integration works faster. I'm still getting sensor update timeouts in the logs and by this system boots much slower.

pbabilas commented 2 years ago

@pbabilas data on elicznik page is refreshed only ~2-3 times a day, so increasing poll interval doesn't make much sense anyway

Hmm, as I've checked elicznik api returns whole day back hour by hour, so we have all data every check, or I'm wrong?

PiotrMachowski commented 2 years ago

Hmm, as I've checked elicznik api returns whole day back hour by hour, so we have all data every check, or I'm wrong?

All hourly data for the previous day is uploaded to elicznik at once and since there is no possibility to store data in HA with a specific timestamp (only "now") all these values are summed in a daily sensor.

GregoryKowalik commented 2 years ago

That's the biggest issue with the way eLicznik updates data. Therefore I use ApexCharts and set the offset to -1day to properly match eLicznik readings to the x axis.

pbabilas commented 2 years ago

That's the biggest issue with the way eLicznik updates data. Therefore I use ApexCharts and set the offset to -1day to properly match eLicznik readings to the x axis.

Ooo, can you say more about this solution?

GregoryKowalik commented 2 years ago

That's the biggest issue with the way eLicznik updates data. Therefore I use ApexCharts and set the offset to -1day to properly match eLicznik readings to the x axis.

Ooo, can you say more about this solution?

Sure :) First of all check this out: ApexCard Then install this card in your HA instance via HACS and let me know so I will provide you with my example :)

pbabilas commented 2 years ago

already got it installed. It's only configured buy yaml?

PiotrMachowski commented 2 years ago

@GregoryKowalik buuuut you still don't have hourly data, right?

GregoryKowalik commented 2 years ago

@GregoryKowalik buuuut you still don't have hourly data, right?

Correct, but I don't need it as I have Shelly 3EM 3-phase power meter with very frequent updates.

GregoryKowalik commented 2 years ago

already got it installed. It's only configured buy yaml?

Yes, you can use my example below. There are 3 series but you might be interested in the first one (entity: sensor.tauron_amiplus_consumption_daily)

type: custom:apexcharts-card
apex_config:
  plotOptions:
    bar:
      borderRadius: 10
  chart:
    height: 400px
    animations:
      enabled: true
      easing: easeinout
      speed: 800
      dynamicAnimation:
        enabled: true
        delay: 350
      animateGradually:
        enabled: true
        delay: 150
  grid:
    show: false
  yaxis:
    show: false
  legend:
    fontSize: 15
    labels:
      colors: darkgrey
  xaxis:
    labels:
      format: dd
      style:
        fontSize: 15px
        colors: darkgrey
  tooltip:
    x:
      show: false
      format: dddd, dd MMMM
      labels:
        format: dddd
update_interval: 1min
graph_span: 30d
span:
  end: day
  offset: '-1day'
cache: false
header:
  show: true
  title: Energia kWh (Miesiąc)
  show_states: false
  colorize_states: true
series:
  - entity: sensor.tauron_amiplus_consumption_daily
    type: column
    name: Energia Pobrana z Sieci
    float_precision: 1
    group_by:
      func: last
      duration: 1d
      fill: 'null'
    show:
      legend_value: false
      datalabels: true
  - entity: sensor.solaredge_energy_today_kwh
    type: column
    name: Energia Wyprodukowana
    float_precision: 1
    group_by:
      func: max
      duration: 1d
    show:
      legend_value: false
      datalabels: true
  - entity: sensor.tauron_amiplus_generation_daily
    type: column
    name: Energia Oddana do Sieci
    float_precision: 1
    color: green
    group_by:
      func: last
      duration: 1d
    show:
      legend_value: false
      datalabels: true
PiotrMachowski commented 2 years ago

Fixed in v2.1.0