diff --git a/app.json b/app.json index d9ffa0b..b98e1db 100644 --- a/app.json +++ b/app.json @@ -172,6 +172,31 @@ } } ] + }, + { + "type": "group", + "label": { + "en": "mmWave" + }, + "children": [ + { + "id": "max_distance", + "type": "number", + "label": { + "en": "mmWave distance" + }, + "value": 600, + "min": 0, + "max": 600, + "step": 1, + "units": { + "en": "cm" + }, + "hint": { + "en": "Configure the distance of the room the sensor is placed in. This is important for accurate mmWave occupancy detection. See the Everything Presence Lite documentation for more information." + } + } + ] } ] }, diff --git a/drivers/everything-presence-lite/device.ts b/drivers/everything-presence-lite/device.ts index 9e7bf7e..6aed2ed 100644 --- a/drivers/everything-presence-lite/device.ts +++ b/drivers/everything-presence-lite/device.ts @@ -150,7 +150,8 @@ const CONNECT_TIMEOUT = 15000; // } +1ms enum DRIVER_SETTINGS { - ESP_32_LED = 'esp32_led' + ESP_32_LED = 'esp32_led', + MMWAVE_DISTANCE = 'max_distance' // Why is this id max_distance and not distance? } const entityStateSchema = z.object({ @@ -486,6 +487,19 @@ class EverythingPresenceLiteDevice extends Homey.Device { // Read and update settings switch (entity.config.objectId) { + case DRIVER_SETTINGS.MMWAVE_DISTANCE: + // Throw when state is not a number + z.number().parse(parsedState.state); + this.debugEntity(`Setting: ${entity.config.objectId}: state event`, parsedState.state); + this.setSettings({ + [entity.config.objectId]: parsedState.state + }).catch((err) => + this.debugEntity( + `Failed to set setting ${entity.config.objectId} to value: ${parsedState.state}, reason:`, + err + ) + ); + break; case DRIVER_SETTINGS.ESP_32_LED: // Throw when state is not a boolean z.boolean().parse(parsedState.state); @@ -529,6 +543,7 @@ class EverythingPresenceLiteDevice extends Homey.Device { this.log('EverythingPresenceLiteDevice settings were changed'); for (const changedKey of changedKeys) { switch (changedKey) { + case DRIVER_SETTINGS.MMWAVE_DISTANCE: case DRIVER_SETTINGS.ESP_32_LED: const entity = this.entities.get(changedKey); if (!entity) throw new Error(`Missing entity ${changedKey}`); diff --git a/drivers/everything-presence-lite/driver.settings.compose.json b/drivers/everything-presence-lite/driver.settings.compose.json index ff6a05d..7237117 100644 --- a/drivers/everything-presence-lite/driver.settings.compose.json +++ b/drivers/everything-presence-lite/driver.settings.compose.json @@ -53,5 +53,24 @@ "hint": { "en": "Enable or disable the ESP32 status LED." } } ] + }, + { + "type": "group", + "label": { "en": "mmWave" }, + "children": [ + { + "id": "max_distance", + "type": "number", + "label": { "en": "mmWave distance" }, + "value": 600, + "min": 0, + "max": 600, + "step": 1, + "units": { "en": "cm" }, + "hint": { + "en": "Configure the distance of the room the sensor is placed in. This is important for accurate mmWave occupancy detection. See the Everything Presence Lite documentation for more information." + } + } + ] } ]