Power Updater is an app that provides Eskom Loadshedding updates - running on AWS Serverless. Users can interact with Power Updater in two ways:
- A Telegram bot: @PowerUpdatedBot
- A web front-end: https://powerupdater.hacksaw.co.za/
The app pulls the Eskom loadshedding stage and schedule info from https://loadshedding.eskom.co.za/LoadShedding/, and makes it available as a Telegram bot and Flask web app. You can interact with the bot directly and request the loadshedding using the /schedule
command, and/or the bot can be added to your Telegram community groups/channels, and it will post the schedule for your area.
The bot will post the following information five times a day (or depending on the EventBridge Schedule):
Buccleuch Loadshedding Notice
Stage 6
The loadshedding schedule for today - Sun, 16 Apr:
16:00 - 20:30 (4 hours)
The loadshedding schedule for tomorrow - Mon, 17 Apr:
06:00 - 08:30
14:00 - 18:30 (4 hours)
22:00 - 02:30
The bot also supports you asking it for the schedule on an ad-hoc basis using the /schedule
command.
The bot has a web front-end: https://powerupdater.hacksaw.co.za/ - where you can see the list of areas and schedules.
Loosely-based off https://github.com/daffster/mypowerstats, but completly re-written.
For a detailed view of the architecture, read my blog about how this uses choreography and orchestration
get_schedule_lambda.py
Lambda function gets invoked via an EventBridge schedule to call the Eskom loadshedding status endpoint and get the loadshedding stage. This is stored on DynamoDB, for each area/location/suburb.- A filter is setup on DynamoDB Streams to send changes to the
notification_lambda.py
Lambda function. If the loadshedding stage has changed, the new stage will be sent, which will be posted to Telegram. - Once a day,
get_schedule_lambda.py
Lambda function gets invoked via an EventBridge schedule to call the Eskom loadshedding schedule endpoint and store the schedule in DynamoDB. - A filter is setup on DynamoDB Streams to send changes to the
notification_lambda.py
Lambda function. If the loadshedding schedule has changed, it will be posted to Telegram - Every 2 hours,
notification_lambda.py
Lambda function gets invoked via cron schedule (EventBridge rule) to send loadshedding reminders. It reads the latest stage and schedule from DynamoDB, and posts to Telegram
-
Create your bot using BotFather, and take note of the token, e.g. 12334342:ABCD124324234
-
Use AWS SAM to build and deploy to AWS:
-
- Install AWS CLI, and configure it
-
- Install AWS SAM CLI
-
To build and deploy your application for the first time, run the following in your shell:
sam build
sam deploy --guided
For future deploys, you can just run:
sam build && sam deploy
- Update the Lambda environment variables for
PowerUpdaterTableName
,TelegramBotToken
andTelegramChatID
- Update your Telegram bot to change from polling to Webhook, by pasting this URL in your browser, or curl'ing it - Use your own bot token and Lambda URL endpoint: https://api.telegram.org/bot12334342:ABCD124324234/setWebHook?url=https://1fgfgfd56.lambda-url.eu-west-1.on.aws/. You can check that it was set correctly by going to https://api.telegram.org/bot12334342:ABCD124324234/getWebhookInfo, which should include the url of your Lambda URL, as well as any errors Telegram is encounterting calling your bot on that API.
- Even though area is a field in the DB, need to configure it properly for multiple areas
- Pull announcements from https://twitter.com/Eskom_SA