Tag: ai

  • 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;


  • Is the algorithm me?

    Of course not, I am human. But the techbros at YouTube would have you believe that the “algorithm” can predict what I will watch next. The Algorithm™ has access to my video watching history based on over ten years of data. Ten years of evidence showing which aspects of current affairs I click on. What news programs I watch, which science videos I rewatch and which channels I binge. The boffins at Amazon built an Algorithm™ that takes my increasingly dwindling purchase history from Amazon and suggest items I may want to purchase next. The Algorithm™ exists for me, my personal Jeeves, as I sail on the ocean of information.

    The Algorithm™ knows all, sees all, processes all and can tell me all. It automates away the process of discovery, that joy of just stumbling upon something while casually strolling through the aisles of a bookshop, glancing and then skimming it, eventually liking it. The Algorithm™ knows me and can predict my thoughts and facilitate my anticipated actions.

    Alas, the algorithm is not me and cannot substitute me. There is some information that another human could glean about my life and preferences via information that the Algorithm™ gathered, but that is surface level at best.

    This leads to an interesting thought experiment. If I died tomorrow, could someone live vicariously as me through the Algorithm™? Would that person know me through my algorithmic recommendations?

    I think not.

    The Algorithm™ knows only what I tell it, what I am unafraid of disclosing. The Algorithm™ does not know my story, my past or my hopes and dreams. It cannot know that I hope to retire and study astronomy, only that I like astronomy now. It cannot know that I dislike techbros, as my copious use of their creations suggests otherwise.

    I realise that the next techbro upgrade to the Algorithm™ is AI. An AI crawler will read this post, and this entire blog. It may successfully predict the next word in a list of preferences of E Rebello. But even AI, can it truly know me the way another human can?

    No.

    Not yet, at least.