Add "last period" price value in PVPC integration (pvpc_hourly_pricing)

For some automations and custom sensor usage, it will be very useful to have not only the current price but also the price in the previous period.

Thanks!

Hi @enriqueflogh,

The next version of the PVPC integration has a lot of new attributes (related to the new 2.0TD tariff), but there isn’t a “previous price” attribute, as there are already all the prices for the day coded in specific attributes.

Anyway, you could get that price playing a bit with templates:

{% set current_hour = (states.sensor.date_time.state.split(" ")[1].split(":")[0])|int  %}
{% set last_hour_attr = "price_" + ((current_hour - 1)|string)  + "h" %}
Current hour is {{current_hour}}h, last PVPC price was {{ state_attr("sensor.pvpc", last_hour_attr) }} (in sensor attribute '{{ last_hour_attr }}')

(that outputs “Current hour is 12h, last PVPC price was 0.06679 (in sensor attribute ‘price_11h’)”, and needs the Time & Date integration in addition to the PVPC. Also, it won’t work on day changes :sweat:)

But, if your automations are triggered in hour changes (as that’s when the price changes!), it’s simpler than that, if you use a state changed trigger with the pvpc sensor: the new price is available in the automation under {{ trigger.to_state.state }}, and the previous one can be accessed in {{ trigger.from_state.state }} :wink:

Hi @azogue
Thank you very very much for your time spent on the template and answering me!
I think I will try first with the trigger aproach (because of the “day change” issue with the template approach) following you indications. Good to know that I can get the old and new states of the trigger entity.

Thanks!

Hola @azogue , imagino que a ti también, pero ha llegado un mail de ESIOS indicando que va a cambiar la infraestructura

Hi! @azogue,a new mail has been arrived indicating the new infraestructure for ESIOS


Como usuario/a del API público de esios api.esios.ree.es , le informamos que se va proceder a la migracion de dicho API a una nueva infraestructura.

El interfaz de todas las operaciones del api se mantendrá sin modificaciones, únicamente se produce un cambio en la cabecera donde se indica el token de acceso a la hora de realizar las llamadas al API.

Actualmente el token de acceso al API se incluye en la siguiente cabecera:

  • Authorization: Token token"xxxxxxxxxx"

La nueva cabecera a utilizar es la siguiente:

  • x-api-key: xxxxxxxxxx

Hemos habilitado el siguiente endpoint de test para que pueda realizar las pruebas necesarias una vez adapte sus llamadas: https://apip.esios.ree.es

Las dos cabeceras son compatibles tanto en el sistema actual como en el nuevo, por lo que ya puede dejar preparados desarrollos con ambas cabeceras si lo desea, y tenerlos actualizados para cuando se despliegue en producción el nuevo sistema.