From 0ae24f4725e17482434687255686b8aaedf40652 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 13 May 2022 14:14:24 -0700 Subject: [PATCH] Document how we sync over enabled state --- docs/api/native-app-integration/sensors.md | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/api/native-app-integration/sensors.md b/docs/api/native-app-integration/sensors.md index e0b16c1a..ff7b1790 100644 --- a/docs/api/native-app-integration/sensors.md +++ b/docs/api/native-app-integration/sensors.md @@ -79,3 +79,33 @@ Only some of the keys are allowed during updates: | state | bool, float, int, string | Yes | The state of the sensor | | type | string | Yes | The type of the sensor. Must be one of `binary_sensor` or `sensor` | | unique_id | string | Yes | An identifier unique to this installation of your app. You'll need this later. Usually best when its a safe version of the sensor name | + +## Keeping enabled sensors in sync between Home Assistant and mobile app + +Users can enable and disable entities in Home Assistant. A disabled entity will not be added to Home Assistant, even if offered by the integration. This means that it won't make sense for phones to keep sending data to entities that are not enabled in Home Assistant. + +### When a sensor is disabled in the app + +When a sensor is enabled/disabled in the app, the app should send a `register_sensor` webhook for this sensor and set `disabled` to `true` or `false`. + +### When a sensor is disabled in Home Assistant + +When the mobile app sends an `update_sensor_states` webhook to update the data for an entity that is disabled, the update result will contain a `disabled` key with a value of `true`. This is an indicator that the mobile app needs to synchroize the enabled states from Home Assistant to the mobile app. + +### Synchronizing enabeld states from Home Assistant to the mobile app + +The `get_config` webhook response contains an `entities` key. This is a dictionary mapping `unique_id` to `{"disabled": boolean}`. The mobile app should adopt these enabled settings. + +```json5 +{ + // ... + "entities": { + "battery_level": { + "disabled": false + }, + "battery_charging": { + "disabled": true + }, + } +} +```