I just integrated my Oral-B toothbrush via MQTT into my OpenHab system and want to share my solution with you.
What you need:
- Oral-B toothbrush which supports bluetooth
- Device with an bluetooth adapter (in my case a raspberry pi)
The logic behind this little project is the following:
Toothbrush → Bluetooth → Raspberry Pi Service → MQTT → OpenHAB
The toothbrush sends a bluetooth low energy signal including the data. This is received by a Raspberry Pi service. The incoming data is processed and sent to OpenHAB via a MQTT.
1. Raspberry Pi
Requirements: Python 3, MQTT Broker (e.g. Mosquitto)
- Download the prepared file by vogler.
- Install the requirements:
sudo pip install bluepy paho-mqtt
. - Find the mac-address of your toothbrush (e.g.
sudo hcitool lescan
) - Create and change the service for your needs (file destination, host, topic):
/etc/systemd/system/toothbrush.service
:
[Unit]
Description=Zahnbuerste Ueberwachung Mqtt
[Service]
User=pi
Type=simple
ExecStart=sudo python3 /home/pi/toothbrush/toothbrush2mqtt.py 11:22:33:44:55:66 host topic
[Install]
WantedBy=multi-user.target
Start the service with sudo systemctl start toothbrush.service
.
Optional: If you have authentication enabled at your MQTT broker you have to add the following line above mqttc.connect(host)
:
mqttc.username_pw_set(username="username", password="password")
2. OpenHAB
Requirements: configured MQTT Binding, JSONPATH transformation
toothbrush.things
(replace the stateTopic
with your topix):
Thing mqtt:topic:toothbrush "toothbrush" (mqtt:broker:mqttbroker) @ "Mqtt"
{
Channels:
Type switch : running "running" [ stateTopic = "toothbrush", transformationPattern="JSONPATH:$.running", on ="true", off = "false" ]
Type number : pressure "pressure" [ stateTopic = "toothbrush", transformationPattern="JSONPATH:$.pressure" ]
Type number : time "time" [ stateTopic = "toothbrush", transformationPattern="JSONPATH:$.time" ]
Type number : mode "mode" [ stateTopic = "toothbrush", transformationPattern="JSONPATH:$.mode" ]
Type number : quadrant "quadrant" [ stateTopic = "toothbrush", transformationPattern="JSONPATH:$.quadrant" ]
Type number : quadrant_percentage "quadrant_percentage" [ stateTopic = "toothbrush", transformationPattern="JSONPATH:$.quadrant_percentage" ]
}
toothbrush.items
:
Group gToothbrush "Toothbrush" ["Sensor"]
Switch Toothbrush_Running "Toothbrush Running" (gToothbrush) ["Power"] {channel="mqtt:topic:toothbrush:running"}
Number Toothbrush_Pressure "Toothbrush Pressure" (gToothbrush) ["Pressure"] {channel="mqtt:topic:toothbrush:pressure"}
Number Toothbrush_Time "Toothbrush Time" (gToothbrush) ["Duration"] {channel="mqtt:topic:toothbrush:time"}
Number Toothbrush_Mode "Toothbrush Mode" (gToothbrush) ["Measurement"] {channel="mqtt:topic:toothbrush:mode"}
Number Toothbrush_Quadrant "Toothbrush Quadrant" (gToothbrush) ["Measurement"] {channel="mqtt:topic:toothbrush:quadrant"}
Number Toothbrush_Quadrant_Percentage "Toothbrush Quadrant Percentage" (gToothbrush) ["Measurement"] {channel="mqtt:topic:toothbrush:quadrant_percentage"}
Have fun with the incoming data and creating awesome rules