4مستشعرات نباتات MiFlora في مساعد المنزل

لقد رفعت دعوى قضائية ضد تكامل MiFlora Home Assistant للحصول على بيانات حول نباتات منزلية مختلفة لفترة من الوقت. ولكن على طول الطريق كان علي التغلب على العديد من العقبات بما في ذلك نطاق محدود من البلوتوث, مشاكل عمر البطارية, والحصول على قيم البطارية للإبلاغ عنها. أخيرًا يبدو أنني قمت بتكسير كل هذه الأشياء ولدي الآن نظام يعمل بشكل موثوق مع الكثير من النباتات حول المنزل. لقد لخصت ما استخدمته أدناه.

المعدات

The first thing to say is that I do have a bluetooth USB dongle attached to my home assist­ant sys­tem. This mon­it­ors the plants in range dir­ectly (بمعنى آخر. تلك الموجودة في نفس غرفة صندوق HA). To mon­it­or more dis­tance devices I have used an ESP32 board with built-in bluetooth mod­ule which I have inside a cheap little case and have powered with an old micro-USB شاحن الجوال

  • USB دونجل: the one I got is no longer avail­able — due to age — but there are plenty of amazon and else­where — just make sure it has sup­port in linux
  • لوحة ESP32: لدي JZK ESP32‑S which is cur­rently £6.49 on amazon
  • الحال بالنسبة لـ ESP32: I found the case for a NodeM­CU Wroom-32D (short aer­i­al) fit­ted my board — this was £4.20 from موقع ئي باي

تكامل مساعد المنزل

Whilst the basic MiFlora integ­ra­tion is built in to home assist­ant I found it uses a lot of bat­tery when used nat­ively. بدلاً من ذلك ، أستخدم ملف Bluetooth Low Energy Mon­it­or 3rd party integ­ra­tion which you can install eas­ily using بطئ
ثم قمت أيضًا بتثبيت ESPHome integ­ra­tion for home assist­ant to man­age my ESP32 BLE repeater
أخيرا, to dis­play the plants in a nice way I added a par­tic­u­lar fork of the lovelace plant card addon via HACS

ترتيب

Once BLE Mon­it­or was installed and con­figured with my bluetooth dongle it picked up the MiFlora sensors with­in range and lis­ted them in its “devices” drop down as well as list­ing the devices and entit­ies on it’s card in the HA configuration
The great thing about BLE mon­it­or is that it listens for the sensors to trans­mit, rather than act­ively polling them, which would run down their bat­ter­ies. ومع ذلك, the sensors don’t trans­mit bat­tery inform­a­tion so to get this we have to act­ively poll for it. Polling just for this, and pass­ively listen­ing for the oth­er data seems to be the best com­prom­ise if you want to have all the data avail­able but also max­im­ise the sensor’s bat­tery life. I have sep­ar­ated my configuration.yaml into mul­tiple sep­ar­ate files to keep things a bit easi­er to man­age so I just have the fol­low­ing line in my configuration.yaml —

المستشعر: !include sensors.yaml

Then in sensors.yaml I have each plant lis­ted as follows

 - منصة: miflora
   mac: 'ماك:عنوان:of:ازدهر:المستشعر:here'
   name: basil
   force_update: true
   scan_interval: 08:00
   الوسيط: 3
   go_unavailable_timeout: 43200
   المراقبة_الظروف:
     - البطارية

Next — to make the plants appear nicely I have a plants con­fig. كما كان من قبل سطر واحد في التكوين. yaml لتبدأ به: 

مصنع: !تشمل النباتات

ثم في النباتات. yaml لدي ما يلي

رَيحان:
  مجسات:
    رُطُوبَة: sensor.ble_moisture_basil
    battery: sensor.basil_battery
    temperature: sensor.ble_temperature_basil
    conductivity: sensor.ble_conductivity_basil
    brightness: sensor.ble_illuminance_basil
  min_battery: 15
  السطوع الأدنى: 2500
  السطوع الأقصى: 60000
  min_temperature: 8
  max_temperature: 32
  الحد الأدنى للرطوبة: 15
  الرطوبة القصوى: 60
  min_conductivity: 350
  الموصلية القصوى: 2000

Note the subtle dif­fer­ence between the entity name for the bat­tery com­pared with the oth­er sensors. The bat­tery entity is com­ing from the miflora plat­form in sensors.yaml whilst the oth­er 4 sensors are com­ing from the BLE integ­ra­tion. There IS a bat­tery entity lis­ted by the BLE integ­ra­tion but this just shows as “unknown” for this plant. This con­fig­ur­a­tion is needed for the plant card to show the plant in a nicely presen­ted way
ثم انتقل ببساطة إلى المكان الذي تريد إضافة نباتك إليه وأضف بطاقة نبات الحب. You will have to “con­fig­ure” the card manu­ally, but it only takes 3 lines…

