DIY मीडिया होम लोगो

अपनी खुद की होम थिएटर और हाय-Fi सेटअप डिजाइन और बनाने के लिए परम साइट.

4गृह सहायक में MiFlora संयंत्र सेंसर

I’ve been suing the MiFlora Home Assist­ant integ­ra­tion to get data on vari­ous house plants for a while. How­ever along the way I’ve had to over­come vari­ous hurdles includ­ing lim­ited range of bluetooth, bat­tery life issues, and get­ting the bat­tery val­ues to report. I finally seem to have cracked all of these and now have a sys­tem that works reli­ably with lots of plants around the house. I’ve sum­mar­ised what I’ve used below.

हार्डवेयर

The first thing to say is that I do have a bluetooth यूएसबी dongle attached to my home assist­ant sys­tem. This mon­it­ors the plants in range dir­ectly (अर्थात. the ones in the same room as the HA box). 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-यूएसबी phone charger

  • यूएसबी डोंगल: 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 board: I got a JZK ESP32‑S which is cur­rently £6.49 on amazon
  • Case for ESP32: I found the case for a NodeM­CU Wroom-32D (short aer­i­al) fit­ted my board — this was £4.20 from ebay

Integrations for Home Assistant

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. Instead I use the Bluetooth Low Energy Mon­it­or 3rd party integ­ra­tion which you can install eas­ily using HACS
I then also installed the 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: '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. config.yaml में एक पंक्ति से पहले की तरह शुरू करने के लिए: 

पौधा: !पौधों को शामिल करें

और फिर plant.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
  न्यूनतम_तापमान: 8
  अधिकतम_तापमान: 32
  न्यूनतम नमी: 15
  अधिकतम_नमी: 60
  न्यूनतम चालकता: 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 कारणों. 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 यूएसबी और इसे मूल ईएसपीहोम छवि के साथ फ्लैश करें
मैंने इस्तेमाल किया 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

esphome:
  नाम: jzk-esp-32s
  platform: ESP32
  board: esp32doit-devkit-v1

# Enable logging
logger:

# Enable Home Assistant एपीआई
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:
    then:
      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:
      then:
        homeassistant.event:
          event: esphome.on_ble_advertise
          data:
            packet: !lambda |-
              अगर (x.size()  2)
              {
                ESP_LOGE("myhomeiot_ble_client", "payload has wrong size (%डी)", x.size());
                return "";
              };
              ESP_LOGI("myhomeiot_ble_client", "बैटरी (%d%%), फर्मवेयर (%एस)", X[0], std::string(x.begin(), x.end()).substr(2).c_str());
              char buffer[70 + 1];
              const uint8_t *remote_bda = xthis.remote_bda();
              snprintf(बफर, sizeof(बफर), "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], X[0]);
              return std::string(बफर).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

उत्तर छोड़ दें

4 टिप्पणियाँ

जेएसजॉन 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 यूएसबी 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 यूएसबी 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.

जवाब दें
टीTony

नमस्ते, 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?

जवाब दें