Integrating the Medisana BS440 Bluetooth enabled bathroom scale

Hello together,

recently I’ve added my BS440 body analysis scale to my home automation system.

In order to achieve a fault tolerant system a Raspberry Pi Zero W was used in the close surrounding of the scale. It served as Bluetooth enabled gateway, which forwards measurements to Home Assistant using MQTT messages.

Bluetooth Gateway (Raspberry Pi Zero W)

The Bluetooth communication was done using the project of keptenkurk, which is available on GitHub. In order to install the Bluetooth stack on the Raspberry Pi, the following step by step instructions were used: https://keptenkurk.wordpress.com/2017/03/05/connecting-the-medisana-bs440-bluetooth-scale-epilogue/. I’ve implemented a generic MQTT plugin for the project. It’s currently available on https://github.com/jinnerbichler/BS440 until the pull request was accepted. The plugin is configured by renaming BS440mqtt.example.ini to BS440mqtt.ini and replacing the proper parameters of the MQTT client. Delete username and password if no credentials are necessary. Don’t forget to install the MQTT client by executing pip install paho-mqtt.

The MQTT client sends the measured data using the topics bs440/person1/ to bs440/person8/ and the following JSON encoding:

{"weight": 63.0, "timestamp": 1502822395, "age": 26, "activity": "normal", "tbw": 51.5, "person": 1, "valid": true, "fat": 26.6, "gender": "female", "model": "BS444", "muscle": 33.5, "kcal": 2217, "bone": 3.0, "size": 163}

Home Assistant (Raspberry Pi 3)

Home Assistant and the MQTT broker are running on a Raspberry 3, which is placed further away from the scale.
The following MQTT sensor was added to the configuration file:

- platform: mqtt
  state_topic: "bs440/person1/"
  name: "weight_person_1"
  unit_of_measurement: "kg"
  value_template: '{{ value_json.weight }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  name: "body_water_person_1"
  unit_of_measurement: "%"
  value_template: '{{ value_json.tbw }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  name: "body_fat_person_1"
  unit_of_measurement: "%"
  value_template: '{{ value_json.fat }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  name: "muscle_mass_person_1"
  unit_of_measurement: "%"
  value_template: '{{ value_json.muscle }}'
- platform: mqtt
  state_topic: "bs440/person1/"
  name: "bone_mass_person_1"
  unit_of_measurement: "kg"
  value_template: '{{ value_json.bone }}'

In the end the following data is available on Home Assistant.

Have fun!

5 Likes

@jinnerbichler
Can you help me to show how to setup the MQQT part of this guide. I have the scale setup running and is sending emails.

I have mosquitto running on the pi3. I’m very new to the mqqt world

I have added mqtt: to the configuration.yml and the sensors info as well but I’m getting errors.

“The following components and platforms could not be set up: * mqtt * sensor.mqtt Please check your config”

my config
mqtt:
broker: 192.168.1.5
port: 1883
username: myusername
password: xxxx
certificate: /etc/letsencrypt/live/www.xxx.xx/cert.pem

Thank you.

in the meantime mqqt issue seems to be fixed but I’m receiving an error when running the command manually

python BS440.py
2017-08-29 21:30:57,867 INFO     <module> Configured plugins: BS440mqtt
2017-08-29 21:30:57,868 INFO     <module> Loading plugin: BS440mqtt
Traceback (most recent call last):
  File "BS440.py", line 225, in <module>
    mod = __import__(plugin)
  File "plugins/BS440mqtt.py", line 41, in <module>
    import paho.mqtt.publish as publish
ImportError: No module named paho.mqtt.publish

Please install paho-mqtt by executing

pip install paho-mqtt

Please let me know if you find any issues.

erorr above gone, restarted the service, mqqt plugin seems to be activated, went on the scale but nothing was reported in the log file… something wrong wit mqqt config as posted above?

config BSS440.ini

Enable your plugins here, use the comma separated basename from the plugins/
Example:
plugins: BS440mqtt

root@DietPi:/opt/BS440# service bs440 status
● bs440.service - Run BS440 bluetooth scale monitor
Loaded: loaded (/etc/systemd/system/bs440.service; enabled)
Active: active (running) since Wed 2017-08-30 09:51:05 CEST; 1h 1min ago
Main PID: 15601 (python)
CGroup: /system.slice/bs440.service
└─15601 /usr/bin/python BS440.py

