SwitchBot Meter Temperature & Humidity (Thermometer & Hygrometer) with Home Assistant

UPDATE - The Home Assistant SwitchBot Bluetooth integration now supports Meters. That along with Bluetooth proxies is a much simpler way to bring your Meters into Home Assistant. I now recommend that you use that method instead.

UPDATE 20 Mar 2021 - Added Docker container option in the Github repository.

The SwitchBot integration for Home Assistant does not support SwitchBot Meter Temperature & Humidity Sensors. sbm2mqtt is an easy way to integrate your Meters with Home Assistant using MQTT instead.

Look here on GitHub.

image

image

sbm2mqtt scans for BLE advertisements from Switchbot Meters, grabs temperature, humidity & battery information from them and then publishes the data to an MQTT topic for easy integration with Home Assistant.

sbm2mqtt cannot be run using the python_script component or under non-“Core” Home Assistant (was Hassio), because it requires extra Python libraries to be imported. Instead run it on a separate pi or similar, or in a separate container.

sbm2mqtt works like this:

  • Scan for Bluetooth Low Energy devices, looking for SwitchBot Meters.
  • For each SwitchBot Meter, grab the MAC address, temperature, humidity and battery level from the BLE advertisement.
  • Publish the temperature, humidity and battery level for each SwitchBot Meter separately to an MQTT topic that includes the MAC address.
  • Print the values to the terminal (if not running in the background) and save them to a log.
  • Based on your configuration of Home Assistant with MQTT sensors for the sbm2mqtt MQTT topics, HA updates the states of those sensors with every new MQTT message.

Enjoy.

5 Likes

I am planning to purchase the Switchbot Meter Temp & Humidity from Amazon. Looking at the installation, I am confuse as how HA will read the temperature data from another rpi device that is running the sbm2mqtt.py script?

What details do I input here? The ip address and mqtt user credential where Hassio is installed?

# MQTT Settings
mqtt_host = 'xxx.xxx.xxx.xxx'
mqtt_port = xxxx
mqtt_timeout = 30
mqtt_client = 'switchbot_meter_checker'
mqtt_user = 'xxxxxx'
mqtt_pass = 'xxxxxx'
mqtt_topic = 'switchbot_meter/'
1 Like

You need to install mosquitto broker on the rpi and then put the rpi as host, 1883 as port (mosquitto user / passwd if used) and then set up an MQTT integration in HA and it will auto appear within minute or two. Hass.io should come with it’s own MQTT broker addon iirc.

I have setup the switchbox meter device with success. On the second rpi, I only had to run these lines as stated in the github. I didn’t have to install mosquitto broker on this rpi.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip libglib2.0-dev
sudo pip3 install bluepy
sudo pip3 install paho-mqtt

My first rpi with Hassio have mosquitto broker add-on installed. The mqtt user credential is what needed to be inputted in the sbm2mqtt_config.py

1 Like

I have this meter from switchbot. my home assistant is on Intel NUC. I have BT dongle installed. Can you explain how I can make it running?

Added Docker container option in the Github repository.

1 Like

Will this also work on the HA Blue? It’s not in HACS I see.

Many thanks for the docker container, I previously tried to make one myself but got in way over my head. Here’s a docker-compose.yml I use the image with after building it.

version: '3'
services:
  sbm2mqtt:
    container_name: sbm2mqtt
    network_mode: host
    image: sbm2mqtt
    privileged: true
    environment:
      - MQTT_HOST=ip
      - MQTT_USER=user
      - MQTT_PASS=pass
      - REPORTING_INTERVAL=60
    restart: unless-stopped

Running great on rpi zero with usb bt dongle.

1 Like

Feel free to open a pull request for this method in Github.

I haven’t tried it, but I think that you could add the Docker container on HA Blue using, for example, the Portainer add-on.

If you’ve got a spare Pi Zero W lying around, it’s simpler to dedicate that to sbm2mqtt with the added bonus that you can locate it near the Switchbot Meters if they are far from your HA Blue box.

Just did the pull req, also have an issue concerning timezone, the container reports the time hour off as opposed to running locally. I think the container is in UTC while I’m in GMT.

Thanks for the reply and the idea. It seems like an interesting project. But it also seems like too much work to integrate a simple device into Home Assistant when so many other devices can easily do the same thing.
I’m not savvy enough to do it myself, but I cannot help but wonder why someone isn’t working on an integration for all of their products and hub.

Switchbot now has a cloud API for the Hub for which it should be possible to error write an integration for Home Assistant. I’m not aware of any such project, though. The API didn’t exist when I wrote sbm2mqtt–and of course you have to be OK with dependency on the cloud.

There is another project for local control of Switchbot devices including Meters that uses an ESP32 board instead of a Pi. You might want to check it out.

If anyone’s interested I built the docker image for Pi (docker pull ghcr.io/hugalafutro/sb2mqtt:latest). I built it on Pi Zero, but I tested it on Rpi3 too and it works ok there too.

1 Like

I’ve set this up on a pi zero, but in my mosquitto log on HA it’s filled with

1623190208: New connection from 192.168.*.* on port 1883.
1623190208: New client connected from 192.168.*.* as sbm2mqtt (p2, c1, k60, u'sbm').
1623190208: Socket error on client sbm2mqtt, disconnecting.

Almost everything I search points to an authentication error, but I have tried a lot, including creating a local mqtt user inside the mosquitto config, or using HA users. I’ve double checked and tripple checked to make sure the usernames and passwords all match. Not sure what else I can try (I also got the same error when trying to run it locally on a HA Blue via portainer, and when running it in a docker on unraid)

Hi, do you think it could be used pyscript instead to integrate sbm2mwtt directly into HA?

I’ve successfully used pyscript to write a simple integration that relied a package that surely is not shipped with HA (it is on pypi though).

Maybe I will give it a try in the weekend.

1 Like

Hello sorry for the total noob question.

I have home assistant running in a VM on a windows machine.

How do I go about setting up what you’ve described?

I am using a couple of Switchbot Hub Minis too, because the signals of the Switchbot Meters are otherwise too far away.

Is anyone able to get all the data from those into HA? If so, how?

simple use esphome proxies