Skip to content

Python library to read the Tilt bluetooth hydrometer and send values to MQTT

Notifications You must be signed in to change notification settings

LinuxChristian/tilt2mqtt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Tilt2MQTT - Stream the Tilt Hydrometer to MQTT

Table of Contents
  1. Inroduction
  2. How to run
  3. Running as a service
  4. Integrate with Home Assistant
  5. Integrate with Brewers Friend

Note: This package requires a MQTT server. To get one read here.

Wrapper for reading messages from Tilt wireless hydrometer and forwarding them to MQTT topics.

The device acts as a simple Bluetooth IBeacon sending the following two values,

  • major: Temperature in Farenheit
  • minor: Specific gravity

The raw values read from the Tilt are uncalibrated and should be calibrated before use. The script works a follows,

  1. Listen for local IBeacon devices
  2. If found the callback is triggered
  • Translate the UUID to a Tilt color
  • Extract and convert measurements from the device
  • Construct a JSON payload
  • Send payload to the MQTT server
  1. Stop listening and sleep for X minutes before getting a new measurement

This script has been tested on Linux. By default the script will create a log file in the path /tmp/tilt.log.

If you are on Linux first install the bluetooth packages,

sudo apt-get install libbluetooth-dev

Then install Python dependencies

pip install beacontools paho-mqtt requests pybluez

Run the script,

python tilt2mqtt.py

Note: If you get a permission error try running the script as root.

The code should now listen for your Tilt device and report values on the MQTT topic that matches your Tilt color.

You can use the mosquitto commandline tool (on Linux) to listen for colors or the build-in MQTT client in Home Assistant,

mosquitto_sub -t 'tilt/#'

To listen for measurements only from Orange devices run,

mosquitto_sub -t 'tilt/Orange/#'

If your MQTT server is not running on the localhost you can set the following environmental variables,

Varable name Default value
MQTT_IP 127.0.0.1
MQTT_PORT 1883
MQTT_AUTH NONE
MQTT_DEBUG TRUE

If you would like to run tilt2MQTT as a service on Linux using systemd add this file to a systemd path (Normally /lib/systemd/system/tilt2mqtt.service or /etc/systemd/system/tilt2mqtt.service)

# On debian Linux add this file to /lib/systemd/system/tilt2mqtt.service

[Unit]
Description=Tilt Hydrometer Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/usr/bin/python3 <PATH TO YOUR FILE>/tilt2mqtt.py
StandardInput=tty-force

[Install]
WantedBy=multi-user.target

Remember to change the PATH variable in the script above. Then update your service,

sudo systemctl reload-daemon

Using the MQTT sensor in home assistant you can now listen for new values and create automations rules based on the values (e.g. start a heater if the temperature is too low).

  - platform: mqtt
    name: "Tilt Orange - Temperature"
    state_topic: "tilt/Orange"
    value_template: "{{ value_json.temperature_celsius_uncali | float + 0.5 | float | round(2) }}"
    unit_of_measurement: "\u2103"

  - platform: mqtt
    name: "Tilt Orange - Gravity"
    state_topic: "tilt/Orange"
    value_template: "{{ value_json.specific_gravity_uncali | float + 0.002 | float | round(3) }}"

Notice that here the calibration value is added directly to the value template in home assistant. The calibration parameters are estimated following the Tilt guide.

Home Assistant - Brewing

Using the following gist it is possible to stream the calibrated values from home assistant to the brewers friend API via a simple Python script. After this you can add the tilt2mqtt.service to

Brewers Friend fermentation overview

About

Python library to read the Tilt bluetooth hydrometer and send values to MQTT

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages