Xiaomi_BLE_Temperature_Display_for_HA
Xiaomi_BLE_Temperature_Display_for_HA copied to clipboard
Using the script in "reconnecting mode" leads to crash the bluetooth service
Hi @all,
I've tried the new version of @AnthonyKNorman blemqtt.sh shell script (with the added -c 1
argument at the call of LYWSD03MMC script to support more than one sensor).
After some connections (I only use one sensor) the connection the the xiaomi sensor can't be established. The python script tries to reconnect endlessly. In this state i manually have to reset the bluetooth service by
sudo systemctl restart bluetooth.service
after this call, the re-execution of the blemqtt.sh script works for some time, before the described error appears again.
Do anyone have the same issues?
I am also experiencing some errors. I will look into it.
I am trying a new tack. I have changed the python script to accept an array of mac addresses. I'll run it overnight and report back.
Hi @AnthonyKNorman ,
what was your experience with your adaption of script?
I have published a fresh version. Is uses a later version of the source script. One notable improvement is that the battery level is actually meaningful. I have not run long term tests yet, but early results seem hopeful. Read.me has been updated. If you would like to test that would be helpful.
Hi @AnthonyKNorman
thanxs for your refreshed version of script.
I tried it with two sensors. Let me show you what happens:
bnestler@BennyPi:~/xiaomi/final_scripts $ ./LYWSD03MMC.py $(<LYWSD03MMC_config)
args.device A4:C1:38:46:B7:2D,A4:C1:38:82:2D:E3
['A4:C1:38:46:B7:2D', 'A4:C1:38:82:2D:E3'] 2
Delay set to 120 seconds
Trying to connect to A4:C1:38:46:B7:2D
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.4
Humidity: 33
Battery voltage: 3.015
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285157)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.015"}
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.4
Humidity: 33
Battery voltage: 3.015
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285157), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285171)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.015"}
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.4
Humidity: 33
Battery voltage: 3.015
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285157), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285171), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285191)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.015"}
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.3
Humidity: 33
Battery voltage: 3.015
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285157), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285171), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285191), Measurement(temperature=19.3, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285204)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.015"}
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.4
Humidity: 33
Battery voltage: 3.015
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285157), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285171), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285191), Measurement(temperature=19.3, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285204), Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285231)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.015"}
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
The script always tries to connect to only one of the sensors (with the MAC A4:C1:38:46:B7:2D). Seems to be that the loop condition to the next mac-address isn't correct.
This is the content of my LYWSD03MMC_config file:
-d A4:C1:38:46:B7:2D,A4:C1:38:82:2D:E3 -r -b 5 -c 1 -m "localhost" -del 120
Maybe my problem is this file. I want to pass all arguments in a kind of argument-file. So no changings to the running service must be done. If I add a sensor I can do it in this argument-file. So my thoughts.
Another thing happens. Do you see the measurements deque
output? What happens here?
Okay now I tried to call the LYWSD03MMC.py without my argument file in this way:
./LYWSD03MMC.py -d A4:C1:38:46:B7:2D,A4:C1:38:82:2D:E3 -r -b 5 -c 1 -m "localhost" -del 120
bnestler@BennyPi:~/xiaomi/final_scripts $ ./LYWSD03MMC.py -d A4:C1:38:46:B7:2D,A4:C1:38:82:2D:E3 -r -b 5 -c 1 -m "localhost" -del 120
args.device A4:C1:38:46:B7:2D,A4:C1:38:82:2D:E3
['A4:C1:38:46:B7:2D', 'A4:C1:38:82:2D:E3'] 2
Delay set to 120 seconds
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.4
Humidity: 33
Battery voltage: 3.015
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.015, calibratedHumidity=0, battery=92, timestamp=1585285692)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.015"}
`Connection lost` `Waiting...` `Trying to connect to A4:C1:38:82:2D:E3` `Connection lost` `Waiting...` `Trying to connect to A4:C1:38:82:2D:E3` `Temperature: 16.6` `Humidity: 45` `Battery voltage: 2.986` `Battery level: 89` `1 measurements collected. Exiting in a moment.` `Topic blemqtt/A4C138822DE3` `measurements deque([Measurement(temperature=16.6, humidity=45, voltage=2.986, calibratedHumidity=0, battery=89, timestamp=1585285835)])` `16.6` `Publishing {"temperature": "16.6", "humidity": "45", "batt": "89", "voltage": "2.986"}` `Connection lost` `Waiting...` `Trying to connect to A4:C1:38:82:2D:E3` `Connection lost` `Waiting...` `Trying to connect to A4:C1:38:82:2D:E3` `Temperature: 16.6` `Humidity: 45` `Battery voltage: 2.986` `Battery level: 89` `1 measurements collected. Exiting in a moment.` `Topic blemqtt/A4C138822DE3` `measurements deque([Measurement(temperature=16.6, humidity=45, voltage=2.986, calibratedHumidity=0, battery=89, timestamp=1585285862)])` `16.6` `Publishing {"temperature": "16.6", "humidity": "45", "batt": "89", "voltage": "2.986"}`
Connection lost
Waiting...
Trying to connect to A4:C1:38:46:B7:2D
Temperature: 19.4
Humidity: 33
Battery voltage: 3.016
Battery level: 92
1 measurements collected. Exiting in a moment.
Topic blemqtt/A4C13846B72D
measurements deque([Measurement(temperature=19.4, humidity=33, voltage=3.016, calibratedHumidity=0, battery=92, timestamp=1585285996)])
19.4
Publishing {"temperature": "19.4", "humidity": "33", "batt": "92", "voltage": "3.016"}
The output is much better. But sometimes is a doubled publish happens. You can see it with the MAC A4:C1:38:82:2D:E3.
Any ideas?
Best regards,
Bluemorph
In the first example your config file is -d A4:C1:38:46:B7:2D,A4:C1:38:82:2D:E3 -r -b 5 -c 1 -m "localhost" -del 120 Remove the quotation marks from around localhost. All the parameters are treated as string anyway. MQTT will be trying to connect to '"localhost"' and therefore raising an exception. This means you will exit the loop before the address gets changed. Can you try that and let me know how you get on.
Hi @AnthonyKNorman,
thanks for your hint. This works much better.
But the failure with the stucking bluetooth service is still alive ... :-(
Same problem in my home, 5 sensors, after few reads "connection lost" I'm using blemqtt.service and code from it:
ExecStart=/home/pi/LYWSD03MMC.py -d A4:C1:38:ED:80:04,A4:C1:38:08:61:1E,A4:C1:38:A5:B6:D6,A4:C1:38:E0:27:FE,A4:C1:38:8A:A4:DC -r -b 5 -c 1 -m 192.168.1.7 -del 20
I am running two devices. They have been running for several days now. @CSnipper can you post an example of your output when it fails?
You might be interested in my new repository that uses ESP32 instead of Raspberry Pi https://github.com/AnthonyKNorman/Xiaomi_LYWSD03MMC_for_HA
This is great - many thanks.
Got it running very quickly on a spare ESP32.
Luke.
On Mon, 27 Apr 2020 at 06:33, AnthonyKNorman [email protected] wrote:
You might be interested in my new repository that uses ESP32 instead of Raspberry Pi https://github.com/AnthonyKNorman/Xiaomi_LYWSD03MMC_for_HA
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AnthonyKNorman/Xiaomi_BLE_Tempertaure_Display_for_HA/issues/11#issuecomment-619732086, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGFCHIBBFF5KJMY5LSNLSGDROUKKFANCNFSM4LN4JWZA .