Custom Input (Xiaom...
 
Notifications
Clear all

[Solved] Custom Input (Xiaomi LYWSD03MMC) Dependency Problem

Page 1 / 5

burrito
(@burrito)
New Member
Joined: 8 months ago
Posts: 3
Topic starter  

Hello! I'm very new to Mycodo, but have absolutely loved what I've seen, so first of all I'd like to thank Kyle and all the work of this kind community that has helped in making this amazing tool.

As someone with little coding experience and a very limited linux background, making Mycodo work has been challenging. I'm currently trying to build a custom input script for the Xiaomi LYWSD03MMC Bluetooth Hygrometer through an awesome library I found called miblepy by benleb.

My problem is that when I try to open the custom input script I load (successfully), I get a dependency problem. miblepy doesn't seem to be installing.

I was wondering if maybe someone with more experience could help me with this? Sorry if it's a dumb question and thanks in advance.

-----

This is my dependency declaration in the script:

'dependencies_module': [
('apt', 'libglib2.0-dev', 'libglib2.0-dev'),
('pip-pypi', 'bluepy', 'bluepy'),
('pip-pypi', 'btlewrap', 'btlewrap'),
('pip-git', 'miblepy', 'git://github.com/benleb/miblepy.git#egg=miblepy')

This is the dependency log output:

[2020-07-14 16:26:04] Dependency installation beginning. Installing: miblepy

[2020-07-14 16:26:04] 
[2020-07-14 16:26:04] #### Installing/updating git://github.com/benleb/miblepy.git#egg=miblepy (pip-git)
[2020-07-14 16:26:06] Looking in indexes:  https://pypi.org/simple,  https://www.piwheels.org/simple
[2020-07-14 16:26:06] Obtaining miblepy from git+git://github.com/benleb/miblepy.git#egg=miblepy
[2020-07-14 16:26:06]   Updating ./env/src/miblepy clone
[2020-07-14 16:26:06]   Running command git fetch -q --tags
[2020-07-14 16:26:06]   Running command git reset --hard -q 989964c470e8d72420c5fde0b3dd34bd00ccff31
[2020-07-14 16:26:06]   Installing build dependencies: started
[2020-07-14 16:26:07]   Installing build dependencies: finished with status 'error'
[2020-07-14 16:26:07]   ERROR: Command errored out with exit status 1:
[2020-07-14 16:26:07]    command: /home/pi/Mycodo/env/bin/python /home/pi/Mycodo/env/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-8_3vfn44/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i  https://pypi.org/simple  --extra-index-url  https://www.piwheels.org/simple  -- 'poetry>=0.12'
[2020-07-14 16:26:07]        cwd: None
[2020-07-14 16:26:07]   Complete output (44 lines):
[2020-07-14 16:26:07]   Traceback (most recent call last):
[2020-07-14 16:26:07]     File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
[2020-07-14 16:26:07]       "__main__", mod_spec)
[2020-07-14 16:26:07]     File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
[2020-07-14 16:26:07]       exec(code, run_globals)
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/__main__.py", line 26, in <module>
[2020-07-14 16:26:07]       sys.exit(_main())
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
[2020-07-14 16:26:07]       command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
[2020-07-14 16:26:07]       module = importlib.import_module(module_path)
[2020-07-14 16:26:07]     File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
[2020-07-14 16:26:07]       return _bootstrap._gcd_import(name[level:], package, level)
[2020-07-14 16:26:07]     File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[2020-07-14 16:26:07]     File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[2020-07-14 16:26:07]     File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
[2020-07-14 16:26:07]     File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
[2020-07-14 16:26:07]     File "<frozen importlib._bootstrap_external>", line 728, in exec_module
[2020-07-14 16:26:07]     File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
[2020-07-14 16:26:07]       from pip._internal.cli.req_command import RequirementCommand, with_cleanup
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 16, in <module>
[2020-07-14 16:26:07]       from pip._internal.index.package_finder import PackageFinder
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_internal/index/package_finder.py", line 21, in <module>
[2020-07-14 16:26:07]       from pip._internal.index.collector import parse_links
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_internal/index/collector.py", line 14, in <module>
[2020-07-14 16:26:07]       from pip._vendor import html5lib, requests
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_vendor/requests/__init__.py", line 114, in <module>
[2020-07-14 16:26:07]       from . import utils
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_vendor/requests/utils.py", line 25, in <module>
[2020-07-14 16:26:07]       from . import certs
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_vendor/requests/certs.py", line 15, in <module>
[2020-07-14 16:26:07]       from pip._vendor.certifi import where
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_vendor/certifi/__init__.py", line 1, in <module>
[2020-07-14 16:26:07]       from .core import contents, where
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/pip/_vendor/certifi/core.py", line 12, in <module>
[2020-07-14 16:26:07]       from importlib.resources import read_text
[2020-07-14 16:26:07]     File "/usr/lib/python3.7/importlib/resources.py", line 11, in <module>
[2020-07-14 16:26:07]       from typing import Iterable, Iterator, Optional, Set, Union   # noqa: F401
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/typing.py", line 1359, in <module>
[2020-07-14 16:26:07]       class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
[2020-07-14 16:26:07]     File "/home/pi/Mycodo/env/lib/python3.7/site-packages/typing.py", line 1007, in __new__
[2020-07-14 16:26:07]       self._abc_registry = extra._abc_registry
[2020-07-14 16:26:07]   AttributeError: type object 'Callable' has no attribute '_abc_registry'
[2020-07-14 16:26:07]   ----------------------------------------
[2020-07-14 16:26:07] ERROR: Command errored out with exit status 1: /home/pi/Mycodo/env/bin/python /home/pi/Mycodo/env/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-8_3vfn44/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i  https://pypi.org/simple  --extra-index-url  https://www.piwheels.org/simple  -- 'poetry>=0.12' Check the logs for full command output.

[2020-07-14 16:26:08] End install of miblepy

[2020-07-14 16:26:08] 
[2020-07-14 16:26:08] #### Setting permissions

[2020-07-14 16:26:09] #### All Dependencies have been installed.

Quote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

Why not try just pip-pypi with miblepy instead of pip-git?

Mycodo Developer


ReplyQuote
burrito
(@burrito)
New Member
Joined: 8 months ago
Posts: 3
Topic starter  

@kylegabriel

Hey! Thanks for the quick reply and thanks for this valuable tool.

pip was giving me a different issue, despite miblepy seemingly being available. I feel like I'm doing something very stupid.

 

dependencies in script:

'dependencies_module': [
('apt', 'libglib2.0-dev', 'libglib2.0-dev'),
('pip-pypi', 'bluepy', 'bluepy'),
('pip-pypi', 'btlewrap', 'btlewrap'),
('pip-pypi', 'miblepy', 'miblepy')
],

 

dependencies log:

[2020-07-14 17:28:46] Dependency installation beginning. Installing: miblepy

[2020-07-14 17:28:46]
[2020-07-14 17:28:46] #### Installing/updating miblepy (pip-pypi)
[2020-07-14 17:28:48] Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
[2020-07-14 17:28:50] ERROR: Could not find a version that satisfies the requirement miblepy (from versions: none)
[2020-07-14 17:28:50] ERROR: No matching distribution found for miblepy

[2020-07-14 17:28:50] End install of miblepy

[2020-07-14 17:28:50]
[2020-07-14 17:28:50] #### Setting permissions

[2020-07-14 17:28:51] #### All Dependencies have been installed.


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

I'm unable to install it either via pypi or pip install from a clone. It doesn't seem to support the software environment of Buster.

Mycodo Developer


ReplyQuote
burrito
(@burrito)
New Member
Joined: 8 months ago
Posts: 3
Topic starter  

Welp, guess I'll look for something else. Thanks for your help and I'll keep you posted if I get the custom input working. :)


