Add crafty skill: BLE control for Storz & Bickel Crafty via storzandbickel-ble
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
.venv/
|
||||||
|
__pycache__/
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
name: crafty
|
||||||
|
description: Steuerung des Storz & Bickel Crafty/Crafty+ Vaporizers über Bluetooth BLE (Scan, Status, Zieltemperatur, Heizung an/aus) via die Python-Library storzandbickel-ble. Nutzen, wenn der Crafty ausgelesen oder ferngesteuert werden soll.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Crafty (Storz & Bickel) per BLE steuern
|
||||||
|
|
||||||
|
Python-CLI unter `bin/crafty` (venv mit `storzandbickel-ble` v0.1.21, Python 3.14).
|
||||||
|
|
||||||
|
## Voraussetzungen
|
||||||
|
|
||||||
|
- Crafty eingeschaltet und in Bluetooth-Reichweite
|
||||||
|
- **S&B-App am Handy getrennt** — das Gerät erlaubt nur eine BLE-Verbindung gleichzeitig
|
||||||
|
- BLE-Adapter aktiv (`bluetoothctl show` → `Powered: yes`)
|
||||||
|
- Firmware ≥ 2.51 empfohlen; darunter blendet das Gerät einige Werte aus
|
||||||
|
|
||||||
|
## Befehle
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bin/crafty scan # nur scannen
|
||||||
|
bin/crafty status # verbinden + Zustand ausgeben (Temp, Batterie, Boost, …)
|
||||||
|
bin/crafty temp 185 # Zieltemperatur setzen (°C)
|
||||||
|
bin/crafty heat on # Heizung ein
|
||||||
|
bin/crafty heat off # Heizung aus
|
||||||
|
```
|
||||||
|
|
||||||
|
## Weitere Funktionen (über die Library direkt)
|
||||||
|
|
||||||
|
`set_boost_temperature()`, `set_superboost()`, `set_led_brightness()`,
|
||||||
|
`set_vibration()`, `set_auto_off_time()`, `set_charge_led()`,
|
||||||
|
`set_permanent_bluetooth()`, `run_analysis()` (lokale Diagnose) — siehe
|
||||||
|
`CraftyDevice` in der Library, API-Browser:
|
||||||
|
`.venv/bin/python -c "from storzandbickel_ble import CraftyDevice; help(CraftyDevice)"`
|
||||||
|
|
||||||
|
## Setup (falls das Repo neu geklont wurde)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd "$(dirname SKILL.md)" && python3 -m venv .venv && .venv/bin/pip install storzandbickel-ble
|
||||||
|
```
|
||||||
|
|
||||||
|
shortcut: Shebang von `bin/crafty` zeigt auf die `.venv` in diesem Checkout — bei Umsiedeln des Repos anpassen.
|
||||||
Executable
+61
@@ -0,0 +1,61 @@
|
|||||||
|
#!/home/markus/workspace/skills/integrations/crafty/.venv/bin/python3
|
||||||
|
"""CLI für Storz & Bickel Crafty über BLE.
|
||||||
|
|
||||||
|
shortcut: Shebang zeigt auf .venv in diesem Checkout — bei Umsiedeln des Repos anpassen.
|
||||||
|
|
||||||
|
|
||||||
|
Usage: crafty [scan|status|temp N|heat on|off]
|
||||||
|
"""
|
||||||
|
import asyncio
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from storzandbickel_ble import StorzBickelClient
|
||||||
|
from storzandbickel_ble.models import DeviceType
|
||||||
|
|
||||||
|
SCAN_TIMEOUT = 15.0
|
||||||
|
|
||||||
|
|
||||||
|
async def connect():
|
||||||
|
client = StorzBickelClient()
|
||||||
|
devices = await client.scan(timeout=SCAN_TIMEOUT, device_type=DeviceType.CRAFTY)
|
||||||
|
if not devices:
|
||||||
|
sys.exit("Kein Crafty gefunden — Gerät eingeschaltet? S&B-App getrennt?")
|
||||||
|
return client, await client.connect_device(devices[0])
|
||||||
|
|
||||||
|
|
||||||
|
def dump_state(state):
|
||||||
|
for k in sorted(vars(state)):
|
||||||
|
v = getattr(state, k)
|
||||||
|
if not k.startswith("_") and v is not None:
|
||||||
|
print(f"{k}: {v}")
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
cmd = sys.argv[1] if len(sys.argv) > 1 else "status"
|
||||||
|
arg = sys.argv[2] if len(sys.argv) > 2 else None
|
||||||
|
|
||||||
|
if cmd == "scan":
|
||||||
|
for d in await StorzBickelClient().scan(timeout=SCAN_TIMEOUT, device_type=DeviceType.CRAFTY):
|
||||||
|
print(d)
|
||||||
|
return
|
||||||
|
|
||||||
|
client, dev = await connect()
|
||||||
|
try:
|
||||||
|
await dev.update_state()
|
||||||
|
if cmd == "status":
|
||||||
|
dump_state(dev.state)
|
||||||
|
elif cmd == "temp" and arg:
|
||||||
|
await dev.set_target_temperature(float(arg))
|
||||||
|
await dev.update_state()
|
||||||
|
print(f"Zieltemperatur: {dev.state.target_temperature} °C")
|
||||||
|
elif cmd == "heat" and arg in ("on", "off"):
|
||||||
|
await (dev.turn_heater_on() if arg == "on" else dev.turn_heater_off())
|
||||||
|
print(f"Heizung: {arg}")
|
||||||
|
else:
|
||||||
|
sys.exit(__doc__)
|
||||||
|
finally:
|
||||||
|
await dev.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
Reference in New Issue
Block a user