Automating my dishwasher for fun and profit
In June we switched to a fully variable electricity tariff, Octopus Agile.
Every half-hour we have a different price per kilowatt-hour. This varies wildly throughout the day:
Image from Agile dashboard
We run a dishwasher every day.
I wondered if I could automate it to optimise the cost and carbon emissions.
Controlling the dishwasher
Fortunately we have a “dumb” dishwasher with manual controls and no timers or internet connection.
Even more fortunately, if you switch the power off while it’s running and switch it on again later, it continues where it left off.
This meant it would be possible to hack together a solution using a smart plug.
Using the Shelly Plus Plug UK
The Shelly Plus Plug UK is a super little smart plug.
It plugs into the socket, then you plug an appliance into it.
It can:
- measure instantaneous power consumption
- switch the appliance on and off
- display different colours on its LED ring
- connect to a Wifi network
- run Javascript!
I’ve been using a few Shellys around the house with simple schedules.
I only recently discovered they can run Javascript with full access to everything the plug can do.
Holding off the dishwasher
Surely I could write a script that detects when the dishwasher is turned on and switches it off until the next cheapest period?
That would offer a simple user experience: load the dishwasher and turn it on as normal. Let the plug do the work. No faffing around with timed starts or annoying apps.
Getting Agile prices with the Octopus API
Since the plug can talk to the internet, it just needs to access prices by calling the Octopus API…
Octopus publishes the half-hourly prices at around 4pm each day for the next day.
They provide an API to get the prices. I used an excellent blog post from Guy Lipman to help me navigate the API.
Once I had access to the prices, I needed to work out the best time to run the dishwasher.
Deciding when to run the dishwasher
version 1: fixed time (1am)
For the first iteration, I simply started it at 1am every morning. On average this massively beats starting at 8pm, when we normally load the dishwasher.
Cut me some slack: I was doing this in random hours around childcare!
version 2: dynamic time, assuming 2 hours flat consumption
I know the dishwasher takes about 2 hours to run.
For the second iteration I simply looked for the cheapest consecutive two-hour period of Agile prices.
This worked well. The start time varied between around 1am and 4am.
version 3: dynamic time, actual consumption profile
I knew that the dishwasher doesn’t consume evenly across the four half-hourly periods.
I added the Shelly as a device in Home Assistant and let the logging begin. The next day I saw a power profile like this:
Interestingly, most consumption is in the first and fourth half-hourly period. That’s the heating and the drying cycle, when the powerful 2.2kW immersion heater comes on. The rest of the time is just a little motor using barely any power.
HomeAssistant recorded a data point any time there was a change in power (Watts). I needed to integrate that (area under the line) so I knocked up a quick Go script to convert HA’s history.csv file into a half-hourly energy profile (kilowatt-hours).
The energy profile came out like this: [0.350, 0.074, 0.014, 0.381]
I updated the code to correlate the consumption profile along the next 12 hours of Agile prices, rather than just looking for the cheapest two hours.
This was a fun optimisation over v2 but probably didn’t gain much. (It would be more important for a 7-hour washer dryer cycle with energy-intensive tumble drying towards the end.)
Putting it all together
The daily user experience looks like this:
- Pack the dishwasher, put the tablet in, select the program,
- Open the cupboard next to the dishwasher and check the Shelly plug is blue (“waiting for dishwasher”)
- Close the dishwasher to start it
- Listen for the dishwasher to start and stop
- Check the Shelly plug has gone red
- Enjoy a quiet evening knowing it will be done by morning
Keep an eye on the LED colour ring of the Shelly plug in the cupboard:
Behind the scenes, this is what happens:
- When the Shelly plug boots, it runs the script. The script enters
waiting
mode and configures the LED settings so that on=blue. - When the dishwasher gets turned on, the script detects that the dishwasher is drawing over 5 Watts.
- It makes an API call to my website which returns a number of seconds to delay.
- It turns the switch off with the
toggle_at
parameter set to the delay (this means the plug will turn itself back on automatically.) - The script flips into
holding
mode. It configures the LED settings so that on=green. - After the defined delay, the plug toggles itself back to on.
- The script flips into
running
mode and starts to monitor power consumption. - After 1 hour of no power consumption > 5 Watts, the script returns to
waiting
mode.
Quiet evenings are an unexpected benefit
As an unexpected benefit, it’s really nice being able to put the dishwasher on straight after dinner and not have it running noisily in the open plan living room.
It’s also nice to be able to add forgotten cups and plates without it complaining. Since it’s powered off, it couldn’t care less if you open the door.
So far it’s working well. I haven’t yet calculated the saving but it’s already deeply satisfying knowing it’s always running on cheap, low carbon electricity.
Win.