ReplyQuote
lemonsquash11
(@lemonsquash11)
Trusted Member
Joined: 1 month ago
Posts: 59
 

Hey there, I have no programming knowledge whatsoever and am also a complete beginner with Mycodo, but im also desperately trying to get this hygrometer connected. There is a plugin for Homebridge on the Pi that allows connecting to the LYWSD03MMC Hygrometer and reading its data ( https://github.com/hannseman/homebridge-mi-hygrothermograph), possibly that could help you find a solution. One thing to note about the LYWSD03MMC compared to the older xiaomi ble hygrometers is that it requires you to get an encryption key from the xiaomi app. The documentation of the linked Homebridge plugin explains this in further detail. 

Could someone help me make this work? Seeing as I lack the knowhow to contribute otherwise, I would be more than happy to contribute to the project with a small donation. I have a bunch of these Hygrometers and they are accurate, wireless and ridiculously affordable so I believe it could be an enrichment for several users.

thank you

 

EDIT: I also found this recently released python library for the Xiaomi LYWSD03MMC: ( https://pypi.org/project/lywsd03mmc/ ), could someone help me create a custom input module with this?


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

This also looks promising: https://github.com/JsBergbau/MiTemperature2

Mycodo Developer


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

I'll see if I can come up with an Input module for you to test.

Mycodo Developer


ReplyQuote
lemonsquash11
(@lemonsquash11)
Trusted Member
Joined: 1 month ago
Posts: 59
 

Thank you, that would be truly amazing! I own 20 of these and at around 3€ a piece they're unbeatable in their flexibility considering they use Sensirion sensors, don't require wiring and have a 3 year battery-life. I'd be happy to sponsor you one for testing purposes if that helps.

 


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

Save the attached file, rename from .txt to .py, import it from the Configure/Custom Inputs menu, add the new Input from the Setup/Data page, configure the new input, and give it a test to see if it returns values.

Mycodo Developer


ReplyQuote
lemonsquash11
(@lemonsquash11)
Trusted Member
Joined: 1 month ago
Posts: 59
 

Hey, thank you so much for trying to make this work!! Unfortunately I'm not getting any values yet. I have flashed the Hygrometer with a custom firmware, that advertises the readings without a bindKey requirement: https://github.com/atc1441/ATC_MiThermometer

This firmware also allows advertising the data without Xiaomi's proprietary format, possibly that makes reading the data easier? Here's the documentation on the custom advertisement format: 

Advertising format of the custom firmware:

The custom firmware sends every minute an update of advertising data on the UUID 0x181A with the Tempereature, Humidity and Battery data.

The format of the advertising data is as follow:
  • Byte 5-10 MAC in correct order
  • Byte 11-12 Temperature in int16
  • Byte 13 Humidity in percent
  • Byte 14 Battery in percent
  • Byte 15-16 Battery in mV uint16_t
  • Byte 17 frame packet counter
Example: 0x0e, 0x16, 0x1a, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xbb, 0xcc, 0xdd, 0xdd, 0x00

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

The module used is the one linked in your original post. From the developer at https://github.com/uduncanu/lywsd03mmc it's stated, "Updating the firmware on the devices is not required", so I don't think it supports ATC mode.

However, the library I linked to ( https://github.com/JsBergbau/MiTemperature2 ) supports ATC mode. I can try to make a second library using that library that you can test.

Mycodo Developer


ReplyQuote
lemonsquash11
(@lemonsquash11)
Trusted Member
Joined: 1 month ago
Posts: 59
 

Here's what the Log reads:

2021-01-21 02:17:42,097 - INFO - mycodo.controllers.controller_input_3157c075 - Activated in 304.2 ms
2021-01-21 02:17:56,923 - ERROR - mycodo.controllers.controller_input_3157c075 - StopIteration raised 3 times. Possibly could not read input. Ensure it's connected properly and detected.

ReplyQuote
lemonsquash11
(@lemonsquash11)
Trusted Member
Joined: 1 month ago
Posts: 59
 

@kylegabriel You're right, using MiTemperature2 seems like a good idea. Besides, the ATC flasher tool turned out to be the most convenient way of obtaining the encryption key which is required one way or another when using the stock firmware.

 

thanks


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

The only issue with https://github.com/JsBergbau/MiTemperature2 is I don't see any straightforward python example code.

Mycodo Developer


ReplyQuote
Page 1 / 5