Git Product home page Git Product logo

Comments (8)

r-jordan avatar r-jordan commented on July 18, 2024 1

Gracias por la dedicación @azogue! :-D

from aiopvpc.

azogue avatar azogue commented on July 18, 2024

Hi @r-jordan, sorry I didn't saw this issue, next time cc' me :)

The "_last_day" tag is a bad solution to attach all prices to the sensor attributes in HA, so that sensor has a lot of info to be used with templates, automations and so on.

Internally, it is storing a dict with datetime: price pairs, using UTC timestamps, but those pairs get localized to the local timezone to create a relatively short number of different keys in the state attributes.

Code is here:

for ts_utc, price_h in self._current_prices.items():

        for ts_utc, price_h in self._current_prices.items():
            ts_local = _local(ts_utc)
            if ts_local.day > actual_time.day:
                attr_key = f"price_next_day_{ts_local.hour:02d}h"
            elif ts_local.day < actual_time.day:
                attr_key = f"price_last_day_{ts_local.hour:02d}h"
            else:
                attr_key = f"price_{ts_local.hour:02d}h"
            if attr_key in attributes:  # DST change with duplicated hour :)
                attr_key += "_d"
            attributes[attr_key] = price_h

It is kind of messy...

from aiopvpc.

r-jordan avatar r-jordan commented on July 18, 2024

Hi @azogue !

Yes, I should mention you. Hehe.

I now understand the difference between price_next_day and price_last_day. I guess that if there are no price_next_day attributes that would mean that they couldn't been retrieved from the source.

Also I would expect that when the day change at 0:00h the attributes of the current day become price_last_day but they don't.
I show you the data in the homeassistant database doing a select on the mysql and pasting only the rows of the 21h+2 and 22h+2 hours:

MariaDB [homeassistant]> select last_updated,state,attributes from states where entity_id="sensor.pvpc" order by last_updated desc limit 24;
| 2020-08-03 22:00:00 | 0.04271 | {"attribution": "Data retrieved from api.esios.ree.es by REE", "tariff": "discrimination", "min_price": 0.03953, "min_price_at": 1, "next_best_at": [1, 2, 4, 5, 3, 6, 0, 11, 23, 12, 7, 10, 9, 8, 16, 15, 14, 13, 17, 18, 22, 19, 21, 20], "price_00h": 0.04271, "price_01h": 0.03953, "price_02h": 0.03979, "price_03h": 0.04036, "price_04h": 0.03998, "price_05h": 0.04021, "price_06h": 0.04221, "price_07h": 0.04814, "price_08h": 0.05116, "price_09h": 0.05113, "price_10h": 0.04923, "price_11h": 0.04597, "price_12h": 0.04736, "price_13h": 0.11289, "price_14h": 0.11115, "price_15h": 0.11045, "price_16h": 0.10927, "price_17h": 0.11418, "price_18h": 0.11725, "price_19h": 0.11835, "price_20h": 0.11877, "price_21h": 0.11875, "price_22h": 0.11768, "price_23h": 0.04606, "unit_of_measurement": "\u20ac/kWh", "friendly_name": "PVPC", "icon": "mdi:currency-eur"}                                                                                                                                                                            |
| 2020-08-03 21:00:00 | 0.0462  | {"attribution": "Data retrieved from api.esios.ree.es by REE", "tariff": "discrimination", "min_price": 0.03838, "min_price_at": 4, "next_best_at": [1, 2, 4, 5, 3, 6, 0, 11, 23, 23, 12, 7, 10, 9, 8, 16, 15, 14, 13, 17, 18, 22, 19, 21, 20], "price_00h": 0.04208, "price_01h": 0.0406, "price_02h": 0.04025, "price_03h": 0.03917, "price_04h": 0.03838, "price_05h": 0.03927, "price_06h": 0.04627, "price_07h": 0.05111, "price_08h": 0.05196, "price_09h": 0.05215, "price_10h": 0.05161, "price_11h": 0.05152, "price_12h": 0.05135, "price_13h": 0.11603, "price_14h": 0.11432, "price_15h": 0.11351, "price_16h": 0.11407, "price_17h": 0.11609, "price_18h": 0.11663, "price_19h": 0.11585, "price_20h": 0.11714, "price_21h": 0.11817, "price_22h": 0.11777, "price_23h": 0.0462, "price_next_day_00h": 0.04271, "price_next_day_01h": 0.03953, "price_next_day_02h": 0.03979, "price_next_day_03h": 0.04036, "price_next_day_04h": 0.03998, "price_next_day_05h": 0.04021, "price_next_day_06h": 0.04221, "price_next_day_07h": 0.04814, "price_next_day_08h": 0.05116, "price_next_day_09h": 0.05113, "price_next_day_10h": 0.04923, "price_next_day_11h": 0.04597, "price_next_day_12h": 0.04736, "price_next_day_13h": 0.11289, "price_next_day_14h": 0.11115, "price_next_day_15h": 0.11045, "price_next_day_16h": 0.10927, "price_next_day_17h": 0.11418, "price_next_day_18h": 0.11725, "price_next_day_19h": 0.11835, "price_next_day_20h": 0.11877, "price_next_day_21h": 0.11875, "price_next_day_22h": 0.11768, "price_next_day_23h": 0.04606, "unit_of_measurement": "\u20ac/kWh", "friendly_name": "PVPC", "icon": "mdi:currency-eur"} |

