Przeglądaj źródła

Clean up README and config

Thomas Dietrich 8 lat temu
rodzic
commit
7d464541cc
4 zmienionych plików z 26 dodań i 27 usunięć
  1. 3 0
      .gitignore
  2. 16 16
      README.md
  3. 4 9
      config.ini
  4. 3 2
      miflora-mqtt-daemon.py

+ 3 - 0
.gitignore

@@ -33,6 +33,9 @@ wheels/
 .installed.cfg
 .installed.cfg
 *.egg
 *.egg
 
 
+# pyCharm
+.idea/
+
 # PyInstaller
 # PyInstaller
 #  Usually these files are written by a python script from a template
 #  Usually these files are written by a python script from a template
 #  before PyInstaller builds the exe, so as to inject date/other infos into it.
 #  before PyInstaller builds the exe, so as to inject date/other infos into it.

+ 16 - 16
README.md

@@ -1,7 +1,8 @@
 # Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
 # Xiaomi Mi Flora Plant 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 Flora plant sensor devices and send the data to an **MQTT** broker,
-e.g., the famous [Eclipse Mosquitto](https://projects.eclipse.org/projects/technology.mosquitto) or the embedded MQTT broker in [Home Assistant](https://home-assistant.io). After data made the hop to the MQTT broker it can be used by home automation software like Home Assistant or [openHAB](https://openhab.org).
+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.
 
 
 ![Demo gif for command line execution](demo.gif)
 ![Demo gif for command line execution](demo.gif)
 
 
@@ -17,8 +18,9 @@ The program can be executed for a single run or in **daemon mode** to run contin
 * Announcement messages to support auto-discovery services
 * Announcement messages to support auto-discovery services
 * MQTT authentication support
 * MQTT authentication support
 * Daemon mode (default)
 * Daemon mode (default)
-* Systemd service file included, sd\_notify messages generated
+* Systemd service, sd\_notify messages generated
 * MQTT-less mode, printing data directly to stdout/file
 * MQTT-less mode, printing data directly to stdout/file
+* Automatic generation of openHAB items and rules
 * Reliable and intuitive
 * Reliable and intuitive
 * Tested on Raspberry Pi 3 and 0W
 * Tested on Raspberry Pi 3 and 0W
 
 
@@ -39,14 +41,14 @@ The Mi Flora sensor offers the following plant and soil readings:
 ### Installation
 ### Installation
 
 
 On a modern Linux system just a few steps are needed.
 On a modern Linux system just a few steps are needed.
-The following example shows the installation under Debian/Raspbian:
+The following example shows the installation under Debian/Raspbian below the `/opt` directory:
 
 
 ```shell
 ```shell
 sudo apt install git python3 python3-pip bluetooth bluez
 sudo apt install git python3 python3-pip bluetooth bluez
 
 
 git clone https://github.com/ThomDietrich/miflora-mqtt-daemon.git /opt/miflora-mqtt-daemon
 git clone https://github.com/ThomDietrich/miflora-mqtt-daemon.git /opt/miflora-mqtt-daemon
-cd /opt/miflora-mqtt-daemon
 
 
+cd /opt/miflora-mqtt-daemon
 sudo pip3 install -r requirements.txt
 sudo pip3 install -r requirements.txt
 ```
 ```
 
 
@@ -54,6 +56,11 @@ sudo pip3 install -r requirements.txt
 
 
 To match personal needs, all operation details can be configured using the file [`config.ini`](config.ini).
 To match personal needs, all operation details can be configured using the file [`config.ini`](config.ini).
 
 
+```shell
+vim /opt/miflora-mqtt-daemon/config.ini
+```
+
+**Attention:**
 You need to add at least one sensor to the configuration.
 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 Flora sensors in your proximity with the command:
 
 
@@ -69,14 +76,13 @@ The device will not be modified and will still work with the official Xiaomi app
 A first test run is as easy as:
 A first test run is as easy as:
 
 
 ```shell
 ```shell
-python3 miflora-mqtt-daemon.py
+python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py
 ```
 ```
 
 
 **⚠️️ Attention:
 **⚠️️ Attention:
 Please ensure a good communication link to all Mi Floras.
 Please ensure a good communication link to all Mi Floras.
-The daemon will currently retry connection to a non-responsive sensor for longer time periods, which will limit the overall usefulness of the application.
-To evaluate connection reliability execute the program in from the command line at least once and pay attention to reported communication problems.
-This problem will be solved in a future version of miflora-mqtt-daemon.**
+Sensors that can not be reached during the initital communication testing phase will be ignored.
+To evaluate connection reliability execute the program in from the command line at least once and pay attention to reported communication problems.**
 
 
 With a correct configuration the result should look similar to the the screencap above.
 With a correct configuration the result should look similar to the the screencap above.
 Pay attention to communication errors due to distance related weak BLE connections.
 Pay attention to communication errors due to distance related weak BLE connections.
@@ -84,7 +90,7 @@ Pay attention to communication errors due to distance related weak BLE connectio
 The extensive output can be reduced to error messages:
 The extensive output can be reduced to error messages:
 
 
 ```shell
 ```shell
-python3 miflora-mqtt-daemon.py > /dev/null
+python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py > /dev/null
 ```
 ```
 
 
 #### Continuous Daemon/Service
 #### Continuous Daemon/Service
@@ -113,12 +119,6 @@ This can be done either by using the internal daemon or cron.
    screen -S miflora-mqtt-daemon -d -m python3 /path/to/miflora-mqtt-daemon.py
    screen -S miflora-mqtt-daemon -d -m python3 /path/to/miflora-mqtt-daemon.py
    ```
    ```
 
 
-1. Cron job - Add a new con job, e.g., `/etc/cron.d/miflora`, execute every 5 minutes
-   
-   ```shell
-   */5 * * * * root python3 /path/to/miflora-mqtt-daemon.py > /dev/null
-   ```
-
 ### Integration
 ### Integration
 
 
 In the "mqtt-json" reporting mode, data will be published to the MQTT broker topic "`miflora/sensorname`" (names configurable).
 In the "mqtt-json" reporting mode, data will be published to the MQTT broker topic "`miflora/sensorname`" (names configurable).
@@ -128,7 +128,7 @@ An example:
 {"light": 5424, "moisture": 30, "temperature": 21.4, "conductivity": 1020, "battery": 100}
 {"light": 5424, "moisture": 30, "temperature": 21.4, "conductivity": 1020, "battery": 100}
 ```
 ```
 
 
-This data can be subscribed to and processed by other applications, like [Home Assistant](https://home-assistant.io) or [openHAB](https://openhab.org).
+This data can be subscribed to and processed by other applications, like [openHAB](https://openhab.org).
 
 
 Enjoy!
 Enjoy!
 
 

+ 4 - 9
config.ini

@@ -43,21 +43,16 @@
 #username = user
 #username = user
 #password = pwd123
 #password = pwd123
 
 
-[MiFlora]
-
-# DEPRECATED
-#cache_timeout = 600
-
 [Sensors]
 [Sensors]
 
 
 # Add your Mi Flora sensors here. Each sensor consists of a name and a Ethernet MAC address.
 # Add your Mi Flora sensors here. Each sensor consists of a name and a Ethernet MAC address.
-# One sensor per line. An additional location information can be added to the name, delimited by an '@'.
+# Additional location information can be added to the name, delimited by an '@'.
 # Scan for sensors from the command line with:
 # Scan for sensors from the command line with:
 #    $ sudo hcitool lescan
 #    $ sudo hcitool lescan
 #
 #
 # Examples:
 # Examples:
 #
 #
-#Schefflera      = C4:7C:8D:11:22:33
-#JapaneseBonsai  = C4:7C:8D:44:55:66
-#Petunia@Balcony = C4:7C:8D:77:88:99
+#Schefflera@Living = C4:7C:8D:11:22:33
+#JapaneseBonsai    = C4:7C:8D:44:55:66
+#Petunia@Balcony   = C4:7C:8D:77:88:99
 
 

+ 3 - 2
miflora-mqtt-daemon.py

@@ -41,8 +41,10 @@ def print_line(text, error = False, warning=False, sd_notify=False, console=True
             print(Fore.MAGENTA + '[{}] '.format(timestamp) + Fore.YELLOW + '{}'.format(text) + Fore.RESET)
             print(Fore.MAGENTA + '[{}] '.format(timestamp) + Fore.YELLOW + '{}'.format(text) + Fore.RESET)
         else:
         else:
             print(Fore.MAGENTA + '[{}] '.format(timestamp) + Fore.RESET + '{}'.format(text))
             print(Fore.MAGENTA + '[{}] '.format(timestamp) + Fore.RESET + '{}'.format(text))
+
+    timestamp_sd = strftime('%b %d %H:%M:%S', localtime())
     if sd_notify:
     if sd_notify:
-        sd_notifier.notify('STATUS={} - {}.'.format(timestamp, text))
+        sd_notifier.notify('STATUS={} - {}.'.format(timestamp_sd, text))
 
 
 
 
 # Eclipse Paho callbacks - http://www.eclipse.org/paho/clients/python/docs/#callbacks
 # Eclipse Paho callbacks - http://www.eclipse.org/paho/clients/python/docs/#callbacks
@@ -98,7 +100,6 @@ daemon_enabled = config['Daemon'].getboolean('enabled', True)
 base_topic = config['MQTT'].get('base_topic', 'homie' if reporting_mode == 'mqtt-homie' else 'miflora').lower()
 base_topic = config['MQTT'].get('base_topic', 'homie' if reporting_mode == 'mqtt-homie' else 'miflora').lower()
 device_id = config['MQTT'].get('homie_device_id', 'miflora-mqtt-daemon').lower()
 device_id = config['MQTT'].get('homie_device_id', 'miflora-mqtt-daemon').lower()
 sleep_period = config['Daemon'].getint('period', 300)
 sleep_period = config['Daemon'].getint('period', 300)
-#miflora_cache_timeout = config['MiFlora'].getint('cache_timeout', 600)
 miflora_cache_timeout = sleep_period - 1
 miflora_cache_timeout = sleep_period - 1
 
 
 # Check configuration
 # Check configuration