Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon

mqtt
xiaomi
miflora
Tags: #<Tag:0x00007f0146e13c48> #<Tag:0x00007f0146e13ae0> #<Tag:0x00007f0146e139a0>

(Kim Skatun) #41

I have 12 of them, really handy for me that does not have green fingers, unfortunately 2 of them is out of the reach for the rpi, so sometime this winter I will add a bridge as rpi0W. I also have some water irragation system that I am working on…


(Antonio) #42

I have the same problem as you. The range does not reach from the pi to the MIflora. If you have any idea how to create a bridge increase the power would be very grateful to collaborate.


Miflora cheap window and door sensor, water sensor, blind sensor etc
( ) #43

Hey, that problem is part of why the daemon relies on MQTT. You can simply set up another RPi0W in Bluetooth range: Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon


(Sergey M) #44

A very expensive repeater turns out :frowning:


(Patrick) #45

Very expensive is a relative term i guess :smirk: When i compared it to other solutions, this setup (even with one or two extra rpi0W) was still the cheapest for me if you want several sensors.


(Brian M. Pedersen) #46

For Node-red users there is a node which auto detects your miflowers and get data from them. you need to install a few nodes also, but it works and it’s up and running without any hassel:


(Kim Skatun) #47

Can you confirm that 10 devices is maximum per rpi?


(Carsten) #48

I am not really sure if I setup my config right cause i got an error after the start… :sweat_smile:

[21:24:44] openhabian@openHABianPi:~$ python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 119, in <module>
    config.read([os.path.join(sys.path[0], 'config.ini.dist'), os.path.join(sys.path[0], 'config.ini')])
  File "/usr/lib/python3.4/configparser.py", line 672, in read
    self._read(fp, filename)
  File "/usr/lib/python3.4/configparser.py", line 1070, in _read
    fpname, lineno)
configparser.DuplicateOptionError: While reading from '/opt/miflora-mqtt-daemon/config.ini' [line 42]: option 'base_topic' in section 'MQTT' already exists

Config.ini

[General]

# The operation mode of the program. Determines wether retrieved sensor data is published via MQTT or stdout/file.
# Currently supported:
#      mqtt-json - Publish to an mqtt broker, json encoded (Default)
#     mqtt-homie - Publish to an mqtt broker following the Homie MQTT convention (https://github.com/marvinroger/homie)
# mqtt-smarthome - Publish to an mqtt broker following the mqtt-smarthome proposal
#                  (https://github.com/mqtt-smarthome/mqtt-smarthome)
#           json - Print to stdout as json encoded string
reporting_method = mqtt-json

# The bluetooth adapter that should be used to connect to Mi Flora 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

[MQTT]

# The hostname or IP address of the MQTT broker to connect to (Default: localhost)
hostname = localhost

# The TCP port the MQTT broker is listening on. SSL/TLS currently not implemented (Default: 1883)
port = 1883

# Maximum period in seconds between ping messages to the broker. (Default: 60)
keepalive = 60

# The MQTT base topic to publish all Mi Flora sensor data topics under.
# Default depends on the configured reporting_mode (mqtt-json, mqtt-smarthome: miflora, mqtt-homie: homie)
base_topic = miflora
base_topic = homie

# Homie specific: The device ID for this daemon instance (Default: miflora-mqtt-daemon)
homie_device_id = miflora-mqtt-daemon

# The MQTT broker authentification credentials (Default: no authentication)
#username = user
#password = pwd123

[Sensors]

# 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 '@'.
# Scan for sensors from the command line with:
#    $ sudo hcitool lescan
#
# Examples:
Einblatt@Bedroom = C4:7C:8D:65:DE:85

mmhh? :confused:


(Rohnny Swennen) #49

Thanks will check,that one out for sure


(Patrick) #50

You’ve got one “base_topic” too much there. You configure the name of the mqtt base topic to publish the messages on, but you only chose one name for that.

Try to comment out the line by adding a # in front.


( ) #51

I can not confirm as I only have 6 sensors.
Not sure where the restriction would come from


(Kim Skatun) #52

Can anyone confirm that Miflora broadcast its values every 30s, which means that if we set up refresh interval in miflora deomon to 30s we will get updates in the interval 0-100s.


(Thomas Bail) #53

@ThomDietrich Hey ist it possible to add a timestamp to the plant data?

Thomas


(Kim Skatun) #54

As said the Miflora broadcast its values at a given interval, and you set up the dameon to forward the values at another interval. So no you can not get exact time when the miflora did its measurement as far as I know.

The question is how accurate do you need it? You can always see when the OH item was last updated and if this is more then 1h then either battery or range is wrong. Or what do you want with the timestamp?


(Thomas Bail) #55

I dont care about the interval the mifloras are braodcasting. I what to know when i last received data in openHAB or last send data from the miflora daemons


( ) #56

@skatun I’m not sure what you mean by broadcast. You can configure how often the daemons polls data from the sensor.
Besides that I’m not sure why you’d want to poll every 30 seconds. No plant sensor value will have fluctuations that high and it will drain your battery.

@Dibbler42 would definitely be possible. I feel like it’s already in there!?


(Patrick) #57

For this part, I have a rule in OH:

rule "Palme Update"
when
Item Palme_LightIntensity received update
or
Item Palme_AirTemperature received update
or
Item Palme_SoilMoisture received update
or
Item Palme_SoilConductivity received update
then
postUpdate(Palme_LastUpdate, new DateTimeType())
end

So if any of the values are updated, Palme_LastUpdate will get an update too. That’s all I need to see that the updates are still working. Maybe that helps?


(Kim Skatun) #58

Well if I solder a push button to the pads and use it as a switch instead of a plant sensor, I need to detect immediately that the button has been pressed. However this will not work immediately because the senor itself only update every 30s, but to see if window is open etc its fine…


( ) #59

That’s always an option but @Dibbler42 has a fair point, those could be part of the MQTT message.

@Dibbler42 could you check if adding

data['timestamp'] = strftime('%Y-%m-%d %H:%M:%S', localtime())

here does it?


( ) #60

Ah one more thing. For easy automatic/direct conversion and storage in a DateTime Item in openHAB you’d should use one of the formats (ideally RFC822) given here: