From 1a7ed95c6b6a651cc2a1944ff8e1de53c2a5a88b Mon Sep 17 00:00:00 2001 From: Adrian Jagielak Date: Thu, 24 Jul 2025 15:54:47 +0200 Subject: [PATCH] Create MQTT components interfaces and documentation --- futurehome/config.yaml | 2 +- .../src/ha/mqtt_components/_component.ts | 60 ++ .../ha/mqtt_components/alarm_control_panel.ts | 339 ++++++++++ .../src/ha/mqtt_components/binary_sensor.ts | 276 ++++++++ futurehome/src/ha/mqtt_components/button.ts | 245 +++++++ futurehome/src/ha/mqtt_components/camera.ts | 213 ++++++ futurehome/src/ha/mqtt_components/climate.ts | 578 ++++++++++++++++ futurehome/src/ha/mqtt_components/cover.ts | 417 ++++++++++++ .../ha/mqtt_components/device_automation.ts | 139 ++++ .../src/ha/mqtt_components/device_tracker.ts | 236 +++++++ futurehome/src/ha/mqtt_components/event.ts | 238 +++++++ futurehome/src/ha/mqtt_components/fan.ts | 400 +++++++++++ .../src/ha/mqtt_components/humidifier.ts | 368 ++++++++++ futurehome/src/ha/mqtt_components/image.ts | 240 +++++++ .../src/ha/mqtt_components/lawn_mower.ts | 272 ++++++++ futurehome/src/ha/mqtt_components/light.ts | 630 ++++++++++++++++++ futurehome/src/ha/mqtt_components/lock.ts | 313 +++++++++ .../src/ha/mqtt_components/manual_mqtt.ts | 184 +++++ futurehome/src/ha/mqtt_components/notify.ts | 237 +++++++ futurehome/src/ha/mqtt_components/number.ts | 278 ++++++++ futurehome/src/ha/mqtt_components/scene.ts | 237 +++++++ futurehome/src/ha/mqtt_components/select.ts | 245 +++++++ futurehome/src/ha/mqtt_components/sensor.ts | 285 ++++++++ futurehome/src/ha/mqtt_components/siren.ts | 272 ++++++++ futurehome/src/ha/mqtt_components/switch.ts | 288 ++++++++ futurehome/src/ha/mqtt_components/tag.ts | 104 +++ futurehome/src/ha/mqtt_components/text.ts | 265 ++++++++ futurehome/src/ha/mqtt_components/update.ts | 277 ++++++++ futurehome/src/ha/mqtt_components/vacuum.ts | 274 ++++++++ futurehome/src/ha/mqtt_components/valve.ts | 343 ++++++++++ .../src/ha/mqtt_components/water_heater.ts | 356 ++++++++++ futurehome/src/ha/publish_device.ts | 121 +--- futurehome/src/services/basic.ts | 2 +- futurehome/src/services/battery.ts | 9 +- futurehome/src/services/color_ctrl.ts | 5 +- futurehome/src/services/fan_ctrl.ts | 5 +- futurehome/src/services/out_bin_switch.ts | 2 +- futurehome/src/services/out_lvl_switch.ts | 2 +- futurehome/src/services/scene_ctrl.ts | 10 +- futurehome/src/services/sensor_accelx.ts | 2 +- futurehome/src/services/sensor_accely.ts | 2 +- futurehome/src/services/sensor_accelz.ts | 2 +- futurehome/src/services/sensor_airflow.ts | 2 +- futurehome/src/services/sensor_airq.ts | 2 +- futurehome/src/services/sensor_anglepos.ts | 2 +- futurehome/src/services/sensor_atmo.ts | 2 +- futurehome/src/services/sensor_baro.ts | 2 +- futurehome/src/services/sensor_co.ts | 2 +- futurehome/src/services/sensor_co2.ts | 2 +- futurehome/src/services/sensor_contact.ts | 2 +- futurehome/src/services/sensor_current.ts | 2 +- futurehome/src/services/sensor_dew.ts | 2 +- futurehome/src/services/sensor_direct.ts | 2 +- futurehome/src/services/sensor_distance.ts | 2 +- futurehome/src/services/sensor_elresist.ts | 2 +- futurehome/src/services/sensor_freq.ts | 2 +- futurehome/src/services/sensor_gp.ts | 2 +- futurehome/src/services/sensor_gust.ts | 2 +- futurehome/src/services/sensor_humid.ts | 2 +- futurehome/src/services/sensor_lumin.ts | 2 +- futurehome/src/services/sensor_moist.ts | 2 +- futurehome/src/services/sensor_noise.ts | 2 +- futurehome/src/services/sensor_power.ts | 2 +- futurehome/src/services/sensor_presence.ts | 2 +- futurehome/src/services/sensor_rain.ts | 2 +- futurehome/src/services/sensor_rotation.ts | 2 +- futurehome/src/services/sensor_seismicint.ts | 2 +- futurehome/src/services/sensor_seismicmag.ts | 2 +- futurehome/src/services/sensor_solarrad.ts | 2 +- futurehome/src/services/sensor_tank.ts | 2 +- futurehome/src/services/sensor_temp.ts | 2 +- futurehome/src/services/sensor_tidelvl.ts | 2 +- futurehome/src/services/sensor_uv.ts | 2 +- futurehome/src/services/sensor_veloc.ts | 2 +- futurehome/src/services/sensor_voltage.ts | 2 +- futurehome/src/services/sensor_watflow.ts | 2 +- futurehome/src/services/sensor_watpressure.ts | 2 +- futurehome/src/services/sensor_wattemp.ts | 2 +- futurehome/src/services/sensor_weight.ts | 2 +- futurehome/src/services/sensor_wind.ts | 2 +- futurehome/src/services/thermostat.ts | 4 +- 81 files changed, 8675 insertions(+), 178 deletions(-) create mode 100644 futurehome/src/ha/mqtt_components/_component.ts create mode 100644 futurehome/src/ha/mqtt_components/alarm_control_panel.ts create mode 100644 futurehome/src/ha/mqtt_components/binary_sensor.ts create mode 100644 futurehome/src/ha/mqtt_components/button.ts create mode 100644 futurehome/src/ha/mqtt_components/camera.ts create mode 100644 futurehome/src/ha/mqtt_components/climate.ts create mode 100644 futurehome/src/ha/mqtt_components/cover.ts create mode 100644 futurehome/src/ha/mqtt_components/device_automation.ts create mode 100644 futurehome/src/ha/mqtt_components/device_tracker.ts create mode 100644 futurehome/src/ha/mqtt_components/event.ts create mode 100644 futurehome/src/ha/mqtt_components/fan.ts create mode 100644 futurehome/src/ha/mqtt_components/humidifier.ts create mode 100644 futurehome/src/ha/mqtt_components/image.ts create mode 100644 futurehome/src/ha/mqtt_components/lawn_mower.ts create mode 100644 futurehome/src/ha/mqtt_components/light.ts create mode 100644 futurehome/src/ha/mqtt_components/lock.ts create mode 100644 futurehome/src/ha/mqtt_components/manual_mqtt.ts create mode 100644 futurehome/src/ha/mqtt_components/notify.ts create mode 100644 futurehome/src/ha/mqtt_components/number.ts create mode 100644 futurehome/src/ha/mqtt_components/scene.ts create mode 100644 futurehome/src/ha/mqtt_components/select.ts create mode 100644 futurehome/src/ha/mqtt_components/sensor.ts create mode 100644 futurehome/src/ha/mqtt_components/siren.ts create mode 100644 futurehome/src/ha/mqtt_components/switch.ts create mode 100644 futurehome/src/ha/mqtt_components/tag.ts create mode 100644 futurehome/src/ha/mqtt_components/text.ts create mode 100644 futurehome/src/ha/mqtt_components/update.ts create mode 100644 futurehome/src/ha/mqtt_components/vacuum.ts create mode 100644 futurehome/src/ha/mqtt_components/valve.ts create mode 100644 futurehome/src/ha/mqtt_components/water_heater.ts diff --git a/futurehome/config.yaml b/futurehome/config.yaml index fc5cc87..c059269 100644 --- a/futurehome/config.yaml +++ b/futurehome/config.yaml @@ -1,6 +1,6 @@ # https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config name: Futurehome -version: "0.0.29" +version: "0.0.30" slug: futurehome description: Local Futurehome Smarthub integration url: "https://github.com/adrianjagielak/home-assistant-futurehome" diff --git a/futurehome/src/ha/mqtt_components/_component.ts b/futurehome/src/ha/mqtt_components/_component.ts new file mode 100644 index 0000000..4fecd2f --- /dev/null +++ b/futurehome/src/ha/mqtt_components/_component.ts @@ -0,0 +1,60 @@ +import { AlarmControlPanelComponent } from './alarm_control_panel'; +import { BinarySensorComponent } from './binary_sensor'; +import { ButtonComponent } from './button'; +import { CameraComponent } from './camera'; +import { ClimateComponent } from './climate'; +import { CoverComponent } from './cover'; +import { DeviceAutomationComponent } from './device_automation'; +import { DeviceTrackerComponent } from './device_tracker'; +import { EventComponent } from './event'; +import { FanComponent } from './fan'; +import { HumidifierComponent } from './humidifier'; +import { ImageComponent } from './image'; +import { LawnMowerComponent } from './lawn_mower'; +import { LightComponent } from './light'; +import { LockComponent } from './lock'; +import { ManualMqttComponent } from './manual_mqtt'; +import { NotifyComponent } from './notify'; +import { NumberComponent } from './number'; +import { SceneComponent } from './scene'; +import { SelectComponent } from './select'; +import { SensorComponent } from './sensor'; +import { SirenComponent } from './siren'; +import { SwitchComponent } from './switch'; +import { TagComponent } from './tag'; +import { TextComponent } from './text'; +import { UpdateComponent } from './update'; +import { VacuumComponent } from './vacuum'; +import { ValveComponent } from './valve'; +import { WaterHeaterComponent } from './water_heater'; + +export type HaMqttComponent = + | AlarmControlPanelComponent + | BinarySensorComponent + | ButtonComponent + | CameraComponent + | ClimateComponent + | CoverComponent + | DeviceAutomationComponent + | DeviceTrackerComponent + | EventComponent + | FanComponent + | HumidifierComponent + | ImageComponent + | LawnMowerComponent + | LightComponent + | LockComponent + | ManualMqttComponent + | NotifyComponent + | NumberComponent + | SceneComponent + | SelectComponent + | SensorComponent + | SirenComponent + | SwitchComponent + | TagComponent + | TextComponent + | UpdateComponent + | VacuumComponent + | ValveComponent + | WaterHeaterComponent; diff --git a/futurehome/src/ha/mqtt_components/alarm_control_panel.ts b/futurehome/src/ha/mqtt_components/alarm_control_panel.ts new file mode 100644 index 0000000..136669a --- /dev/null +++ b/futurehome/src/ha/mqtt_components/alarm_control_panel.ts @@ -0,0 +1,339 @@ +/** + * Represents an MQTT Alarm Control Panel component for Home Assistant MQTT Discovery. + * + * The `mqtt` alarm control panel integration enables control of MQTT capable alarm panels. + * The Alarm icon will change state after receiving updates from `state_topic`. If using the MQTT RETAIN flag, + * the panel receives an initial state instantly. Otherwise, the initial state is `unknown`. + * + * Valid states accepted from the Alarm Panel (case insensitive): + * `disarmed`, `armed_home`, `armed_away`, `armed_night`, `armed_vacation`, + * `armed_custom_bypass`, `pending`, `triggered`, `arming`, `disarming` + * + * For full documentation see: + * https://www.home-assistant.io/integrations/alarm_control_panel.mqtt/ + */ +export interface AlarmControlPanelComponent { + /** + * Must be `alarm_control_panel`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'alarm_control_panel'; + + /** + * An ID that uniquely identifies this alarm panel. + * If two alarm panels have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The MQTT topic subscribed to receive state updates. + * A `None` payload resets to an `unknown` state. + * An empty payload is ignored. + * Valid state payloads are: + * `armed_away`, `armed_custom_bypass`, `armed_home`, `armed_night`, + * `armed_vacation`, `arming`, `disarmed`, `disarming`, `pending` and `triggered`. + */ + state_topic: string; + + /** + * The MQTT topic to publish commands to change the alarm state. + */ + command_topic: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * If defined, specifies a code to enable or disable the alarm in the frontend. + * Note that the code is validated locally and blocks sending MQTT messages to the remote device. + * For remote code validation use special values `REMOTE_CODE` (numeric code) or `REMOTE_CODE_TEXT` (text code). + * In that case local validation is bypassed, but frontend will display a corresponding code dialog. + * Use `command_template` to send the code to the remote device. + */ + code?: string; + + /** + * If true the code is required to arm the alarm. If false the code is not validated. + * Default: true + */ + code_arm_required?: boolean; + + /** + * If true the code is required to disarm the alarm. If false the code is not validated. + * Default: true + */ + code_disarm_required?: boolean; + + /** + * If true the code is required to trigger the alarm. If false the code is not validated. + * Default: true + */ + code_trigger_required?: boolean; + + /** + * The [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * used for the command payload. + * Available variables: `action` and `code`. + * Default: "action" + */ + command_template?: string; + + /** + * Information about the device this alarm panel is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name of the alarm. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Alarm" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The payload to set armed-away mode on your Alarm Panel. + * Default: "ARM_AWAY" + */ + payload_arm_away?: string; + + /** + * The payload to set armed-home mode on your Alarm Panel. + * Default: "ARM_HOME" + */ + payload_arm_home?: string; + + /** + * The payload to set armed-night mode on your Alarm Panel. + * Default: "ARM_NIGHT" + */ + payload_arm_night?: string; + + /** + * The payload to set armed-vacation mode on your Alarm Panel. + * Default: "ARM_VACATION" + */ + payload_arm_vacation?: string; + + /** + * The payload to set armed-custom-bypass mode on your Alarm Panel. + * Default: "ARM_CUSTOM_BYPASS" + */ + payload_arm_custom_bypass?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload to disarm your Alarm Panel. + * Default: "DISARM" + */ + payload_disarm?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload to trigger the alarm on your Alarm Panel. + * Default: "TRIGGER" + */ + payload_trigger?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * A list of features that the alarm control panel supports. + * The available list options are `arm_home`, `arm_away`, `arm_night`, `arm_vacation`, `arm_custom_bypass`, and `trigger`. + * Default: ["arm_home", "arm_away", "arm_night", "arm_vacation", "arm_custom_bypass", "trigger"] + */ + supported_features?: Array< + | 'arm_home' + | 'arm_away' + | 'arm_night' + | 'arm_vacation' + | 'arm_custom_bypass' + | 'trigger' + >; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the value. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/mqtt_components/binary_sensor.ts b/futurehome/src/ha/mqtt_components/binary_sensor.ts new file mode 100644 index 0000000..8575739 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/binary_sensor.ts @@ -0,0 +1,276 @@ +/** + * Represents a MQTT Binary Sensor component for Home Assistant MQTT Discovery. + * + * The `mqtt` binary sensor platform uses an MQTT message received to set the binary sensor's state to `on`, `off` or `unknown`. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/binary_sensor.mqtt/ + */ +export interface BinarySensorComponent { + /** + * Must be `binary_sensor`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'binary_sensor'; + + /** + * An ID that uniquely identifies this sensor. + * If two sensors have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The MQTT topic subscribed to receive sensor's state. + * Valid states are `OFF` and `ON`. + * Custom `OFF` and `ON` values can be set with the `payload_off` and `payload_on` config options. + */ + state_topic?: string; + + /** + * Sets the [class of the device](https://www.home-assistant.io/integrations/binary_sensor/#device-class), + * changing the device state and icon that is displayed on the frontend. + * The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * The string that represents the `on` state. + * It will be compared to the message in the `state_topic` (see `value_template` for details). + * Default: "ON" + */ + payload_on?: string; + + /** + * The string that represents the `off` state. + * It will be compared to the message in the `state_topic` (see `value_template` for details). + * Default: "OFF" + */ + payload_off?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that returns a string to be compared to `payload_on`/`payload_off` or an empty string, + * in which case the MQTT message will be removed. + * Remove this option when `payload_on` and `payload_off` are sufficient to match your payloads + * (i.e no preprocessing of original message is required). + */ + value_template?: string; + + /** + * Sends update events (which results in update of [state object](https://www.home-assistant.io/docs/configuration/state_object/)'s `last_changed`) + * even if the sensor's state hasn't changed. Useful if you want to have meaningful value graphs in history + * or want to create an automation that triggers on *every* incoming state message (not only when the sensor's new state is different to the current one). + * Default: false + */ + force_update?: boolean; + + /** + * If set, it defines the number of seconds after the sensor's state expires, + * if it's not updated. After expiry, the sensor's state becomes `unavailable`. + * Default the sensor's state never expires. + */ + expire_after?: number; + + /** + * The encoding of the payloads received. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The name of the binary sensor. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT binary sensor" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity/#generic-properties) of the entity. + * When set, the entity category must be `diagnostic` for sensors. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * If set, the sensor will send `off` state after this amount of seconds when the sensor only sends `on` state updates. + */ + off_delay?: number; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive birth and LWT messages from the MQTT device. + * If `availability` is not defined, the binary sensor will always be considered `available` and its state will be `on`, `off` or `unknown`. + * If `availability` is defined, the binary sensor will be considered as `unavailable` by default and the sensor's initial state will be `unavailable`. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The string that represents the `online` state. + * Default: "online" + */ + payload_available?: string; + + /** + * The string that represents the `offline` state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Information about the device this binary sensor is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/device_registry_index/). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/button.ts b/futurehome/src/ha/mqtt_components/button.ts new file mode 100644 index 0000000..593df2d --- /dev/null +++ b/futurehome/src/ha/mqtt_components/button.ts @@ -0,0 +1,245 @@ +/** + * Represents a MQTT Button component for Home Assistant MQTT Discovery. + * + * The `mqtt` button platform lets you send an MQTT message when the button is pressed in the frontend + * or the button press action is called. This can be used to expose some service of a remote device, for example reboot. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/button.mqtt/ + */ +export interface ButtonComponent { + /** + * Must be `button`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'button'; + + /** + * An ID that uniquely identifies this button. + * If two buttons have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The MQTT topic to publish commands to trigger the button. + */ + command_topic: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * The payload To send to trigger the button. + * Default: "PRESS" + */ + payload_press?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Information about the device this button is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * The [type/class](https://www.home-assistant.io/integrations/button/#device-class) of the button to set the icon in the frontend. + * The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the published messages. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name to use when displaying this button. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Button" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id` + */ + object_id?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; +} diff --git a/futurehome/src/ha/mqtt_components/camera.ts b/futurehome/src/ha/mqtt_components/camera.ts new file mode 100644 index 0000000..0f27375 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/camera.ts @@ -0,0 +1,213 @@ +/** + * Represents an MQTT Camera component for Home Assistant MQTT Discovery. + * + * The `mqtt` camera platform allows you to integrate the content of an image file sent through MQTT into Home Assistant as a camera. + * Every time a message under the `topic` is received, the image displayed in Home Assistant will be updated. + * Messages received on `topic` should be the full contents of an image file, e.g., a JPEG image, without additional encoding or metadata unless `image_encoding` is used. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/camera.mqtt/ + */ +export interface CameraComponent { + /** + * Must be `camera`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'camera'; + + /** + * An ID that uniquely identifies this camera. + * If two cameras have the same unique ID Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The MQTT topic to subscribe to. + */ + topic: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + * + * See https://www.home-assistant.io/integrations/mqtt/#availability_mode + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Information about the device this camera is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[] | string; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received. + * Set to `""` to disable decoding of incoming payload. + * Use `image_encoding` to enable Base64 decoding on `topic`. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * The encoding of the image payloads received. + * Set to `"b64"` to enable base64 decoding of image payload. + * If not set, the image payload must be raw binary data. + */ + image_encoding?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Implies `force_update` of the current sensor state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * The name of the camera. + * Can be set to `null` if only the device name is relevant. + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; +} diff --git a/futurehome/src/ha/mqtt_components/climate.ts b/futurehome/src/ha/mqtt_components/climate.ts new file mode 100644 index 0000000..3fe38c3 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/climate.ts @@ -0,0 +1,578 @@ +/** + * Represents an MQTT HVAC (Climate) component for Home Assistant MQTT Discovery. + * + * The `mqtt` climate platform lets you control your MQTT enabled HVAC devices. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/climate.mqtt/ + */ +export interface ClimateComponent { + /** + * Must be `climate`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'climate'; + + /** + * An ID that uniquely identifies this HVAC. + * If two HVACs have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * A template to render the value received on the `action_topic` with. + */ + action_template?: string; + + /** + * The MQTT topic to subscribe for changes of the current action. + * If this is set, the climate graph uses the value received as data source. + * A "None" payload resets the current action state. An empty payload is ignored. + * Valid action values: `off`, `heating`, `cooling`, `drying`, `idle`, `fan`. + */ + action_topic?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest". + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * A template with which the value received on `current_humidity_topic` will be rendered. + */ + current_humidity_template?: string; + + /** + * The MQTT topic on which to listen for the current humidity. + * A `"None"` value received will reset the current humidity. + * Empty values (`''`) will be ignored. + */ + current_humidity_topic?: string; + + /** + * A template with which the value received on `current_temperature_topic` will be rendered. + */ + current_temperature_template?: string; + + /** + * The MQTT topic on which to listen for the current temperature. + * A `"None"` value received will reset the current temperature. + * Empty values (`''`) will be ignored. + */ + current_temperature_topic?: string; + + /** + * Information about the device this HVAC device is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true. + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * A template to render the value sent to the `fan_mode_command_topic` with. + */ + fan_mode_command_template?: string; + + /** + * The MQTT topic to publish commands to change the fan mode. + */ + fan_mode_command_topic?: string; + + /** + * A template to render the value received on the `fan_mode_state_topic` with. + */ + fan_mode_state_template?: string; + + /** + * The MQTT topic to subscribe for changes of the HVAC fan mode. + * If this is not set, the fan mode works in optimistic mode (see below). + * A "None" payload resets the fan mode state. An empty payload is ignored. + */ + fan_mode_state_topic?: string; + + /** + * A list of supported fan modes. + * Default: ['auto', 'low', 'medium', 'high'] + */ + fan_modes?: string[]; + + /** + * Set the initial target temperature. + * The default value depends on the temperature unit and will be 21° or 69.8°F. + */ + initial?: number; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The minimum target humidity percentage that can be set. + * Default: 30. + */ + min_humidity?: number; + + /** + * Minimum set point available. The default value depends on the temperature unit, + * and will be 7°C or 44.6°F. + */ + min_temp?: number; + + /** + * The maximum target humidity percentage that can be set. + * Default: 99. + */ + max_humidity?: number; + + /** + * Maximum set point available. The default value depends on the temperature unit, + * and will be 35°C or 95°F. + */ + max_temp?: number; + + /** + * A template to render the value sent to the `mode_command_topic` with. + */ + mode_command_template?: string; + + /** + * The MQTT topic to publish commands to change the HVAC operation mode. + */ + mode_command_topic?: string; + + /** + * A template to render the value received on the `mode_state_topic` with. + */ + mode_state_template?: string; + + /** + * The MQTT topic to subscribe for changes of the HVAC operation mode. + * If this is not set, the operation mode works in optimistic mode (see below). + * A "None" payload resets to an `unknown` state. An empty payload is ignored. + */ + mode_state_topic?: string; + + /** + * A list of supported modes. Needs to be a subset of the default values. + * Default: ['auto', 'off', 'cool', 'heat', 'dry', 'fan_only'] + */ + modes?: string[]; + + /** + * The name of the HVAC. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT HVAC" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag that defines if the climate works in optimistic mode. + * Default: `true` if no state topic defined, else `false`. + */ + optimistic?: boolean; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload sent to turn off the device. + * Default: "OFF" + */ + payload_off?: string; + + /** + * The payload sent to turn the device on. + * Default: "ON" + */ + payload_on?: string; + + /** + * A template to render the value sent to the `power_command_topic` with. + * The `value` parameter is the payload set for `payload_on` or `payload_off`. + */ + power_command_template?: string; + + /** + * The MQTT topic to publish commands to change the HVAC power state. + * Sends the payload configured with `payload_on` if the climate is turned on via the `climate.turn_on`, + * or the payload configured with `payload_off` if the climate is turned off via the `climate.turn_off` action. + * Note that `optimistic` mode is not supported through `climate.turn_on` and `climate.turn_off` actions. + * When called, these actions will send a power command to the device but will not optimistically update the state + * of the climate entity. The climate device should report its state back via `mode_state_topic`. + */ + power_command_topic?: string; + + /** + * The desired precision for this device. + * Can be used to match your actual thermostat's precision. + * Supported values are `0.1`, `0.5` and `1.0`. + * Default: 0.1 for Celsius and 1.0 for Fahrenheit. + */ + precision?: number; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `preset_mode_command_topic`. + */ + preset_mode_command_template?: string; + + /** + * The MQTT topic to publish commands to change the preset mode. + */ + preset_mode_command_topic?: string; + + /** + * The MQTT topic subscribed to receive climate speed based on presets. + * When preset 'none' is received or `None` the `preset_mode` will be reset. + */ + preset_mode_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the `preset_mode` value from the payload received on `preset_mode_state_topic`. + */ + preset_mode_value_template?: string; + + /** + * List of preset modes this climate is supporting. + * Common examples include `eco`, `away`, `boost`, `comfort`, `home`, `sleep` and `activity`. + * Default: [] + */ + preset_modes?: string[]; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Defines if published messages should have the retain flag set. + * Default: false + */ + retain?: boolean; + + /** + * A template to render the value sent to the `swing_horizontal_mode_command_topic` with. + */ + swing_horizontal_mode_command_template?: string; + + /** + * The MQTT topic to publish commands to change the swing horizontal mode. + */ + swing_horizontal_mode_command_topic?: string; + + /** + * A template to render the value received on the `swing_horizontal_mode_state_topic` with. + */ + swing_horizontal_mode_state_template?: string; + + /** + * The MQTT topic to subscribe for changes of the HVAC swing horizontal mode. + * If this is not set, the swing horizontal mode works in optimistic mode (see below). + */ + swing_horizontal_mode_state_topic?: string; + + /** + * A list of supported swing horizontal modes. + * Default: ['on', 'off'] + */ + swing_horizontal_modes?: string[]; + + /** + * A template to render the value sent to the `swing_mode_command_topic` with. + */ + swing_mode_command_template?: string; + + /** + * The MQTT topic to publish commands to change the swing mode. + */ + swing_mode_command_topic?: string; + + /** + * A template to render the value received on the `swing_mode_state_topic` with. + */ + swing_mode_state_template?: string; + + /** + * The MQTT topic to subscribe for changes of the HVAC swing mode. + * If this is not set, the swing mode works in optimistic mode (see below). + */ + swing_mode_state_topic?: string; + + /** + * A list of supported swing modes. + * Default: ['on', 'off'] + */ + swing_modes?: string[]; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `target_humidity_command_topic`. + */ + target_humidity_command_template?: string; + + /** + * The MQTT topic to publish commands to change the target humidity. + */ + target_humidity_command_topic?: string; + + /** + * The MQTT topic subscribed to receive the target humidity. + * If this is not set, the target humidity works in optimistic mode (see below). + * A `"None"` value received will reset the target humidity. Empty values (`''`) will be ignored. + */ + target_humidity_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract a value for the climate `target_humidity` state. + */ + target_humidity_state_template?: string; + + /** + * A template to render the value sent to the `temperature_command_topic` with. + */ + temperature_command_template?: string; + + /** + * The MQTT topic to publish commands to change the target temperature. + */ + temperature_command_topic?: string; + + /** + * A template to render the value sent to the `temperature_high_command_topic` with. + */ + temperature_high_command_template?: string; + + /** + * The MQTT topic to publish commands to change the high target temperature. + */ + temperature_high_command_topic?: string; + + /** + * A template to render the value received on the `temperature_high_state_topic` with. + * A `"None"` value received will reset the temperature high set point. Empty values (`''`) will be ignored. + */ + temperature_high_state_template?: string; + + /** + * The MQTT topic to subscribe for changes in the target high temperature. + * If this is not set, the target high temperature works in optimistic mode (see below). + */ + temperature_high_state_topic?: string; + + /** + * A template to render the value sent to the `temperature_low_command_topic` with. + */ + temperature_low_command_template?: string; + + /** + * The MQTT topic to publish commands to change the target low temperature. + */ + temperature_low_command_topic?: string; + + /** + * A template to render the value received on the `temperature_low_state_topic` with. + * A `"None"` value received will reset the temperature low set point. Empty values (`''`) will be ignored. + */ + temperature_low_state_template?: string; + + /** + * The MQTT topic to subscribe for changes in the target low temperature. + * If this is not set, the target low temperature works in optimistic mode (see below). + */ + temperature_low_state_topic?: string; + + /** + * A template to render the value received on the `temperature_state_topic` with. + */ + temperature_state_template?: string; + + /** + * The MQTT topic to subscribe for changes in the target temperature. + * If this is not set, the target temperature works in optimistic mode (see below). + * A `"None"` value received will reset the temperature set point. Empty values (`''`) will be ignored. + */ + temperature_state_topic?: string; + + /** + * Defines the temperature unit of the device, `C` or `F`. + * If this is not set, the temperature unit is set to the system temperature unit. + */ + temperature_unit?: string; + + /** + * Step size for temperature set point. + * Default: 1 + */ + temp_step?: number; + + /** + * Default template to render the payloads on *all* `*_state_topic`s with. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/mqtt_components/cover.ts b/futurehome/src/ha/mqtt_components/cover.ts new file mode 100644 index 0000000..c74a126 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/cover.ts @@ -0,0 +1,417 @@ +/** + * Represents a MQTT Cover component for Home Assistant MQTT Discovery. + * + * The `mqtt` cover platform allows you to control an MQTT cover (such as blinds, a roller shutter or a garage door). + * + * A cover entity can be in states (`open`, `opening`, `closed`, `closing` or `stopped`). + * See the full documentation at https://www.home-assistant.io/integrations/cover.mqtt/ + */ +export interface CoverComponent { + /** + * Must be `cover`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'cover'; + + /** + * An ID that uniquely identifies this cover. + * If two covers have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + * + * Each item describes: + * - topic: An MQTT topic subscribed to receive availability (online/offline) updates. + * - payload_available: The payload that represents the available state. Default: "online" + * - payload_not_available: The payload that represents the unavailable state. Default: "offline" + * - value_template: Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. To determine the device's availability, + * the result of this template will be compared to `payload_available` and `payload_not_available`. + * + * See https://www.home-assistant.io/integrations/mqtt/ for more info on availability. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. To determine the device's availability, + * the result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: `all`, `any`, `latest`. + * Default: "latest" + * + * - "all": `payload_available` must be received on all configured availability topics before the entity is marked as online. + * - "any": `payload_available` must be received on at least one configured availability topic before the entity is marked as online. + * - "latest": The last `payload_available` or `payload_not_available` received on any configured availability topic controls the availability. + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. To determine the device's availability, + * the result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The subscribed-to MQTT topic to receive birth and LWT messages from the MQTT cover device. + * If an `availability` topic is not defined, the cover availability state will always be `available`. + * If an `availability` topic is defined, the cover availability state will be `unavailable` by default. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The MQTT topic to publish commands to control the cover. + */ + command_topic?: string; + + /** + * Information about the device this cover is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Sets the [class of the device](https://www.home-assistant.io/integrations/cover/#device_class), + * changing the device state and icon that is displayed on the frontend. + * The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name of the cover. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Cover" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag that defines if switch works in optimistic mode. + * Default: `false` if `state_topic` or `position_topic` defined, else `true`. + */ + optimistic?: boolean; + + /** + * The payload that represents the online state. + * Default: "online" + */ + payload_available?: string; + + /** + * The command payload that closes the cover. + * Set to `null` to disable the close command. + * Default: "CLOSE" + */ + payload_close?: string | null; + + /** + * The payload that represents the offline state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The command payload that opens the cover. + * Set to `null` to disable the open command. + * Default: "OPEN" + */ + payload_open?: string | null; + + /** + * The command payload that stops the cover. + * Set to `null` to disable the stop command. + * Default: "STOP" + */ + payload_stop?: string | null; + + /** + * Number which represents closed position. + * Default: 0 + */ + position_closed?: number; + + /** + * Number which represents open position. + * Default: 100 + */ + position_open?: number; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that can be used to extract the payload for the `position_topic` topic. + * Within the template the following variables are available: `entity_id`, `position_open`, `position_closed`, `tilt_min`, `tilt_max`. + * The `entity_id` can be used to reference the entity's attributes with help of the [states](https://www.home-assistant.io/docs/configuration/templating/#states) template function. + */ + position_template?: string; + + /** + * The MQTT topic subscribed to receive cover position messages. + */ + position_topic?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Defines if published messages should have the retain flag set. + * Default: false + */ + retain?: boolean; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to define the position to be sent to the `set_position_topic` topic. + * Incoming position value is available for use in the template `{% raw %}{{ position }}{% endraw %}`. + * Within the template the following variables are available: `entity_id`, `position`, the target position in percent; `position_open`; `position_closed`; `tilt_min`; `tilt_max`. + * The `entity_id` can be used to reference the entity's attributes with help of the [states](https://www.home-assistant.io/docs/configuration/templating/#states) template function. + */ + set_position_template?: string; + + /** + * The MQTT topic to publish position commands to. + * If `set_position_topic` is used, `position_topic` should also be set. + * Use `set_position_template` if `position_topic` wants different values than within range `position_closed` - `position_open`. + */ + set_position_topic?: string; + + /** + * The payload that represents the closed state. + * Default: "closed" + */ + state_closed?: string; + + /** + * The payload that represents the closing state. + * Default: "closing" + */ + state_closing?: string; + + /** + * The payload that represents the open state. + * Default: "open" + */ + state_open?: string; + + /** + * The payload that represents the opening state. + * Default: "opening" + */ + state_opening?: string; + + /** + * The payload that represents the stopped state (for covers that do not report `open`/`closed` state). + * Default: "stopped" + */ + state_stopped?: string; + + /** + * The MQTT topic subscribed to receive cover state messages. + * State topic can only read a (`open`, `opening`, `closed`, `closing` or `stopped`) state. + * A `"None"` payload resets to an `unknown` state. + * An empty payload is ignored. + */ + state_topic?: string; + + /** + * The value that will be sent on a `close_cover_tilt` command. + * Default: 0 + */ + tilt_closed_value?: number; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * that can be used to extract the payload for the `tilt_command_topic` topic. + * Within the template the following variables are available: `entity_id`, `tilt_position`, the target tilt position in percent; `position_open`; `position_closed`; `tilt_min`; `tilt_max`. + * The `entity_id` can be used to reference the entity's attributes with help of the [states](https://www.home-assistant.io/docs/configuration/templating/#states) template function. + */ + tilt_command_template?: string; + + /** + * The MQTT topic to publish commands to control the cover tilt. + */ + tilt_command_topic?: string; + + /** + * The maximum tilt value. + * Default: 100 + */ + tilt_max?: number; + + /** + * The minimum tilt value. + * Default: 0 + */ + tilt_min?: number; + + /** + * The value that will be sent on an `open_cover_tilt` command. + * Default: 100 + */ + tilt_opened_value?: number; + + /** + * Flag that determines if tilt works in optimistic mode. + * Default: `true` if `tilt_status_topic` is not defined, else `false`. + */ + tilt_optimistic?: boolean; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that can be used to extract the payload for the `tilt_status_topic` topic. + * Within the template the following variables are available: `entity_id`, `position_open`, `position_closed`, `tilt_min`, `tilt_max`. + * The `entity_id` can be used to reference the entity's attributes with help of the [states](https://www.home-assistant.io/docs/configuration/templating/#states) template function. + */ + tilt_status_template?: string; + + /** + * The MQTT topic subscribed to receive tilt status update values. + */ + tilt_status_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that can be used to extract the payload for the `state_topic` topic. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/mqtt_components/device_automation.ts b/futurehome/src/ha/mqtt_components/device_automation.ts new file mode 100644 index 0000000..64784d2 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/device_automation.ts @@ -0,0 +1,139 @@ +/** + * Represents a MQTT Device Trigger component for Home Assistant MQTT Discovery. + * + * The `mqtt` device trigger platform uses an MQTT message payload to generate device trigger events. + * + * An MQTT device trigger is a better option than a [binary sensor](https://www.home-assistant.io/integrations/binary_sensor.mqtt/) + * for buttons, remote controls, etc. + * + * MQTT device triggers are only supported through [MQTT discovery](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery), + * manual setup through `configuration.yaml` is not supported. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/device_automation.mqtt/ + */ +export interface DeviceAutomationComponent { + /** + * Must be `device_automation`. Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'device_automation'; + + /** + * An ID that uniquely identifies this device trigger. + * If two device triggers have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The type of automation, must be 'trigger'. + */ + automation_type: 'trigger'; + + /** + * Optional payload to match the payload being sent over the topic. + */ + payload?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * The MQTT topic subscribed to receive trigger events. + */ + topic: string; + + /** + * The type of the trigger, e.g. `button_short_press`. + * Entries supported by the frontend: + * `button_short_press`, `button_short_release`, `button_long_press`, `button_long_release`, + * `button_double_press`, `button_triple_press`, `button_quadruple_press`, `button_quintuple_press`. + * If set to an unsupported value, will render as `subtype type`, + * e.g. `button_1 spammed` with `type` set to `spammed` and `subtype` set to `button_1`. + */ + type: string; + + /** + * The subtype of the trigger, e.g. `button_1`. + * Entries supported by the frontend: + * `turn_on`, `turn_off`, `button_1`, `button_2`, `button_3`, `button_4`, `button_5`, `button_6`. + * If set to an unsupported value, will render as `subtype type`, + * e.g. `left_button pressed` with `type` set to `button_short_press` and `subtype` set to `left_button`. + */ + subtype: string; + + /** + * Information about the device this device trigger is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * At least one of identifiers or connections must be present to identify the device. + */ + device: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the value. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/mqtt_components/device_tracker.ts b/futurehome/src/ha/mqtt_components/device_tracker.ts new file mode 100644 index 0000000..5b5dcce --- /dev/null +++ b/futurehome/src/ha/mqtt_components/device_tracker.ts @@ -0,0 +1,236 @@ +/** + * Represents a MQTT Device Tracker component for Home Assistant MQTT Discovery. + * + * The `mqtt` device tracker platform allows tracking devices' presence and location + * through MQTT messages. It supports tracking using state topics and/or JSON attributes topics, + * with optional availability topics for device online/offline state reporting. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/device_tracker.mqtt/ + */ +export interface DeviceTrackerComponent { + /** + * Must be `device_tracker`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'device_tracker'; + + /** + * An ID that uniquely identifies this device tracker. + * If two device trackers have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The MQTT topic subscribed to receive device tracker state changes. + * The states defined in `state_topic` override the location states defined by the `json_attributes_topic`. + * This state override is turned inactive if the `state_topic` receives a message containing `payload_reset`. + * The `state_topic` can only be omitted if `json_attributes_topic` is used. + * An empty payload is ignored. + * Valid payloads are `not_home`, `home` or any other custom location or zone name. + * Payloads for `not_home`, `home` can be overridden with the `payload_not_home` and `payload_home` config options. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that returns a device tracker state. + */ + value_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary message containing device tracker attributes. + * + * This topic can be used to set the location of the device tracker under the following conditions: + * - If the attributes in the JSON message include `longitude`, `latitude`, and `gps_accuracy` (optional). + * - If the device tracker is within a configured [zone](https://www.home-assistant.io/integrations/zone/). + * + * If these conditions are met, it is not required to configure `state_topic`. + * + * Be aware that any location message received at `state_topic` overrides the location received via `json_attributes_topic` until a message configured with `payload_reset` is received at `state_topic`. + * + * For a more generic usage example of the `json_attributes_topic`, refer to the [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The name of the MQTT device_tracker. + */ + name?: string; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Attribute of a device tracker that affects state when being used to track a [person](https://www.home-assistant.io/integrations/person/). + * Valid options are `gps`, `router`, `bluetooth`, or `bluetooth_le`. + */ + source_type?: 'gps' | 'router' | 'bluetooth' | 'bluetooth_le' | string; + + /** + * The payload value that represents the 'home' state for the device. + * Default: "home" + */ + payload_home?: string; + + /** + * The payload value that represents the 'not_home' state for the device. + * Default: "not_home" + */ + payload_not_home?: string; + + /** + * The payload value that will have the device's location automatically derived from Home Assistant's zones. + * Default: '"None"' + */ + payload_reset?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The MQTT topic subscribed to receive birth and LWT messages from the MQTT device. + * If `availability` is not defined, the device tracker will always be considered `available`. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest". + * + * When set to `all`, `payload_available` must be received on all configured availability topics before the entity is marked as online. + * When set to `any`, `payload_available` must be received on at least one configured availability topic before the entity is marked as online. + * When set to `latest`, the last `payload_available` or `payload_not_available` received on any configured availability topic controls the availability. + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Information about the device this device tracker is a part of that ties it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; +} diff --git a/futurehome/src/ha/mqtt_components/event.ts b/futurehome/src/ha/mqtt_components/event.ts new file mode 100644 index 0000000..47433c9 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/event.ts @@ -0,0 +1,238 @@ +/** + * Represents a MQTT Event component for Home Assistant MQTT Discovery. + * + * The `mqtt` event platform allows you to process event info from an MQTT message. Events are signals that are emitted when something happens, + * for example, when a user presses a physical button like a doorbell or when a button on a remote control is pressed. + * With the event some event attributes can be sent to become available as an attribute on the entity. + * MQTT events are stateless. For example, a doorbell does not have a state like being "on" or "off" but instead is momentarily pressed. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/event.mqtt/ + */ +export interface EventComponent { + /** + * Must be `event`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'event'; + + /** + * An ID that uniquely identifies this event entity. + * If two events have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id: string; + + /** + * The MQTT topic subscribed to receive JSON event payloads. + * The JSON payload should contain the `event_type` element. + * The event type should be one of the configured `event_types`. + * Note that replayed retained messages will be discarded. + */ + state_topic: string; + + /** + * A list of valid `event_type` strings. + */ + event_types: string[]; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Information about the device this event is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/core/device_registry_index/). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * The [type/class](https://www.home-assistant.io/integrations/event/#device-class) of the event to set the icon in the frontend. + * The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the published messages. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity/#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name to use when displaying this event. + * Default: "MQTT Event" + */ + name?: string; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the value and render it to a valid JSON event payload. + * If the template throws an error, the current state will be used instead. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/mqtt_components/fan.ts b/futurehome/src/ha/mqtt_components/fan.ts new file mode 100644 index 0000000..ba5023b --- /dev/null +++ b/futurehome/src/ha/mqtt_components/fan.ts @@ -0,0 +1,400 @@ +/** + * Represents a MQTT Fan component for Home Assistant MQTT Discovery. + * + * The `mqtt` fan platform lets you control your MQTT enabled fans. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/fan.mqtt/ + */ +export interface FanComponent { + /** + * Must be `fan`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'fan'; + + /** + * An ID that uniquely identifies this fan. + * If two fans have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish commands to change the fan state. + */ + command_topic: string; + + /** + * The MQTT topic subscribed to receive state updates. + * A "None" payload resets to an `unknown` state. + * An empty payload is ignored. + * By default, valid state payloads are `OFF` and `ON`. + * The accepted payloads can be overridden with the `payload_off` and `payload_on` config options. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract a value from the state. + */ + state_value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * The MQTT topic subscribed to receive direction state updates. + */ + direction_state_topic?: string; + + /** + * The MQTT topic to publish commands to change the direction state. + */ + direction_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract a value from the direction. + */ + direction_value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `direction_command_topic`. + */ + direction_command_template?: string; + + /** + * The MQTT topic subscribed to receive oscillation state updates. + */ + oscillation_state_topic?: string; + + /** + * The MQTT topic to publish commands to change the oscillation state. + */ + oscillation_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract a value from the oscillation. + */ + oscillation_value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `oscillation_command_topic`. + */ + oscillation_command_template?: string; + + /** + * The MQTT topic subscribed to receive fan speed based on percentage. + */ + percentage_state_topic?: string; + + /** + * The MQTT topic to publish commands to change the fan speed state based on a percentage. + */ + percentage_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the `percentage` value from the payload received on `percentage_state_topic`. + */ + percentage_value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `percentage_command_topic`. + */ + percentage_command_template?: string; + + /** + * The MQTT topic subscribed to receive fan speed based on presets. + */ + preset_mode_state_topic?: string; + + /** + * The MQTT topic to publish commands to change the preset mode. + */ + preset_mode_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the `preset_mode` value from the payload received on `preset_mode_state_topic`. + */ + preset_mode_value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `preset_mode_command_topic`. + */ + preset_mode_command_template?: string; + + /** + * List of preset modes this fan is capable of running at. + * Common examples include `auto`, `smart`, `whoosh`, `eco` and `breeze`. + */ + preset_modes?: string[]; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The name of the fan. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Fan" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * Flag that defines if fan works in optimistic mode. + * Default: `true` if no state topic defined, else `false`. + */ + optimistic?: boolean; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: true + */ + retain?: boolean; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive birth and LWT messages from the MQTT device. + * If `availability` is not defined, the fan will always be considered `available` and its state will be as per the last command/state. + * If `availability` is defined, the fan will be considered as `unavailable` by default. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload that represents the stop state. + * Default: "OFF" + */ + payload_off?: string; + + /** + * The payload that represents the running state. + * Default: "ON" + */ + payload_on?: string; + + /** + * The payload that represents the oscillation off state. + * Default: "oscillate_off" + */ + payload_oscillation_off?: string; + + /** + * The payload that represents the oscillation on state. + * Default: "oscillate_on" + */ + payload_oscillation_on?: string; + + /** + * A special payload that resets the `percentage` state attribute to `unknown` when received at the `percentage_state_topic`. + * Default: "None" + */ + payload_reset_percentage?: string; + + /** + * A special payload that resets the `preset_mode` state attribute to `unknown` when received at the `preset_mode_state_topic`. + * Default: "None" + */ + payload_reset_preset_mode?: string; + + /** + * The maximum of numeric output range (representing 100 %). + * The `percentage_step` is defined by `100` / the number of speeds within the speed range. + * Default: 100 + */ + speed_range_max?: number; + + /** + * The minimum of numeric output range (`off` not included, so `speed_range_min` - `1` represents 0 %). + * The `percentage_step` is defined by `100` / the number of speeds within the speed range. + * Default: 1 + */ + speed_range_min?: number; + + /** + * Information about the device this fan is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/humidifier.ts b/futurehome/src/ha/mqtt_components/humidifier.ts new file mode 100644 index 0000000..d912674 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/humidifier.ts @@ -0,0 +1,368 @@ +/** + * Represents a MQTT Humidifier component for Home Assistant MQTT Discovery. + * + * The `mqtt` humidifier platform lets you control your MQTT enabled humidifiers. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/humidifier.mqtt/ + */ +export interface HumidifierComponent { + /** + * Must be `humidifier`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'humidifier'; + + /** + * An ID that uniquely identifies this humidifier. + * If two humidifiers have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish commands to change the humidifier state. + */ + command_topic: string; + + /** + * The MQTT topic to publish commands to change the humidifier target humidity state based on a percentage. + */ + target_humidity_command_topic: string; + + /** + * The MQTT topic subscribed to receive state updates. + * A `"None"` payload resets to an `unknown` state. + * An empty payload is ignored. + * Valid state payloads are `OFF` and `ON`. + * Custom `OFF` and `ON` values can be set with the `payload_off` and `payload_on` config options. + */ + state_topic?: string; + + /** + * The MQTT topic on which to listen for the current humidity. + * A `"None"` value received will reset the current humidity. + * Empty values (`''`) will be ignored. + */ + current_humidity_topic?: string; + + /** + * The MQTT topic subscribed to receive humidifier target humidity. + */ + target_humidity_state_topic?: string; + + /** + * The MQTT topic subscribed to receive the humidifier `mode`. + */ + mode_state_topic?: string; + + /** + * The MQTT topic to publish commands to change the `mode` on the humidifier. + * This attribute must be configured together with the `modes` attribute. + */ + mode_command_topic?: string; + + /** + * The MQTT topic to subscribe for changes of the current action. + * Valid values: `off`, `humidifying`, `drying`, `idle` + */ + action_topic?: string; + + /** + * Flag that defines if humidifier works in optimistic mode. + * Defaults to `true` if no state topic defined, else `false`. + */ + optimistic?: boolean; + + /** + * A list of available modes this humidifier is capable of running at. + * Common examples include `normal`, `eco`, `away`, `boost`, `comfort`, `home`, `sleep`, `auto` and `baby`. + * These examples offer built-in translations but other custom modes are allowed as well. + * This attribute must be configured together with the `mode_command_topic` attribute. + */ + modes?: string[]; + + /** + * The [device class](https://www.home-assistant.io/integrations/humidifier/#device-class) of the MQTT device. + * Must be either `humidifier`, `dehumidifier` or `null`. + * Default: `humidifier` + */ + device_class?: 'humidifier' | 'dehumidifier' | null; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that returns a string to be compared to the payload. + * Used to extract a value for the humidifier `target_humidity` state. + */ + target_humidity_state_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that returns a string to be compared to the payload. + * Used to extract a value for the humidifier `mode` state. + */ + mode_state_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * with which the value received on `current_humidity_topic` will be rendered. + */ + current_humidity_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `target_humidity_command_topic`. + */ + target_humidity_command_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `mode_command_topic`. + */ + mode_command_template?: string; + + /** + * A special payload that resets the `target_humidity` state attribute to an `unknown` state + * when received at the `target_humidity_state_topic`. + * When received at `current_humidity_topic`, it will reset the current humidity state. + * Default: `"None"` + */ + payload_reset_humidity?: string; + + /** + * A special payload that resets the `mode` state attribute to an `unknown` state + * when received at the `mode_state_topic`. + * Default: `"None"` + */ + payload_reset_mode?: string; + + /** + * The payload that represents the running state. + * Default: `"ON"` + */ + payload_on?: string; + + /** + * The payload that represents the stop state. + * Default: `"OFF"` + */ + payload_off?: string; + + /** + * The maximum target humidity percentage that can be set. + * Default: 100 + */ + max_humidity?: number; + + /** + * The minimum target humidity percentage that can be set. + * Default: 0 + */ + min_humidity?: number; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The string that represents the `online` state. + * Default: `"online"` + */ + payload_available?: string; + + /** + * The string that represents the `offline` state. + * Default: `"offline"` + */ + payload_not_available?: string; + + /** + * The name of the humidifier. + * Can be set to `null` if only the device name is relevant. + * Default: `"MQTT humidifier"` + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: `"utf-8"` + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: true + */ + retain?: boolean; + + /** + * Information about the device this humidifier is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/image.ts b/futurehome/src/ha/mqtt_components/image.ts new file mode 100644 index 0000000..2c21b75 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/image.ts @@ -0,0 +1,240 @@ +/** + * Represents an MQTT Image component for Home Assistant MQTT Discovery. + * + * The `mqtt` image platform allows you to integrate the content of an image file sent through MQTT into Home Assistant as an image. + * The `image` platform is a simplified version of the `camera` platform that only accepts images. + * Every time a message under the `image_topic` in the configuration is received, the image displayed in Home Assistant will also be updated. + * Messages received on `image_topic` should contain the full contents of an image file, e.g., a JPEG image, without any additional encoding or metadata. + * + * Alternatively, the `url_topic` option can be used to receive an image URL for a new picture to show. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/image.mqtt/ + */ +export interface ImageComponent { + /** + * Must be `image`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'image'; + + /** + * An ID that uniquely identifies this image. + * If two images have the same unique ID Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to subscribe to receive the image payload of the image to be downloaded. + * Ensure the `content_type` type option is set to the corresponding content type. + * This option cannot be used together with the `url_topic` option. + * At least one of these options (`image_topic` or `url_topic`) is required. + */ + image_topic?: string; + + /** + * The MQTT topic to subscribe to receive an image URL. + * A `url_template` option can extract the URL from the message. + * The `content_type` will be derived from the image when downloaded. + * This option cannot be used together with the `image_topic` option. + * At least one of these options (`url_topic` or `image_topic`) is required. + */ + url_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the image URL from a message received at `url_topic`. + */ + url_template?: string; + + /** + * The content type of an image data message received on `image_topic`. + * This option cannot be used with the `url_topic` because the content type is derived when downloading the image. + * Default: "image/jpeg" + */ + content_type?: string; + + /** + * The encoding of the image payloads received. + * Set to `"b64"` to enable base64 decoding of image payload. + * If not set, the image payload must be raw binary data. + */ + image_encoding?: string; + + /** + * The encoding of the payloads received. + * Set to `""` to disable decoding of incoming payload. + * Use `image_encoding` to enable `Base64` decoding on `image_topic`. + * Default: "utf-8" + */ + encoding?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest" + * See https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The name of the image. + * Can be set to `null` if only the device name is relevant. + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Implies `force_update` of the current sensor state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Information about the device this image is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works through [MQTT discovery](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery) and when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/lawn_mower.ts b/futurehome/src/ha/mqtt_components/lawn_mower.ts new file mode 100644 index 0000000..a724520 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/lawn_mower.ts @@ -0,0 +1,272 @@ +/** + * Represents a MQTT Lawn Mower component for Home Assistant MQTT Discovery. + * + * The `mqtt` lawn_mower platform allows controlling a lawn mower over MQTT. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/lawn_mower.mqtt/ + */ +export interface LawnMowerComponent { + /** + * Must be `lawn_mower`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'lawn_mower'; + + /** + * An ID that uniquely identifies this lawn mower. + * If two lawn mowers have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic subscribed to receive an update of the activity. + * Valid activities are `mowing`, `paused`, `docked`, and `error`. + * Use `activity_value_template` to extract the activity state from a custom payload. + * When payload `none` is received, the activity state will be reset to `unknown`. + */ + activity_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the value. + */ + activity_value_template?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the device's availability from the `topic`. + * To determine the device's availability, the result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid entries are `all`, `any`, and `latest`. + * If set to `all`, `payload_available` must be received on all configured availability topics before the entity is marked as online. + * If set to `any`, `payload_available` must be received on at least one configured availability topic before the entity is marked as online. + * If set to `latest`, the last `payload_available` or `payload_not_available` received on any configured availability topic controls the availability. + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, the result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * Information about the device this lawn mower is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when the [`unique_id`](#unique_id) is set. + * At least one of the identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://`, or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example, a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs or parent devices of a sub-device. + * This is used to show the device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `dock_command_topic`. + * The `value` parameter in the template will be set to `dock`. + */ + dock_command_template?: string; + + /** + * The MQTT topic that publishes commands when the `lawn_mower.dock` action is performed. + * The value `dock` is published when the action is used. + * Use a `dock_command_template` to publish a custom format. + */ + dock_command_topic?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of the incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes. + * Implies `force_update` of the current activity state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * The name of the lawn mower. + * Can be set to `null` if only the device name is relevant. + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag that defines if the lawn mower works in optimistic mode. + * Default: `true` if no `activity_state_topic` defined, else `false`. + */ + optimistic?: boolean; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `pause_command_topic`. + * The `value` parameter in the template will be set to `pause`. + */ + pause_command_template?: string; + + /** + * The MQTT topic that publishes commands when the `lawn_mower.pause` action is performed. + * The value `pause` is published when the action is used. + * Use a `pause_command_template` to publish a custom format. + */ + pause_command_topic?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `start_mowing_command_topic`. + * The `value` parameter in the template will be set to `start_mowing`. + */ + start_mowing_template?: string; + + /** + * The MQTT topic that publishes commands when the `lawn_mower.start_mowing` action is performed. + * The value `start_mowing` is published when the action is used. + * Use a `start_mowing_command_template` to publish a custom format. + */ + start_mowing_command_topic?: string; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; +} diff --git a/futurehome/src/ha/mqtt_components/light.ts b/futurehome/src/ha/mqtt_components/light.ts new file mode 100644 index 0000000..cbaf9f9 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/light.ts @@ -0,0 +1,630 @@ +/** + * Represents a MQTT Light component for Home Assistant MQTT Discovery. + * + * The `mqtt` light platform lets you control your MQTT enabled lights through one of the supported message schemas, + * `default`, `json` or `template`. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/light.mqtt/ + */ +export interface LightComponent { + /** + * Must be `light`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'light'; + + /** + * An ID that uniquely identifies this light. + * If two lights have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Flag that defines if light supports brightness when the `rgb`, `rgbw`, or `rgbww` color mode is supported. + * Only for JSON schema. + * Default: false + */ + brightness?: boolean; + + /** + * Defines the maximum brightness value (i.e., 100%) of the MQTT device. + * Default: 255 + */ + brightness_scale?: number; + + /** + * The MQTT topic to publish commands to change the light’s brightness. + * Only for default schema. + */ + brightness_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `brightness_command_topic`. + * Available variables: `value`. + * Only for default schema. + */ + brightness_command_template?: string; + + /** + * The MQTT topic subscribed to receive brightness state updates. + * Only for default schema. + */ + brightness_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the brightness value. + * Only for default schema. + */ + brightness_value_template?: string; + + /** + * The flag that defines if the light works in optimistic mode. + * Optimistic mode means the light immediately changes state after command, + * without waiting for confirmation from state topic. + * Default: `true` if no state topic defined, else `false`. + */ + optimistic?: boolean; + + /** + * The MQTT topic to publish commands to change the light’s color temperature state. + * Default range: 153 to 500 mireds or if `color_temp_kelvin` true: 2000 to 6535 Kelvin. + * Only for default schema. + */ + color_temp_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `color_temp_command_topic`. + * Available variables: `value`. + * Only for default schema. + */ + color_temp_command_template?: string; + + /** + * The MQTT topic subscribed to receive color temperature state updates. + * Only for default schema. + */ + color_temp_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the color temperature value. + * Only for default schema. + */ + color_temp_value_template?: string; + + /** + * When set to `true`, color temperature commands and states are in Kelvin units. + * When not set, values are converted to/from mireds. + * Default: false + */ + color_temp_kelvin?: boolean; + + /** + * The MQTT topic subscribed to receive color mode updates. + * If not configured, `color_mode` is auto set based on last color/type received. + * Only for default schema. + */ + color_mode_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the color mode value. + * Only for default schema. + */ + color_mode_value_template?: string; + + /** + * The MQTT topic to publish commands to change the light's effect state. + */ + effect_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `effect_command_topic`. + * Available variables: `value`. + */ + effect_command_template?: string; + + /** + * The list of effects the light supports. + */ + effect_list?: string[]; + + /** + * The MQTT topic subscribed to receive effect state updates. + */ + effect_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the effect value. + */ + effect_value_template?: string; + + /** + * Flag that defines if the light supports effects. + * Only for JSON schema. + * Default: false + */ + effect?: boolean; + + /** + * Flag that defines if light supports the flash feature. + * Only for JSON schema. + * Default: true + */ + flash?: boolean; + + /** + * The duration, in seconds, of a “long” flash. + * Only for JSON schema. + * Default: 10 + */ + flash_time_long?: number; + + /** + * The duration, in seconds, of a “short” flash. + * Only for JSON schema. + * Default: 2 + */ + flash_time_short?: number; + + /** + * The MQTT topic to publish commands to change the light color in HS format (Hue Saturation). + * Range Hue: 0° .. 360°, Saturation: 0..100. + * Note: Brightness is sent separately to `brightness_command_topic`. + * Only for default schema. + */ + hs_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `hs_command_topic`. + * Available variables: `hue`, `sat`. + */ + hs_command_template?: string; + + /** + * The MQTT topic subscribed to receive HS color state updates. + * Expected payload example: `359.5,100.0`. + * Note: Brightness is received separately in the `brightness_state_topic`. + */ + hs_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the HS color value. + */ + hs_value_template?: string; + + /** + * The MQTT topic to publish commands to change the light's RGB state. + */ + rgb_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `rgb_command_topic`. + * Available variables: `red`, `green`, `blue`. + */ + rgb_command_template?: string; + + /** + * The MQTT topic subscribed to receive RGB state updates. + * Expected payload example: `255,0,127`. + */ + rgb_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the RGB value. + */ + rgb_value_template?: string; + + /** + * The MQTT topic to publish commands to change the light's RGBW state. + */ + rgbw_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `rgbw_command_topic`. + * Available variables: `red`, `green`, `blue`, `white`. + */ + rgbw_command_template?: string; + + /** + * The MQTT topic subscribed to receive RGBW state updates. + * Expected payload example: `255,0,127,64`. + */ + rgbw_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the RGBW value. + */ + rgbw_value_template?: string; + + /** + * The MQTT topic to publish commands to change the light's RGBWW state. + */ + rgbww_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `rgbww_command_topic`. + * Available variables: `red`, `green`, `blue`, `cold_white`, `warm_white`. + */ + rgbww_command_template?: string; + + /** + * The MQTT topic subscribed to receive RGBWW state updates. + * Expected payload example: `255,0,127,64,32`. + */ + rgbww_state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the RGBWW value. + */ + rgbww_value_template?: string; + + /** + * The MQTT topic to publish commands to change the light to white mode with a given brightness. + */ + white_command_topic?: string; + + /** + * Defines the maximum white level (i.e., 100%) of the MQTT device. + * Used when setting the light to white mode. + * Default: 255 + */ + white_scale?: number; + + /** + * The MQTT topic subscribed to receive the state updates in MQTT default or JSON format. + * For default schema: expected payloads are `ON`, `OFF` or `None` (unknown). + * For JSON schema: expected payload is a JSON object with different keys. + * For template schema: format flexible. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the state value from the `state_topic`. + */ + state_value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the state value from the `state_topic`. + * In template schema, called `state_template`. + */ + state_template?: string; + + /** + * The MQTT topic to publish commands to change the switch state. + */ + command_topic: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Flag to indicate if the published messages should have the retain flag set. + * Default: false + */ + retain?: boolean; + + /** + * The name of the light. + * Can be set to null if only the device name is relevant. + * Default: "MQTT Light" or "MQTT JSON Light" or "MQTT Template Light" depending on schema. + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration). + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration). + */ + json_attributes_topic?: string; + + /** + * The maximum color temperature in Kelvin. + * Default: 6535 + */ + max_kelvin?: number; + + /** + * The minimum color temperature in Kelvin. + * Default: 2000 + */ + min_kelvin?: number; + + /** + * The maximum color temperature in mireds. + */ + max_mireds?: number; + + /** + * The minimum color temperature in mireds. + */ + min_mireds?: number; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload that represents the off state. + * Default: "OFF" + */ + payload_off?: string; + + /** + * The payload that represents the on state. + * Default: "ON" + */ + payload_on?: string; + + /** + * Information about the device this light is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/device_registry_index/). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * The schema to use. + * Must be one of `basic` (default), `json`, or `template`. + */ + schema?: 'basic' | 'json' | 'template'; + + /** + * Defines when `payload_on` is sent. + * Options: + * - `last`: send style topics first (brightness, color, etc), then `payload_on` to `command_topic`. + * - `first`: send `payload_on` first, then style topics. + * - `brightness`: only send brightness commands instead of `payload_on` to turn light on. + * Only for default schema. + */ + on_command_type?: 'last' | 'first' | 'brightness'; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * for *on* state changes. + * Available variables: `state`, `brightness`, `color_temp`, `red`, `green`, `blue`, `hue`, `sat`, `flash`, `transition`, `effect`. + */ + command_on_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * for *off* state changes. + * Available variables: `state`, `transition`. + */ + command_off_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract blue color from the state payload value. + * Expected result is an integer in 0-255 range. + */ + blue_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract brightness from the state payload value. + * Expected result is an integer in 0-255 range. + */ + brightness_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract color temperature from the state payload value. + * Expected result is an integer. Interpreted in Kelvin if `color_temp_kelvin` true, else mireds. + */ + color_temp_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the effect from the state payload value. + */ + effect_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract green color from the state payload value. + * Expected result is an integer in 0-255 range. + */ + green_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract red color from the state payload value. + * Expected result is an integer in 0-255 range. + */ + red_template?: string; + + /** + * Used in template schema: A [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the XY color from the state payload value. + */ + xy_value_template?: string; + + /** + * The MQTT topic to publish commands to change the light's XY state. + */ + xy_command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to compose message which will be sent to `xy_command_topic`. + * Available variables: `x`, `y`. + */ + xy_command_template?: string; + + /** + * The MQTT topic subscribed to receive XY state updates. + * Expected payload example: `0.675,0.322`. + */ + xy_state_topic?: string; +} diff --git a/futurehome/src/ha/mqtt_components/lock.ts b/futurehome/src/ha/mqtt_components/lock.ts new file mode 100644 index 0000000..02440e3 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/lock.ts @@ -0,0 +1,313 @@ +/** + * Represents a MQTT Lock component for Home Assistant MQTT Discovery. + * + * The `mqtt` lock platform lets you control your MQTT enabled locks. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/lock.mqtt/ + */ +export interface LockComponent { + /** + * Must be `lock`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'lock'; + + /** + * An ID that uniquely identifies this lock. + * If two locks have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish commands to change the lock state. + */ + command_topic: string; + + /** + * The MQTT topic subscribed to receive state updates. + * It accepts states configured with `state_jammed`, `state_locked`, `state_unlocked`, `state_locking` or `state_unlocking`. + * A "None" payload resets to an `unknown` state. + * An empty payload is ignored. + */ + state_topic?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * A regular expression to validate a supplied code when it is set during the action to `open`, `lock` or `unlock` the MQTT lock. + */ + code_format?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + * The lock command template accepts the parameters `value` and `code`. + * The `value` parameter will contain the configured value for either `payload_open`, `payload_lock` or `payload_unlock`. + * The `code` parameter is set during the action to `open`, `lock` or `unlock` the MQTT lock and will be set `None` if no code was passed. + */ + command_template?: string; + + /** + * Information about the device this lock is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[] | string; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name of the lock. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Lock" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag that defines if lock works in optimistic mode. + * Default: `true` if no `state_topic` defined, else `false`. + */ + optimistic?: boolean; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload sent to the lock to lock it. + * Default: "LOCK" + */ + payload_lock?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload sent to the lock to unlock it. + * Default: "UNLOCK" + */ + payload_unlock?: string; + + /** + * The payload sent to the lock to open it. + */ + payload_open?: string; + + /** + * A special payload that resets the state to `unknown` when received on the `state_topic`. + * Default: '"None"' + */ + payload_reset?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * The payload sent to `state_topic` by the lock when it's jammed. + * Default: "JAMMED" + */ + state_jammed?: string; + + /** + * The payload sent to `state_topic` by the lock when it's locked. + * Default: "LOCKED" + */ + state_locked?: string; + + /** + * The payload sent to `state_topic` by the lock when it's locking. + * Default: "LOCKING" + */ + state_locking?: string; + + /** + * The payload sent to `state_topic` by the lock when it's unlocked. + * Default: "UNLOCKED" + */ + state_unlocked?: string; + + /** + * The payload sent to `state_topic` by the lock when it's unlocking. + * Default: "UNLOCKING" + */ + state_unlocking?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract a state value from the payload. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/mqtt_components/manual_mqtt.ts b/futurehome/src/ha/mqtt_components/manual_mqtt.ts new file mode 100644 index 0000000..831a2f3 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/manual_mqtt.ts @@ -0,0 +1,184 @@ +/** + * Represents a MQTT manual alarm control panel component for Home Assistant MQTT Discovery. + * + * The `manual_mqtt` alarm control panel platform extends the [manual alarm](https://www.home-assistant.io/integrations/manual) + * by adding support for MQTT control of the alarm by a remote device. It can be used to create external keypads which simply change the state of + * the manual alarm in Home Assistant. + * + * It's essentially the opposite of the [MQTT Alarm Panel](https://www.home-assistant.io/integrations/alarm_control_panel.mqtt/) + * which allows Home Assistant to observe an existing, fully-featured alarm where all of the alarm logic is embedded in that physical device. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/manual_mqtt.mqtt/ + */ +export interface ManualMqttComponent { + /** + * Must be `button`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'manual_mqtt'; + + /** + * An ID that uniquely identifies this manual alarm control panel. + * If two manual alarm control panels have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic Home Assistant will publish state updates to. + * This topic is where Home Assistant will publish the current state of the alarm. + * + * Required. + */ + state_topic: string; + + /** + * The MQTT topic Home Assistant will subscribe to, to receive commands from a remote device to change the alarm state. + * Commands accepted are: + * - "DISARM" + * - "ARM_HOME" + * - "ARM_AWAY" + * - "ARM_NIGHT" + * - "ARM_VACATION" + * - "ARM_CUSTOM_BYPASS" + * + * Required. + */ + command_topic: string; + + /** + * The name of the alarm. + * Default: "HA Alarm" + */ + name?: string; + + /** + * If defined, specifies a code to enable or disable the alarm in the frontend. + * This code is not required for MQTT interactions. + * Only one of `code` and `code_template` can be specified. + */ + code?: string; + + /** + * If defined, returns a code to enable or disable the alarm in the frontend; an empty string disables checking the code. + * Inside the template, the variables `from_state` and `to_state` identify the current and desired state. + * Only one of `code` and `code_template` can be specified. + */ + code_template?: string; + + /** + * If true, the code is required to arm the alarm. If false, the code is not validated. + * Default: true + */ + code_arm_required?: boolean; + + /** + * The time in seconds of delay added to the triggered state's `pending_time` before triggering the alarm. + * Default: 0 + */ + delay_time?: number; + + /** + * The time in seconds of the pending time before effecting a state change. + * Default: 60 + */ + pending_time?: number; + + /** + * The time in seconds of the trigger time in which the alarm is firing. + * Default: 120 + */ + trigger_time?: number; + + /** + * If true, the alarm will automatically disarm after it has been triggered instead of returning to the previous state. + * Default: false + */ + disarm_after_trigger?: boolean; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * The payload to disarm this Alarm Panel. + * Default: "DISARM" + */ + payload_disarm?: string; + + /** + * The payload to set armed-home mode on this Alarm Panel. + * Default: "ARM_HOME" + */ + payload_arm_home?: string; + + /** + * The payload to set armed-away mode on this Alarm Panel. + * Default: "ARM_AWAY" + */ + payload_arm_away?: string; + + /** + * The payload to set armed-night mode on this Alarm Panel. + * Default: "ARM_NIGHT" + */ + payload_arm_night?: string; + + /** + * The payload to set armed-vacation mode on this Alarm Panel. + * Default: "ARM_VACATION" + */ + payload_arm_vacation?: string; + + /** + * The payload to set armed-custom bypass mode on this Alarm Panel. + * Default: "ARM_CUSTOM_BYPASS" + */ + payload_arm_custom_bypass?: string; + + /** + * State specific settings for each of the following states: + * - armed_home + * - armed_away + * - armed_night + * - armed_vacation + * - armed_custom_bypass + * - disarmed + * - triggered + * + * Each state key can have the following optional fields: + * - delay_time: State specific setting for delay_time (all states except triggered). + * - pending_time: State specific setting for pending_time (all states except disarmed). + * - trigger_time: State specific setting for trigger_time (all states except triggered). + */ + armed_home?: StateConfig; + armed_away?: StateConfig; + armed_night?: StateConfig; + armed_vacation?: StateConfig; + armed_custom_bypass?: StateConfig; + disarmed?: StateConfig; + triggered?: StateConfig; +} + +/** + * Interface for state-specific settings in Manual MQTT Alarm Control Panel. + */ +export interface StateConfig { + /** + * State specific setting for delay_time (all states except triggered). + */ + delay_time?: number; + + /** + * State specific setting for pending_time (all states except disarmed). + */ + pending_time?: number; + + /** + * State specific setting for trigger_time (all states except triggered). + */ + trigger_time?: number; +} diff --git a/futurehome/src/ha/mqtt_components/notify.ts b/futurehome/src/ha/mqtt_components/notify.ts new file mode 100644 index 0000000..d514ed4 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/notify.ts @@ -0,0 +1,237 @@ +/** + * Represents an MQTT Notify component for Home Assistant MQTT Discovery. + * + * The MQTT notify platform lets you send an MQTT message when the `send_message` action is called. + * This can be used to expose an action of a remote device that allows processing a message, + * such as showing it on a screen. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/notify.mqtt/ + */ +export interface NotifyComponent { + /** + * Must be `notify`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'notify'; + + /** + * An ID that uniquely identifies this notify entity. + * If two notify entities have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish send message commands at. + */ + command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * If set to "all", `payload_available` must be received on all configured availability topics before the entity is marked as online. + * If set to "any", `payload_available` must be received on at least one configured availability topic before the entity is marked as online. + * If set to "latest", the last `payload_available` or `payload_not_available` received on any configured availability topic controls the availability. + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The encoding of the published messages. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * The name to use when displaying this notify entity. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT notify" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Information about the device this notify entity is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/number.ts b/futurehome/src/ha/mqtt_components/number.ts new file mode 100644 index 0000000..ca56b39 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/number.ts @@ -0,0 +1,278 @@ +/** + * Represents a MQTT Number component for Home Assistant MQTT Discovery. + * + * The `mqtt` Number platform allows integrating devices that expose configuration + * options through MQTT into Home Assistant as a Number. Every time a message under + * the `state_topic` is received, the number entity will be updated in Home Assistant + * and vice-versa, keeping the device and Home Assistant in sync. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/number.mqtt/ + */ +export interface NumberComponent { + /** + * Must be `number`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'number'; + + /** + * An ID that uniquely identifies this number entity. + * If two number entities have the same unique ID Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish commands to change the number. + */ + command_topic: string; + + /** + * The MQTT topic subscribed to receive number values. An empty payload is ignored. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the value. + */ + value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * Minimum value. + * Default: 1 + */ + min?: number; + + /** + * Maximum value. + * Default: 100 + */ + max?: number; + + /** + * Step value. Smallest value `0.001`. + * Default: 1 + */ + step?: number; + + /** + * Control how the number should be displayed in the UI. Can be set to `box` or `slider` to force a display mode. + * Default: "auto" + */ + mode?: string; + + /** + * Defines the unit of measurement of the sensor, if any. The `unit_of_measurement` can be `null`. + */ + unit_of_measurement?: string | null; + + /** + * The [type/class](https://www.home-assistant.io/integrations/number/#device-class) of the number. The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as number attributes. + * Implies `force_update` of the current number state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * Flag that defines if number works in optimistic mode. + * Default: `true` if no `state_topic` defined, else `false`. + */ + optimistic?: boolean; + + /** + * A special payload that resets the state to `unknown` when received on the `state_topic`. + * Default: "None" + */ + payload_reset?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * The name of the Number. Can be set to `null` if only the device name is relevant. + * Default: "MQTT Number" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Information about the device this Number is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/scene.ts b/futurehome/src/ha/mqtt_components/scene.ts new file mode 100644 index 0000000..cb3c247 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/scene.ts @@ -0,0 +1,237 @@ +/** + * Represents a MQTT Scene component for Home Assistant MQTT Discovery. + * + * The `mqtt` scene platform lets you control your MQTT enabled scenes. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/scene.mqtt/ + */ +export interface SceneComponent { + /** + * Must be `scene`. Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'scene'; + + /** + * An ID that uniquely identifies this scene entity. + * If two scenes have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish `payload_on` to activate the scene. + */ + command_topic?: string; + + /** + * The payload that will be sent to `command_topic` when activating the MQTT scene. + * Default: "ON" + */ + payload_on?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + * + * If set to `all`, `payload_available` must be received on all configured availability topics before + * the entity is marked as online. + * If set to `any`, `payload_available` must be received on at least one configured availability topic before + * the entity is marked as online. + * If set to `latest`, the last `payload_available` or `payload_not_available` received on any configured availability topic + * controls the availability. + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Information about the device this scene is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://` or `https://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[] | string; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * The encoding of the published messages. + * Default: "utf-8" + */ + encoding?: string; + + /** + * Icon for the scene. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name to use when displaying this scene. + * Default: "MQTT Scene" + */ + name?: string; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; +} diff --git a/futurehome/src/ha/mqtt_components/select.ts b/futurehome/src/ha/mqtt_components/select.ts new file mode 100644 index 0000000..73252b6 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/select.ts @@ -0,0 +1,245 @@ +/** + * Represents a MQTT Select component for Home Assistant MQTT Discovery. + * + * The `mqtt` Select platform allows you to integrate devices that might expose configuration + * options through MQTT into Home Assistant as a Select. Every time a message under the + * `state_topic` is received, the select entity will be updated in Home Assistant and vice-versa, + * keeping the device and Home Assistant in sync. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/select.mqtt/ + */ +export interface SelectComponent { + /** + * Must be `select`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'select'; + + /** + * An ID that uniquely identifies this select. + * If two selects have the same unique ID Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic subscribed to receive update of the selected option. + * A "None" payload resets to an `unknown` state. An empty payload is ignored. + */ + state_topic?: string; + + /** + * The MQTT topic to publish commands to change the selected option. + */ + command_topic: string; + + /** + * List of options that can be selected. An empty list or a list with a single item is allowed. + */ + options: string[]; + + /** + * Flag that defines if the select works in optimistic mode. + * Default: `true` if no `state_topic` defined, else `false`. + */ + optimistic?: boolean; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the value. + */ + value_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes. + * Implies `force_update` of the current select state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * The name of the Select. Can be set to `null` if only the device name is relevant. + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Information about the device this Select is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * If `availability` is not defined, the select will always be considered `available`. + * Must not be used together with `availability`. + */ + availability_topic?: string; +} diff --git a/futurehome/src/ha/mqtt_components/sensor.ts b/futurehome/src/ha/mqtt_components/sensor.ts new file mode 100644 index 0000000..69fc91b --- /dev/null +++ b/futurehome/src/ha/mqtt_components/sensor.ts @@ -0,0 +1,285 @@ +/** + * Represents an MQTT Sensor component for Home Assistant MQTT Discovery. + * + * This `mqtt` sensor platform uses the MQTT message payload as the sensor value. + * If messages in this `state_topic` are published with the *RETAIN* flag, + * the sensor will receive an instant update with last known value. + * Otherwise, the initial state will be undefined. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/sensor.mqtt/ + */ +export interface SensorComponent { + /** + * Must be `sensor`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'sensor'; + + /** + * An ID that uniquely identifies this sensor. + * If two sensors have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic subscribed to receive sensor values. + * If `device_class`, `state_class`, `unit_of_measurement` or `suggested_display_precision` is set, + * and a numeric value is expected, an empty value `''` will be ignored and will not update the state, + * a `'None'` value will set the sensor to an `unknown` state. + * + * If a `value_template` is used to parse a JSON payload, a `null` value in the JSON + * [will be rendered as](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) `'None'`. + * Note that the `device_class` can be `null`. + */ + state_topic?: string; + + /** + * The [type/class](https://www.home-assistant.io/integrations/sensor/#device-class) of the sensor to set the icon in the frontend. + * The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * The [state_class](https://developers.home-assistant.io/docs/core/entity/sensor#available-state-classes) of the sensor. + */ + state_class?: string; + + /** + * Defines the units of measurement of the sensor, if any. + * The `unit_of_measurement` can be `null`. + */ + unit_of_measurement?: string | null; + + /** + * The number of decimals which should be used in the sensor's state after rounding. + */ + suggested_display_precision?: number; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the value. + * If the template throws an error, the current state will be used instead. + */ + value_template?: string; + + /** + * The name of the MQTT sensor. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Sensor" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + * When set, the entity category must be `diagnostic` for sensors. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Implies `force_update` of the current sensor state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * Sends update events even if the value hasn't changed. + * Useful if you want to have meaningful value graphs in history. + * Default: false + */ + force_update?: boolean; + + /** + * If set, it defines the number of seconds after the sensor's state expires, + * if it's not updated. After expiry, the sensor's state becomes `unavailable`. + * Default the sensor's state never expires. + */ + expire_after?: number; + + /** + * List of allowed sensor state value. An empty list is not allowed. + * The sensor's `device_class` must be set to `enum`. + * The `options` option cannot be used together with `state_class` or `unit_of_measurement`. + */ + options?: string[]; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the last_reset. + * When `last_reset_value_template` is set, the `state_class` option must be `total`. + * Available variables: `entity_id`. The `entity_id` can be used to reference the entity's attributes. + */ + last_reset_value_template?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * If `availability` is not defined, the sensor will always be considered `available`. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Information about the device this sensor is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/device_registry_index/). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/siren.ts b/futurehome/src/ha/mqtt_components/siren.ts new file mode 100644 index 0000000..227292d --- /dev/null +++ b/futurehome/src/ha/mqtt_components/siren.ts @@ -0,0 +1,272 @@ +/** + * Represents a MQTT Siren component for Home Assistant MQTT Discovery. + * + * The `mqtt` siren platform lets you control your MQTT enabled sirens and text based notification devices. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/siren.mqtt/ + */ +export interface SirenComponent { + /** + * Must be `siren`. Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'siren'; + + /** + * An ID that uniquely identifies this siren. + * If two sirens have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * List of available tones the siren supports. When configured, this enables the support for setting a `tone` and enables the `tone` state attribute. + */ + available_tones?: string[]; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to generate a custom payload to send to `command_topic`. The variable `value` will be assigned with the configured `payload_on` or `payload_off` setting. The siren turn on action parameters `tone`, `volume_level` or `duration` can be used as variables in the template. When operating in optimistic mode the corresponding state attributes will be set. Turn on parameters will be filtered if a device misses the support. + */ + command_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to generate a custom payload to send to `command_topic` when the siren turn off action is called. By default `command_template` will be used as template for action turn off. The variable `value` will be assigned with the configured `payload_off` setting. + */ + command_off_template?: string; + + /** + * The MQTT topic to publish commands to change the siren state. Without command templates, a default JSON payload like `{"state":"ON", "tone": "bell", "duration": 10, "volume_level": 0.5 }` is published. When the siren turn on action is performed, the startup parameters will be added to the JSON payload. The `state` value of the JSON payload will be set to the the `payload_on` or `payload_off` configured payload. + */ + command_topic?: string; + + /** + * Information about the device this siren is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/core/device_registry_index/). Only works when [`unique_id`](#unique_id) is set. At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. For example the MAC address of a network interface: `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. For example a serial number. + */ + identifiers?: string[] | string; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. Examples of such devices are hubs, or parent devices of a sub-device. This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the JSON dictionary from messages received on the `json_attributes_topic`. Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name to use when displaying this siren. Can be set to `null` if only the device name is relevant. + * Default: "MQTT Siren" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag that defines if siren works in optimistic mode. + * Default: `true` if no `state_topic` defined, else `false`. + */ + optimistic?: boolean; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload that represents `off` state. If specified, will be used for both comparing to the value in the `state_topic` (see `value_template` and `state_off` for details) and sending as `off` command to the `command_topic`. + * Default: "OFF" + */ + payload_off?: string; + + /** + * The payload that represents `on` state. If specified, will be used for both comparing to the value in the `state_topic` (see `value_template` and `state_on` for details) and sending as `on` command to the `command_topic`. + * Default: "ON" + */ + payload_on?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * The payload that represents the `off` state. Used when value that represents `off` state in the `state_topic` is different from value that should be sent to the `command_topic` to turn the device `off`. + * Default: "`payload_off` if defined, else `'OFF'`" + */ + state_off?: string; + + /** + * The payload that represents the `on` state. Used when value that represents `on` state in the `state_topic` is different from value that should be sent to the `command_topic` to turn the device `on`. + * Default: "`payload_on` if defined, else `'ON'`" + */ + state_on?: string; + + /** + * The MQTT topic subscribed to receive state updates. The state update may be either JSON or a simple string. When a JSON payload is detected, the `state` value of the JSON payload should supply the `payload_on` or `payload_off` defined payload to turn the siren on or off. Additionally, the state attributes `duration`, `tone` and `volume_level` can be updated. Use `value_template` to transform the received state update to a compliant JSON payload. Attributes will only be set if the function is supported by the device and a valid value is supplied. When a non-JSON payload is detected, it should be either of the `payload_on` or `payload_off` defined payloads or `None` to reset the siren's state to `unknown`. The initial state will be `unknown`. The state will be reset to `unknown` if a `None` payload or `null` JSON value is received as a state update. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract device's state from the `state_topic`. To determine the siren's state result of this template will be compared to `state_on` and `state_off`. Alternatively `value_template` can be used to render to a valid JSON payload. + */ + state_value_template?: string; + + /** + * Set to `true` if the MQTT siren supports the `duration` turn on action parameter and enables the `duration` state attribute. + * Default: true + */ + support_duration?: boolean; + + /** + * Set to `true` if the MQTT siren supports the `volume_set` turn on action parameter and enables the `volume_level` state attribute. + * Default: true + */ + support_volume_set?: boolean; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract device's availability from the `topic`. To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. Valid values: "all", "any", "latest". Default: "latest". + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract device's availability from the `availability_topic`. To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. Must not be used together with `availability`. + */ + availability_topic?: string; +} diff --git a/futurehome/src/ha/mqtt_components/switch.ts b/futurehome/src/ha/mqtt_components/switch.ts new file mode 100644 index 0000000..509eee4 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/switch.ts @@ -0,0 +1,288 @@ +/** + * Represents a MQTT Switch component for Home Assistant MQTT Discovery. + * + * The `mqtt` switch platform lets you control your MQTT enabled switches. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/switch.mqtt/ + */ +export interface SwitchComponent { + /** + * Must be `switch`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'switch'; + + /** + * An ID that uniquely identifies this switch. + * If two switches have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish commands to change the switch state. + */ + command_topic: string; + + /** + * The MQTT topic subscribed to receive state updates. + * A "None" payload resets to an `unknown` state. An empty payload is ignored. + * By default, valid state payloads are `OFF` and `ON`. + * The accepted payloads can be overridden with the `payload_off` and `payload_on` config options. + */ + state_topic?: string; + + /** + * The [type/class](https://www.home-assistant.io/integrations/switch/#device-class) of the switch to set the icon in the frontend. The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name to use when displaying this switch. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Switch" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag that defines if switch works in optimistic mode. + * Default: `true` if no `state_topic` defined, else `false`. + */ + optimistic?: boolean; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload that represents `off` state. + * If specified, will be used for both comparing to the value in the `state_topic` (see `value_template` and `state_off` for details) + * and sending as `off` command to the `command_topic`. + * Default: "OFF" + */ + payload_off?: string; + + /** + * The payload that represents `on` state. + * If specified, will be used for both comparing to the value in the `state_topic` (see `value_template` and `state_on` for details) + * and sending as `on` command to the `command_topic`. + * Default: "ON" + */ + payload_on?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * The payload that represents the `off` state. + * Used when value that represents `off` state in the `state_topic` is different from value that should be sent to the `command_topic` to turn the device `off`. + * Default: `payload_off` if defined, else `OFF` + */ + state_off?: string; + + /** + * The payload that represents the `on` state. + * Used when value that represents `on` state in the `state_topic` is different from value that should be sent to the `command_topic` to turn the device `on`. + * Default: `payload_on` if defined, else `ON` + */ + state_on?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to generate the payload to send to `command_topic`. + * The switch command template accepts the parameter `value`. + * The `value` parameter will contain the configured value for either `payload_on` or `payload_off`. + */ + command_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract device's state from the `state_topic`. + * To determine the switch's state, the result of this template will be compared to `state_on` and `state_off`. + */ + value_template?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * Information about the device this switch is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/tag.ts b/futurehome/src/ha/mqtt_components/tag.ts new file mode 100644 index 0000000..e855558 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/tag.ts @@ -0,0 +1,104 @@ +/** + * Represents a MQTT Tag Scanner component for Home Assistant MQTT Discovery. + * + * The `mqtt` tag scanner platform uses an MQTT message payload to generate tag scanned events. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/tag.mqtt/ + */ +export interface TagComponent { + /** + * Must be `tag`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'tag'; + + /** + * An ID that uniquely identifies this tag. + * If two tags have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic subscribed to receive tag scanned events. + */ + topic: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) that returns a tag ID. + */ + value_template?: string; + + /** + * Information about the device this device trigger is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * At least one of identifiers or connections must be present to identify the device. + */ + device: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/text.ts b/futurehome/src/ha/mqtt_components/text.ts new file mode 100644 index 0000000..caebcc4 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/text.ts @@ -0,0 +1,265 @@ +/** + * Represents a MQTT Text component for Home Assistant MQTT Discovery. + * + * The `mqtt` Text platform allows you to integrate devices that show text that can be set remotely. + * Optionally the text state can be monitored too using MQTT. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/text.mqtt/ + */ +export interface TextComponent { + /** + * Must be `text`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'text'; + + /** + * An ID that uniquely identifies this text entity. + * If two text entities have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish the text value that is set. + */ + command_topic: string; + + /** + * The MQTT topic subscribed to receive text state updates. + * Text state updates should match the `pattern` (if set) and meet the size constraints `min` and `max`. + * Can be used with `value_template` to render the incoming payload to a text update. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the text state value from the payload received on `state_topic`. + */ + value_template?: string; + + /** + * The name of the text entity. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Text" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The maximum size of a text being set or received (maximum is 255). + * Default: 255 + */ + max?: number; + + /** + * The minimum size of a text being set or received. + * Default: 0 + */ + min?: number; + + /** + * The mode off the text entity. + * Must be either `text` or `password`. + * Default: text + */ + mode?: 'text' | 'password'; + + /** + * A valid regular expression the text being set or received must match with. + */ + pattern?: string; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes. + * Implies `force_update` of the current select state when a message is received on this topic. + */ + json_attributes_topic?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The string that represents the `online` state. + * Default: "online" + */ + payload_available?: string; + + /** + * The string that represents the `offline` state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * Information about the device this of text capability is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/update.ts b/futurehome/src/ha/mqtt_components/update.ts new file mode 100644 index 0000000..886ffc1 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/update.ts @@ -0,0 +1,277 @@ +/** + * Represents an MQTT Update component for Home Assistant MQTT Discovery. + * + * The `mqtt` update platform allows integration of devices exposing firmware or software installed and latest versions through MQTT. + * Each message received under configured topics updates the entity state in Home Assistant. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/update.mqtt/ + */ +export interface UpdateComponent { + /** + * Must be `update`. + * Required and only allowed in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'update'; + + /** + * An ID that uniquely identifies this update entity. + * If two update entities have the same unique ID, Home Assistant will raise an exception. + */ + unique_id?: string; + + /** + * The MQTT topic subscribed to receive state updates. + * The payload may be JSON or a simple string with `installed_version` value. + * When JSON, the payload can include: `installed_version`, `latest_version`, `title`, `release_summary`, `release_url`, `entity_picture`, `in_progress` (boolean), and `update_percentage` (number). + */ + state_topic?: string; + + /** + * The MQTT topic subscribed to receive an update of the latest version. + * Use `state_topic` with `latest_version_template` if all update state values are in a single JSON payload. + */ + latest_version_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the latest version value. + * Use with `latest_version_topic` or `state_topic`. + */ + latest_version_template?: string; + + /** + * The MQTT topic to publish `payload_install` to start the installation process. + */ + command_topic?: string; + + /** + * The MQTT payload to start installing process. + */ + payload_install?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the `installed_version` state value or to render to a valid JSON payload from the payload received on `state_topic`. + */ + value_template?: string; + + /** + * The type/class of the update to set the icon in the frontend. + * See [device classes](https://www.home-assistant.io/integrations/update/#device-classes). + * Can be null. + */ + device_class?: string | null; + + /** + * Number of decimal digits for display of update progress. + * Default: 0 + */ + display_precision?: number; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the JSON dictionary from messages received on the `json_attributes_topic`. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes. + * Implies `force_update` of the current select state when receiving a message on this topic. + */ + json_attributes_topic?: string; + + /** + * The name of the Update. Can be set to `null` if only the device name is relevant. + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * A summary of the release notes or changelog. + * Suitable for a brief update description (max 255 characters). + */ + release_summary?: string; + + /** + * URL to the full release notes of the latest version available. + */ + release_url?: string; + + /** + * Flag if the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * Title of the software or firmware update. + * Helps differentiate between device/entity name and the update software title. + */ + title?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. Result compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * Result compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The string that represents the `online` state. + * Default: "online" + */ + payload_available?: string; + + /** + * The string that represents the `offline` state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Information about the device this Update is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when `unique_id` is set. At least one of identifiers or connections must be present. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * Example: `[["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. For example a serial number. + */ + identifiers?: string[] | string; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples: hubs, or parent devices of a sub-device. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/vacuum.ts b/futurehome/src/ha/mqtt_components/vacuum.ts new file mode 100644 index 0000000..1c5b25d --- /dev/null +++ b/futurehome/src/ha/mqtt_components/vacuum.ts @@ -0,0 +1,274 @@ +/** + * Represents a MQTT Vacuum component for Home Assistant MQTT Discovery. + * + * The `mqtt` vacuum integration allows you to control your MQTT-enabled vacuum. + * The initial state of the MQTT vacuum entity is `unknown` and can be reset by sending a `null` payload as state. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/vacuum.mqtt/ + */ +export interface VacuumComponent { + /** + * Must be `vacuum`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'vacuum'; + + /** + * An ID that uniquely identifies this vacuum. + * If two vacuums have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest". + * Default: "latest" + * + * See also: + * https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The MQTT topic to publish commands to control the vacuum. + */ + command_topic?: string; + + /** + * Information about the device this vacuum is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/core/device_registry_index/). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * List of possible fan speeds for the vacuum. + */ + fan_speed_list?: string[]; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The name of the vacuum. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT Vacuum" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload to send to the `command_topic` to begin a spot cleaning cycle. + * Default: "clean_spot" + */ + payload_clean_spot?: string; + + /** + * The payload to send to the `command_topic` to locate the vacuum (typically plays a song). + * Default: "locate" + */ + payload_locate?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The payload to send to the `command_topic` to pause the vacuum. + * Default: "pause" + */ + payload_pause?: string; + + /** + * The payload to send to the `command_topic` to tell the vacuum to return to base. + * Default: "return_to_base" + */ + payload_return_to_base?: string; + + /** + * The payload to send to the `command_topic` to begin the cleaning cycle. + * Default: "start" + */ + payload_start?: string; + + /** + * The payload to send to the `command_topic` to stop cleaning. + * Default: "stop" + */ + payload_stop?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * If the published message should have the retain flag on or not. + * Default: false + */ + retain?: boolean; + + /** + * The MQTT topic to publish custom commands to the vacuum. + */ + send_command_topic?: string; + + /** + * The MQTT topic to publish commands to control the vacuum's fan speed. + */ + set_fan_speed_topic?: string; + + /** + * The MQTT topic subscribed to receive state messages from the vacuum. + * Messages received on the `state_topic` must be a valid JSON dictionary, + * with a mandatory `state` key and optionally `battery_level` and `fan_speed` keys. + */ + state_topic?: string; + + /** + * List of features that the vacuum supports. + * Possible values: "start", "stop", "pause", "return_home", "battery", "status", "locate", "clean_spot", "fan_speed", "send_command". + * Default: "start", "stop", "return_home", "status", "battery", "clean_spot" + */ + supported_features?: string[]; +} diff --git a/futurehome/src/ha/mqtt_components/valve.ts b/futurehome/src/ha/mqtt_components/valve.ts new file mode 100644 index 0000000..89f5fb5 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/valve.ts @@ -0,0 +1,343 @@ +/** + * Represents a MQTT Valve component for Home Assistant MQTT Discovery. + * + * The `mqtt` valve platform allows control of an MQTT valve such as gas or water valves. + * Valve states can be `open`, `opening`, `closed`, or `closing`. + * The valve can also report and set position if `reports_position` is enabled. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/valve.mqtt/ + */ +export interface ValveComponent { + /** + * Must be `valve`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'valve'; + + /** + * An ID that uniquely identifies this valve. + * If two valves have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The MQTT topic to publish commands to control the valve. + * The value sent can be a value defined by `payload_open`, `payload_close`, or `payload_stop`. + * If `reports_position` is set to `true`, a numeric value will be published instead. + */ + command_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) + * to generate the payload to send to `command_topic`. + */ + command_template?: string; + + /** + * The MQTT topic subscribed to receive valve state messages. + * State topic accepts a state payload (`open`, `opening`, `closed`, or `closing`) or, if `reports_position` is supported, + * a numeric value representing the position. + * In JSON format, both `state` and `position` can be reported together. + * A `null` state value resets to an `unknown` state. + * An empty string is ignored. + */ + state_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * that can be used to extract the payload for the `state_topic` topic. + * The rendered value should be a defined state payload or, if reporting a `position` and `reports_position` is `true`, + * a numeric value expected representing the position. See also `state_topic`. + */ + value_template?: string; + + /** + * Flag that defines if the valve works in optimistic mode. + * Optimistic mode means the valve immediately changes state after command is sent, + * without waiting for state update from the device. + * Defaults to `false` if `state_topic` or position topics are defined; `true` otherwise. + */ + optimistic?: boolean; + + /** + * Set to `true` if the valve reports the position or supports setting the position. + * Enabling this causes position to be published instead of payloads defined by `payload_open`, `payload_close`, or `payload_stop`. + * When receiving messages, `state_topic` accepts numeric payloads or one of the states: `open`, `opening`, `closed`, or `closing`. + */ + reports_position?: boolean; + + /** + * Number which represents the closed position. + * The valve's position will be scaled to the (`position_closed`...`position_open`) range when an action is performed and scaled back when a value is received. + * Default: 0 + */ + position_closed?: number; + + /** + * Number which represents the open position. + * The valve's position will be scaled to the (`position_closed`...`position_open`) range when an action is performed and scaled back when a value is received. + * Default: 100 + */ + position_open?: number; + + /** + * The command payload that opens the valve. + * Only used when `reports_position` is `false` (default). + * Not allowed if `reports_position` is `true`. + * Can be set to `null` to disable the valve's open option. + * Default: "OPEN" + */ + payload_open?: string | null; + + /** + * The command payload that closes the valve. + * Only used when `reports_position` is `false` (default). + * Not allowed if `reports_position` is `true`. + * Can be set to `null` to disable the valve's close option. + * Default: "CLOSE" + */ + payload_close?: string | null; + + /** + * The command payload that stops the valve. + * If not configured, the valve will not support the `valve.stop` action. + */ + payload_stop?: string; + + /** + * The payload that represents the open state. + * Only allowed when `reports_position` is `false` (default). + * Default: "open" + */ + state_open?: string; + + /** + * The payload that represents the opening state. + * Default: "opening" + */ + state_opening?: string; + + /** + * The payload that represents the closed state. + * Only allowed when `reports_position` is `false` (default). + * Default: "closed" + */ + state_closed?: string; + + /** + * The payload that represents the closing state. + * Default: "closing" + */ + state_closing?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as valve attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the device's availability from the `topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template will be compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive birth and LWT messages from the MQTT valve device. + * If an `availability` topic is not defined, the valve availability state will always be `available`. + * If an `availability` topic is defined, the valve availability state will be `unavailable` by default. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The payload that represents the online state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the offline state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Defines if published messages should have the retain flag set. + * Default: false + */ + retain?: boolean; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * The name of the valve. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT valve" + */ + name?: string | null; + + /** + * Used instead of `name` to have the `entity_id` generated automatically. + */ + object_id?: string; + + /** + * Sets the [class of the device](https://www.home-assistant.io/integrations/valve/#device_class), + * changing the device state and icon that is displayed on the frontend. + * The `device_class` can be `null`. + */ + device_class?: string | null; + + /** + * Information about the device this valve is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example, the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. + * For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; +} diff --git a/futurehome/src/ha/mqtt_components/water_heater.ts b/futurehome/src/ha/mqtt_components/water_heater.ts new file mode 100644 index 0000000..50b3276 --- /dev/null +++ b/futurehome/src/ha/mqtt_components/water_heater.ts @@ -0,0 +1,356 @@ +/** + * Represents a MQTT Water Heater component for Home Assistant MQTT Discovery. + * + * The `mqtt` water heater platform lets you control your MQTT enabled water heater devices. + * + * For detailed documentation see: + * https://www.home-assistant.io/integrations/water_heater.mqtt/ + */ +export interface WaterHeaterComponent { + /** + * Must be `water_heater`. + * Only allowed and required in [MQTT auto discovery device messages](https://www.home-assistant.io/integrations/mqtt/#device-discovery-payload). + */ + platform: 'water_heater'; + + /** + * An ID that uniquely identifies this water heater. + * If two water heaters have the same unique ID, Home Assistant will raise an exception. + * Required when used with device-based discovery. + */ + unique_id?: string; + + /** + * The name of the water heater. + * Can be set to `null` if only the device name is relevant. + * Default: "MQTT water heater" + */ + name?: string | null; + + /** + * Used instead of `name` for automatic generation of `entity_id`. + */ + object_id?: string; + + /** + * Flag which defines if the entity should be enabled when first added. + * Default: true + */ + enabled_by_default?: boolean; + + /** + * The encoding of the payloads received and published messages. + * Set to `""` to disable decoding of incoming payload. + * Default: "utf-8" + */ + encoding?: string; + + /** + * The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity. + */ + entity_category?: string; + + /** + * Picture URL for the entity. + */ + entity_picture?: string; + + /** + * [Icon](https://www.home-assistant.io/docs/configuration/customizing-devices/#icon) for the entity. + */ + icon?: string; + + /** + * Information about the device this water heater device is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). + * Only works through [MQTT discovery](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery) and when [`unique_id`](#unique_id) is set. + * At least one of identifiers or connections must be present to identify the device. + */ + device?: { + /** + * A link to the webpage that can manage the configuration of this device. + * Can be either an `http://`, `https://` or an internal `homeassistant://` URL. + */ + configuration_url?: string; + + /** + * A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. + * For example the MAC address of a network interface: + * `"connections": [["mac", "02:5b:26:a8:dc:12"]]`. + */ + connections?: Array<[string, string]>; + + /** + * The hardware version of the device. + */ + hw_version?: string; + + /** + * A list of IDs that uniquely identify the device. For example a serial number. + */ + identifiers?: string[]; + + /** + * The manufacturer of the device. + */ + manufacturer?: string; + + /** + * The model of the device. + */ + model?: string; + + /** + * The model identifier of the device. + */ + model_id?: string; + + /** + * The name of the device. + */ + name?: string; + + /** + * The serial number of the device. + */ + serial_number?: string; + + /** + * Suggest an area if the device isn’t in one yet. + */ + suggested_area?: string; + + /** + * The firmware version of the device. + */ + sw_version?: string; + + /** + * Identifier of a device that routes messages between this device and Home Assistant. + * Examples of such devices are hubs, or parent devices of a sub-device. + * This is used to show device topology in Home Assistant. + */ + via_device?: string; + }; + + /** + * A list of MQTT topics subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability_topic`. + */ + availability?: Array<{ + /** + * An MQTT topic subscribed to receive availability (online/offline) updates. + */ + topic: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `topic`. + * To determine the device's availability, result of this template is compared to `payload_available` and `payload_not_available`. + */ + value_template?: string; + }>; + + /** + * When `availability` is configured, this controls the conditions needed to set the entity to `available`. + * Valid values: "all", "any", "latest" + * Default: "latest" + */ + availability_mode?: 'all' | 'any' | 'latest'; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract device's availability from the `availability_topic`. + * To determine the device's availability, result of this template is compared to `payload_available` and `payload_not_available`. + */ + availability_template?: string; + + /** + * The MQTT topic subscribed to receive availability (online/offline) updates. + * Must not be used together with `availability`. + */ + availability_topic?: string; + + /** + * The payload that represents the available state. + * Default: "online" + */ + payload_available?: string; + + /** + * The payload that represents the unavailable state. + * Default: "offline" + */ + payload_not_available?: string; + + /** + * The MQTT topic to publish commands to change the water heater operation mode. + */ + mode_command_topic?: string; + + /** + * A template to render the value sent to the `mode_command_topic` with. + */ + mode_command_template?: string; + + /** + * The MQTT topic to subscribe for changes of the water heater operation mode. + * If this is not set, the operation mode works in optimistic mode (see below). + * A "None" payload resets to an `unknown` state. An empty payload is ignored. + */ + mode_state_topic?: string; + + /** + * A template to render the value received on the `mode_state_topic` with. + */ + mode_state_template?: string; + + /** + * A list of supported modes. + * Needs to be a subset of the default values. + * Default: ['off', 'eco', 'electric', 'gas', 'heat_pump', 'high_demand', 'performance'] + */ + modes?: string[]; + + /** + * The MQTT topic to publish commands to change the water heater power state. + * Sends the payload configured with `payload_on` if the water heater is turned on via the `water_heater.turn_on`, + * or the payload configured with `payload_off` if the water heater is turned off via the `water_heater.turn_off` action. + * Note that `optimistic` mode is not supported through `water_heater.turn_on` and `water_heater.turn_off` actions. + * When called, these actions will send a power command to the device but will not optimistically update the state of the water heater. + * The water heater device should report its state back via `mode_state_topic`. + */ + power_command_topic?: string; + + /** + * A template to render the value sent to the `power_command_topic` with. + * The `value` parameter is the payload set for `payload_on` or `payload_off`. + */ + power_command_template?: string; + + /** + * The payload that represents enabled state. + * Default: "ON" + */ + payload_on?: string; + + /** + * The payload that represents disabled state. + * Default: "OFF" + */ + payload_off?: string; + + /** + * Flag that defines if the water heater works in optimistic mode. + * Default: "`true` if no state topic defined, else `false`." + */ + optimistic?: boolean; + + /** + * The MQTT topic to publish commands to change the target temperature. + */ + temperature_command_topic?: string; + + /** + * A template to render the value sent to the `temperature_command_topic` with. + */ + temperature_command_template?: string; + + /** + * The MQTT topic to subscribe for changes in the target temperature. + * If this is not set, the target temperature works in optimistic mode (see below). + * A `"None"` value received will reset the temperature set point. + * Empty values (`'''`) will be ignored. + */ + temperature_state_topic?: string; + + /** + * A template to render the value received on the `temperature_state_topic` with. + */ + temperature_state_template?: string; + + /** + * Defines the temperature unit of the device, `C` or `F`. + * If this is not set, the temperature unit is set to the system temperature unit. + */ + temperature_unit?: string; + + /** + * The desired precision for this device. + * Can be used to match your actual water heater's precision. + * Supported values are `0.1`, `0.5` and `1.0`. + * Default: 0.1 for Celsius and 1.0 for Fahrenheit. + */ + precision?: number; + + /** + * Set the initial target temperature. + * The default value depends on the temperature unit, and will be 43.3°C or 110°F. + */ + initial?: number; + + /** + * Maximum set point available. + * The default value depends on the temperature unit, and will be 60°C or 140°F. + */ + max_temp?: number; + + /** + * Minimum set point available. + * The default value depends on the temperature unit, and will be 43.3°C or 110°F. + */ + min_temp?: number; + + /** + * A template with which the value received on `current_temperature_topic` will be rendered. + */ + current_temperature_template?: string; + + /** + * The MQTT topic on which to listen for the current temperature. + * A `"None"` value received will reset the current temperature. + * Empty values (`'''`) will be ignored. + */ + current_temperature_topic?: string; + + /** + * Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) + * to extract the JSON dictionary from messages received on the `json_attributes_topic`. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation. + */ + json_attributes_template?: string; + + /** + * The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. + * Usage example can be found in [MQTT sensor](https://www.home-assistant.io/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation. + */ + json_attributes_topic?: string; + + /** + * The maximum QoS level to be used when receiving and publishing messages. + * Default: 0 + */ + qos?: number; + + /** + * Defines if published messages should have the retain flag set. + * Default: false + */ + retain?: boolean; + + /** + * Default template to render the payloads on *all* `*_state_topic`s with. + */ + value_template?: string; +} diff --git a/futurehome/src/ha/publish_device.ts b/futurehome/src/ha/publish_device.ts index 4aa0eab..15438d9 100644 --- a/futurehome/src/ha/publish_device.ts +++ b/futurehome/src/ha/publish_device.ts @@ -50,6 +50,7 @@ import { sensor_wattemp__components } from "../services/sensor_wattemp"; import { sensor_weight__components } from "../services/sensor_weight"; import { thermostat__components } from "../services/thermostat"; import { ha } from "./globals"; +import { HaMqttComponent } from "./mqtt_components/_component"; type HaDeviceConfig = { // device @@ -74,7 +75,7 @@ type HaDeviceConfig = { }; // components cmps: { - [key: string]: HaComponent; + [key: string]: HaMqttComponent; }, // state topic stat_t: string, @@ -83,122 +84,8 @@ type HaDeviceConfig = { qos: number, } -export type HaComponent = SensorComponent | BinarySensorComponent | SwitchComponent | NumberComponent | ClimateComponent | SelectComponent | FanComponent | LightComponent; - -// Device class supported values: https://www.home-assistant.io/integrations/homeassistant/#device-class - -/// https://www.home-assistant.io/integrations/sensor.mqtt/ -/// https://www.home-assistant.io/integrations/sensor/#device-class -export type SensorComponent = { - unique_id: string; - // platform - p: 'sensor'; - device_class?: string; - unit_of_measurement: string; - value_template: string; -} - -/// https://www.home-assistant.io/integrations/binary_sensor.mqtt/ -/// https://www.home-assistant.io/integrations/binary_sensor/#device-class -export type BinarySensorComponent = { - unique_id: string; - // platform - p: 'binary_sensor'; - device_class?: string; - value_template: string; -} - -/// https://www.home-assistant.io/integrations/switch.mqtt/ -/// https://www.home-assistant.io/integrations/switch/#device-class -export type SwitchComponent = { - unique_id: string; - // platform - p: 'switch'; - command_topic: string; - optimistic: boolean; - value_template: string; -} - -/// https://www.home-assistant.io/integrations/number.mqtt/ -/// https://www.home-assistant.io/integrations/number/#device-class -export type NumberComponent = { - unique_id: string; - // platform - p: 'number'; - min: number; - max: number; - step: number; - command_topic: string; - optimistic: boolean; - value_template: string; -} - -/// https://www.home-assistant.io/integrations/climate.mqtt/ -export type ClimateComponent = { - unique_id: string; - // platform - p: 'climate'; - modes: string[]; - mode_command_topic: string; - mode_state_topic: string; - mode_state_template: string; - temperature_command_topic: string; - temperature_state_topic: string; - temperature_state_template: string; - min_temp: number; - max_temp: number; - temp_step: number; - optimistic: boolean; -} - -/// https://www.home-assistant.io/integrations/select.mqtt/ -export type SelectComponent = { - unique_id: string; - // platform - p: 'select'; - options: string[]; - command_topic: string; - optimistic: boolean; - value_template: string; -} - -/// https://www.home-assistant.io/integrations/fan.mqtt/ -export type FanComponent = { - unique_id: string; - // platform - p: 'fan'; - command_topic: string; - optimistic: boolean; - preset_modes: string[]; - preset_mode_command_topic: string; - preset_mode_state_template: string; - state_value_template: string; - preset_mode_value_template: string; -}; - -/// https://www.home-assistant.io/integrations/light.mqtt/ -export type LightComponent = { - unique_id: string; - // platform - p: "light"; - command_topic?: string; - state_topic?: string; - state_value_template?: string; - rgb_command_topic?: string; - rgb_state_topic?: string; - rgb_value_template?: string; - brightness_state_topic?: string; - brightness_value_template?: string; - optimistic?: boolean; - color_temp_command_topic?: string; - color_temp_state_topic?: string; - color_temp_value_template?: string; - min_mireds?: number; - max_mireds?: number; -}; - export type ServiceComponentsCreationResult = { - components: { [key: string]: HaComponent }; + components: { [key: string]: HaMqttComponent }; commandHandlers?: CommandHandlers; } @@ -258,7 +145,7 @@ const serviceHandlers: { }; export function haPublishDevice(parameters: { hubId: string, vinculumDeviceData: VinculumPd7Device, deviceInclusionReport: InclusionReport | undefined }): { commandHandlers: CommandHandlers } { - const components: { [key: string]: HaComponent } = {}; + const components: { [key: string]: HaMqttComponent } = {}; const handlers: CommandHandlers = {}; // e.g. "homeassistant/device/futurehome_123456_1" diff --git a/futurehome/src/services/basic.ts b/futurehome/src/services/basic.ts index b3fc867..1b9c90b 100644 --- a/futurehome/src/services/basic.ts +++ b/futurehome/src/services/basic.ts @@ -27,7 +27,7 @@ export function basic__components( components: { [svc.addr]: { unique_id: svc.addr, - p: "number", + platform: 'number', min: MIN_LVL, max: MAX_LVL, step: 1, diff --git a/futurehome/src/services/battery.ts b/futurehome/src/services/battery.ts index 0f5fccc..2a43e0d 100644 --- a/futurehome/src/services/battery.ts +++ b/futurehome/src/services/battery.ts @@ -1,17 +1,18 @@ import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; -import { HaComponent, ServiceComponentsCreationResult } from "../ha/publish_device"; +import { HaMqttComponent } from "../ha/mqtt_components/_component"; +import { ServiceComponentsCreationResult } from "../ha/publish_device"; export function battery__components( topicPrefix: string, device: VinculumPd7Device, svc: VinculumPd7Service ): ServiceComponentsCreationResult | undefined { - const components: Record = {}; + const components: Record = {}; if (svc.intf?.includes('evt.alarm.report')) { components[`${svc.addr}_alarm`] = { unique_id: `${svc.addr}_alarm`, - p: 'binary_sensor', + platform: 'binary_sensor', device_class: 'battery', value_template: `{{ (value_json['${svc.addr}'].alarm.status == 'activ') | iif('ON', 'OFF') }}`, }; @@ -20,7 +21,7 @@ export function battery__components( if (svc.intf?.includes('evt.lvl.report')) { components[`${svc.addr}_lvl`] = { unique_id: `${svc.addr}_lvl`, - p: 'sensor', + platform: 'sensor', device_class: 'battery', unit_of_measurement: svc.props?.sup_units?.[0] ?? '%', value_template: `{{ value_json['${svc.addr}'].lvl }}`, diff --git a/futurehome/src/services/color_ctrl.ts b/futurehome/src/services/color_ctrl.ts index 5acba4d..dac597a 100644 --- a/futurehome/src/services/color_ctrl.ts +++ b/futurehome/src/services/color_ctrl.ts @@ -1,6 +1,7 @@ import { sendFimpMsg } from "../fimp/fimp"; import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; -import { ServiceComponentsCreationResult, CommandHandlers, LightComponent } from "../ha/publish_device"; +import { LightComponent } from "../ha/mqtt_components/light"; +import { ServiceComponentsCreationResult, CommandHandlers } from "../ha/publish_device"; export function color_ctrl__components( topicPrefix: string, @@ -47,7 +48,7 @@ export function color_ctrl__components( // Create the light component configuration const lightComponent: LightComponent = { unique_id: svc.addr, - p: 'light', + platform: 'light', // Basic on/off control command_topic: commandTopic, diff --git a/futurehome/src/services/fan_ctrl.ts b/futurehome/src/services/fan_ctrl.ts index e9ee93b..fa6b998 100644 --- a/futurehome/src/services/fan_ctrl.ts +++ b/futurehome/src/services/fan_ctrl.ts @@ -17,15 +17,14 @@ export function fan_ctrl__components( components: { [svc.addr]: { unique_id: svc.addr, - p: "fan", + platform: 'fan', command_topic: commandTopic, optimistic: true, preset_modes: supModes, preset_mode_command_topic: commandTopic, - preset_mode_state_template: `{{ value_json['${svc.addr}'].mode }}`, + preset_mode_value_template: `{{ value_json['${svc.addr}'].mode }}`, // Fan is considered "on" if mode is not off/stop state_value_template: `{{ 'ON' if value_json['${svc.addr}'].mode not in ['off', 'stop'] else 'OFF' }}`, - preset_mode_value_template: `{{ value_json['${svc.addr}'].mode }}`, }, }, diff --git a/futurehome/src/services/out_bin_switch.ts b/futurehome/src/services/out_bin_switch.ts index cbfecae..f1a0b94 100644 --- a/futurehome/src/services/out_bin_switch.ts +++ b/futurehome/src/services/out_bin_switch.ts @@ -13,7 +13,7 @@ export function out_bin_switch__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'switch', + platform: 'switch', command_topic: commandTopic, optimistic: false, value_template: `{{ (value_json['${svc.addr}'].binary) | iif('ON', 'OFF') }}`, diff --git a/futurehome/src/services/out_lvl_switch.ts b/futurehome/src/services/out_lvl_switch.ts index 4d14b49..2327b1f 100644 --- a/futurehome/src/services/out_lvl_switch.ts +++ b/futurehome/src/services/out_lvl_switch.ts @@ -16,7 +16,7 @@ export function out_lvl_switch__components( components: { [svc.addr]: { unique_id: svc.addr, - p: "number", + platform: 'number', min: minLvl, max: maxLvl, step: 1, diff --git a/futurehome/src/services/scene_ctrl.ts b/futurehome/src/services/scene_ctrl.ts index 01440e7..3fec88f 100644 --- a/futurehome/src/services/scene_ctrl.ts +++ b/futurehome/src/services/scene_ctrl.ts @@ -10,9 +10,9 @@ import { sendFimpMsg } from "../fimp/fimp"; import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; +import { HaMqttComponent } from "../ha/mqtt_components/_component"; import { CommandHandlers, - HaComponent, ServiceComponentsCreationResult, } from "../ha/publish_device"; @@ -24,14 +24,14 @@ export function scene_ctrl__components( _device: VinculumPd7Device, svc: VinculumPd7Service ): ServiceComponentsCreationResult | undefined { - const components: Record = {}; + const components: Record = {}; const handlers: CommandHandlers = {}; // ───────────── read-only entities ───────────── if (svc.intf?.includes("evt.scene.report")) { components[`${svc.addr}_scene`] = { unique_id: `${svc.addr}_scene`, - p: "sensor", + platform: 'sensor', unit_of_measurement: "", value_template: `{{ value_json['${svc.addr}'].scene }}`, }; @@ -40,7 +40,7 @@ export function scene_ctrl__components( if (svc.intf?.includes("evt.lvl.report")) { components[`${svc.addr}_lvl`] = { unique_id: `${svc.addr}_lvl`, - p: "sensor", + platform: 'sensor', unit_of_measurement: "", value_template: `{{ value_json['${svc.addr}'].lvl }}`, }; @@ -53,7 +53,7 @@ export function scene_ctrl__components( components[`${svc.addr}_select`] = { unique_id: `${svc.addr}_select`, - p: "select", + platform: 'select', options: supScenes, command_topic: commandTopic, optimistic: true, diff --git a/futurehome/src/services/sensor_accelx.ts b/futurehome/src/services/sensor_accelx.ts index 898b9fa..b47a99f 100644 --- a/futurehome/src/services/sensor_accelx.ts +++ b/futurehome/src/services/sensor_accelx.ts @@ -13,7 +13,7 @@ export function sensor_accelx__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_accely.ts b/futurehome/src/services/sensor_accely.ts index 35a2ff6..ec92a7b 100644 --- a/futurehome/src/services/sensor_accely.ts +++ b/futurehome/src/services/sensor_accely.ts @@ -13,7 +13,7 @@ export function sensor_accely__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_accelz.ts b/futurehome/src/services/sensor_accelz.ts index 612038d..98ea8ae 100644 --- a/futurehome/src/services/sensor_accelz.ts +++ b/futurehome/src/services/sensor_accelz.ts @@ -13,7 +13,7 @@ export function sensor_accelz__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_airflow.ts b/futurehome/src/services/sensor_airflow.ts index c749f4e..a2209af 100644 --- a/futurehome/src/services/sensor_airflow.ts +++ b/futurehome/src/services/sensor_airflow.ts @@ -13,7 +13,7 @@ export function sensor_airflow__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_airq.ts b/futurehome/src/services/sensor_airq.ts index a2c4e0c..c5884c2 100644 --- a/futurehome/src/services/sensor_airq.ts +++ b/futurehome/src/services/sensor_airq.ts @@ -13,7 +13,7 @@ export function sensor_airq__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_anglepos.ts b/futurehome/src/services/sensor_anglepos.ts index a78c871..188002c 100644 --- a/futurehome/src/services/sensor_anglepos.ts +++ b/futurehome/src/services/sensor_anglepos.ts @@ -13,7 +13,7 @@ export function sensor_anglepos__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_atmo.ts b/futurehome/src/services/sensor_atmo.ts index baf578f..3f15696 100644 --- a/futurehome/src/services/sensor_atmo.ts +++ b/futurehome/src/services/sensor_atmo.ts @@ -13,7 +13,7 @@ export function sensor_atmo__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_baro.ts b/futurehome/src/services/sensor_baro.ts index 54ba66e..8ea6f31 100644 --- a/futurehome/src/services/sensor_baro.ts +++ b/futurehome/src/services/sensor_baro.ts @@ -13,7 +13,7 @@ export function sensor_baro__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_co.ts b/futurehome/src/services/sensor_co.ts index 5859692..cbab6c5 100644 --- a/futurehome/src/services/sensor_co.ts +++ b/futurehome/src/services/sensor_co.ts @@ -13,7 +13,7 @@ export function sensor_co__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_co2.ts b/futurehome/src/services/sensor_co2.ts index 847aead..3be4b04 100644 --- a/futurehome/src/services/sensor_co2.ts +++ b/futurehome/src/services/sensor_co2.ts @@ -13,7 +13,7 @@ export function sensor_co2__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_contact.ts b/futurehome/src/services/sensor_contact.ts index 34bfef8..2077eeb 100644 --- a/futurehome/src/services/sensor_contact.ts +++ b/futurehome/src/services/sensor_contact.ts @@ -12,7 +12,7 @@ export function sensor_contact__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'binary_sensor', + platform: 'binary_sensor', device_class: device_class, value_template: `{{ value_json['${svc.addr}'].open | iif('ON', 'OFF') }}`, }, diff --git a/futurehome/src/services/sensor_current.ts b/futurehome/src/services/sensor_current.ts index 602ac0b..181bd87 100644 --- a/futurehome/src/services/sensor_current.ts +++ b/futurehome/src/services/sensor_current.ts @@ -13,7 +13,7 @@ export function sensor_current__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_dew.ts b/futurehome/src/services/sensor_dew.ts index e8cc4c3..1960875 100644 --- a/futurehome/src/services/sensor_dew.ts +++ b/futurehome/src/services/sensor_dew.ts @@ -15,7 +15,7 @@ export function sensor_dew__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_direct.ts b/futurehome/src/services/sensor_direct.ts index e0052e3..6ff8c7b 100644 --- a/futurehome/src/services/sensor_direct.ts +++ b/futurehome/src/services/sensor_direct.ts @@ -13,7 +13,7 @@ export function sensor_direct__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_distance.ts b/futurehome/src/services/sensor_distance.ts index be30146..5f6b327 100644 --- a/futurehome/src/services/sensor_distance.ts +++ b/futurehome/src/services/sensor_distance.ts @@ -13,7 +13,7 @@ export function sensor_distance__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_elresist.ts b/futurehome/src/services/sensor_elresist.ts index 3de0068..da90d1f 100644 --- a/futurehome/src/services/sensor_elresist.ts +++ b/futurehome/src/services/sensor_elresist.ts @@ -13,7 +13,7 @@ export function sensor_elresist__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_freq.ts b/futurehome/src/services/sensor_freq.ts index 3b63255..130d77d 100644 --- a/futurehome/src/services/sensor_freq.ts +++ b/futurehome/src/services/sensor_freq.ts @@ -13,7 +13,7 @@ export function sensor_freq__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_gp.ts b/futurehome/src/services/sensor_gp.ts index cc3adfc..5c869d3 100644 --- a/futurehome/src/services/sensor_gp.ts +++ b/futurehome/src/services/sensor_gp.ts @@ -13,7 +13,7 @@ export function sensor_gp__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_gust.ts b/futurehome/src/services/sensor_gust.ts index 700924d..14e99c1 100644 --- a/futurehome/src/services/sensor_gust.ts +++ b/futurehome/src/services/sensor_gust.ts @@ -14,7 +14,7 @@ export function sensor_gust__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_humid.ts b/futurehome/src/services/sensor_humid.ts index 0f9c1c4..2ed2c8b 100644 --- a/futurehome/src/services/sensor_humid.ts +++ b/futurehome/src/services/sensor_humid.ts @@ -13,7 +13,7 @@ export function sensor_humid__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_lumin.ts b/futurehome/src/services/sensor_lumin.ts index 1a3ded8..beffa2a 100644 --- a/futurehome/src/services/sensor_lumin.ts +++ b/futurehome/src/services/sensor_lumin.ts @@ -13,7 +13,7 @@ export function sensor_lumin__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_moist.ts b/futurehome/src/services/sensor_moist.ts index 4b49273..42702f6 100644 --- a/futurehome/src/services/sensor_moist.ts +++ b/futurehome/src/services/sensor_moist.ts @@ -13,7 +13,7 @@ export function sensor_moist__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_noise.ts b/futurehome/src/services/sensor_noise.ts index 30d1b4e..ab77045 100644 --- a/futurehome/src/services/sensor_noise.ts +++ b/futurehome/src/services/sensor_noise.ts @@ -13,7 +13,7 @@ export function sensor_noise__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_power.ts b/futurehome/src/services/sensor_power.ts index a644f4a..5eca9f1 100644 --- a/futurehome/src/services/sensor_power.ts +++ b/futurehome/src/services/sensor_power.ts @@ -13,7 +13,7 @@ export function sensor_power__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_presence.ts b/futurehome/src/services/sensor_presence.ts index d95fa0f..96f7ccc 100644 --- a/futurehome/src/services/sensor_presence.ts +++ b/futurehome/src/services/sensor_presence.ts @@ -12,7 +12,7 @@ export function sensor_presence__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'binary_sensor', + platform: 'binary_sensor', device_class: device_class, value_template: `{{ value_json['${svc.addr}'].presence | iif('ON', 'OFF') }}`, }, diff --git a/futurehome/src/services/sensor_rain.ts b/futurehome/src/services/sensor_rain.ts index 7d6237a..7772d38 100644 --- a/futurehome/src/services/sensor_rain.ts +++ b/futurehome/src/services/sensor_rain.ts @@ -13,7 +13,7 @@ export function sensor_rain__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_rotation.ts b/futurehome/src/services/sensor_rotation.ts index 594f6bd..3321291 100644 --- a/futurehome/src/services/sensor_rotation.ts +++ b/futurehome/src/services/sensor_rotation.ts @@ -13,7 +13,7 @@ export function sensor_rotation__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_seismicint.ts b/futurehome/src/services/sensor_seismicint.ts index 836bafc..1a153ac 100644 --- a/futurehome/src/services/sensor_seismicint.ts +++ b/futurehome/src/services/sensor_seismicint.ts @@ -13,7 +13,7 @@ export function sensor_seismicint__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_seismicmag.ts b/futurehome/src/services/sensor_seismicmag.ts index 7db6543..64c51e9 100644 --- a/futurehome/src/services/sensor_seismicmag.ts +++ b/futurehome/src/services/sensor_seismicmag.ts @@ -13,7 +13,7 @@ export function sensor_seismicmag__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_solarrad.ts b/futurehome/src/services/sensor_solarrad.ts index 905ff69..3179633 100644 --- a/futurehome/src/services/sensor_solarrad.ts +++ b/futurehome/src/services/sensor_solarrad.ts @@ -13,7 +13,7 @@ export function sensor_solarrad__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_tank.ts b/futurehome/src/services/sensor_tank.ts index 91d1385..883c5e9 100644 --- a/futurehome/src/services/sensor_tank.ts +++ b/futurehome/src/services/sensor_tank.ts @@ -13,7 +13,7 @@ export function sensor_tank__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_temp.ts b/futurehome/src/services/sensor_temp.ts index c6f62cc..b24c702 100644 --- a/futurehome/src/services/sensor_temp.ts +++ b/futurehome/src/services/sensor_temp.ts @@ -15,7 +15,7 @@ export function sensor_temp__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_tidelvl.ts b/futurehome/src/services/sensor_tidelvl.ts index 5aa553d..32ddc09 100644 --- a/futurehome/src/services/sensor_tidelvl.ts +++ b/futurehome/src/services/sensor_tidelvl.ts @@ -13,7 +13,7 @@ export function sensor_tidelvl__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_uv.ts b/futurehome/src/services/sensor_uv.ts index 6e68c9a..afa5eb1 100644 --- a/futurehome/src/services/sensor_uv.ts +++ b/futurehome/src/services/sensor_uv.ts @@ -13,7 +13,7 @@ export function sensor_uv__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_veloc.ts b/futurehome/src/services/sensor_veloc.ts index 514dedb..86ca572 100644 --- a/futurehome/src/services/sensor_veloc.ts +++ b/futurehome/src/services/sensor_veloc.ts @@ -13,7 +13,7 @@ export function sensor_veloc__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_voltage.ts b/futurehome/src/services/sensor_voltage.ts index 4c7915a..e97afe4 100644 --- a/futurehome/src/services/sensor_voltage.ts +++ b/futurehome/src/services/sensor_voltage.ts @@ -13,7 +13,7 @@ export function sensor_voltage__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_watflow.ts b/futurehome/src/services/sensor_watflow.ts index c2cf765..e9a7477 100644 --- a/futurehome/src/services/sensor_watflow.ts +++ b/futurehome/src/services/sensor_watflow.ts @@ -13,7 +13,7 @@ export function sensor_watflow__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_watpressure.ts b/futurehome/src/services/sensor_watpressure.ts index 63e2d01..12fed0a 100644 --- a/futurehome/src/services/sensor_watpressure.ts +++ b/futurehome/src/services/sensor_watpressure.ts @@ -13,7 +13,7 @@ export function sensor_watpressure__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_wattemp.ts b/futurehome/src/services/sensor_wattemp.ts index 00ba512..aaf98fa 100644 --- a/futurehome/src/services/sensor_wattemp.ts +++ b/futurehome/src/services/sensor_wattemp.ts @@ -15,7 +15,7 @@ export function sensor_wattemp__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_weight.ts b/futurehome/src/services/sensor_weight.ts index c00af85..2cc4ad9 100644 --- a/futurehome/src/services/sensor_weight.ts +++ b/futurehome/src/services/sensor_weight.ts @@ -13,7 +13,7 @@ export function sensor_weight__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/sensor_wind.ts b/futurehome/src/services/sensor_wind.ts index ae91b34..02bae9c 100644 --- a/futurehome/src/services/sensor_wind.ts +++ b/futurehome/src/services/sensor_wind.ts @@ -13,7 +13,7 @@ export function sensor_wind__components( components: { [svc.addr]: { unique_id: svc.addr, - p: 'sensor', + platform: 'sensor', device_class: device_class, unit_of_measurement: unit, value_template: `{{ value_json['${svc.addr}'].sensor }}`, diff --git a/futurehome/src/services/thermostat.ts b/futurehome/src/services/thermostat.ts index 48847fb..2658fa3 100644 --- a/futurehome/src/services/thermostat.ts +++ b/futurehome/src/services/thermostat.ts @@ -11,8 +11,8 @@ import { sendFimpMsg } from "../fimp/fimp"; import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; +import { ClimateComponent } from "../ha/mqtt_components/climate"; import { - ClimateComponent, CommandHandlers, ServiceComponentsCreationResult, } from "../ha/publish_device"; @@ -54,7 +54,7 @@ export function thermostat__components( // ───────────── MQTT climate component ───────────── const climate: ClimateComponent = { unique_id: svc.addr, - p: "climate", + platform: 'climate', // HVAC modes modes: supModes,