home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.8k stars 30.51k forks source link

Sensor: MiFlora #74585

Closed P-Stenbumling closed 2 years ago

P-Stenbumling commented 2 years ago

The problem

Platform error sensor.miflora - Requirements for miflora not found: ['bluepy==1.3.0'].

What version of Home Assistant Core has the issue?

2022.7.0

What was the last working version of Home Assistant Core?

2022.6. latest

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Mi Flora

Link to integration documentation on our website

https://www.home-assistant.io/integrations/miflora/

Diagnostics information

No response

Example YAML snippet

- platform: miflora
    mac: "C4:7C:8D:6A:A7:02"
    name: Chili
    force_update: false
    median: 1
    monitored_conditions:
      - moisture
      - light
      - temperature
      - conductivity
      - battery

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

Hey there @danielhiversen, @basnijholt, mind taking a look at this issue as it has been labeled with an integration (miflora) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


miflora documentation miflora source (message by IssueLinks)

frog32 commented 2 years ago

This is mentioned in the breaking changes (see "Bluetooth (multiple integrations)") and due to bluepy not working with python 3.10. This will unlikely be fixed unless someone takes on the challenge of porting it to a new library that is still supported.

andreheuer commented 2 years ago

There is already a issue pending with the used miflora package: https://github.com/basnijholt/miflora/issues/170

lucasfijen commented 2 years ago

It actually looks like the best approach would be to add an extra bleak backend entry in btlewrap, the library that miflora uses for its bluetooth interactions,
https://github.com/ChristianKuehnel/btlewrap/blob/master/btlewrap/bluepy.py relevant issue

austwhite commented 2 years ago

At the moment, the only fix is to revert to 2022.6.x version of Home Assistant. Hopefully the code owners can convert this to BLEAK, or maybe someone can fork and fix bluepy. I don't have the knowledge to do this though, so I am staying on 2022.6.7 for now Mianly commented so I can follow this and see the outcome :)

basnijholt commented 2 years ago

No need to fork, I would welcome any PR fixing this issue.

lucasfijen commented 2 years ago

Small update: I've been playing around with bleak today -don't have a lot of knowledge on bluetooth tbh-, but I'm struggling with translating the handle IDS towards UUIDS / bleak ints which don't seem to match with the hexa codes from bluepy

for example Mi flora with bluepy uses the following handle: _HANDLE_READ_NAME = 0x03 which cant be found with just that hexa using bleak. However, i could find the right value by using the UUID 00002a00-0000-1000-8000-00805f9b34fb

So now I'm trying to figure out how to convert all the needed hexa's to the related UUIDS. Attached some of my code to play around with bleak:

#%%
import asyncio
from bleak import BleakScanner, BleakClient

address = 'YOURADRESSHERE'

async def main(address):
    cl = BleakClient(address)
    async with cl as client:

        services = await client.get_services()
        chars = services.characteristics
        for i in services.characteristics:
            char = chars[i]
            descs = [f'{i.description=} {i.handle=} {i.uuid=}' for i in char.descriptors]
            descsvals = [await client.read_gatt_descriptor(i.handle) for i in char.descriptors] if 'read' in char.properties else 'nopenope'
            gattchar = await client.read_gatt_char(i) if 'read' in char.properties else 'nope'

            print(f'''---------------------
{gattchar=}
{char.handle=}
{char.description=}
{descs=}
{descsvals=}
{char.handle=}
{char.properties=}
{char.service_handle=}
{char.service_uuid=}
{char.uuid=}
--------------------''')

await main(address)

I did find some translation in the bluepy library (link to related code found) but with that I was still not able to get this same translation:

val = 0x03
val = "%04X" % val
val = val.replace("-", "")
s = ("0" * (8 - len(val))) + val + "00001000800000805F9B34FB"
"-".join([s[0:8], s[8:12], s[12:16], s[16:20], s[20:32]])

which makes from 0x03 the uuid '00000003-0000-1000-8000-00805F9B34FB' which is not the expected 00002a00-0000-1000-8000-00805f9b34fb

FluffyGeraffe commented 2 years ago

At the moment, the only fix is to revert to 2022.6.x version of Home Assistant. Hopefully the code owners can convert this to BLEAK, or maybe someone can fork and fix bluepy. I don't have the knowledge to do this though, so I am staying on 2022.6.7 for now Mianly commented so I can follow this and see the outcome :)