Aug 30 09:51:05 DietPi systemd[1]: Started Run BS440 bluetooth scale monitor.
Aug 30 09:51:05 DietPi python[15601]: 2017-08-30 09:51:05,899 INFO Configured plugins: BS440mqtt
Aug 30 09:51:05 DietPi python[15601]: 2017-08-30 09:51:05,899 INFO Loading plugin: BS440mqtt

root@DietPi:/opt/BS440# tail -v -f BS440.log
==> BS440.log <==
Wed, 30 Aug 2017 09:51:05 INFO Configured plugins: BS440mqtt
Wed, 30 Aug 2017 09:51:05 INFO Loading plugin: BS440mqtt
Wed, 30 Aug 2017 09:51:05 INFO init Initialising plugin: BS440mqtt
Wed, 30 Aug 2017 09:51:05 INFO init Read config from: /opt/BS440/plugins/BS440mqtt.ini

Have you setup persons on the scale?
It might be necessary in order to let the scale report its analysis.
You can do this using the companion App from Medisana.

yes, just me 1 user done since the first setup a year ago
sending emails works but not mqqt

@jinnerbichler how can I test the mqqt broker is working correctly. Can I push/publisha a test weight manually to person 1 to home assistant?

Great project, would this also work for a BS A40 that anyone knows?

Edit: alright, everything came along pretty good, just this error:

root@raspberrypi:~# journalctl -l -f -u bs440
-- Logs begin at Sat 2019-08-17 20:21:17 BST. --
Aug 17 20:21:43 raspberrypi systemd[1]: Started Run BS440 bluetooth scale monitor.
Aug 17 20:21:45 raspberrypi python[411]: Traceback (most recent call last):
Aug 17 20:21:45 raspberrypi python[411]:   File "BS440.py", line 199, in <module>
Aug 17 20:21:45 raspberrypi python[411]:     config.get('Program', 'loglevel').upper(),
Aug 17 20:21:45 raspberrypi python[411]:   File "/usr/lib/python2.7/ConfigParser.py", line 607, in get
Aug 17 20:21:45 raspberrypi python[411]:     raise NoSectionError(section)
Aug 17 20:21:45 raspberrypi python[411]: ConfigParser.NoSectionError: No section: 'Program'
Aug 17 20:21:45 raspberrypi systemd[1]: bs440.service: Main process exited, code=exited, status=1/FAILURE
Aug 17 20:21:45 raspberrypi systemd[1]: bs440.service: Failed with result 'exit-code'.

Any idea where to start fixing this?
I was able to connect to my scale and follow the guide.

It works for the BS A40.
Also I’m trying to get this on bt-mqtt-gateway but It doesn’t respond on the command with data. Is there anybody who has a Medisana scale + python + bluetooth knowledge who wants to help? I can share the code that I have so far.

Got it working for now, but the only problem is I have to have my rPi Zero W within 1 meter from my scale, is the BLE antenna so weak?
I want to have my rPi on top of the ceiling in the bathroom, and the scale on the ground, distance is 2 meters, but that doesn’t work.

And another question. I want to have my google home speaker talk to me when I weigh myself, so the speaker can say You are too fat, start running! whenever I measure… But, it seems it take 1 or 2 minutes before the results are transferred over MQTT, which is my trigger for google home, is there any way it can go faster?

@eh50, had a similar problem with the version mentioned here (which fixes the configparser-problem).

Traceback (most recent call last):
  File "/home/pi/BS440-HA-AD/BS440.py", line 204, in <module>
    config.get('Program', 'loglevel').upper(),
  File "/usr/lib/python3.9/configparser.py", line 781, in get
    d = self._unify_values(section, vars)
  File "/usr/lib/python3.9/configparser.py", line 1149, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'Program'

In my case I forgot to rename BS440.example.ini into BS440.ini.

Quick update on this: Pretty neat project I have to say. Issued two bugfixes as PRs. Would be happy to contribute further if time permits / if others are interested in contributing as well.

Just installed it here with an BS430 and RPI3 and mqtt to HA. Now trying to figure out were to place the RPI to get a stable BT signal from the scale.

Complements Keptenkurk who already started this project 8 years ago!

Ble, shitty close. I have a temp sensor outside, connects fine over 3 to 4 meters with wall in between. There is not much stretch in that

Read a lot about this online, but in my case a BS444 and a RPi 3 have Monotonien whatsoever talking through a massive concrete/steel wall.

Yes! One could say „visionary“.

Anybody tried to connect the scale via a Bluetooth proxy?

esphome on ESP32 project to read measurements GitHub - bwynants/weegschaal