Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of "Xiaomi Mijia Temperature and Humidity Sensor" #74

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
# Xiaomi Mi Bluetooth Sensor MQTT Client/Daemon

A simple Linux python script to query arbitrary Mi Flora plant sensor devices and send the data to an **MQTT** broker,
A simple Linux python script to query arbitrary Mi Bluetooth sensor devices and send the data to an **MQTT** broker,
e.g., the famous [Eclipse Mosquitto](https://projects.eclipse.org/projects/technology.mosquitto).
After data made the hop to the MQTT broker it can be used by home automation software, like [openHAB](https://openhab.org) or Home Assistant.

Expand All @@ -9,15 +9,30 @@ After data made the hop to the MQTT broker it can be used by home automation sof
The program can be executed in **daemon mode** to run continuously in the background, e.g., as a systemd service.

## About Mi Flora
* [Xiaomi Mi Flora sensors](https://xiaomi-mi.com/sockets-and-sensors/xiaomi-huahuacaocao-flower-care-smart-monitor) ([e.g. 12-17€](https://www.aliexpress.com/wholesale?SearchText=xiaomi+mi+flora+plant+sensor)) are meant to keep your plants alive by monitoring soil moisture, soil conductivity and light conditions
* [Xiaomi Mi Flora sensors](https://www.huahuacaocao.com) ([e.g. 12-17€](https://www.aliexpress.com/wholesale?SearchText=xiaomi+mi+flora+plant+sensor)) are meant to keep your plants alive by monitoring soil moisture, soil conductivity and light conditions
* The sensor uses Bluetooth Low Energy (BLE) and has a rather limited range
* A coin cell battery is used as power source, which should last between 1.5 to 2 years under normal conditions
* Food for thought: The sensor can also be used for other things than plants, like in the [fridge](https://community.openhab.org/t/refrigerator-temperature-sensors/40076) or as [door and blind sensor](https://community.openhab.org/t/miflora-cheap-window-and-door-sensor-water-sensor-blind-sensor-etc/38232)

![Promotional image](https://ae01.alicdn.com/kf/HTB1WAd1XEvrK1RjSszfq6xJNVXaB/International-Version-Original-Xiaomi-Flower-Care-Soil-Water-Light-Smart-Flower-Monitor-for-Garden-Plants.jpg_640x640.jpg)

## About Xiaomi Mijia Temperature and Humidity Sensor
* ''Xiaomi Mijia Temperature and Humidity Sensor'' ([e.g. $13](https://www.aliexpress.com/wholesale?SearchText=Mijia+Bluetooth+Temperature+Humidity+Sensor)) are for monitoring indoor air temperature and humidity
* The sensor uses Bluetooth Low Energy (BLE) and has a rather limited range
* Weight: 43 g
* Screen size: 1.78 inch
* Temperature range: -9.9°C-60°C
* Humidity range: 0~99.9%
* Rated power: 0.18 mW
* Powered By: Battery (AAA)

![Promotional image](http://ae01.alicdn.com/kf/HTB11qrpeStYBeNjSspkq6zU8VXax.jpg)

## Features

* Tested with Mi Flora firmware v2.6.2, v2.6.4, v2.6.6, v3.1.4, others anticipated
* Build on top of [open-homeautomation/miflora](https://github.com/open-homeautomation/miflora)
* Tested with Xiaomi Mijia Temperature and Humidity Sensor (MJ_HT_V1) firmware v00.00.66
* Build on top of [open-homeautomation/miflora](https://github.com/open-homeautomation/miflora) and [mitemp_bt](https://github.com/flavio20002/mitemp_bt)
* Highly configurable
* Data publication via MQTT
* Configurable topic and payload:
Expand All @@ -26,6 +41,7 @@ The program can be executed in **daemon mode** to run continuously in the backgr
* following the [mqtt-smarthome architecture proposal](https://github.com/mqtt-smarthome/mqtt-smarthome)
* using the [HomeAssistant MQTT discovery format](https://home-assistant.io/docs/mqtt/discovery/)
* using the [ThingsBoard.io](https://thingsboard.io/) MQTT interface
* following the [Wiren Board MQTT Conventions](https://github.com/contactless/homeui/blob/master/conventions.md)
* Announcement messages to support auto-discovery services
* MQTT authentication support
* No special/root privileges needed
Expand All @@ -35,9 +51,7 @@ The program can be executed in **daemon mode** to run continuously in the backgr
* Automatic generation of openHAB items and rules
* Reliable and intuitive
* Tested on Raspberry Pi 3 and Raspberry Pi 0W


![Promotional image](https://xiaomi-mi.com/uploads/ck/xiaomi-flower-monitor-001.jpg)
* Wiren Board 5 (Debian Stretch)

### Readings

Expand All @@ -51,6 +65,14 @@ The Mi Flora sensor offers the following plant and soil readings:
| `conductivity` | [Soil fertility](https://www.plantcaretools.com/measure-fertilization-with-ec-meters-for-plants-faq), in [µS/cm] |
| `battery` | Sensor battery level, in [%] |

The Xiaomi Mijia Temperature and Humidity Sensor offers the following readings:

| Name | Description |
|-----------------|-------------|
| `temperature` | Air temperature, in [°C] (0.1°C resolution) |
| `humidity` | Air humidity in [%] |
| `battery` | Sensor battery level, in [%] |

## Prerequisites

An MQTT broker is needed as the counterpart for this daemon.
Expand All @@ -73,7 +95,7 @@ sudo pip3 install -r requirements.txt

The daemon depends on `gatttool`, an external tool provided by the package `bluez` installed just now.
Make sure gatttool is available on your system by executing the command once:

```shell
gatttool --help
```
Expand All @@ -90,13 +112,13 @@ vim /opt/miflora-mqtt-daemon/config.ini

**Attention:**
You need to add at least one sensor to the configuration.
Scan for available Mi Flora sensors in your proximity with the command:
Scan for available Mi Bluetooth sensors in your proximity with the command:

```shell
sudo hcitool lescan
```

Interfacing your Mi Flora sensor with this program is harmless.
Interfacing your Mi Bluetooth sensor with this program is harmless.
The device will not be modified and will still work with the official Xiaomi app.

## Execution
Expand Down Expand Up @@ -225,6 +247,15 @@ to integrate with [ThingsBoard.io](https://thingsboard.io/):
1. in your `config.ini` assign unique sensor names for your plants
1. on the ThingsBoard platform create devices and use `Access token` as `Credential type` and the chosen sensor name as token

### Wiren Board

to integrate with [Wiren Board](https://wirenboard.com/en/) in your `config.ini` set:

1. `reporting_method = wirenboard-mqtt`
1. set `hostname` with address of [Wiren Board](https://wirenboard.com/en/) controller and optionally `username` and `password`

sensors will automatically appear on [Wiren Board](https://wirenboard.com/en/) as separate devices

----

#### Disclaimer and Legal
Expand Down
20 changes: 15 additions & 5 deletions config.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@
# (https://www.home-assistant.io/docs/mqtt/discovery/)
# thingsboard-json - Publish to the ThingsBoard MQTT broker
# (https://thingsboard.io)
# wirenboard-mqtt - Publish to the Wiren Board MQTT broker
# (https://wirenboard.com)
# json - Print to stdout as json encoded strings
#
#reporting_method = mqtt-json

# The bluetooth adapter that should be used to connect to Mi Flora devices (Default: hci0)
# The bluetooth adapter that should be used to connect to Mi Bluetooth devices (Default: hci0)
#adapter = hci0

[Daemon]

# Enable or Disable an endless execution loop (Default: true)
#enabled = true

# The period between two measurements in seconds (Default: 300)
#period = 300
# The period between two measurements in seconds for MiFlora sensors (Default: 300)
#period_miflora = 300

# The period between two measurements in seconds for MiTempBt sensors (Default: 60)
#period_mitempbt = 60

[MQTT]

Expand All @@ -45,10 +50,11 @@

# The MQTT base topic to publish all Mi Flora sensor data topics under.
# Default depends on the configured reporting_method
#base_topic = miflora # Default for: mqtt-json, mqtt-smarthome
#base_topic = misensor # Default for: mqtt-json, mqtt-smarthome
#base_topic = homie # Default for: mqtt-homie
#base_topic = homeassistant # Default for: homeassistant-mqtt
#base_topic = v1/devices/me/telemetry # Default for: thingsboard-json
#base_topic = # Default for: wirenboard-mqtt

# Homie specific: The device ID for this daemon instance (Default: miflora-mqtt-daemon)
#homie_device_id = miflora-mqtt-daemon
Expand All @@ -69,7 +75,7 @@
# Path to TLS client auth certificate file
#tls_certfile =

[Sensors]
[MiFlora]

# Add your Mi Flora sensors here. Each sensor consists of a name and a Ethernet MAC address.
# Additional location information can be added to the name, delimited by an '@'.
Expand All @@ -81,3 +87,7 @@
#Schefflera@Living = C4:7C:8D:11:22:33
#JapaneseBonsai = C4:7C:8D:44:55:66
#Petunia@Balcony = C4:7C:8D:77:88:99

[MiTempBt]

# Add your Mi Temerature & Humidity sensors here. Setup is same as for [MiFlora] section
Loading