ESP-8266 Smart Dishwasher (smart Plug / Smart Socket)

by didier_windey in Circuits > Wireless

9484 Views, 35 Favorites, 0 Comments

ESP-8266 Smart Dishwasher (smart Plug / Smart Socket)

Publicatie1.jpg

We buy electricity from a local windfarm. Of course we are connected to the regular net with a steady supply of electricity. But I always wanted to adjust our consumption patern according to the available wind. Therefore I build a home system to monitor the availebility of windpower. The system monitors the national wind power, with forcasts for the next few days. The output is a chart of the forcasted wind power. This way we could manually switch devices. See my Instructable : WindPowerMonitor.

This new Instructable automates the process. I have build a wifi controlled socket to switch the dishwasher. Of course this wifi controlled socket can be used for any other purpose. And if you're the owner of solar panels, an addapted version of the underlaying program would be very usefull to switch some of your devices according to the availabilty of home produced solar power.

Why a dischwasher ?

  • it consumes quite a bit of electricity per cycle
  • it is often used (daily)
  • the task is most often not urgent and must only be done before a specific time (e.g. tomorrow before coming home from work)

The Hardware : Wifi Controlled Socket (ESP-8266)

55a8058d50e1b671a1000706.jpeg
20150712_124154_resized.jpg

First of all you'll need to build the wifi controlled power socket.

I have used the ESP-8266-12 as the controller and wifi connection. The ESP-8266 is very cheap. I bought 10 of them straigt from China for less than €50 ! And on top of that it is a real conroller, with 10 of so GPIO pins. No need of any other controller is needed. I used the "12" model because it has most of the GPIO pins broken out. With the "1" model the 2 available pins may never be pulled up at start-up, which sometimes can be in issue.

Bill of material :

  • ESP-8266-12 (any other model may do)
  • Relay 5V / 230v-10A
  • transistor BC547B + resistor
  • voltage regulator LM317 + resitor + resitor + condensator + condensator (to 3.3v for the ESP-8266)
  • optocoupler
  • voltage regulator 230v AC to 5v DC
  • socket + large enough box
  • wires 230v - 10A
  • wires 5v
  • sordering board
  • soldering equipment

How it works :

The high voltage circuit is switched by the relay.

The relay is switch by the ESP-8266. But to get there is a bit more complicated :

  • 230v-AC is transformed to 5v through the large voltage regulator.
  • Because the ESP runs best at 3.3V, the LM317 regulates a 3.3v circuit from the 5v ciruit. The output is connected to the ESP.
  • Pin 16 on the ESP give a digital signal (HIGH of LOW). But because the relay works on 5v, and can disturb the circuit on pulling high, the ESP and the relay are connected through an optocoupler.
  • The optocoupler I used did not give enough current. So to eventually switch the relay, a transistor was build in between.

The relay is connected in the 'normaly closed' position. So the socket is always ready to use. The switching programm actually first activates the relay and disconnects the socket. At the programmed time the switch is closed again.

The included image is not a working circuit but more a schematic how it basically works.

WATCH OUT : HIGH VOLTAGE ON THE CIRCUIT !

Smart Socket Software

esp server.JPG

The hardware by itself will not just work. The ESP8266 controller first needs to be programmed.

I have used the NodeMCU firmware, which runs the Lua language. So first you'll need to flash the firmware.

Than you upload the init.lua file to the ESP.

What the program does :

  • set wifi network parameters (fill in your SSID and passsword)
  • give it a fixed IP
  • give the chip an ID (in this case 1234)
  • set led2 as 0 (0 is the index for pin 16)
  • set led2 to output
  • set ESP as a mini server
  • when a request comes in, read GET variables
  • if the Meth variable is "A", the request comes form a planned job (later in next step). It then checkes if the massage is for this chipID, and switches the device (ON or OFF)
  • if Meth is empty, it's about a direct request by a human from a browser. It opens a little webpage with 2 buttons (ON of OFF). When the user presses one of the buttons, the device is switched and returns the new value.

So basically the ESP is connected to your local network (router). In my case it's IP is 192.168.0.106. (adjust if necessary to your local gateway). If you type the IP into your browser, you'll get straight into your smartplug and control it from there. But it also can be switched from a job on a server.

Downloads

Colllecting Data - Part 1 : MySQL

Devices.JPG
jobs.JPG
slots.JPG
tijdinst.JPG
wind.JPG

Now the smartplug is running, we want it to run the dishwasher on a specific moment. To eventually do this, we need some data. And the best way to collect, store and manipulate data is to work with a database on a server.

As a server I chose the tiny but yet powerfull Raspberry Pi. It is cheap and compact and above all uses only little power (about 7W). So first of all you'll need to install your Pi with Apache.