I almost never see the price_last_day attributes. I only saw them at very rare occasion and I don't know why. Any reason about that?

Thank you!

from aiopvpc.

azogue avatar azogue commented on July 18, 2024

Ok, this smells a lot like a timezone mess, probably in my code, so it's worth the investigation :)

Let's see, I'll need some data from you:

  1. What is your local timezone? (I would assume it is Canary Islands or Europe/Madrid, as they are the only ones where these prices operate :), but I may be assuming too much!)
  2. What is the timezone you have set in your HA Core settings and/or in the lovelace UI?
  3. What's the timezone of the timestamps of your MariaDB? (the ones you posted above)

And yes, that is why I said

It is kind of messy...

:)

from aiopvpc.

r-jordan avatar r-jordan commented on July 18, 2024

Ok!

My local timezone is the Spanish peninsula timezone Europe/Madrid. Homeassistant core version running now is 0.112.4 and it's reporting his timezone is also Europe/Madrid in the /config/info page. I've not configured any specific timezone in Lovelace UI. About MariaDB I don't know how to see the timezone but I'm running the MariaDB addon with very standard configuration. When times are queried they are returned in UTC reference time. When 21:00 is returned it's 23:00 in local timezone and when 22:00 is returned it's 00:00 of the next day in local timezone.

Yes, it's a bit messy xD

Anything else just ask me.

from aiopvpc.

azogue avatar azogue commented on July 18, 2024

My local timezone is the Spanish peninsula timezone Europe/Madrid. Homeassistant core version running now is 0.112.4 and it's reporting his timezone is also Europe/Madrid in the /config/info page. I've not configured any specific timezone in Lovelace UI. About MariaDB I don't know how to see the timezone but I'm running the MariaDB addon with very standard configuration. When times are queried they are returned in UTC reference time. When 21:00 is returned it's 23:00 in local timezone and when 22:00 is returned it's 00:00 of the next day in local timezone.

Vale! Creía que estarías más lejos :) Podríamos ser vecinos 😝

Pues si hay una configuración donde tiene que funcionar sin ninguna pega es exactamente esa: horario peninsular!

Para otras timezones, como los precios vienen en bloques de día completo (en península), a la hora de hacer esa generación de atributos surge el concepto de "día anterior" (por ej, en Canarias creo que se ve siempre el "price_last_day_23h"), y si te vas más lejos (aunque no tenga sentido configurar el sensor en Miami!), el nº de horas que caen en el día anterior se eleva.

Sobre el misterio de:

I almost never see the price_last_day attributes. I only saw them at very rare occasion and I don't know why. Any reason about that?

Los verías en el día del cambio de hora, muy posiblemente :), si no, sí sería un bug

Sobre las entradas de la DB:

