0.0.1-0 • Published 2 months ago

fp2-proxy v0.0.1-0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

FP2 Proxy

Downloads Version

GitHub issues GitHub pull requests JavaScript Style Guide

Proxy for Aqara Presence Sensor FP2

Copyright © 2023-2024 Erik Baauw. All rights reserved.

This repository provides a daemon programme, fp2-proxy, that creates a virtual device, mirroring an Aqara Presence Sensor FP2, on a deCONZ gateway or Hue bridge.

This virtual device enables the FP2 to be used in rules on the deCONZ gateway or on the Hue bridge. Generally speaking, these rules are more reliable, more responsive, and functionally richer than HomeKit automations. Furthermore, these rules don't require an Apple home hub.

The virtual device can be exposed to HomeKit through Homebridge deCONZ or Homebridge Hue2. This provides a richer experience than using the native HomeKit feature of the FP2, as the Homebridge plugins include additional characteristics for Last Motion, Dark, and Daylight and history for Motion and Light Level.

Work in Progress

This repository is work in progress. I managed to pair the FP2 to fp2-proxy, persisting the pair data. Notably, the following features have yet to be implemented:

  • The actual proxy daemon;
  • Use a "lite", native JavaScript clone of hap-controller without the BLE logic;
  • Optionally connect to a Hue bridge instead of a deCONZ gateway.

Aqara FP2

The Aqara Presence Sensor FP2 is a mmWave presence detector supporting multiple detection zones. It also contains a light level sensor. The sensor is powered over a USB-C connection, like the Aqara FP1 Human Presence Sensor. However, unlike the FP1, the FP2 communicates over WiFi rather than Zigbee. It supports HomeKit natively, exposing an Occupancy Sensor and Light Sensor service by default. See the Wiki for details.

The FP2 can be bound to the Aqara app, next to its pairing with HomeKit. It is configured through the Aqara app, as far as I can tell over the Aqara IoT server in the cloud. Once configured, the sensor can be unbound from the app, and no longer communicates with the Aqara IoT server. For each configured detection zone, an additional Occupancy Sensor service is exposed to HomeKit.

Virtual Device

The virtual device consist of a number of CLIPPresence and CLIPLightLevel sensors resources on the deCONZ gateway or the Hue bridge. fp2-proxy creates the CLIP resources and mirrors state changes of the FP2 to these, effectively creating a proxy FP2 sensor on the deCONZ gateway or Hue bridge.

To REST API clients, including Homebridge deCONZ and Homebridge Hue2, these CLIP resources are similar to the ZHAPresence and ZHALightLevel resources for a Zigbee motion sensor. Only the state of the CLIP resources is updated through the API, instead of from the Zigbee device.

Configuration

Without any command arguments, fp2-proxy connects to and monitors paired FP2 devices, mirroring any state changes to the corresponding virtual devices on the deCONZ gateway. Typically, you would run fp2-proxy as a service on system startup. I recommend running fp2-proxy on the same server as deCONZ.

fp2-proxy keeps its configuration in a hidden configuration file, ~/.fp2-proxy. It contains parameters like the API key for the deCONZ gateway, and the HomeKit pair data for the FP2. While running, fp-proxy monitors the configuration file for changes, adding or deleting virtual FP2 devices on the deCONZ gateway, as FP2 devices are paired or unpaired. To pair or unpair FP2 devices, run fp2-proxy pair or fp2-proxy unpair.

Acknowledgements

Conceptually, fp2-proxy consists of a HAP client to connect to the FP2 devices, and a REST API client to connect to the deCONZ gateway or Hue bridge. The HAP client is from hap-controller. The REST API client is s are from Homebridge deCONZ and Homebridge Hue2.