Home Tutorials Home Assistant Integrate the best Xiaomi Mi Scales in Home Assistant

Integrate the best Xiaomi Mi Scales in Home Assistant

Mi Scales in Home Assistant

0
4378
Integrate Xiaomi scales tutorial

We already reviewed the Xiaomi Mi Scale. Xiaomi have beautiful Smart scales for a affordable prices.
The Xiaomi scales are available in de mi-home app, but we want more! A while ago I found a great open source project on github: https://github.com/lolouk44/xiaomi_mi_scale
Due to the work of a fanatic Home assistant user with the nickname Lolouk it’s now possible to integrate several Xiaomi Mi scales in Home Assistant. All credits goes to Lolouk for his work, and help to other users.

Why would you do that? Because it is possible. we want everything in our Home Assistant, everything connected, monitored and controlled, even if we don’t actually use it. Think about things you can do with it: make automations that do something after a weight, or use it so you don’t need the official apps anymore.

Contents

What do you need to Integrate Xiaomi Mi Scales

One of the supported Xiaomi scales (see below), bluetooth (this is a cheap bluetooth dongle for around 4 euro) on your system and time to read this short article 🙂

Two methods to Integrate Xiaomi Mi Scales in Home Assistant

Lolouk made a very nice script. There are two ways to get the scale software up and running. A Home Assistant Add-on which start a docker in the background, and give you the options to configure it in the add-on. Both methods are using the same configuration parameters and send the Weight measuring by MQTT.

If you are not using the add-on store or you have to run the software on another system you can use the manual docker installation. The bluetooth on my Home Assistant machines was not stable enough, so instead of the add-on I switched to the docker setup. I run the docker on a raspberry Pi that I use for octoprint but is perfectly capable of running this docker parallel.

How to configure the Mi Scale script?

Which method you choose is up to you, but configuration is the same for both methods.

1: retrieve the unique bluetooth Mac adress. This can be done by several bleutooth scanner apps but ofcourse also in the Mi Fit App.

MAC Address you need to Integrate Xiaomi Mi Scales in Home Assistant

Because the software is using MQTT to send the data to your broker, you must enter your own settings.

OptionTypeRequiredDescription
HCI_DEVstringNoBluetooth hci device to use. Defaults to hci0
MISCALE_MACstringYesBluetooth Mac address of your scale
MQTT_PREFIXstringNoMQTT Topic Prefix. Defaults to miscale
MQTT_HOSTstringYesMQTT Server (defaults to 127.0.0.1)
MQTT_USERNAMEstringNoUsername for MQTT server (comment out if not required)
MQTT_PASSWORDstringNoPassword for MQTT (comment out if not required)
MQTT_PORTintNoDefaults to 1883
TIME_INTERVALintNoTime in sec between each query to the scale, to allow other applications to use the Bluetooth module. Defaults to 30
MQTT_DISCOVERYboolNoMQTT Discovery for Home Assistant Defaults to true
MQTT_DISCOVERY_PREFIXstringNoMQTT Discovery Prefix for Home Assistant. Defaults to homeassistant

Beside your MQTT settings you need to setup 1 or more users.

OptionTypeRequiredDescription
USER1_GTintYesIf the weight (in kg) is greater than this number, we’ll assume that we’re weighing User #1
USER1_SEXstringYesmale / female
USER1_NAMEstringYesName of the user
USER1_HEIGHTintYesHeight (in cm) of the user
USER1_DOBstringYesDOB (in yyyy-mm-dd format)
USER2_LTintNoIf the weight (in kg) is less than this number, we’ll assume that we’re weighing User #2. Defaults to USER1_GT Value
USER2_SEXstringNomale / female. Defaults to female
USER2_NAMEstringNoName of the user. Defaults to Serena
USER2_HEIGHTintNoHeight (in cm) of the user. Defaults to 95
USER2_DOBstringNoDOB (in yyyy-mm-dd format). Defaults to 1990-01-01
USER3_SEXstringNomale / female. Defaults to female
USER3_NAMEstringNoName of the user. Defaults to Missy
USER3_HEIGHTintNoHeight (in cm) of the user. Defaults to 150
USER3_DOBstringNoDOB (in yyyy-mm-dd format). Defaults to 1990-01-01


