My journey into integrating a kettle into openHAB for someone else - @spicerackk
This is not intended for the beginner but give it a go.
Prerequisite
- Mqtt Binding
- Mqtt Broker / mosquitto
- RegEx Transformation
- JsonPath Transformation
- JavaScript Transformation
Put tasmota onto kettle using TUYA-CONVERT
Setup tasmota to connect to wifi
Connect to the webpage for kettle and setup module
Configuration - Configure Other
Template
{"NAME":"Kogan Kettle","GPIO":[255,107,255,108,255,255,0,0,255,255,255,255,255],"FLAG":0,"BASE":54}
Then Configure MQTT with the topic kettle.
In Tasmota console change Setoption4 1
SetOption66 1
Test kettle is working on the tasmota webpage.
Test I can see messages in mqtt from tasmota kettle. I did this using mqtt explorer
A message from kettle for change in temperature
{"TuyaReceived":
{"Data":"55AA00070008050200040000003F58","Cmnd":7,"CmndData":"050200040000003F",
"DpId":5,"DpIdType":2,"DpIdData":"0000003F"}}
Right the kettle has Power, warm mode and reports temperature.
Blackadder Info - Someone already figured all this out.
Yay now we can look at the openHAB to MQTT
I use VScode to edit config files to add things to openHAB but adding in the UI will also work the same.
Things file - Docs
Bridge mqtt:broker:myMQTTBroker [ host ="192.168.1.128", secure =false, username ="open", password ="wide" , clientID ="dentist" ]
{
Thing topic Kettle "Kettle in Kitchen" @ "Kitchen" [ availabilityTopic ="tele/kettle/LWT", payloadAvailable ="Online", payloadNotAvailable ="Offline"] {
Channels:
Type switch : PowerSwitch [ stateTopic ="stat/kettle/POWER", commandTopic ="cmnd/kettle/POWER", on="ON", off="OFF"]
Type string : WarmMode [ commandTopic ="cmnd/kettle/TuyaSend4"]
Type number : temperature "Temperature [%.0f °C]" [ stateTopic ="tele/kettle/TUYARECEIVED", transformationPattern ="REGEX:(.*DpId\":5.*)∩JSONPATH:$.TuyaReceived.DpIdData∩JS:HEXtoDEC.js" ]
}
}
If you are putting this into the ui ∩ is not N
Items
Switch KettleInKitchenPowerSwitch {channel="mqtt:topic:myMQTTBroker:Kettle:PowerSwitch"}
String KettleInKitchenWarmMode {channel="mqtt:topic:myMQTTBroker:Kettle:WarmMode"}
Number KettleInKitchenTemperature "Temperature [%.0f °c]" {channel="mqtt:topic:myMQTTBroker:Kettle:temperature"}
Kettle.sitemap
sitemap Kettle label="Kitchen" {
Frame label="Kettle" {
Switch item=KettleInKitchenPowerSwitch label="Kettle []" icon="kettle" mappings=[ON="On", OFF="Off"]
Text item=KettleInKitchenTemperature icon="temperature_hot"
Switch item=KettleInKitchenWarmMode label="[]" icon="none" mappings=["102,0"="OFF","102,1"="40c","102,2"="50c","102,3"="60c","102,4"="80c","102,5"="90c"]
}
}
Now because the kettle is sending the temperature in hex and I would like it in deg c it needs to be transformed, so I created a file in the transform folder.
HEXtoDEC.js
(function(i) {
if (i == 'NULL') { return i; }
if ((i == '-') || (i == 'UNDEF')) { return 'Undefined'; }
return (parseInt(i,16));
})(input)
Done kettle all working.
Additional comments
transformationPattern =
"REGEX:(.*DpId\":5.*)∩JSONPATH:$.TuyaReceived.DpIdData∩JS:HEXtoDEC.js" ]
REGEX:(.DpId":5.) Filter out all messages we don’t want
JSONPATH:$.TuyaReceived.DpIdData Only look at the temp data in hex
JS:HEXtoDEC.js Convert HEX to DEC
If you want to put warm mode into a rule you would do it like.
// Warm to 60°c
KettleInKitchenWarmMode.sendCommand("102,3")