نوع: مخصص:flower-card
entity: plant.basil
species: البازيليك

Note that the spe­cies is lis­ted for 2 REAS فيرفكس. Firstly it will dis­play the name on the card, ولكن أكثر استيراد وantly, it will also dis­play a pic­ture of the plant if you have down­loaded the plant images and added them into \config\www\images\plants using the lat­in names — the inform­a­tion on the data­base is avail­able on the lovelace plant card documentation

توسيع النطاق

أخيرا, نحن بحاجة إلى توسيع النطاق الذي يمكننا الوصول إليه. لهذا نحتاج إلى جهاز ESP32. The first thing to do is to get it hooked up to your com­puter via USB وفلاشها بصورة أساسية ESPHome
لقد استخدمت ESPHome Flash­er و cp210x uni­ver­sal win­dows driver from SiL­abs and fol­lowed the guide provided by the ESPHome Home­As­sist­ant integration
The con­fig I used for my ESP32 device is below

إسفومي:
  اسم: jzk-esp-32s
  platform: ESP32
  board: esp32doit-devkit-v1

# Enable logging
logger:

# Enable Home Assistant API
api:

واي فاي:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32 Fallback Hotspot"
    كلمة السر: "random-password-here"
    
external_components:
  - مصدر: github://myhomeiot/esphome-components
    
esp32_ble_tracker:
    
ble_gateway:
  الأجهزة:
    - mac_address: mac:عنوان:of:ازدهر:المستشعر:إلى:monitor:goes:here
  on_ble_advertise:
    ثم:
      homeassistant.event:
        event: esphome.on_ble_advertise
        data:
          packet: !lambda return packet;
          
myhomeiot_ble_host:

myhomeiot_ble_client:
  - mac_address: mac:عنوان:of:ازدهر:المستشعر:إلى:monitor:goes:here
    service_uuid: '1204'
    characteristic_uuid: '1A02'
    update_interval: 4h
    on_value:
      ثم:
        homeassistant.event:
          event: esphome.on_ble_advertise
          data:
            packet: !lambda |-
              إذا (x.size()  2)
              {
                ESP_LOGE("myhomeiot_ble_client", "payload has wrong size (%د)", x.size());
                عودة "";
              };
              ESP_LOGI("myhomeiot_ble_client", "بطارية (%d%%), البرامج الثابتة (%ق)", س[0], std::string(x.begin(), x.end()).SUBSTR(2).c_str());
              char buffer[70 + 1];
              const uint8_t *remote_bda = xthis.remote_bda();
              snprintf(buffer, sizeof(buffer), "043E2002010000%02X%02X%02X%02X%02X%02X14020106030295FE0C1695FE41209800000A1001%02X00",
                remote_bda[5], remote_bda[4], remote_bda[3], remote_bda[2], remote_bda[1], remote_bda[0], س[0]);
              return std::string(buffer).c_str();

Then save and update to your esp32 device via wifi. The ESP32 device will pick up the data from the miflora sensor and will ‘push’ it via wifi to the BLE integ­ra­tion which will cre­ate a device and entit­ies auto­mat­ic­ally. Devices pushed in this way do appear to show their bat­teyr level (thanks to the code at the bot­tom of the myhomeiot_ble_client sec­tion I believe). You then just need to give the device a nice name (and let the entit­ies be renamed too) and then cre­ate an entry in plants.yaml with the right entities

Leave a Reply

4 Comments

JSJon Scaife

مرحبا
نعم فعلا, I actu­ally use ESP32 repeat­ers myself now as they are able to use “pass­ive” mode AND col­lect bat­tery data.
If you have a USB bluetooth device then you can pair the MiFlora devices dir­ectly to that first and then when you set up the ESP32 it will send the inform­a­tion into HA and it will show up for the cor­rect entit­ies automatically

You need to use the code as I describe in the “Extend­ing range” section.
You also need to have the “Bluetooth Low Energy Mon­it­or” integ­ra­tion installed (via HACS)

If you don’t have a USB Bluetooth then there is a way to get the devices to show up in Bluetooth Low Energy Mon­it­or. I can­’t remem­ber the link where I read it but I think it’s part of the Bluetooth Low Energy Mon­it­or Wiki or FAQs

If you do it that way then you don’t need to use the manu­al YAML that Barry uses. His post is from 2020 — I think before Bluetooth Low Energy Mon­it­or could do it or maybe before it even existed.

الرد
Tتوني

مرحبًا, thank you for post­ing this great solution.
Can the esp32 Bluetooth gate­way trans­mit data more than one bluetooth device or or do you have to provide one ESP 32 for each Bluetooth device we want to extend the range for?

الرد
JSJon Scaife

Hi Tony
The ESP will trans­mit data for any BT devices with­in range I believe although as mine is cur­rently only used for 1 BT device I can­’t con­firm 100% — but that is cer­tainly my understanding

الرد