I’ve got the Kogan Smart Kettle. Following instructions found here I quickly managed to integrate the core functionality with HA (flashed Tasmota, using MQTT). I can turn it on/off and have the water temperature as a sensor.
Now I have one usage scenario that I don’t know how to script: heating water to a given temperature as exactly as possible. Background: it is winter here and I want to fill a hot water bottle with water of 80 degrees.
Problem: the temperature sensor is laggy. It takes time to measure and more importantly: if I turn off the kettle at a given temperature the energy already stored in the heating element of the kettle will further raise the water temperature.
With a given water volume and target temperature I can manually anticipate events, in this example: target is 80, but I turn off the kettle when I measure 75. Works well with about 1l of water.
Goal: make the script flexible so it works with different water volumes and temperatures. Idea: if I could measure how much the temperature rises over say 5 seconds I could use that information to estimate volume present and calculate based on that information when to turn off the heating element. How can that be implemented in code?
The specific heat capacity of water is 4.2K Joules per kilogram (litre) per degree Celsius, i.e. it takes 4,200 J to raise the temperature of 1 kg of water by 1°C.
1 Watt = 1 Joule per second
You know the power of the kettle.
So from that you can work out the time required to heat any volume of water to 80°C. Then you just have to try it in practise and add an efficiency factor.
e.g.
m = mass of water to be heated in kg (or litres)
T = temperature rise required (above cold water T or ambient T).
P = power of kettle in watts
t = time required in seconds
n = efficiency factor (0 to 1)
t = ( n * T * m * 4200 ) / P
As the only thing you don’t know is n, assume it is 1 and calculate the theoretical time. Then run a few tests and calculate n as theoretical time divided by actual time measured in practice.
The overshoot from the energy required to heat the thermal mass of the element could also be included as a separate calculation, or just by adjusting n.
Actually, what I can’t lock in is ‘m’. I want to be able to run my script to heat any quantity of water that happens to be in the kettle to 80 degrees. Or even more flexibly to a temperature I can define as an input. The physics isn’t the problem here though. What I don’t know is how I can script a sequence like:
turn on kettle
wait a few seconds for heating element to warm up
measure how many degrees the water temperature rises in say 5 seconds
based on the value found in 3) calculate a turn off temperature that will be used to turn off the kettle when reached. Intention: after adding in all the lags I end up with water at the actual target temperature, which will be higher than the turn-off temperature.
use that calculated value to turn off the kettle
1,2 and 5 are easy, I just don’t know how I can script 3 and 4. I’m happy to arrive at the formula used in calculating 4 by trial and error.
What I don’t know is how to carry over information between the steps and how to have steps that just perform calculations. In any regular programming language I would just use temporary variables, is there something like that available for scripts in HA or do I need to learn how to create a python script for that?
The keep warm is the easiest solution. I had never tried it before because I misread the user manual. I thought it would always boil first before then keeping warm.
I also tried the other way to learn using input_numbers for other scenarios. Storing temperatures in input_numbers worked fine. What I didn’t get to work was to use an input_number in a wait template, see below. It just never triggered. Any idea why?
I must admit this is the first time I’ve read about the wait_template. I’m a new HA user as well.
Do you know “Developer Tools - Template”? It’s a great way to verify templates, by breaking them down line by line.
Yep, I’ve tested the code in “Developer Tools - Template”. It correctly returns True/False.
If I specify a fixed number like I did in the original code up top, the wait_template works. Just not when I compare to the input_number. Tried with " and ', tried squeezing it all into 1 line to rule out indentation problems. Hmmm.