The goal of this project is to have my kettle boil when I get up in the morning. It should boil only once every 45 minutes, and only within a set time window between 5:45 and 7 am. The signal that I am up in the morning is that (I have left my bedroom and) motion is detected in my living room. The system should still function when internet is not available, during an outage.
Hardware
This project makes use of a wifi connected kettle called a smart kettle called Appkettle, a Hue motion sensor (which requires a hub), and a raspberry pi (a pi zero or model 3 are equally fine) or alternative hardware which can run Home-assistant. The kettle and motion sensor are shown below and both look pretty smart in my opinion.
Hue motion sensor
This work follows on from an earlier project using the Hue remote and in this case makes use of the Hue motion sensor. This sensor is a very useful product in my opinion, since it runs on a battery which in my case has lasted for over a year, and can be queried via a nice API. It detects motion, but also light levels (lux) and temperature. The sensor itself isn't the cheapest on the market, but I was able to pick up a couple for half price in an Amazon deal, so keep an eye out for those.
Appkettle
The second product in this project is the Appkettle which is a wifi connected smart kettle. The kettle is well made, with very nice pouring (no drips!) and looks quite stylish in my opinion. The Appkettle has an app from which you can control the kettle and set it to boil daily at specified times. This intrigued me since I have always liked the idea of having my kettle boil exactly as I get out of bed, and reminds me of a certain Mr Bean sketch. Using the Appkettle app you can easily set the kettle to boil every day at 7 am when you get up. However in my case I don't get up the same time every day, and I don't want the kettle boiling when I am still in bed our ages after I am up, and therefore the app wasn't a solution. Fortunately Appkettle recently release IFTTT integration, which enables linking the kettle into the IFTTT ecosystem.
IFTTT
IFTTT is a useful service for makers since it provides a way to link various hardware and software services using short scripts which IFTTT calls Applets. Applets have the logic if {this} then {that}
. IFTTT provides services for both Appkettle and the Hue sensor so I could setup an IFTTT rule that if {motion is detected} then {boil the kettle}
. However this does not fulfil my project requirements since there is no time filter or limiting of the number of times the kettle can be boiled by the Applet. Using the IFTTT maker service it is possible to create more nuanced Applets with multiple filters, so I could create if {motion is detected} and {it is between 5:45 & 7 Am} then {boil the kettle}
. It may also be possible to limit the number of times the applet runs to once per day, but I haven't spent enough time reading about the maker service to be able to comment on this. My reason is that I actually don't make much use of IFTTT since is a cloud service, and I have experienced that when I suffer an internet outage at home (surprisingly frequent, despite paying for a 100 MBit/s connection and living in a capital city!), IFTTT cannot function. Instead I use the self-hosted home automation platform Home-assistant. Since it is self-hosted (e.g. on a raspberry pi) I am unaffected by internet outages, minimising the frustration during these events. Nevertheless this project makes use of the Appkettle IFTTT service to turn on the kettle since the Appkettle does not yet have a dedicated API that would allow local control. The maker of Appkettle has indicated that a local API will be coming eventually, so this project will remain 'in progress' until IFTTT can be replaced with local control.
Home-assistant
Home-assistant is an open source home automation platform that is run locally, typically on a raspberry pi. With a recent release setting up Home-assistant couldn't be easier, and consists of downloading a disk image, flashing that to an SD card, plugging the card into the pi, and running through a basic setup.
Adding the motion sensor to Home-assistant
In Home-assistant many devices have their own dedicated 'component' which makes setting up these devices very straightforward, just a matter of entering some details in a configuration file. The Hue component should automatically discover your Hue hub and all connected lights, but not the sensors since these are not currently natively supported by Home-assistant. Therefore to add the motion sensors to Home-assistant we will use a component called an aREST binary sensor which makes use of the Hue API that is running locally on the hub.
You first need a URL to read the hub status, and the full steps are detailed at https://developers.meethue.com/documentation/getting-started. Once you have the URL I recommend viewing the state of you hub in a web browser. I found a useful Chrome plugin which nicely formats the JSON called the JSON Viewer. In the browser paste the URL (with your information in the < >):
http://<bridge ip address>/api/<username>
The page will list all the lights and sensors configured with the hub. The Hue sensors can be isolated with:
http://<bridge ip address>/api/<username>/sensors
In my case I have a list of 16 sensors, each identified by a number, which in the example below is 15. You will need to check the 'name' field of each sensor until you have identified the motion sensor you are interested in.
"15": {
"state": {
"presence": false,
"lastupdated": "2017-07-26T05:26:16"
},
"config": {
"on": true,
"battery": 100,
"reachable": true,
"alert": "lselect",
"ledindication": false,
"usertest": false,
"sensitivity": 2,
"sensitivitymax": 2,
"pending": [
]
},
"name": "Living room sensor",
"type": "ZLLPresence",
"modelid": "SML001",
"manufacturername": "Philips",
"swversion": "6.1.0.18912",
"uniqueid": "00:etc"
}
Now we have all the information required to setup Home-assistant. The following text needs to be changed for your motion sensor number (mine is 15) and added to the Home-assistant configuration file.
binary_sensor:
- platform: rest
resource: http://<bridge ip address>/api/<username>/sensors/15
name: living_room_motion_sensor
value_template: '{{value_json.state.presence}}'
scan_interval: 1
Whilst you have the configuration file open, also add the IFTTT component we will use later. Now restart Home-assistant and you will see the motion sensor within the list of entities which can be navigated to from the Home-assistant front end using the States developer tool. Check that the motion sensor is working and changing state from 'off' to 'on' when there is motion.
Setup the kettle with IFTTT
As described earlier the kettle has IFTTT support and can be turned on (boiled) from Home-assistant using the IFTTT component. First setup your Appkettle with IFTTT. Next create an IFTTT webhooks applet that when receiving a web request with event name “boil_kettle” will turn on the kettle. When added correctly the applet should look identical to:
Create the Home-assistant automation
We are now ready to add the automation to switch on the kettle when we get up in the morning. Home-assistant has a handy automations editor and I strongly recommend following the instructions to set this up. Assuming you have done this add the following code to your autonamtions.yaml file to get things setup correctly :
- id: morning_kettle_id
alias: Morning kettle
trigger:
- entity_id: binary_sensor.living_room_motion_sensor
from: 'off'
platform: state
to: 'on'
condition:
- after: 05:45:00
before: 07:00:00
condition: time
action:
- data:
event: boil_kettle
data_template:
event: boil_kettle
service: ifttt.trigger
- data:
entity_id: automation.morning_kettle
service: automation.turn_off
- delay:
minutes: 45
- data:
entity_id: automation.morning_kettle
service: automation.turn_on
This automation should now appear within the automation editor and you can make any changes you want. Restart Home-assistant and check that the automation appears within the list of entities. At this point everything should be working, so celebrate with a cup of tea. If you do run into problems check the Home-assistant documentation or make a post on the very active Home-assistant forum. In particular, I have noticed that the automations editor can over-write the delay field with garbage (mine was showing [object Object]) since delays are not yet supported by the editor. If this happens, you have to manually edit the automations.yaml file in a text editor, and just avoid re-opening your morning kettle automation in the automation editor.
Wemo plug integration
I've got an interest in monitoring my energy usage, so I recently purchased a Wemo Insight switch (shown below in Figure 2). As well as being able to switch this plug on/off from home-assistant via its component, the switch monitors the power (Watts) and energy (Kilowatts hour) usage. I've also configured home-assistant to notify me when the kettle has boiled.
The Wemo plug is auto-discovered by home-assistant, or you can manually configure it using the IP address of the plug. If manually configuring, I recommend using a DHCP reservation on your router to ensure the plugs IP doesn't change over time.
It is straightforward to create template sensors for the power and energy usage, as these are attributes of the Wemo switch entity (switch.wemo_insight
). The configuration in sensors.yaml is given below:
- platform: template
sensors:
wemo_current_power_w:
friendly_name: 'Wemo current power'
value_template: '{{float(states.switch.wemo_insight.attributes.current_power_w)}}'
unit_of_measurement: W
wemo_today_energy_kwh:
friendly_name: 'Wemo today energy'
value_template: '{{float(states.switch.wemo_insight.attributes.today_energy_kwh)}}'
unit_of_measurement: Kwh
When the kettle is in standby, it appears to draw a steady 1.8 Watts. When the kettle is on the boil it draws around 2 kW. This means we can use a threshold binary sensor to detect when the kettle is on the boil. The configuration in binary_sensor.yaml is shown below, where Ive set the threshold of 20 Watts above which the kettle is assumed on the boil:
- platform: threshold
name: 'Kettle'
entity_id: sensor.wemo_current_power_w
upper: 20
Since the water in the kettle will be warm for some time after boiling the kettle, I would like a sensor to display when the water is still warm. To do this I use a timer which is started when I turn on the kettle to boil the water. I use a template binary sensor to display when the timer is active
. After the configured time, the timer will finish and its states becomes idle
. The config for the timer is below:
timer:
kettle:
duration: '00:05:00'
The template boolean is below:
- platform: template
sensors:
kettle_warm:
value_template: >-
{{ is_state("timer.kettle", "active") }}
I use an automation to turn on the timer when the kettle is switched on, the code generated by the automations editor is below:
- action:
- data:
entity_id: timer.kettle
service: timer.start
alias: Kettle on timer
condition: []
id: '1518374196815'
trigger:
- entity_id: binary_sensor.kettle
platform: state
to: 'on'
I used the customisation tool on the home-assistant front end to customise the appearance of the icons, with the final result shown below in Figure 3.
All my configuration is on Github, in case you want to see the whole picture.
Summary
This project fulfils most of its objectives, and hopefully if an API is released for the Appkettle could complete all of its objectives by having a completely local system that functions even during an internet outage.
Comments
Please log in or sign up to comment.