Tag: electricity

  • Vibe coding to estimate my electric bills

    Access a working version of my ULO bill estimator here – https://eldrichrebello.github.io/OntarioULOestimator/testing/

    I use AI regularly. At work, I use AI as a sort of supercharged Wikipedia. I’m always careful to verify what it tells me. I always ask whether a response is plausible. Generally, I’m working with things that I understand, even if not fully.

    I spend some time every week on a website called Hacker News. This is a group of software bros (mostly) talking about things that interest them. Often, it includes people from google, apple, and farcebook – the people building the AI machines. We are about two years into the AI hype cycle and the advantages of AI are often sold as making people more productive. Productivity is a loaded word and it means different things in the software world as it does to me. My productivity is higher when I can access a translation tool that captures intent instead of translating every word by itself. A software developer’s productivity is higher when they can write more code quickly and verify that it is high quality code. There’s one other application that comes up often – vibe coding. Essentially, using English language prompts to generate code. Basically, you describe what you want to do and the AI machine conjures up the code to achieve that goal. The point here is that it raises the floor. People who have a problem, know the steps to solve it but are unable to translate that into code can now create that code with LLMs.

    I wanted to know whether my electricity bill was as low as it could be. The province of Ontario introduced a new electricity rate called the ultra-low overnight (ULO) plan. It gives you access to dirt cheap electricity rates between 11 PM and 7 AM. The catch, however, is that between 4 PM and 9 PM. Now, my wife’s commute is long. Long enough that we were spending $ 400 per month on petrol. We still spend on fuel, but around $ 50 per month on electricity. Since I am Indian, I wondered if I could reduce our bill even further with the ULO electricity rates. Could I?

    One way to answer this question is to download my electricity date from my utilities’ website and to then do some maths. I could do this but it is annoying. Instead, I decided to vibe code my way out of this problem. I do know how to write HTML, I know what CSS is and I know how to build a webpage to do this. But I could not be arsed to do all of it. Why bother when the machine could possibly do it for me? That was exactly what I did and I was surprised by the results. The HTML file I eventually built worked, but it was not without some dangers.

    Here was the prompt I typed into Microsoft’s Copilot:

    Write html code. This code allows the user to upload a CSV file showing hourly electrical energy usage.

    Create a series of 48 sliders. The first 24 show average energy consumption for weekdays. The second 24 show hourly energy consumption for weekends i.e. saturdays and sundays. All sliders should be modifiable by the user. Sliders are named by hour i.e. starting at 01:00, ending at 24:00.

    Here are the column names, in row 1 – Date Hour 1 Hour 2 Hour 3 Hour 4 Hour 5 Hour 6 Hour 7 Hour 8 Hour 9 Hour 10 Hour 11 Hour 12 Hour 13 Hour 14 Hour 15 Hour 16 Hour 17 Hour 18 Hour 19 Hour 20 Hour 21 Hour 22 Hour 23 Hour 24

    The first column has dates formatted as yyyy-mm-dd. The remaining columns are the electrical energy consumption by hour. Hours start at 01:00 and end at 24:00.

    First, add a column at the end. convert the date into a day of the week. Filter rows by weekdays. For each column, calculate the average energy consumption for that hour. Assign the value of each weekday column average to the corresponding weekday slider. repeat for all hours of weekdays.

    This gave me code that worked, but I ran into a couple of problems. First, the CSV file from my utility did not work and the code I had provided no hints as to why. I also had no idea how to debug HTML. Ok, so I uploaded an example file to Copilot. It told me that the CSV file was comma separated but the code assumed it was separated by spaces. Ok, the AI fixed that.

    Next, I noticed that the hourly average energy consumption was off. Every single calculation was off. Ok, now I asked the machine to create two tables at the bottom, showing the dates, the corresponding date of the week, the hourly energy values and the averages at the bottom. Great, but now the days of the week were all one behind? The first of May 2025 was a Wednesday. This table showed it as a Tuesday? I asked the AI machine and apparently, these dates were processed as a date-time in UTC, and then converted to my local time. Since I live in the Eastern time zone in North America, all days of the week were one day behind. Ok, the machine fixed that as well. Now I had average hourly energy calculations that were correct.

    Great. I next added calculation logic for the energy calculation. I pointed the machine to the OEB website with electricity plans and rates. For some reason, the machine used the correct time blocks for electricity rates, but the wrong rates (in cents / kWh). No matter, I had a text box where I could input the rates.

    There were a series of other errors as well, all of which I fixed. For each of these, I refined the calculation logic. The AI machine, however, gave me code that would not work. The calculation logic used an if…elseif construct. The start is always with an if statement. The code snippets that Copilot gave me always started with an elseif block. If I did not know that this was a problem, my HTML code would not work and I would have no idea why. It is possible that the machine would eventually notice but I cannot be sure. After all, the machine wrote the initial code and then lost track of what it was modifying. Very often, the code snippets included extra braces and brackets. Again, something I knew how to fix.

    In all, my experience was excellent. I spent about five hours of a weekend wrangling Copilot and Google Gemini. Time well spent because I would never have produced this much code in five hours. I do not fully understand the code I have, but I verified at least one calculation and it is correct. The other calculations are plausible so I have more faith in them. AI is excellent at this but it requires some basic competence with writing and debugging code. Producing code that is correct also requires specific knowledge, in my case, what a reasonable electricity bill looks like. Someone without this knowledge would never have spotted the errors that I did. Should the average person use LLMs to write code? Absolutely, but please verify, else you have no idea what your code does or how it works. Will I continue to use LLMs to write code? Absolutely and I will expand my uses of it. I will likely write excel macros and automate some tedious tasks on my computer, such as editing photos.

    <script>
    function calculateCost() {
      const model = document.getElementById('pricingModel').value;
      let totalCost = 0;
      let costDetails = '';
    
      const weekdayAverages = weekdayData.map(arr => arr.length ? arr.reduce((a, b) => a + b) / arr.length : 0);
      const weekendAverages = weekendData.map(arr => arr.length ? arr.reduce((a, b) => a + b) / arr.length : 0);
      const allHours = [...weekdayAverages, ...weekendAverages];
      const monthlyHours = allHours.map(val => val * 4); // scale to monthly
    
    //very often, the LLM would tell me to update this if block, 
    //but it would start the block with an elseif
    //and a misplaced brace
    if (model === 'tou') {
      const season = document.getElementById('touSeason').value;
      const off = parseFloat(document.getElementById('touOffPeak').value) / 100;
      const mid = parseFloat(document.getElementById('touMidPeak').value) / 100;
      const on = parseFloat(document.getElementById('touOnPeak').value) / 100;
    
      let weekdayTOU = { off: 0, mid: 0, on: 0 };
      let weekendTOU = { off: 0, mid: 0, on: 0 };
    
      // Calculate average TOU energy for one weekday
      for (let h = 0; h < 24; h++) {
        const val = weekdayAverages[h];
        if (season === 'summer') {
          if (h >= 11 && h < 17) weekdayTOU.on += val;
          else if ((h >= 7 && h < 11) || (h >= 17 && h < 19)) weekdayTOU.mid += val;
          else weekdayTOU.off += val;


  • Operating a heat pump in Ontario, Canada

    I live in a part of the world with four distinct seasons. One season is winter and winter in Canada is cold. Winter in Ontario is often quite cold. Our house has two halves, one is the original brick structure with terrible insulation (non existent, actually) and the other is an extension built to standards of the 90s so it has some insulation. The extension has insulation but poor HVAC design – there are not enough supply and return lines for air.

    The result of this is that my bedroom remains uncomfortably warm in the summer and is too cold in the winter. In 2024, the Feds ran a home retrofit program called Greener Homes and we participated. We received a generous amount of money to swap out our 30 year old furnace and 20 year old AC with a new furnace and a heat pump. This is a dual-fuel system, similar to a Toyota Prius, but without the limit on battery capacity. I can choose to heat my home with either electricity or methane depending on conditions.

    This is certainly more efficient than our previous situation but the truly efficient solution is to properly insulate the house. I asked around and the cost was six figures. Not something we could afford easily and we were not keen on investing so much money into a seventy year old house. The solution was obvious – a more efficient heating system and so a dual-fuel system it was.

    I did my research about which systems NRCan would accept and finally bought a 2.5 ton heat pump from Dettson, which is a rebadged Chinese unit. The internet suggests that Midea is the original brand. The furnace is a standard high-efficiency Trane furnace and we kept our smart thermostat. We run the heat pump in non-communicating mode so it has three operating levels – zero, 50% and 100%. The image at the top is our heat pump in the dead of winter. You can see weeks of ice accumulated under.

    All information I had access to said that a heat pump is so much more efficient than a gas furnace that it is often cheaper. Many of these calculations assume a consumer carbon price so they tend to favour electric heating. With the consumer carbon price at zero in 2025, did the heat pump really reduce our gas consumption? I decided to run the numbers and was shocked at the difference it made.

    The results are below. Notice the red arrows showing the fall in winter gas consumption. I removed the vertical scale (m3) for privacy reasons but I will repeat – our house has terrible insulation so our gas usage in the winter is relatively high. Despite this, the heat pump put a massive dent in our gas consumption. The winter of 2025 was colder than the winter of 2024. On average, by around 5° C in January and February. Despite this, our gas consumption was down by approximately 60% and we even raised the temperature by 0.5° C indoors. I hoped for a lower bill, but did not expect this reduction. On the coldest days, our heat pump struggled to raise the indoor temperature but it did manage to compensate for the loss of heat through our walls. The gas furnace essentially served to raise the indoor temperature every hour or so, running for about 15 minutes. In years prior, the furnace ran for almost the entire hour, turning off for only about five or ten minutes.

    2025-09-06 – Updated to show that the temperatures indicated are mean outdoor temperatures.

    I should not be astonished but I still am. I understand how heat pumps work but this still feels like magic. A heat pump is literally an AC with a reversing valve. That’s it. Anyone who tells you that a heat pump doesn’t work in Canada is lying. Ours is rated to – 30° C and I can confirm that it worked well on the coldest day of 2025 – a full 25 degrees Celsius below freezing. A heat pump may not work well on the coldest days in the Canadian prairies but a simple resistive heater will get you through. Better still, keep your gas furnace and do what we did – get a dual fuel system. If the furnace fails, I still have heat. There is a lot of fear mongering from HVAC sales folks who will sell you oversized furnaces and pretend that heat pumps are some magical technology that is bound to fail. Nonsense. Heat pumps work extremely well.

    Our heat pump worked so well that we decided to buy a second one. This time, a 1.5 ton ductless system for our bedrooms with two indoor units. This model is from Moovair, also a rebadged Midea unit. It is rated down to – 25 C and works extremely well in the summer. So well that it regularly operates at 30% capacity and keeps our bedroom at a steady 24° C. We will see how it fares in the winter, but I have no doubts that it will work well.

    Get a heat pump. If it works in our home, it will work in yours.