For the database I choose MySql. You easaly find packages to install Apache and MySql in one run.

Then setup the database. I called it SensiHome, and it runs a lot more than just the dishwasher.

In the database we'll find 5 tables (see images for details) :

Devices :

  • stores the settings of the devices in the network.
  • for the dishwasher the cycletime and cycle Wh are of extra importance. They are used to calculated the best moment.

Tijdinstellingen (TimeSettings) :

  • it is easely to calculate time in PHP. So you can say 'tomorrow at 5pm' and PHP will understand what you mean. This little tables stores the moments I desire, with an extra column with the translation to my language.

Timeslots :

  • In my case I want only a few moments to have the dishwasher be ready : today when I come back from work, before tomorrow morning but starting from 22h, before tomorrow when I come back from work, or now.
  • It takes the data from 'Tijdsinstellingen'

Jobs :

  • Eventually you want the server to switch on the dishwasher. This table is filled by date coming from the php programm in the next step.

Wind :

  • The data in this table is a live feed from the webserver from our national grid manager (Elia, Belgium).
  • Every 5 minutes my server request an XML file, with data about the acctual Wind Power production and the forcast for the next 3 days.
  • On how to get this data, check this step in my Instructable : XML from Grid Manager

Choosing When the Jobs Needs to Be Done - Part 2 : Php Program

Knipsel.JPG
SQL TIME.JPG

Doing the dishes is most of the time not very urgent, but in the end you want them done when it's convenient to you.

To do so you use a little app in a web brower (see image). The app displays the preset possibilities in a button. In this case :

  • now (NU)
  • between now and 17h today (VANDAAG) (not displayed in image)
  • between 22h today and 6h tomorrow (NACHT)
  • between 22h today and 17h tomorrow (MORGEN)

you can change these settings in the database.

The button shows how much power is available in the 2 hour cycle (set in de DEVICE table) from the forcasted wind power production. If there is enough power, the button is green, if not enough it is red (also set in the DEVICE table). The button also showes the switching time.

All you have to do is go to the website (192.168.0.156/Vaatwasser.php) and choose the moment you want. the dishes to be done. Once you have done so, a green bar will apear with the switching time.

Quite simple for the user. The php programm to get there is a bit more complicated.

Vaatwasser.php :

  • The first section is CSS to set the style of the buttons
  • Than the variables for connecting to the database are set
  • The first query ($q_SQL0) checks if a time is set already. if so, a green bar with the time is displayed
  • $SQL_TIME may look very comlex, but only to give the result in the image (device, momentPHPfrom,...). But very important for later calculations. Note that the blank fields represent zero for PHP to calculate NOW

  • next $q_SQL retrieves the cycle time and cycle kWh

  • $q_SQL2 retrieves data about available wind power, within the specific time references

  • $q_SQL3 than scrolls throug the data, looking for the moment with the most wind power and stores the outcome in $Start

  • Then there are some program leftovers from development time. Not used anymore, but maybe usefull to you. Origianaly the relay was switched as normaly open. The device than was switched ON and at the end of the cycle switched OFF again.

  • than the buttons are made. When you press one of the buttons the program switches to 'Jobs4.php'

Jobs4.php

This programm runs in the back, so the user nerver sees it. The jobs table is the place where all switching jobs are stored.

  • if there already is set a switching time, it deletes this entry from the Jobs table in the database
  • It inserts the chosen moment into the jobs table
  • it switches the socket to OFF
  • returns to the Vaatwasser.php program

Executing the Job - Part 3 : Cronjob

crontab.JPG
jobs.JPG

Now the magic happens. Every minute the jobs.php program is ran (with a cronjob from the Raspberry Pi). The query looks for records to execute.

What it does :

  • running a query to look for jobs 'ToBeExecuted' or 'NO_REPLY'
  • Isends a message to the according device. This is done by a GET url.
  • Waiting for an answer from the device.
  • If no reply, it alters the record to 'no reply'. No replies are retried again with the next run (next minute), but after 5 times it stops and gives an error message in the record.

Downloads

NFC Chip

nfc-tag-stickers.jpg

I have made going to the website (app) very easy. An NFC sticker (Near Field Chip) is attatched inside the door of the dishwasher. When you move your smartphone (with NFC detection) over the chip it directly goes to the URL. This way everyone can switch the dishwasher.
How to programm the chip :

  • download a NFC programming app (e.g. NFC TASKS for android)
  • switch the NFC detector to ON on your smartphone
  • open the NFC app in the write setting
  • enter the URL of the website (in our case 192.168.0.156/Vaatwasser.php)
  • put your Phone on the NFC tag and write the url to the chip