fhempy: ble_monitor (Bluetooth Low Energy)

Begonnen von dominik, 15 Februar 2022, 23:36:47

Vorheriges Thema - Nächstes Thema

Nighthawk

Hier das log:

Exception ignored in: <coroutine object BaseEventLoop._create_connection_transport at 0x7f3d90b44a40>
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1122, in _create_connection_transport
    transport.close()
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 697, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 751, in call_soon
    self._check_closed()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
2022-05-22 19:26:41,967 - ERROR    - asyncio: Task was destroyed but it is pending!
task: <Task pending name='Task-107' coro=<Event.wait() done,
defined at /usr/lib/python3.9/asyncio/locks.py:213> wait_for=<Future pending cb=[<TaskWakeupMethWrapper
object at 0x7f3d907f83a0>()]> cb=[_release_waiter(<Future pendi...d907f8be0>()]>)() at /usr/lib/python3.9/asyncio/tasks.py:416]>


Mir ist auch aufgefallen, dass nichts passiert wenn ich den FHEMPyServer neustarte, weder eine Reaktion im Webinterface, noch im Log.

marboj

nochmals kurz zur Konkretisierung meines Problems:

Ich möchte das Xiaomi Thermometer LY...03 mit der alternativen FW an mein FHEM anbinden.

Bei Nutzung des Moduls ble_monitor erscheint der o.g. Fehler im STATE.

Bei Nutzung des Moduls mitemp wird der Name des Geräts als reading angelegt, nicht mehr nicht weniger...

Gruß
Marco
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

dominik

@Nighthawk, kannst du bitte mit der Version 358 testen? Bitte poste dann wieder das Log, danke!

@marboj, ok, ich hatte wohl übersehen, dass ble_monitor doch 3.8 oder höher benötigt. Sorry! Kannst du bitte nochmals mit 3.9 und Version 358 testen?
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

Hallo Dominik,

hier das Log, leider ohne Veränderung:

                                                                                                                                                                                                                                                                                                                                                                                                                                                       
2022-05-23 20:25:32,123 - INFO     - fhempy.lib.pkg_installer: Attempting install of fhempy
2022-05-23 20:25:32,705 - ERROR    - fhempy.lib.pkg_installer: Unable to install package fhempy: Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/__main__.py", line 29, in <module>
    from pip._internal.cli.main import main as _main
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/configuration.py", line 26, in <module>
    from pip._internal.utils.logging import getLogger
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 27, in <module>
    from pip._internal.utils.misc import ensure_dir
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 39, in <module>
    from pip._internal.locations import get_major_minor_version
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 14, in <module>
    from . import _distutils, _sysconfig
  File "/opt/fhem/.local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 9, in <module>
    from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils.cmd'
2022-05-23 20:25:33,196 - INFO     - fhempy.lib.fhem_pythonbinding: Starting fhempy...
2022-05-23 20:25:33,198 - INFO     - fhempy.lib.fhem_pythonbinding: Waiting for FHEM connection
2022-05-23 20:25:33,227 - INFO     - websockets.server: server listening on 0.0.0.0:15733
2022-05-23 20:25:43,296 - INFO     - websockets.server: connection open
2022-05-23 20:25:43,299 - INFO     - fhempy.lib.fhem_pythonbinding: Incoming FHEM connection: 127.0.0.1
2022-05-23 20:25:43,381 - WARNING  - zeroconf: Error with socket 12 (('192.168.42.0', 5353))): [Errno 126] Required key not available
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 1053, in sendto
    self._sock.sendto(data, addr)
OSError: [Errno 126] Required key not available
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2022-05-23 20:25:48,948 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:25:53,955 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:25:58,962 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:26:03,967 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:26:08,973 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:27:16,753 - INFO     - fhempy.lib.fhem_pythonbinding: Starting fhempy...
2022-05-23 20:27:16,756 - INFO     - fhempy.lib.fhem_pythonbinding: Waiting for FHEM connection
2022-05-23 20:27:16,791 - INFO     - websockets.server: server listening on 0.0.0.0:15733
2022-05-23 20:27:34,764 - INFO     - websockets.server: connection open
2022-05-23 20:27:34,767 - INFO     - fhempy.lib.fhem_pythonbinding: Incoming FHEM connection: 127.0.0.1
2022-05-23 20:27:34,797 - WARNING  - zeroconf: Error with socket 12 (('192.168.42.0', 5353))): [Errno 126] Required key not available
Traceback (most recent call last):
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 1053, in sendto
    self._sock.sendto(data, addr)
OSError: [Errno 126] Required key not available
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 171, in run
    conn[hci], btctrl[hci] = self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 171, in run
    conn[hci], btctrl[hci] = self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2022-05-23 20:27:43,823 - ERROR    - Feuermelder_Galerie: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:27:48,827 - ERROR    - Feuermelder_Galerie: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:27:53,831 - ERROR    - Feuermelder_Galerie: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:27:58,835 - ERROR    - Feuermelder_Galerie: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-23 20:28:03,839 - ERROR    - Feuermelder_Galerie: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.

dominik

Ich glaube da liegt noch ein Fehler beim Update vor. Wie hast du fhempy aktualisiert? Weil das Log ist noch von einer älteren Version.
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

marboj

Hallo Dominik,

das Problem ist, dass ich zur Abfrage meiner Tür- und Fensterkontakte ebenfalls Python benötige und die Scripte geben Fehler unter 3.8 aus. Leider bin ich in Python niht fit um zu wissen, wie man die Scripte unter 3.8 lauffähig bekommt.