I have reverted to 2022.6 some days ago and hassio still doesn't update my sensors :/ weird...

frenck commented 2 years ago

Before someone decides to go all out on this one, there is actually effort being put into bringing a generic bluetooth integration (and Bluetooth device discovery) into Home Assistant.

The first iteration bluetooth integration has been merged into the dev branch at this point.

austwhite commented 2 years ago

@FluffyGeraffe Not sure what happened with your install. I reverted to 2022.6.7 and all is working fine for my 10 Mi Flora sensors.

Hopefully the new work will be successful and help solve it. I think the developer of the BTL wrapper is also working to move over to bleak

FluffyGeraffe commented 2 years ago

@FluffyGeraffe Not sure what happened with your install. I reverted to 2022.6.7 and all is working fine for my 10 Mi Flora sensors.

Hopefully the new work will be successful and help solve it. I think the developer of the BTL wrapper is also working to move over to bleak

Thanks @austwhite for confirming, that it should work after reverting. Maybe I'll readd my 3 sensors again or I'll just wait for the update. Lucky for you that it still works with 10 sensors. That would have been annoying in my case 😁

tediroca commented 2 years ago

@FluffyGeraffe Not sure what happened with your install. I reverted to 2022.6.7 and all is working fine for my 10 Mi Flora sensors. Hopefully the new work will be successful and help solve it. I think the developer of the BTL wrapper is also working to move over to bleak

Thanks @austwhite for confirming, that it should work after reverting. Maybe I'll readd my 3 sensors again or I'll just wait for the update. Lucky for you that it still works with 10 sensors. That would have been annoying in my case 😁

I can also confirm that after reverting to 2022.6.7 all 3 sensors started to work straight without having to perform any other changes.

selleronom commented 2 years ago

Made an add-on as a work-around until bleak is supported in btlewrap. Check it out here, https://github.com/selleronom/xiaomi-mi-flora

Jc2k commented 2 years ago

Bleak is async, it doesn't look like btlewrap is. So we should just probably use bleak directly instead of waiting for btlewrap.

I've started writing a bleak based client for this device. But I need some more batteries before I can turn it on and test it.

With the new Bluetooth framework we should actually just be able to listen to the data in the BLE broadcasts and only need to poll for the battery. So might reduce battery consumption!

stephan890 commented 2 years ago

I can actually confirm this approach will save the miflora battery as this was my reason for me to start using the hacs passive ble monitor for listening only to the miflora and used the miflora integration only to poll the battery status once a day….

austwhite commented 2 years ago

I know the maintainer of btlewrap was looking at Bleak at one point. That said, if the Home Assistant team, as indicated by @frenck, are working on it, then it shouldn't be too long before a solution is found.

Jc2k commented 2 years ago

We are working on a new approach to Bluetooth in Home Assistant, not a fix to this exactly. But by implementing the new best practices we will fix it as a side effect - because the broken dependency (bluepy) will be gone.

oleueberolsen commented 2 years ago

Any idea when this might be implemented? As early as 2022.8?

Jc2k commented 2 years ago

No promises, I am rammed and I've been given at ETA of Friday for the APIs to land in HA core, and that's if they clear review. So there isn't going to be much time to get my stuff written and landed.

Also because the Mi Flora actually uses the same framing protocol as a bunch of other devices it's been requested I don't do something just for this device.

If I do get something out it'll likely be just the values that are advertised (ie no battery support), then I'll come back to battery support in 09. Otherwise everything would be in 09.

warlordattack commented 2 years ago

I use home assistant with synology ds918+ nas, inside Virtual Machine Manager, i have this error (trying to install AwoX Mesh lighs integration) :

Logger: homeassistant.util.package Source: util/package.py:96 First occurred: 22:59:09 (1 occurrences) Last logged: 22:59:09