MariaDB [homeassistant]> select last_updated,state,attributes from states where entity_id="sensor.pvpc" order by last_updated desc limit 24;
| 2020-08-03 22:00:00 | 0.04271 | {"attribution": "Data retrieved from api.esios.ree.es by REE", "tariff": "discrimination", "min_price": 0.03953, "min_price_at": 1, "next_best_at": [1, 2, 4, 5, 3, 6, 0, 11, 23, 12, 7, 10, 9, 8, 16, 15, 14, 13, 17, 18, 22, 19, 21, 20], "price_00h": 0.04271, "price_01h": 0.03953, "price_02h": 0.03979, "price_03h": 0.04036, "price_04h": 0.03998, "price_05h": 0.04021, "price_06h": 0.04221, "price_07h": 0.04814, "price_08h": 0.05116, "price_09h": 0.05113, "price_10h": 0.04923, "price_11h": 0.04597, "price_12h": 0.04736, "price_13h": 0.11289, "price_14h": 0.11115, "price_15h": 0.11045, "price_16h": 0.10927, "price_17h": 0.11418, "price_18h": 0.11725, "price_19h": 0.11835, "price_20h": 0.11877, "price_21h": 0.11875, "price_22h": 0.11768, "price_23h": 0.04606, "unit_of_measurement": "\u20ac/kWh", "friendly_name": "PVPC", "icon": "mdi:currency-eur"}                                                                                                                                                                            |
| 2020-08-03 21:00:00 | 0.0462  | {"attribution": "Data retrieved from api.esios.ree.es by REE", "tariff": "discrimination", "min_price": 0.03838, "min_price_at": 4, "next_best_at": [1, 2, 4, 5, 3, 6, 0, 11, 23, 23, 12, 7, 10, 9, 8, 16, 15, 14, 13, 17, 18, 22, 19, 21, 20], "price_00h": 0.04208, "price_01h": 0.0406, "price_02h": 0.04025, "price_03h": 0.03917, "price_04h": 0.03838, "price_05h": 0.03927, "price_06h": 0.04627, "price_07h": 0.05111, "price_08h": 0.05196, "price_09h": 0.05215, "price_10h": 0.05161, "price_11h": 0.05152, "price_12h": 0.05135, "price_13h": 0.11603, "price_14h": 0.11432, "price_15h": 0.11351, "price_16h": 0.11407, "price_17h": 0.11609, "price_18h": 0.11663, "price_19h": 0.11585, "price_20h": 0.11714, "price_21h": 0.11817, "price_22h": 0.11777, "price_23h": 0.0462, "price_next_day_00h": 0.04271, "price_next_day_01h": 0.03953, "price_next_day_02h": 0.03979, "price_next_day_03h": 0.04036, "price_next_day_04h": 0.03998, "price_next_day_05h": 0.04021, "price_next_day_06h": 0.04221, "price_next_day_07h": 0.04814, "price_next_day_08h": 0.05116, "price_next_day_09h": 0.05113, "price_next_day_10h": 0.04923, "price_next_day_11h": 0.04597, "price_next_day_12h": 0.04736, "price_next_day_13h": 0.11289, "price_next_day_14h": 0.11115, "price_next_day_15h": 0.11045, "price_next_day_16h": 0.10927, "price_next_day_17h": 0.11418, "price_next_day_18h": 0.11725, "price_next_day_19h": 0.11835, "price_next_day_20h": 0.11877, "price_next_day_21h": 0.11875, "price_next_day_22h": 0.11768, "price_next_day_23h": 0.04606, "unit_of_measurement": "\u20ac/kWh", "friendly_name": "PVPC", "icon": "mdi:currency-eur"} |

Son consistentes:

  • A las 21 UTC, 23h locales, el sensor ya tiene los precios del día siguiente, por lo que los attrs incluyen los precios del 8 de marzo y los del 9 de marzo. El state es 0.0462, correspondiendo con "price_23h": 0.0462, y el siguiente precio será el "price_next_day_00h": 0.04271.
  • A las 22 UTC, 0h locales (del día siguiente!), el sensor desecha los precios del 8/marzo y los sustituye por los next_day, volviendo a tener sólo 24 precios en attrs. El state es el esperado, 0.04271, coincidente con "price_00h": 0.04271.

from aiopvpc.

r-jordan avatar r-jordan commented on July 18, 2024

Hola Eugenio! Pues sí podríamos ser vecinos :-)

Disculpa que no te haya contestado hasta ahora. Comprendí completamente tu explicación. Pero resulta que ayer ocurrió de nuevo el fallo que he tenido alguna vez esporádica y se trata que aparece price_last_day en lugar de price_next_day. Estos son los datos recogidos en la base de datos las 21:00 que es cuando se reciben los datos del día siguiente desde la API de REE:

