diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f3b4c4 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Description + +This tool provides various utilities for Home Assistant via MQTT autodiscovery. + +See [sample config](sample_config). + +## Features + +### Presence detection + +This feature is for aggregating network presence (you have to set up a fix IP address for the device you want to track) and BLE presence (via [ESPresense](https://github.com/ESPresense/ESPresense)). + +## Experimental features + +These features might have breaking changes without a major version bump. + +### Cover control + +You will be able to set up covers with different opening/closing durations controlled by a remote device in Home Assistant (for example via the [Broadlink integration](https://www.home-assistant.io/integrations/broadlink)). diff --git a/Sources/Wiring/Presence/BlePresenceDetector.swift b/Sources/Wiring/Presence/BlePresenceDetector.swift index de4096b..b5fa3a0 100644 --- a/Sources/Wiring/Presence/BlePresenceDetector.swift +++ b/Sources/Wiring/Presence/BlePresenceDetector.swift @@ -38,10 +38,15 @@ actor BlePresenceDetector { await updateOutput() } } + scheduleAway() } private func updateOutput() async { await presenceDetectorAggregator.setBlePresence(true) + scheduleAway() + } + + private func scheduleAway() { presenceTimeoutTask?.cancel() presenceTimeoutTask = Task { try await Task.sleep(for: .seconds(presenceConfig.espresenseTimeout.seconds), tolerance: .seconds(0.1)) diff --git a/sample_config/README.md b/sample_config/README.md new file mode 100644 index 0000000..87e7d60 --- /dev/null +++ b/sample_config/README.md @@ -0,0 +1,9 @@ +# Description + +Config files other than `config.general.json` are optional. + +Comments are not supported in config files, they are only included in the sample config to help setting up. + +Optional parameters that have a value in the sample will default to that value if you omit them. + +`*_interval` and `*_timeout` parameters support both numeric values (seconds) and text values ("hours:minutes:seconds" or "minutes:seconds"). diff --git a/sample_config/config/config.general.json b/sample_config/config/config.general.json new file mode 100644 index 0000000..a556b8b --- /dev/null +++ b/sample_config/config/config.general.json @@ -0,0 +1,11 @@ +{ + "mqtt": { + "host": "localhost", + "port": 1883, + "user": null, // optional + "password": null, // optional + "base_topic": "wiring", // optional + "home_assistant_base_topic": "homeassistant" // optional + }, + "enable_debug_logging": false // optional +} \ No newline at end of file diff --git a/sample_config/config/config.presence.json b/sample_config/config/config.presence.json new file mode 100644 index 0000000..37129e0 --- /dev/null +++ b/sample_config/config/config.presence.json @@ -0,0 +1,17 @@ +{ + "espresense_devices_base_topic": "espresense/devices", // optional + "ping_interval": 5, // optional, ping is used to speed up detecting away status for network presence detection, usually takes around 0.5-1 minutes + "arp_interval": 5, // optional, arp reads the systems network neighbour cache, it adds a bit of CPU load and devices are usually discovered via BLE first + "espresense_timeout": 11, // optional, ESPresense sends updates about every 5-6 seconds if the device is nearby and there hasn't been any significant change + "away_timeout": "05:00", // optional + "entries": { + "Person_1": { // Supported characters in Home Assistant: [a-zA-Z0-9_-] (alphanumerics, underscore and hyphen) + "ip": "192.168.1.11", // optional + "espresense_device": "person_1_phone" // optional + }, + "Person_2": { + "ip": "192.168.1.12", + "espresense_device": "person_2_phone" + } + } +} \ No newline at end of file diff --git a/sample_config/docker-compose.yaml b/sample_config/docker-compose.yaml new file mode 100644 index 0000000..db7c314 --- /dev/null +++ b/sample_config/docker-compose.yaml @@ -0,0 +1,14 @@ +services: + wiring: + image: ghcr.io/cyberbeni/wiring:v1 + container_name: wiring + mem_limit: '128m' + cpus: 1 + restart: unless-stopped + user: 1000:1000 + network_mode: host + environment: + TZ: 'Europe/Budapest' # Time-zone identifier, used for the time in logs + LANG: 'hu' # Language identifier, used for the time format in logs + volumes: + - ./config:/config