Skip to main content

Command Palette

Search for a command to run...

How I built an AI-powered tool to help people in Spain save on electricity bills with Amazon Bedrock - Part 1

Published
4 min read
How I built an AI-powered tool to help people in Spain save on electricity bills with Amazon Bedrock - Part 1
B

👨‍💻 Sofware Engineer · 💬 Consultant · 🚀 Indie Maker · ⚡️ Serverless

🔧 serverless-appsync-plugin · serverless-appsync-simulator · middy-appsync

🐈 and 🍵

If you're on Spain's regulated electricity tariff (PVPC), timing is everything. Prices change every hour based on supply, demand, and energy source — meaning your dishwasher costs three times more to run at 8pm than at 2pm.

The alternative is going with a fixed-price plan from a private provider — more predictable, but often more expensive in the long run.

For those of us on PVPC, knowing when to run appliances (Washing machine, dishwasher, or charge an EV can make a real difference on the bill. The problem? You'd need to check prices every single day.

That's what I set out to solve — and that's how Luz was born.

💡
Luz is a Spanish feminine name which means Light. "La luz" is also how people usually refer to electricity. e.g. "La factura de la luz" (The electricity bill).

There are dozens of bots and websites out there which already do a daily summary of prices. So why build yet another one? Well, first of all, I wanted to learn something new. But I also wanted to make it different than others. Not just a dull "Here are the prices for today" message.

Amazon Bedrock had received a lot of hype in the past few years, but I actually never got to explore it, let alone to actually use it. So I thought it was a good opportunity for Luz. I wanted to use AI to make it sound less repetitive and more original.

High-level Implementation

The overall idea is simple. Red Eléctrica (the transmission system operator of the Spanish electricity grid) publishes consumer prices every night for the following day. I'd create a cron job which uses the API to fetch prices, stores them into a DynamoDB table, and then, uses Amazon Bedrock to generate a custom message to push to users through X, WhatsApp and Telegram.

Content Generation with Amazon Bedrock

Every night, once I collected the daily prices, I do a simple API call to Amazon Bedrock, using the TypeScript SDK. But first, I need to generate a prompt.

I won't share the full prompt here, but the key ingredients are

  • Full list of the 24 daily prices (per hour)

  • The computed lowest, highest and average prices for the day

  • Spread: difference between the highest and lowest price.
    This helps Luz understand the intensity of the day. (i.e. does it fluctuate a lot?)

  • Instructions on how it should generate the message

    • Tone

    • min/max characters

    • use emojis

    • give the user a daily recommendation

const client = new BedrockRuntimeClient({});
const response = await this.client.send(
  new ConverseCommand({
    modelId: 'eu.amazon.nova-pro-v1:0',
    inferenceConfig: {
      maxTokens: maxTokens,
      temperature: 0.75,
      topP: 0.9,
    },
    messages: [
      {
        role: 'user',
        content: [{ text: prompt }],
      },
    ],
  }),
);
💡
Notice that I slightly increased the temperature and topP values. This is because I wanted Luz to be a little more creative and original.

Finally, the generated message is stored into a DynamoDB table for archive and forwarded to the fan-out service which sends the message through the different social media services.

What I learned

Leveraging Amazon Bedrock for content generation is remarkably straightforward. You can integrate AI into your applications without needing a complex infrastructure. With a variety of models available, such as Claude, GPT, and Nova, you have plenty of options to choose from.

Playing and adjusting the Prompt, the temperature and other parameters like topP can considerably alter and improve results. It was interesting to see how changing them alters the result and fine-tuning them can improve he output. I feel like there's still a lot to master here and it's definitely something I want to explore more. After letting Luz run for a couple of weeks now, I still see some margin for improvement.

💡
You can find Luz on X, Whatsapp, Telegram and https://laluz.today

What's next?

Next, I plan to delve deeper and create an Agent that enables users to ask Luz questions directly, such as "What is the best time to do laundry today?" or "Compare providers on the market and help me choose the best one for my needs." I'll discuss this further in Part 2, which will be presented as a webinar on Friday the 15th (SLS day). You can register now.