Was ist denn mit dem mitemp-Modul? Läuft das unter 3.7? Das sollte doch auch funktionieren, oder?

Gruß
Marco
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

marboj

Habe jetzt 3.8 installiert, parallel zu 3.7.

Leider nutzt Fhempy trotzdem beim Start 3.7. Wie kann man das steuern?

Es gibt 2 Auswahlmöglichkeiten für die Alternative python (welche /usr/bin/python bereitstellen).

  Auswahl      Pfad                      Priorität Status
------------------------------------------------------------
* 0            /usr/local/bin/python3.8   2         automatischer Modus
  1            /usr/bin/python3.7         1         manueller Modus
  2            /usr/local/bin/python3.8   2         manueller Modus

meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

Nighthawk

Hallo Dominik,

Das Update habe ich wie gewohnt mit Update all ausgeführt und anschließend  ein shutdown restart hinterhergeschoben.

Aktuell sieht es aus wie auf dem Screenshot, wenn ich Update check ausführe.


Nighthawk

Hallo Dominik,

gibt es wirklich keine Möglichkeit das Problem einzufangen und zu lösen?
Ich habe nun alles was mit fhempy zu tun hatte rausgelöscht und fhempy neu angelegt, leider ohne einen sichtbaren Erfolg.

AlexMuc

#99
Hallo zusammen,
mir ist ein "Eve Window Guard" zugelaufen. Der funktioniert mit Bluetooth LE und mit der App "nRF Connect" ist der auf dem iPhone "zu sehen". Also funktioniert er schon mal grundsätzlich. Das Teil stammt in Wirklichkeit vom Hersteller Eimsig, wird aber mit Eve Anleitung verkauft.
Nun zu meinem Problem: Wie kriege ich das Teil nun in Fhem? Mein Raspberry Pi4 hat angeblich Buetooth, auch wenn ich es dort noch nie (wissentlich) verwendet habe. Weder Eve noch Eimsig stehen bisher in der Liste der unterstützten Hersteller bei Supported devices. Bevor ich jetzt anfange, neue Pakete auf dem Pi zu installieren, wie stehen die Chancen, das Teil in Fhem nutzen zu können. Bisher habe ich keine externen Hubs an die ich das Teil anlernen kann. Es sollte also direkt mit Bordmitteln vom Pi funktionieren.
Was sol ich machen damit mir wer helfen kann?

Vielen Dank
Alex

dominik

Antwort von Claude ;)

Hallo Alex,

kurz vorweg: Mit ble_monitor wird das leider nichts. ble_monitor liest nur Sensoren aus, die ihre Messwerte offen in der Bluetooth-Werbung (Advertisement) mitsenden (Xiaomi, Govee, Inkbird usw.). Der Eve Window Guard ist ein reines HomeKit-Gerät über Bluetooth LE. Der sendet in der Werbung nur "ich bin ein HomeKit-Gerät, und es hat sich etwas geändert". Die eigentlichen Werte (Fenster zu/gekippt/offen, Alarm, Batterie) gibt es nur über eine verschlüsselte Verbindung, nachdem das Gerät mit dem Setup-Code gekoppelt wurde.

Die gute Nachricht: Einen Hub brauchst du nicht. Ich habe das homekit-Modul von fhempy erweitert, damit es HomeKit-Geräte auch direkt über Bluetooth koppeln kann. Das ist im nächsten fhempy-Release enthalten. Der eingebaute Bluetooth-Chip vom Pi 4 reicht dafür. Ausprobiert hat es mit einem echten Window Guard aber noch niemand, du wärst also der Erste. Rückmeldung, ob es klappt, wäre super.

Vorher wichtig:

Ein HomeKit-Gerät kann nur einen "Besitzer" haben. Wenn der Window Guard gerade in Apple Home bzw. der Eve-App eingebunden ist, musst du ihn dort entfernen (bzw. zurücksetzen), damit FHEM ihn koppeln kann. Beides gleichzeitig geht nicht.
Du brauchst den 8-stelligen HomeKit-Setup-Code (Format 123-45-678). Der steht auf dem Gerät oder in der Anleitung.
Für den Anfang das Gerät nicht zu weit vom Pi entfernt lassen.
So geht's nach dem Update:

fhempy aktualisieren.
Wenn du die fhempy-Autodiscovery nutzt, sollte der Window Guard dort als HomeKit-Gerät auftauchen, sobald er nicht mehr in Apple Home gekoppelt ist. Dann einfach den Setup-Code eingeben und anlegen.
Ohne Autodiscovery geht es auch von Hand, dafür brauchst du die HomeKit-ID des Geräts. Die steht in nRF Connect bei "Manufacturer data" (Apple, 0x004C): Die Daten fangen mit 0x06 an, dann folgen zwei weitere Bytes und danach 6 Bytes HomeKit-ID. Ein Screenshot davon hier im Forum reicht, dann sage ich dir die ID und den passenden define.
Nach dem Koppeln legt das Modul ein eigenes Gerät für den Window Guard an. Die Werte kommen dort als Readings an. Das Gerät meldet Änderungen selbst, es wird nicht ständig abgefragt, damit die Batterie lange hält.

Falls es nicht klappt, bitte posten:

einen Screenshot aus nRF Connect vom Window Guard (Name und "Manufacturer data"),
die Ausgabe von bluetoothctl auf dem Pi: bluetoothctl, dann scan on, warten bis das Gerät auftaucht, dann scan off und info <MAC-Adresse>,
das fhempy-Log rund um das Koppeln,
deine fhempy-Version und das Raspberry Pi OS (z.B. Bookworm oder Trixie).
Viele Grüße
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik