Supporting Kegtron v1 via Bluetooth LE scanning

In my home kegerator I have a nifty device called Kegtron that monitors the flow rate of two kegs and reports out data using Bluetooth LE Advertisement beacons. The team at Kegtron has recently documented there full BLE messaging format here:

Gen1BLEMessageFormat.pdf (kegtron.com)

I would really like to get this data into Home Assistant, and it seems like all the base ingredients to build a simple integration are there, but my (already limited) coding skills have greatly atrophied over the years and I’ve not attempted to write a HA integration before, so I’m hoping some kind soul will take pity on me and offer some help or advice on my quest.

On my RPi4/HassOS based installation, I can see the Kegtron BLE Advertisement data broadcasts when running bluetoothctl from the command line and enabling scanning.

Looking at the code for the Bluetooth LE Tracker, it appears scan for similar BLE messages, and I don’t need to connect to the device or interrogate UUID properties as all the data is presented in the passive scans. However, the existing BLE Tracker integration isn’t a perfect template, as it doesn’t appear to consume the advertising packets from the devices so I’ll need to figure that out. A quick look the pygatt library implies scanning is only used to find devices, not to listen for advertising broadcasts, but I could be missing something there.

If anyone has any advice, or wants to come along for the ride please let me know. Thanks!

I just ordered the Kegtron v1 and one of my goals is to get it into HA. I am thinking that this might be doable with one of the BLEtoMQTT options out there. Will need to get it and give it a try. Let me know if you make any progress.

It looks like this might support the kegtron. Need to do some more research: Passive BLE Monitor integration

I think this has just been added to the custom component: Passive BLE monitor.

It is installable via HACS

Yep, I have added support for Kegtron recently to Passive BLE Monitor. One remark, you will have to enable active_scan to get the data from your Kegtron device.

1 Like

The support for Kegtron v1 in the Passive BLE monitor component is fantastic. Thanks again to @Ernst for the support.

image

1 Like

Hi millercentral.

That was a great card you made for your keg. Do you mind sharing how you created it?

I can find port name, keg type, keg size and dispensed litres, but how did you find out drinks served, and drinks remaining? I assumes you calculate the percentage keg remain, or do you read this in some smart way from the Kegtron?

This is what I see:

image

Yes, you have to calculate it from the starting volume and the volume dispensed. I made a couple of template sensors in configuration.yaml to track this:

sensor:
  - platform: template
    sensors:
      # Kegtron Template Sensors
      kegerator_right_tap_name:
        friendly_name: "Kegerator Right Tap Name"
        value_template: "{{ state_attr('sensor.kegerator_right_tap_volume_dispensed', 'port name') }}"

      kegerator_right_tap_keg_type:
        friendly_name: "Kegerator Right Tap Keg Type"
        value_template: "{{ state_attr('sensor.kegerator_right_tap_volume_dispensed', 'keg size') }}"

      kegerator_right_tap_drinks_served:
        friendly_name: "Kegerator Right Tap Drinks Served"
        value_template: "{{ ( states('sensor.kegerator_right_tap_volume_dispensed') | float / 0.473 ) | round | int }}"
        icon_template: mdi:glass-mug-variant

      kegerator_right_tap_drinks_remaining:
        friendly_name: "Kegerator Right Tap Drinks Remaining"
        value_template: "{{ ( (state_attr('sensor.kegerator_right_tap_volume_dispensed', 'volume start') | float - states('sensor.kegerator_right_tap_volume_dispensed') | float ) / 0.473 ) | round | int }}"
        icon_template: mdi:glass-mug-variant

      kegerator_right_tap_keg_remaining_percent:
        friendly_name: "Kegerator Right Tap Percent Remaining"
        value_template: "{{ ( ( ( state_attr('sensor.kegerator_right_tap_volume_dispensed', 'volume start') | float - states('sensor.kegerator_right_tap_volume_dispensed') | float ) / state_attr('sensor.kegerator_right_tap_volume_dispensed', 'volume start') | float ) * 100 ) | round(1) }}"
        unit_of_measurement: "%"

I also made template sensors to make it a bit easier to display the other attributes of the sensor.

Note that I’m simply assuming a served drink is always a US Pint (0.473 liters) as that works for my use case. A more robust solution may be to use a input_select entity to allow you to choose what serving size you want to track.

Other cool things to do with this integration: I send an alert when either tap drops below 10% remaining, and when its been more than 2 months since the lines were cleaned (this is also tracked manually). I’m also going to add a “Days on tap” sensor that auto-resets when the volume dispensed sensor reverts to zero.

What I really, really want to do is integrate this with the untappd APIs to display an utappd beer card for the tapped kegs. Getting the data from untappd is pretty easy using the REST integration (and you could store the untappd beerid in the kegtron “beer name” field using the kegtron app), but I don’t have the lovelace custom-card skills to recreate this info card in lovelace:


…but hopefully I’ll figure it out eventually.

1 Like

Curious does this work with the new built in Bluetooth support? Considering picking up a few but want to be sure it still works

Anyone know how to get other values out of Kegtron? Like Date Tapped, Days on Tap, Date Cleaned, etc.?

Those values aren’t saved to the device or broadcast by the BLE signal from the Kegtron, they are just locally stored by the Kegtron app. I just made equivalent ones in Home Assistant. The only thing I use the kegtron app for now is to reset the volume and keg size when I get a new keg, everything else is in home assistant.

I wish Untappd didn’t kill their API, I would have loved to pull beer information from Untappd for the kegerator as well.

Btw, a little late to mention here, but we have moved the Kegtron support to an official HA integration, using the build in Bluetooth integration. BLE monitor also still functional as before.

I’m getting a very weird thing, a random Bluetooth hexagon light panel (Chinese) device is showing up as a Kegtron device, what is the thing that determines what integration to match to a device ?