1: Xiaomi scale Add-on

image 13

Go to the Home assistant add-on store, add the repository: https://github.com/lolouk44/hassio-addons in the box and click on Add. In the list with available add-ons a Xiaomi Mi Scale is added. Click on the add-on to install and go to the configuration before you start the add-on.

2: Docker

The docker methode is a little bit more difficult. In some situations you have no other option.
The easiest way to create the docker, is by using the composer methode.
Please read more about docker, docker-compose and portainer, because it’s fantastic. It’s very simple: create a docker-compose.yaml with your personal settings and save. In the terminal type: nano docker-compose.yaml and paste the (modified) code from below into it and save.
Start up the container with the command docker-compose up -d

version: '3'
services:

  mi-scale:
    image: lolouk44/xiaomi-mi-scale:latest
    container_name: mi-scale
    restart: always

    network_mode: host
    privileged: true

    environment:
    - HCI_DEV=hci0                  # Bluetooth hci device to use. Defaults to hci0
    - MISCALE_MAC=00:00:00:00:00:00 # Mac address of your scale
    - MQTT_HOST=127.0.0.1           # MQTT Server (defaults to 127.0.0.1)
    - MQTT_PREFIX=miscale           # MQTT Topic Prefix. Defaults to miscale
    - MQTT_USERNAME=                # Username for MQTT server (comment out if not required)
    - MQTT_PASSWORD=                # Password for MQTT (comment out if not required)
    - MQTT_PORT=                    # Defaults to 1883
    - TIME_INTERVAL=30              # Time in sec between each query to the scale, to allow other applications to use the Bluetooth module. Defaults to 30
    - MQTT_DISCOVERY=true           # Home Assistant Discovery (true/false), defaults to true
    - MQTT_DISCOVERY_PREFIX=        # Home Assistant Discovery Prefix, defaults to homeassistant

      # Auto-gender selection/config -- This is used to create the calculations such as BMI, Water/Bone Mass etc...
      # Up to 3 users possible as long as weights do not overlap!


      # Here is the logic used to assign a measured weight to a user:
      # if [measured value in kg] is greater than USER1_GT, assign it to USER1
      # else if [measured value in kg] is less than USER2_LT, assign it to USER2
      # else assign it to USER3 (e.g. USER2_LT < [measured value in kg] < USER1_GT)

    - USER1_GT=70                   # If the weight (in kg) is greater than this number, we'll assume that we're weighing User #1
    - USER1_SEX=male                # male / female
    - USER1_NAME=Jo                 # Name of the user
    - USER1_HEIGHT=175              # Height (in cm) of the user
    - USER1_DOB=1990-01-01          # DOB (in yyyy-mm-dd format)

    - USER2_LT=35                   # If the weight (in kg) is less than this number, we'll assume that we're weighing User #2
    - USER2_SEX=female              # male / female
    - USER2_NAME=Serena             # Name of the user
    - USER2_HEIGHT=95               # Height (in cm) of the user
    - USER2_DOB=1990-01-01          # DOB (in yyyy-mm-dd format)

    - USER3_SEX=female              # male / female
    - USER3_NAME=Missy              # Name of the user
    - USER3_HEIGHT=150              # Height (in cm) of the user
    - USER3_DOB=1990-01-01          # DOB (in yyyy-mm-dd format)

Integrate in Domoticz or other platforms by MQTT

The software is using MQTT to transfer data to the broker you are using. The only thing you need to have is a MQTT broker. This means that you can pick up the data from your broker also by Domoticz, Node-red or other programs that support MQTT. This way you can integrate Xiaomi Mi Scales in almost everything 🙂

Supported Xiaomi Scales

Mi Smart Scale 2                                                                                              XMTZCO1HM, XMTZC04HMMi Scale_2
Mi Body Composition ScaleXMTZC02HMMi Scale
Mi Body Composition Scale 2XMTZC05HMMi Body Composition Scale 2

Related Xiaomi Mi Scale articles on Gadget-freakz

Review of the Xiaomi Mi-Scale smart scale.