Skip to content

Bot that sends energy prices for next day according to the PVPC tariff

Notifications You must be signed in to change notification settings

guigomcha/pvpc_to_telegram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pvpc_to_telegram

Telegram Bot that sends energy prices according to the PVPC webpage. Updates are sent at 20:30 of the day before with the prices per hour in the form of a barchart.

Subscribe at: https://t.me/info_pvpc_spain

Screenshot

Current version of the app is deployed in a Raspberry pi 4 and orchestrated via Node Red: Screenshot

Telegram package

This package makes use of a Telegram bot as handler for the standard logging library. In order to use this you will need to carry out some configurations outside the scope of this repository.

How to create a Telegram Bot and link it to a chat/channel

The process is very well documented online. I found this link (https://dev.to/rizkyrajitha/get-notifications-with-telegram-bot-537l) very easy to follow.

  1. Copy the Bot's token in tokens.json under the 'bot_token' object.
  2. Copy the Chat's token in tokens.json under the 'chats_token' list. More than a single chat can be used seamlessly

Note: It was found required to have sent at least one message to the group/channel in order to fetch the id from 2)

How to create a logging handler for a Telegram Bot

This section of the project is actually forked from https://github.com/dmitryikh/loggingbot with some fixes that I found required for my setup.

Clone my forked repo at least until PR is accepted

  1. git clone https://github.com/Guillelerial/loggingbot.git

How to configure the scrapper

Two scrappers are implemented and configurable by manually replacing which implementation is used in controllers/api.py (scrapper argument to PVPC class). In previous versions the web Tarifa Luz Hora was used since it does not require any auth. Latest update in the Bot involve a migration to the official ESIOS REE API (https://api.esios.ree.es/) which requires a personal access token provided by them (email to consultasios@ree.es). If choosing to use the ESIOS version, then provide esios_ree_token in the request to /telegram/ (add it to tokens.json)

Install and usage

Locally

pip install -r requirements.txt
pip install .
python3 -u pvpcservice/rest_manager.py

Container

bash deploy.exe

If required, start fresh restarting Docker desktop and running

docker rm $(docker ps -a -q) -f
docker rmi $(docker images -a -q) -f

Then access http://localhost:8080/ui to use the endpoints.

  1. \telegram\ Paste tokens.json contents as payload
  2. \v2\prices\ Will return a NGSI-v2 object describing prices for today

Roadmap

1) Pending to add color to graph.

2) Pending to decide how to make the code run automatically every midnight --> Node-red microservice

  1. Fully integrate NGSI-v2 format

  2. Parametrize the date for which prices are returned

5) Migrate to a https://www.esios.ree.es/es/pvpc to access to data at 20:30 of the day before

  1. Integrate with FIWARE QuantumLeap and plot prices in Grafana

About

Bot that sends energy prices for next day according to the PVPC tariff

Topics

Resources

Stars

Watchers

Forks