Unable to install package bluepy>=1.3.0: error: subprocess-exited-with-error Γ— python setup.py bdist_wheel did not run successfully. β”‚ exit code: 1 ╰─> [8 lines of output] /usr/local/lib/python3.10/site-packages/setuptools/dist.py:772: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead warnings.warn( running bdist_wheel running build running build_py Working dir is /tmp/pip-install-ume9b6ym/bluepy_feb51896dc3c4ad2b8f2ab1835113634 execute make -C ./bluepy clean error: [Errno 2] No such file or directory: 'make' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for bluepy error: subprocess-exited-with-error Γ— Running setup.py install for bluepy did not run successfully. β”‚ exit code: 1 ╰─> [10 lines of output] /usr/local/lib/python3.10/site-packages/setuptools/dist.py:772: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead warnings.warn( running install /usr/local/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py Working dir is /tmp/pip-install-ume9b6ym/bluepy_feb51896dc3c4ad2b8f2ab1835113634 execute make -C ./bluepy clean error: [Errno 2] No such file or directory: 'make' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure Γ— Encountered error while trying to install package. ╰─> bluepy note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.

Logger: aiohttp.server Source: requirements.py:267 First occurred: 23:01:22 (1 occurrences) Last logged: 23:01:22

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 145, in post return await super().post(request) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper result = await method(view, request, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 70, in post result = await self._flow_mgr.async_init( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 222, in async_init flow, result = await task File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 240, in _async_init flow = await self.async_create_flow(handler, context=context, data=data) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 779, in async_create_flow await async_process_deps_reqs(self.hass, self._hass_config, integration) File "/usr/src/homeassistant/homeassistant/setup.py", line 360, in async_process_deps_reqs await requirements.async_get_integration_with_requirements( File "/usr/src/homeassistant/homeassistant/requirements.py", line 49, in async_get_integration_with_requirements return await manager.async_get_integration_with_requirements(domain) File "/usr/src/homeassistant/homeassistant/requirements.py", line 168, in async_get_integration_with_requirements await self._async_process_integration(integration, done) File "/usr/src/homeassistant/homeassistant/requirements.py", line 183, in _async_process_integration await self.async_process_requirements( File "/usr/src/homeassistant/homeassistant/requirements.py", line 236, in async_process_requirements await self._async_process_requirements(name, missing) File "/usr/src/homeassistant/homeassistant/requirements.py", line 267, in _async_process_requirements raise RequirementsNotFound(name, list(failures)) homeassistant.requirements.RequirementsNotFound: Requirements for awox not found: ['bluepy>=1.3.0'].

Logger: aiohttp.server Source: requirements.py:252 First occurred: 23:03:52 (1 occurrences) Last logged: 23:03:52

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 145, in post return await super().post(request) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper result = await method(view, request, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 70, in post result = await self._flow_mgr.async_init( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 222, in async_init flow, result = await task File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 240, in _async_init flow = await self.async_create_flow(handler, context=context, data=data) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 779, in async_create_flow await async_process_deps_reqs(self.hass, self._hass_config, integration) File "/usr/src/homeassistant/homeassistant/setup.py", line 360, in async_process_deps_reqs await requirements.async_get_integration_with_requirements( File "/usr/src/homeassistant/homeassistant/requirements.py", line 49, in async_get_integration_with_requirements return await manager.async_get_integration_with_requirements(domain) File "/usr/src/homeassistant/homeassistant/requirements.py", line 168, in async_get_integration_with_requirements await self._async_process_integration(integration, done) File "/usr/src/homeassistant/homeassistant/requirements.py", line 183, in _async_process_integration await self.async_process_requirements( File "/usr/src/homeassistant/homeassistant/requirements.py", line 230, in async_process_requirements self._raise_for_failed_requirements(name, missing) File "/usr/src/homeassistant/homeassistant/requirements.py", line 252, in _raise_for_failed_requirements raise RequirementsNotFound(integration, [req]) homeassistant.requirements.RequirementsNotFound: Requirements for awox not found: ['bluepy>=1.3.0'].

austwhite commented 2 years ago

@warlordattack Most likely related as your errors are related to bluepy. You'd ned to downgrade to Home Assistant 2022.6.x versions.

This issue is particualrly related to MiFlora devices, but the fix on this would likely fix your issue too.

warlordattack commented 2 years ago

thank you,

i have core-2022.7.5, where can i find 2022.6.x ?

i installed https://github.com/home-assistant/operating-system/releases/download/8.2/haos_ova-8.2.vmdk.zip this is wmdk for synology virtual machine manager

DoctorOctagonapus commented 2 years ago

@warlordattack you need CLI access, either by SSH or the Terminal addon, then the command is ha core update version=2022.6.7

warlordattack commented 2 years ago

so it will downgrade the system ? will it break everything ?

DoctorOctagonapus commented 2 years ago

Correct. It says update but the version parameter will install whatever version you specify.

warlordattack commented 2 years ago

will this problem be patched in new versions one day ?

austwhite commented 2 years ago

@warlordattack Read the release notes for 2022.7 for information.

They are working on things, but it will take time to move to a new bluetooth platform. I am also on 2022.6.7 still due to this. Unless you need a particular feature of 2022.7 then 2022.6 will work absolutely fine

warlordattack commented 2 years ago

ok i will try this

also i see there is newer version : https://github.com/home-assistant/operating-system/releases/tag/8.3

if i want to test can i upgrade to this version ?

warlordattack commented 2 years ago

where can i find release notes please ? (i am big noob :))

austwhite commented 2 years ago

@warlordattack
I'll give you the information, but please bare in mind this is an issue thread and not a help forum https://www.home-assistant.io/blog/2022/07/06/release-20227/ Thanks

warlordattack commented 2 years ago

ok thank you for advice

warlordattack commented 2 years ago

i did something wrong ? 2022-07-19_235254

DoctorOctagonapus commented 2 years ago

Ah my bad it's -version=2022.6.7 with a hyphen in front.

warlordattack commented 2 years ago

thank you :)

finally looks OK πŸ‘Œ

2022-07-19_235254

warlordattack commented 2 years ago

this is finally OK, thank you very much πŸ‘ 2022-07-20_002512

oleueberolsen commented 2 years ago

No promises, I am rammed and I've been given at ETA of Friday for the APIs to land in HA core, and that's if they clear review. So there isn't going to be much time to get my stuff written and landed.

Also because the Mi Flora actually uses the same framing protocol as a bunch of other devices it's been requested I don't do something just for this device.

If I do get something out it'll likely be just the values that are advertised (ie no battery support), then I'll come back to battery support in 09. Otherwise everything would be in 09.

Okay, I understand. Thanks for the answer!

Jc2k commented 2 years ago

Hey guys - as i said above I wanted to work on getting MiFlora supported using bleak and the new Bluetooth infrastructure thats coming in the 08 release.

The initial plan was to make a new miflora library that was optimised for homeassistant, bleak and asnycio and then contribute to the existing miflora integration. But It turns out the HHCCJY01 is supported by another integration that was planned based on that new infratructure. It covers a bunch of devices using Xiaomi / MiBeacon bluetooth advertisements (using the parser from the ble_monitor custom component). Because it covers more devices i collaborated to get that integration landed.

It has made it onto dev in time for the next beta and so should be in the August release. It's working well with my own MiFlora devices:

Screenshot 2022-07-23 at 11 19 11

As its based on the new bluetooth component your MiFlora should appear as "Discoveries" when you upgrade. No more faffing around with CLI tools to find MAC addresses. Unfortunately as its a different integration there isn't an automated migration path.

As its based on bluetooth advertisements its "push" based - you should get new sensor data as soon as the device knows it, rather than having the lag of polling. But without increasing battery use. In fact, your battery burn rate will decrease.

Right now there is no battery sensor. I do plan to add support for polling the battery for MiFlora to that integration too, but that won't make it into the August release based on the time I have left and the release date of the first beta. But the core sensors are present and working. I'm hoping to add "identify" support too - you'll be able to use a button or service call to make the light on the miflora flash, so if you mix them up you can easily find which is which.

austwhite commented 2 years ago

@Jc2k This looks pretty awesome. It sounds like the new bluetooth infrastructrue is going to solve a lot of issues and make bluetooth a lot more reliable. I assume, like the ESPHome versions, this will not be able to pull the battery information?

Jc2k commented 2 years ago

Right now there is no battery sensor. I do plan to add support for polling the battery for MiFlora to that integration too, but that won't make it into the August release based on the time I have left and the release date of the first beta.

peterjuras commented 2 years ago

@Jc2k Thanks for your work on getting MiFlora sensors to work again! πŸ™

Is there an issue we can follow for the battery polling support? I'm still on 2022.6 and would wait with updating until sensors are fully supported again.

Jc2k commented 2 years ago

No theres no issue, though i'll probably post here when i implement it. Hoping it will be 2022.9, but it was a real challenge to get the main sensors supported in 2022.8 with life commitments etc and likely to be lots of triage over the next 2 weeks with the new xiaomi_ble integration (e.g. already had a lot of trouble with the LYWSD03MMC and that was just with beta testers) and new bluetooth support in homekit_controller - expecting both to suck up a lot of what little time i have.

peterjuras commented 2 years ago

I see, no worries - posting here would also help! 😊

TonyBostonTB commented 2 years ago

Thanks for that! One thing though. I've written down which MAC-Address is which plant. Now I don't see MAC-Addresses anymore. Is there a way to get to see those? Every device is just called "Flower Care"

Jc2k commented 2 years ago

That's annoying! One of mine gets named after is MAC address and another is just "Flower Care".

Will try to do something about that, and I also plan to add a "flash the LED" button to each one so new users will never see the MAC address and never need to.

TonyBostonTB commented 2 years ago

Yeah, one out of my 10 was named after its MAC Address as well, but thats only one :)

denysdovhan commented 2 years ago

I've been testing new Xiaomi BLE integration for last two weeks. I have to say it works dramatically worse that Passive BLE Monitor.

Xiaomi BLE is unavailable most of the time, not reporting the values for days, whereas Passive BLE works reliably and reports values every 15-30 minutes.

ioannispelelis commented 2 years ago

I've been testing new Xiaomi BLE integration for last two weeks. I have to say it works dramatically worse that Passive BLE Monitor.

Xiaomi BLE is unavailable most of the time, not reporting the values for days, whereas Passive BLE works reliably and reports values every 15-30 minutes.

On my end it is also not reliable but I don't think it is the Xiaomi ble integration for the flora sensors Because I face similar issues with switchbot Bluetooth intΓ©gration with thermometer After booting Homeassistant Bluetooth passive scans of flora and switchbot devices will work for a few minutes (best case few hours) and then will stop getting new data. Bluetooth dongle is still working however for "active " requests since it can still communicate with my switchbot curtain motors and control them fine.. Only passive polling seems to be unreliable.. Only way to temporarily fix for me is to unplug the USB Bluetooth dongle for a few seconds. Replug it. then reboot Homeassistant. Then it will work for some time (few hours max) and then it will stop again getting new data...πŸ€·πŸ»β€β™‚οΈ

austwhite commented 2 years ago

@denysdovhan and @ioannispelelis Check the bluetooth adapters you are using compared to the list on the Bluetooth integration. Also try removing the Flowercare products and readding them. Mine went unavailable once, but the remove and readd fixed it and they have been rock solid ever since. Also make sure your config.yaml has all the old MiFlora stuff removed.

If you are still having an issue after that, please look to log a new issue as this issue is closed.

tediroca commented 2 years ago

I've been using the new Xiaomi BLE integration with 3 Flora devices using the built-in bluetooth adapter from a Pi 4 without any issues so far.

These 3 Flora devices are quite far away from the Raspberry itself, considering the propagation of BT (2 x backyard, 1 x front yard) and the data is still received without any problems.

Regards / Saludos / Salutacions,

Tedi Roca https://tedi.es

On Thu, 11 Aug 2022 at 15:55, austwhite @.***> wrote:

@denysdovhan https://github.com/denysdovhan and @ioannispelelis https://github.com/ioannispelelis Check the bluetooth adapters you are using compared to the list on the Bluetooth integration. Also try removing the Flowercare products and readding them. Mine went unavailable once, but the remove and readd fixed it and they have been rock solid ever since. Also make sure your config.yaml has all the old MiFlora stuff removed.

If you are still having an issue after that, please look to log a new issue as this issue is closed.

β€” Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/74585#issuecomment-1212023904, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOPRCFFLZGDZ2VL5IB57KTVYUA5PANCNFSM524QMEZQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

stephan890 commented 2 years ago

My experience, using a HA OS VM with USB passthrough bluetooth dongle, was that the passive BLE AND the new flora integration did not cooperate nicely running both at the same time. After removing passive ble (not using it for other purposes) the new flora integration worked as reliable as passive ble before. Regards, Stephan