| 2020-08-31 19:00:00 | 0.13514 | {"attribution": "Data retrieved from api.esios.ree.es by REE", "tariff": "discrimination", "min_price": 0.04093, "min_price_at": 2, "next_best_at": [3, 2, 4, 1, 23, 5, 0, 23, 6, 12, 10, 8, 9, 7, 11, 22, 19, 14, 15, 20, 18, 16, 17, 13, 21, 22, 21], "price_00h": 0.04546, "price_01h": 0.04274, "price_02h": 0.04093, "price_03h": 0.04099, "price_04h": 0.04206, "price_05h": 0.04708, "price_06h": 0.05829, "price_07h": 0.05508, "price_08h": 0.05604, "price_09h": 0.05507, "price_10h": 0.05138, "price_11h": 0.05016, "price_12h": 0.05489, "price_13h": 0.12197, "price_14h": 0.12187, "price_15h": 0.12167, "price_16h": 0.1215, "price_17h": 0.12199, "price_18h": 0.12355, "price_19h": 0.12583, "price_20h": 0.12977, "price_21h": 0.13514, "price_22h": 0.12974, "price_23h": 0.05729, "price_last_day_00h": 0.05503, "price_last_day_01h": 0.04995, "price_last_day_02h": 0.04856, "price_last_day_03h": 0.04746, "price_last_day_04h": 0.04872, "price_last_day_05h": 0.05142, "price_last_day_06h": 0.06115, "price_last_day_07h": 0.06345, "price_last_day_08h": 0.06285, "price_last_day_09h": 0.06326, "price_last_day_10h": 0.06197, "price_last_day_11h": 0.06448, "price_last_day_12h": 0.06177, "price_last_day_13h": 0.12661, "price_last_day_14h": 0.12395, "price_last_day_15h": 0.12423, "price_last_day_16h": 0.12583, "price_last_day_17h": 0.12649, "price_last_day_18h": 0.12513, "price_last_day_19h": 0.12317, "price_last_day_20h": 0.12498, "price_last_day_2 1h": 0.12744, "price_last_day_22h": 0.12148, "price_last_day_23h": 0.05103, "unit_of_measurement": "\u20ac/kWh", friendly_name": "PVPC", "icon": "mdi:currency-eur"} |

Los datos de las siguientes horas son muy similares hasta que llegan las doce de la noche cuando los precios de price_last_day se convierten en los price del día actual como se puede ver en los datos recogidos en la base de datos a las 00:00:

| 2020-08-31 22:00:00 | 0.05503 | {"attribution": "Data retrieved from api.esios.ree.es by REE", "tariff": "discrimination", "min_price": 0.04746, "min_price_at": 3, "next_best_at": [3, 2, 4, 1, 23, 5, 0, 6, 12, 10, 8, 9, 7, 11, 22, 19, 14, 15, 20, 18, 16, 17, 13, 21], "price_00h": 0.05503, "price_01h": 0.04995, "price_02h": 0.04856, "price_03h": 0.04746, "price_04h": 0.04872, "price_05h": 0.05142, "price_06h": 0.06115, "price_07h": 0.06345, "price_08h": 0.06285, "price_09h": 0.06326, "price_10h": 0.06197, "price_11h": 0.06448, "price_12h": 0.06177, "price_13h": 0.12661, "price_14h": 0.12395, "price_15h": 0.12423, "price_16h": 0.12583, "price_17h": 0.12649, "price_18h": 0.12513, "price_19h": 0.12317, "price_20h": 0.12498, "price_21h": 0.12744, "price_22h": 0.12148, "price_23h": 0.05103, "unit_of_measurement": "\u20ac/kWh", "friendly_name": "PVPC", "icon": "mdi:currency-eur"}|

No sé si le puedes dar una explicación a este comportamiento tan extraño.

Gracias por todo!

from aiopvpc.

azogue avatar azogue commented on July 18, 2024

aparece price_last_day en lugar de price_next_day

Hola @r-jordan, por fin he tenido algo de tiempo y le he pegado una revisioncilla a la librería, creo q he solucionado este problema (en #14), que se daba en los cambios de mes (era una cosa bastante tonta por mi parte, sorry about that 😥)

Trataré de hacer un PR en HA para actualizar a v2.1.0 próximamente...

Cierro esta issue :)

from aiopvpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.