diff --git a/README.md b/README.md index fc6c60e..d1ec6a7 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,31 @@ -Advanced Device icon +Advanced Device icon # Advanced Device -A Home Assistant custom integration that turns a switchable power plug with a power sensor into its own smart device for the appliance plugged into it, such as a washing machine, PC, TV or printer. +Your washing machine, PC or TV gets its own device in Home Assistant, built from the smart plug it is plugged into. -## Concept +Advanced Device reads the plug's power draw and tells you whether the appliance is off, in standby or running. It counts every run with its duration, energy and cost. When you switch the plug off, it can wait until the appliance has actually finished, so a nightly "everything off" automation no longer cuts a dishwasher mid-cycle or a PC mid-update. -Each configured plug becomes one Home Assistant device with its own entities. The plug's original switch is hidden, and the new device is the one you control. Status, shutdown protection, cycles and maintenance are tracked and exposed by the integration itself, not written as attributes into entities owned by other integrations. +Add device dialog in Home Assistant -The focus is on **control, status and protection**. It is not a program recognition engine. For detecting washing programs, remaining time and cycle phases, use [WashData](https://github.com/3dg1luk43/ha_washdata), which this integration can be linked to. +## What you get -## Features +- A status sensor for the appliance (`off`, `standby`, `idle`, `running` and a few states in between), worked out from smoothed power with thresholds you can tune. +- A shutdown lock. A switch-off waits for standby and can run a script first, for example one that shuts a PC down cleanly. +- A one-time lock that lets one device skip the next switch-off. +- Optionally, the plug switches back on if something else turns it off while the appliance is running. +- Duration, energy and cost of each cycle, plus operating hours and a maintenance reminder. +- A problem sensor for a missing power sensor or a cycle that runs too long. +- Auto-off after a set time in standby. +- Profiles with starting values for washing machines, dryers, dishwashers, PCs, TVs, printers and coffee machines. +- Events, device triggers and actions for your automations. +- Setup and options in the UI, in English and German. -- **Status from power.** `off`, `starting`, `on`, `standby`, `idle`, `running`, `shutting_down` and `unavailable`, derived from smoothed power with configurable thresholds and durations. -- **Shutdown lock.** A switch-off waits until the appliance is in standby. An optional action runs first (for example a script that enables the appliance's own shutdown), and a delay and maximum wait can be set. -- **Re-enable after external off.** If the plug is switched off by something other than this integration while the device is running, it is switched back on, up to three times. This needs the shutdown lock to be on and the option **Switch back on after external off** to be enabled. -- **One-time lock.** Blocks the next switch-off once, with an optional expiry. Useful for a nightly "everything off" automation. -- **Cycles and statistics.** Start and end of each run, with duration, energy and cost (when a price sensor is set). -- **Auto-off.** Switches the plug off after a configurable time in standby. -- **Device profiles.** Starting values for common appliance types. -- **Problem and maintenance.** A problem sensor for a missing power sensor or an overlong cycle, and operating hours with a maintenance reminder. -- **Automation hooks.** Events, device triggers and actions for use in automations. -- **Fully configurable in the UI.** German and English translations. +The original plug switch is hidden, so the new device is the only one you control. Program detection is not part of this integration. For washing programs and remaining time, link a [WashData](https://github.com/3dg1luk43/ha_washdata) device; Advanced Device then follows its cycles. + +The device page after setup, here with German entity names: + +Device page of a configured Advanced Device ## Installation @@ -31,54 +35,18 @@ The focus is on **control, status and protection**. It is not a program recognit 2. Search for **Advanced Device** in HACS and download it. 3. Restart Home Assistant. -## Setup - -1. Go to **Settings → Devices & Services → Add Integration** and search for **Advanced Device**. -2. **Device:** enter a name, choose a profile, select the plug switch and, optionally, the power sensor. Keep "Hide original switch" enabled to use only this integration's switch. -3. **Power thresholds:** only if a power sensor is set. Values are prefilled from the profile. -4. **Shutdown lock:** optional. Requires a standby threshold above 0 W. -5. **Extras:** price sensor, auto-off, maximum cycle duration, maintenance interval, WashData link and status icons. - -Every option except the plug switch and power sensor can be changed later under **Configure**. The plug switch and power sensor are changed under **Reconfigure**. - -Without a power sensor, the device only tracks on and off. Shutdown lock, cycles and power-based functions are not available. - -## Profiles - -Profiles set starting values. All values can be changed afterwards. - -| Profile | Standby (W / s) | Idle (s) | Running (W / s) | Smoothing (s) | Min. cycle | Shutdown lock | Auto-off | -|---|---|---|---|---|---|---|---| -| Generic | 1.0 / 60 | 120 | 10.0 / 30 | 10 | 1 min | no | off | -| Washing machine | 2.5 / 300 | 600 | 15.0 / 60 | 30 | 10 min | yes | off | -| Dryer | 1.5 / 300 | 300 | 100.0 / 60 | 30 | 10 min | yes | off | -| Dishwasher | 1.0 / 300 | 300 | 30.0 / 60 | 30 | 15 min | yes | off | -| PC | 5.0 / 60 | 600 | 40.0 / 30 | 20 | 1 min | no | off | -| TV | 3.0 / 60 | 300 | 80.0 / 60 | 30 | 5 min | no | off | -| Printer | 1.0 / 120 | 300 | 20.0 / 10 | 5 | 30 s | no | 15 min | -| Coffee machine | 0.5 / 60 | 180 | 800.0 / 30 | 10 | 1 min | no | 30 min | +Then go to **Settings → Devices & Services → Add Integration** and pick **Advanced Device**. Setup takes up to four short dialogs. Without a power sensor the device only tracks on and off, and the power-based functions are left out. -Washing machine, dryer and dishwasher have auto-off off by default, because a delayed start looks like standby and would be cut off. - -The values are starting points based on typical consumption, not measurements. Measurements from real devices are welcome through the "Device profile" issue template. - -## WashData - -[WashData](https://github.com/3dg1luk43/ha_washdata) (`ha_washdata`) detects cycles and programs. If you select a WashData device under **Extras**: - -- Cycles and cycle events follow WashData instead of this integration's own thresholds. -- The shutdown lock is released only when WashData reports `finished`, `clean`, `off` or `idle`. It is never released while WashData reports `running`, `paused`, `user_paused`, `ending` or `anti_wrinkle`. -- Program, time remaining and progress sensors are added to the device and mirror WashData. - -**Recommendation:** in WashData, use the **original plug switch** (the one this integration hides) as the pause/resume switch, not the Advanced Device switch. Pausing turns the plug off from outside this integration. While WashData reports a pause, the integration tolerates that off and does not switch the plug back on. - -If the linked WashData device is removed or not loaded, the coupling is inactive, a repair issue is shown, and the integration uses its own logic. Setup does not fail. After WashData is loaded again, reload the Advanced Device entry or restart Home Assistant. +## Documentation -**Program detection?** Use WashData. This integration does not recognise programs. +The [documentation](https://developer-simon.github.io/ha-advanced-device/) walks through every setup dialog with screenshots and lists everything the integration creates: -## Documentation +- [Configuration](https://developer-simon.github.io/ha-advanced-device/configuration.html): setup dialogs, options and device profiles +- [Entities](https://developer-simon.github.io/ha-advanced-device/entities.html): entities and status values +- [Events and actions](https://developer-simon.github.io/ha-advanced-device/events-actions.html): events, actions and device triggers +- [Behaviour](https://developer-simon.github.io/ha-advanced-device/behaviour.html): switch-off sequence, locks, persistence and WashData -- [Reference: configuration, entities, events, actions and triggers](docs/integration.md) +Measurements from real appliances help improve the profiles. Send them through the "Device profile" issue template. ## Built with AI diff --git a/custom_components/advanced_device/brand/icon.png b/custom_components/advanced_device/brand/icon.png index ba76c90..a02bbfb 100644 Binary files a/custom_components/advanced_device/brand/icon.png and b/custom_components/advanced_device/brand/icon.png differ diff --git a/custom_components/advanced_device/brand/icon.svg b/custom_components/advanced_device/brand/icon.svg index 394f592..305d446 100644 --- a/custom_components/advanced_device/brand/icon.svg +++ b/custom_components/advanced_device/brand/icon.svg @@ -1,9 +1,13 @@ - Advanced Device — smart plug that becomes its own device - - - - - - + Advanced Device: smart plug with status ring and power scope + + + + + + + + + + diff --git a/custom_components/advanced_device/brand/icon@2x.png b/custom_components/advanced_device/brand/icon@2x.png index dd52c90..da2dc5d 100644 Binary files a/custom_components/advanced_device/brand/icon@2x.png and b/custom_components/advanced_device/brand/icon@2x.png differ diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000..7f3185f --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,17 @@ +title: Advanced Device +description: Home Assistant integration that turns a smart plug into its own device. +url: https://developer-simon.github.io +baseurl: /ha-advanced-device +remote_theme: just-the-docs/just-the-docs +plugins: + - jekyll-remote-theme + - jekyll-relative-links +relative_links: + enabled: true + collections: false +logo: /assets/icon.svg +search_enabled: true +aux_links: + GitHub: https://github.com/Developer-Simon/ha-advanced-device +aux_links_new_tab: true +back_to_top: true diff --git a/docs/assets/AddDeviceDialog.png b/docs/assets/AddDeviceDialog.png new file mode 100644 index 0000000..b4d5c8c Binary files /dev/null and b/docs/assets/AddDeviceDialog.png differ diff --git a/docs/assets/ConfiguredDevice.png b/docs/assets/ConfiguredDevice.png new file mode 100644 index 0000000..202102f Binary files /dev/null and b/docs/assets/ConfiguredDevice.png differ diff --git a/docs/assets/ExtrasDialog.png b/docs/assets/ExtrasDialog.png new file mode 100644 index 0000000..891311d Binary files /dev/null and b/docs/assets/ExtrasDialog.png differ diff --git a/docs/assets/PowerThresholdDialog.png b/docs/assets/PowerThresholdDialog.png new file mode 100644 index 0000000..069bf22 Binary files /dev/null and b/docs/assets/PowerThresholdDialog.png differ diff --git a/docs/assets/ShutdownLockDialog.png b/docs/assets/ShutdownLockDialog.png new file mode 100644 index 0000000..0baafbe Binary files /dev/null and b/docs/assets/ShutdownLockDialog.png differ diff --git a/docs/assets/icon.svg b/docs/assets/icon.svg new file mode 100644 index 0000000..305d446 --- /dev/null +++ b/docs/assets/icon.svg @@ -0,0 +1,13 @@ + + Advanced Device: smart plug with status ring and power scope + + + + + + + + + + + diff --git a/docs/behaviour.md b/docs/behaviour.md new file mode 100644 index 0000000..5f91f29 --- /dev/null +++ b/docs/behaviour.md @@ -0,0 +1,72 @@ +--- +title: Behaviour +nav_order: 5 +--- + +# Behaviour + +## Switch-off sequence + +A switch-off from the main switch or the auto-off is handled in this order: + +1. **One-time lock active:** the switch-off is discarded and the lock is used up. The plug stays on, and `advanced_device_shutdown_blocked` fires with `reason: one_time_lock`. +2. **Shutdown lock off:** the plug switches off immediately. +3. **Shutdown lock on and status `standby`:** the plug switches off after the delay. +4. **Shutdown lock on, any other status:** the status becomes `shutting_down`. The pre-action runs, and the integration waits for `standby`. Then it waits for the delay and switches off. + - If the maximum wait is exceeded, the plug is **not** switched off. The shutdown is cancelled, the status returns to the value derived from the power, and `advanced_device_shutdown_aborted` fires. + +The **Force off** button and the `force_off` action do not go through this sequence. They switch the plug off at once, ignore the one-time lock and the shutdown lock, and remove an active lock. + +Switching the main switch on during `shutting_down` cancels the shutdown. + +## Re-enable after external off + +If the plug is switched off by something other than this integration (a physical button, another integration) while the device is `running`, the shutdown lock is on, and **Switch back on after external off** is enabled, the integration switches the plug back on. This happens at most three times. `advanced_device_shutdown_blocked` fires with `reason: external_off`. + +An external off while WashData reports `paused` or `user_paused` is tolerated and not reversed. + +## One-time lock + +- Turning on the **One-time lock** switch, or calling `lock_shutdown`, arms the lock. The switch uses the default expiry from the options. +- The lock ends at the first switch-off it blocks, at its expiry, when the switch is turned off manually, or when `unlock_shutdown` is called, whichever happens first. +- The lock does not block **Force off**. +- Expiry is stored. A lock whose expiry passed while Home Assistant was stopped is off after the restart. + +## Auto-off + +After the configured time in uninterrupted `standby`, the integration switches the plug off through the normal switch-off path. The one-time lock and the shutdown lock are respected. + +## Problem sensor + +The problem sensor reports these reasons in its `reasons` attribute: + +- `power_missing`: the plug is on and the power sensor is unavailable. +- `cycle_too_long`: the running cycle exceeds the maximum cycle duration. + +## Safety principle + +The integration must not switch a device off unexpectedly. If the state is unclear (missing power data, unavailable sensor, restart during a pending shutdown), the plug stays on. A pending shutdown is discarded on restart. + +## Persistence + +Cycle counter, operating hours, maintenance counter, last cycle values and the one-time lock expiry are stored with Home Assistant's storage helper. They survive restarts. + +Without WashData, a running cycle is stored too, with its start time and the energy up to the last update. After a restart the cycle continues with its original start, and no new cycle starts. The downtime counts towards the duration: if the cycle ends soon after the restart, `duration_s` is measured from the original start. Energy from the last seconds before the restart may be missing. With WashData linked, no cycle is stored, and the cycle state comes from WashData again after a restart. + +## Removing the entry + +When the config entry is removed, the original switch is shown again, but only if it is still hidden by this integration. A switch that you hid yourself stays hidden. + +## WashData + +[WashData](https://github.com/3dg1luk43/ha_washdata) (`ha_washdata`) detects cycles and programs. Advanced Device does not recognise programs itself. If you select a WashData device under **Extras**: + +- Cycles and cycle events follow WashData instead of this integration's own thresholds. +- The shutdown lock is released only when WashData reports `finished`, `clean`, `off` or `idle`. It is never released while WashData reports `running`, `paused`, `user_paused`, `ending` or `anti_wrinkle`. +- Program, time remaining and progress sensors are added to the device and mirror WashData. + +In WashData, set the original plug switch (the one this integration hides) as the pause/resume switch, not the Advanced Device switch. Pausing turns the plug off from outside this integration. While WashData reports a pause, the integration tolerates that off and does not switch the plug back on. + +A linked WashData entry that is not loaded when the device is set up is not used. That includes a removed WashData device and a WashData entry that is still retrying its setup when Home Assistant starts. The device then uses its own cycle logic and shows a repair issue, and setup does not fail. After WashData is loaded again, reload the Advanced Device entry or restart Home Assistant. + +To remove a stale link, open the options and save the **Extras** step. diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..870cec1 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,91 @@ +--- +title: Configuration +nav_order: 2 +--- + +# Configuration + +Add the integration under **Settings → Devices & Services → Add Integration → Advanced Device**. Each config entry is one plug and creates one device. + +Steps that do not apply are skipped. Without a power sensor, the power and shutdown-lock steps are not shown, and the auto-off and cycle-limit fields are hidden. + +## Add device (`user`) + +Add device dialog + +| Field | Required | Default | Notes | +|---|---|---|---| +| Name | yes | | Name of the new device. Also the name of the main switch. | +| Device profile | yes | Generic | Starting values for the following steps. See [Profiles](#profiles). | +| Plug switch | yes | | A `switch` entity. | +| Power sensor | no | | A `sensor` with device class `power`. Without it, only on and off are tracked. | +| Hide original switch | yes | on | Hides the plug's original switch. Restored when the entry is removed. | + +## Power thresholds (`power`, only with a power sensor) + +Power thresholds dialog + +| Field | Unit | Default | Meaning | +|---|---|---|---| +| Standby threshold | W | from profile | Below this power the device counts as standby once the standby duration is reached. Must not be above the running threshold. | +| Standby duration | s | from profile | How long the power must stay below the standby threshold. | +| Idle duration | s | from profile | How long the power must stay in the idle band before the status becomes `idle`. | +| Running threshold | W | from profile | Above this power the device counts as running once the running duration is reached. | +| Running duration | s | from profile | How long the power must stay above the running threshold. | +| Smoothing window | s | from profile | Moving average over this window. 0 uses the raw value. | + +Validation: the standby threshold must not be above the running threshold. + +## Shutdown lock (`protection`, only with a power sensor) + +Shutdown lock dialog + +| Field | Unit | Default | Meaning | +|---|---|---|---| +| Enable shutdown lock | | from profile | A switch-off waits until the device is in standby. | +| Action before switching off | | none | Optional. A `script`, `button` or `input_button` entity. It runs when a switch-off is requested, before waiting for standby. | +| Delay from standby to off | s | 0 | Extra wait after standby is reached. | +| Maximum wait | s | 0 | Longest time a switch-off waits for standby. 0 waits without limit. | +| Switch back on after external off | | off | See [Re-enable after external off](behaviour.md#re-enable-after-external-off). | +| Default expiry of one-time lock | min | 60 | Default duration of a one-time lock. 0 means no expiry: the lock ends only when a switch-off uses it up, or when it is turned off manually. | + +Validation: the shutdown lock needs a standby threshold above 0 W. + +## Extras (`extras`) + +Extras dialog + +| Field | Unit | Default | Meaning | +|---|---|---|---| +| Electricity price sensor | | none | Optional `sensor` or `input_number` with the price per kWh. Enables the last cycle cost sensor. | +| Auto-off after standby | min | from profile | Switches the plug off after this long in uninterrupted standby. 0 disables it. The washing machine, dryer and dishwasher profiles default to 0, because these appliances can wait in standby during a delayed start. | +| Maximum cycle duration | min | 0 | A longer cycle sets the problem sensor. 0 disables it. | +| Maintenance interval | operating hours | 0 | Reminder interval. 0 disables the reminder. | +| WashData device | | none | Only shown if `ha_washdata` is installed. See [WashData](behaviour.md#washdata). | +| Icon per status | | from profile | One icon for each of the eight statuses. | + +## Options and reconfigure + +- **Configure** (options flow) changes profile, hide-original, thresholds, shutdown lock, extras and icons. The steps are the same as above, prefilled with the stored values. + - Changing the profile alone only stores the new profile key. + - **Apply profile values to thresholds and protection** overwrites thresholds and the shutdown lock with the profile's values. It is off by default. +- **Reconfigure** changes the plug switch and the power sensor. The device is reloaded afterwards. + +## Profiles + +Profiles set starting values. All values can be changed afterwards. + +| Profile | Standby (W / s) | Idle (s) | Running (W / s) | Smoothing (s) | Min. cycle | Shutdown lock | Auto-off | +|---|---|---|---|---|---|---|---| +| Generic | 1.0 / 60 | 120 | 10.0 / 30 | 10 | 1 min | no | off | +| Washing machine | 2.5 / 300 | 600 | 15.0 / 60 | 30 | 10 min | yes | off | +| Dryer | 1.5 / 300 | 300 | 100.0 / 60 | 30 | 10 min | yes | off | +| Dishwasher | 1.0 / 300 | 300 | 30.0 / 60 | 30 | 15 min | yes | off | +| PC | 5.0 / 60 | 600 | 40.0 / 30 | 20 | 1 min | no | off | +| TV | 3.0 / 60 | 300 | 80.0 / 60 | 30 | 5 min | no | off | +| Printer | 1.0 / 120 | 300 | 20.0 / 10 | 5 | 30 s | no | 15 min | +| Coffee machine | 0.5 / 60 | 180 | 800.0 / 30 | 10 | 1 min | no | 30 min | + +Washing machine, dryer and dishwasher have auto-off off by default, because a delayed start looks like standby and would be cut off. + +The values are starting points based on typical consumption, not measurements. Measurements from real devices are welcome through the "Device profile" issue template. diff --git a/docs/entities.md b/docs/entities.md new file mode 100644 index 0000000..2ba39eb --- /dev/null +++ b/docs/entities.md @@ -0,0 +1,57 @@ +--- +title: Entities +nav_order: 3 +--- + +# Entities + +A configured device with a power sensor, shown with German entity names: + +Device page of a configured Advanced Device + +All entities belong to the device of the config entry. Entity IDs are derived from the device name. + +| Key | Platform | Condition | Notes | +|---|---|---|---| +| `main` | `switch` | always | Main switch, named after the device. Follows the plug, including during `shutting_down`. | +| `status` | `sensor` | always | Enum sensor with the states listed below. | +| `one_time_lock` | `switch` | always | One-time lock. | +| `one_time_lock_until` | `sensor` | always | Timestamp of the lock expiry. Empty when the lock is off or has no expiry. | +| `force_off` | `button` | always | Switches off now, ignoring the one-time lock. | +| `protection` | `switch` | power sensor | Shutdown lock (configuration category). | +| `shutdown_at` | `sensor` | power sensor | Timestamp of the planned shutdown. | +| `running` | `binary_sensor` | power sensor | On while a cycle is active. | +| `problem` | `binary_sensor` | power sensor | Device class `problem`. The reasons are in the `reasons` attribute. | +| `last_cycle_duration` | `sensor` | power sensor | Duration of the last cycle. | +| `last_cycle_energy` | `sensor` | power sensor | Energy of the last cycle. | +| `last_cycle_cost` | `sensor` | power sensor and price sensor | Cost of the last cycle. | +| `last_cycle_end` | `sensor` | power sensor | Timestamp of the end of the last cycle. | +| `cycles` | `sensor` | power sensor | Number of cycles (`total_increasing`). | +| `operating_hours` | `sensor` | always | Total operating hours (diagnostic). | +| `operating_hours_since_maintenance` | `sensor` | always | Operating hours since the last maintenance reset (diagnostic). | +| `maintenance_due` | `binary_sensor` | maintenance interval above 0 | On when the maintenance interval is reached. | +| `reset_maintenance` | `button` | maintenance interval above 0 | Resets the maintenance counter (configuration category). | +| `washdata_program` | `sensor` | WashData device | Mirrors the WashData program. | +| `washdata_time_remaining` | `sensor` | WashData device | Mirrors the WashData time remaining. | +| `washdata_progress` | `sensor` | WashData device | Mirrors the WashData progress. | + +Operating hours count the time in `running` when a power sensor is set. Without a power sensor, they count the time the plug is on. + +## Status values + +The `status` sensor reports one of these states. + +| State | Meaning | +|---|---| +| `off` | The plug is off. | +| `starting` | The plug is on, but the power has not been classified yet. | +| `on` | The plug is on and no standby threshold is used (no power sensor, or standby threshold 0). | +| `standby` | Smoothed power is below the standby threshold for at least the standby duration. | +| `idle` | Smoothed power is between the standby and running thresholds for at least the idle duration. | +| `running` | Smoothed power is at or above the running threshold for at least the running duration. | +| `shutting_down` | A switch-off was requested and is waiting for standby, the delay, or the pre-action. | +| `unavailable` | The plug switch is unavailable. | + +If the power sensor becomes unavailable, the status keeps its last value and the problem sensor reports `power_missing`. The integration does not switch the plug off on its own in this case: auto-off does not fire, and a pending shutdown is not completed until power data returns. A switch-off you request still follows the shutdown lock. If the lock is on, it waits for power data. + +If the plug switch becomes unavailable, the status is `unavailable`, but a running cycle is kept. When the plug is on again, the status comes from the power data. Switching the plug off ends the cycle, unless WashData owns the cycle. diff --git a/docs/events-actions.md b/docs/events-actions.md new file mode 100644 index 0000000..5cf2618 --- /dev/null +++ b/docs/events-actions.md @@ -0,0 +1,64 @@ +--- +title: Events and actions +nav_order: 4 +--- + +# Events and actions + +## Events + +Events are fired on the Home Assistant event bus. Every event contains these fields: + +| Field | Content | +|---|---| +| `entry_id` | Config entry ID. | +| `device_id` | Device registry ID. | +| `name` | Name of the device. | + +Additional fields per event: + +| Event | Additional fields | When | +|---|---|---| +| `advanced_device_cycle_started` | none | A cycle starts (transition to `running`). | +| `advanced_device_cycle_finished` | `duration_s`, `energy_kwh`, `cost` | A cycle ends. `cost` is empty without a price sensor. Cycles shorter than the profile's minimum duration are not counted. | +| `advanced_device_shutdown_blocked` | `reason`: `one_time_lock` or `external_off` | A switch-off was blocked by the one-time lock, or an external off was reversed. | +| `advanced_device_shutdown_aborted` | `reason`: `switch_failed` when the switch-off command failed; no `reason` field when the maximum wait was exceeded | A switch-off was cancelled. The plug stays on. | + +Example automation trigger: + +```yaml +trigger: + - platform: event + event_type: advanced_device_cycle_finished + event_data: + entry_id: 01J0EXAMPLE +``` + +## Actions + +All actions take a device target. Select Advanced Device devices in the UI, or pass `device_id` as a list. + +| Action | Fields | Effect | +|---|---|---| +| `advanced_device.force_off` | `device_id` (required) | Switches the plug off now, ignoring the one-time lock. Same as the **Force off** button. | +| `advanced_device.lock_shutdown` | `device_id` (required), `duration` (optional) | Blocks the next switch-off once. `duration` is a time period. If empty, the default expiry from the options is used. | +| `advanced_device.unlock_shutdown` | `device_id` (required) | Removes the one-time lock. | + +```yaml +action: advanced_device.lock_shutdown +target: + device_id: 0123456789abcdef +data: + duration: "00:30:00" +``` + +## Device triggers + +Device triggers are available under the device's **Automations** tab. + +| Trigger type | Available | Fires on | +|---|---|---| +| Cycle started | with a power sensor or WashData device | `advanced_device_cycle_started` event | +| Cycle finished | with a power sensor or WashData device | `advanced_device_cycle_finished` event | +| Shutdown blocked | always | `advanced_device_shutdown_blocked` event | +| Status changed | always | Change of the `status` sensor. Optional field **To status** limits it to one state. | diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..a936928 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,17 @@ +--- +title: Overview +nav_order: 1 +--- + +Advanced Device icon + +# Advanced Device + +Advanced Device turns a switchable plug with a power sensor into a Home Assistant device of its own, one for the appliance plugged into it. These pages explain the setup dialogs and what the integration creates and does afterwards. Installation and a short overview are in the [README on GitHub](https://github.com/Developer-Simon/ha-advanced-device#readme). + +| Page | Content | +|---|---| +| [Configuration](configuration.md) | The four setup dialogs with every field, options and reconfigure, device profiles | +| [Entities](entities.md) | Entities per device and the values of the status sensor | +| [Events and actions](events-actions.md) | Events on the event bus, actions and device triggers | +| [Behaviour](behaviour.md) | Switch-off sequence, locks, auto-off, persistence and the WashData link | diff --git a/docs/integration.md b/docs/integration.md deleted file mode 100644 index c4212c3..0000000 --- a/docs/integration.md +++ /dev/null @@ -1,234 +0,0 @@ -# Advanced Device: configuration, entities, events and actions - -Reference for the Advanced Device integration. For installation and an overview, see the [README](../README.md). - -## Configuration - -Add the integration under **Settings → Devices & Services → Add Integration → Advanced Device**. Each config entry is one plug and creates one device. - -Steps that do not apply are skipped. Without a power sensor, the power and shutdown-lock steps are not shown, and the auto-off and cycle-limit fields are hidden. - -### Add device (`user`) - -| Field | Required | Default | Notes | -|---|---|---|---| -| Name | yes | | Name of the new device. Also the name of the main switch. | -| Device profile | yes | Generic | Starting values for the following steps. See the profile table in the README. | -| Plug switch | yes | | A `switch` entity. | -| Power sensor | no | | A `sensor` with device class `power`. Without it, only on and off are tracked. | -| Hide original switch | yes | on | Hides the plug's original switch. Restored when the entry is removed. | - -### Power thresholds (`power`, only with a power sensor) - -| Field | Unit | Default | Meaning | -|---|---|---|---| -| Standby threshold | W | from profile | Below this power the device counts as standby once the standby duration is reached. Must not be above the running threshold. | -| Standby duration | s | from profile | How long the power must stay below the standby threshold. | -| Idle duration | s | from profile | How long the power must stay in the idle band before the status becomes `idle`. | -| Running threshold | W | from profile | Above this power the device counts as running once the running duration is reached. | -| Running duration | s | from profile | How long the power must stay above the running threshold. | -| Smoothing window | s | from profile | Moving average over this window. 0 uses the raw value. | - -Validation: the standby threshold must not be above the running threshold. - -### Shutdown lock (`protection`, only with a power sensor) - -| Field | Unit | Default | Meaning | -|---|---|---|---| -| Enable shutdown lock | | from profile | A switch-off waits until the device is in standby. | -| Action before switching off | | none | Optional. A `script`, `button` or `input_button` entity. It runs when a switch-off is requested, before waiting for standby. | -| Delay from standby to off | s | 0 | Extra wait after standby is reached. | -| Maximum wait | s | 0 | Longest time a switch-off waits for standby. 0 waits without limit. | -| Switch back on after external off | | off | See [Re-enable after external off](#re-enable-after-external-off). | -| Default expiry of one-time lock | min | 60 | Default duration of a one-time lock. 0 means no expiry: the lock ends only when a switch-off uses it up, or when it is turned off manually. | - -Validation: the shutdown lock needs a standby threshold above 0 W. - -### Extras (`extras`) - -| Field | Unit | Default | Meaning | -|---|---|---|---| -| Electricity price sensor | | none | Optional `sensor` or `input_number` with the price per kWh. Enables the last cycle cost sensor. | -| Auto-off after standby | min | from profile | Switches the plug off after this long in uninterrupted standby. 0 disables it. The washing machine, dryer and dishwasher profiles default to 0, because these appliances can wait in standby during a delayed start. | -| Maximum cycle duration | min | 0 | A longer cycle sets the problem sensor. 0 disables it. | -| Maintenance interval | operating hours | 0 | Reminder interval. 0 disables the reminder. | -| WashData device | | none | Only shown if `ha_washdata` is installed. See the README. | -| Icon per status | | from profile | One icon for each of the eight statuses. | - -## Options and reconfigure - -- **Configure** (options flow) changes profile, hide-original, thresholds, shutdown lock, extras and icons. The steps are the same as above, prefilled with the stored values. - - Changing the profile alone only stores the new profile key. - - **Apply profile values to thresholds and protection** overwrites thresholds and the shutdown lock with the profile's values. It is off by default. -- **Reconfigure** changes the plug switch and the power sensor. The device is reloaded afterwards. - -## Entities - -All entities belong to the device of the config entry. Entity IDs are derived from the device name. - -| Key | Platform | Condition | Notes | -|---|---|---|---| -| `main` | `switch` | always | Main switch, named after the device. Follows the plug, including during `shutting_down`. | -| `status` | `sensor` | always | Enum sensor with the states listed below. | -| `one_time_lock` | `switch` | always | One-time lock. | -| `one_time_lock_until` | `sensor` | always | Timestamp of the lock expiry. Empty when the lock is off or has no expiry. | -| `force_off` | `button` | always | Switches off now, ignoring the one-time lock. | -| `protection` | `switch` | power sensor | Shutdown lock (configuration category). | -| `shutdown_at` | `sensor` | power sensor | Timestamp of the planned shutdown. | -| `running` | `binary_sensor` | power sensor | On while a cycle is active. | -| `problem` | `binary_sensor` | power sensor | Device class `problem`. The reasons are in the `reasons` attribute. | -| `last_cycle_duration` | `sensor` | power sensor | Duration of the last cycle. | -| `last_cycle_energy` | `sensor` | power sensor | Energy of the last cycle. | -| `last_cycle_cost` | `sensor` | power sensor and price sensor | Cost of the last cycle. | -| `last_cycle_end` | `sensor` | power sensor | Timestamp of the end of the last cycle. | -| `cycles` | `sensor` | power sensor | Number of cycles (`total_increasing`). | -| `operating_hours` | `sensor` | always | Total operating hours (diagnostic). | -| `operating_hours_since_maintenance` | `sensor` | always | Operating hours since the last maintenance reset (diagnostic). | -| `maintenance_due` | `binary_sensor` | maintenance interval above 0 | On when the maintenance interval is reached. | -| `reset_maintenance` | `button` | maintenance interval above 0 | Resets the maintenance counter (configuration category). | -| `washdata_program` | `sensor` | WashData device | Mirrors the WashData program. | -| `washdata_time_remaining` | `sensor` | WashData device | Mirrors the WashData time remaining. | -| `washdata_progress` | `sensor` | WashData device | Mirrors the WashData progress. | - -Operating hours count the time in `running` when a power sensor is set. Without a power sensor, they count the time the plug is on. - -## Status values - -The `status` sensor reports one of these states. - -| State | Meaning | -|---|---| -| `off` | The plug is off. | -| `starting` | The plug is on, but the power has not been classified yet. | -| `on` | The plug is on and no standby threshold is used (no power sensor, or standby threshold 0). | -| `standby` | Smoothed power is below the standby threshold for at least the standby duration. | -| `idle` | Smoothed power is between the standby and running thresholds for at least the idle duration. | -| `running` | Smoothed power is at or above the running threshold for at least the running duration. | -| `shutting_down` | A switch-off was requested and is waiting for standby, the delay, or the pre-action. | -| `unavailable` | The plug switch is unavailable. | - -If the power sensor becomes unavailable, the status keeps its last value and the problem sensor reports `power_missing`. The integration does not switch the plug off on its own in this case: auto-off does not fire, and a pending shutdown is not completed until power data returns. A switch-off you request still follows the shutdown lock. If the lock is on, it waits for power data. - -If the plug switch becomes unavailable, the status is `unavailable`, but a running cycle is kept. When the plug is on again, the status comes from the power data. Switching the plug off ends the cycle, unless WashData owns the cycle. - -## Events - -Events are fired on the Home Assistant event bus. Every event contains these fields: - -| Field | Content | -|---|---| -| `entry_id` | Config entry ID. | -| `device_id` | Device registry ID. | -| `name` | Name of the device. | - -Additional fields per event: - -| Event | Additional fields | When | -|---|---|---| -| `advanced_device_cycle_started` | none | A cycle starts (transition to `running`). | -| `advanced_device_cycle_finished` | `duration_s`, `energy_kwh`, `cost` | A cycle ends. `cost` is empty without a price sensor. Cycles shorter than the profile's minimum duration are not counted. | -| `advanced_device_shutdown_blocked` | `reason`: `one_time_lock` or `external_off` | A switch-off was blocked by the one-time lock, or an external off was reversed. | -| `advanced_device_shutdown_aborted` | `reason`: `switch_failed` when the switch-off command failed; no `reason` field when the maximum wait was exceeded | A switch-off was cancelled. The plug stays on. | - -Example automation trigger: - -```yaml -trigger: - - platform: event - event_type: advanced_device_cycle_finished - event_data: - entry_id: 01J0EXAMPLE -``` - -## Actions - -All actions take a device target. Select Advanced Device devices in the UI, or pass `device_id` as a list. - -| Action | Fields | Effect | -|---|---|---| -| `advanced_device.force_off` | `device_id` (required) | Switches the plug off now, ignoring the one-time lock. Same as the **Force off** button. | -| `advanced_device.lock_shutdown` | `device_id` (required), `duration` (optional) | Blocks the next switch-off once. `duration` is a time period. If empty, the default expiry from the options is used. | -| `advanced_device.unlock_shutdown` | `device_id` (required) | Removes the one-time lock. | - -```yaml -action: advanced_device.lock_shutdown -target: - device_id: 0123456789abcdef -data: - duration: "00:30:00" -``` - -## Device triggers - -Device triggers are available under the device's **Automations** tab. - -| Trigger type | Available | Fires on | -|---|---|---| -| Cycle started | with a power sensor or WashData device | `advanced_device_cycle_started` event | -| Cycle finished | with a power sensor or WashData device | `advanced_device_cycle_finished` event | -| Shutdown blocked | always | `advanced_device_shutdown_blocked` event | -| Status changed | always | Change of the `status` sensor. Optional field **To status** limits it to one state. | - -## Behaviour - -### Switch-off sequence - -A switch-off from the main switch or the auto-off is handled in this order: - -1. **One-time lock active:** the switch-off is discarded and the lock is used up. The plug stays on, and `advanced_device_shutdown_blocked` fires with `reason: one_time_lock`. -2. **Shutdown lock off:** the plug switches off immediately. -3. **Shutdown lock on and status `standby`:** the plug switches off after the delay. -4. **Shutdown lock on, any other status:** the status becomes `shutting_down`. The pre-action runs, and the integration waits for `standby`. Then it waits for the delay and switches off. - - If the maximum wait is exceeded, the plug is **not** switched off. The shutdown is cancelled, the status returns to the value derived from the power, and `advanced_device_shutdown_aborted` fires. - -The **Force off** button and the `force_off` action do not go through this sequence. They switch the plug off at once, ignore the one-time lock and the shutdown lock, and remove an active lock. - -Switching the main switch on during `shutting_down` cancels the shutdown. - -### Re-enable after external off - -If the plug is switched off by something other than this integration (a physical button, another integration) while the device is `running`, the shutdown lock is on, and **Switch back on after external off** is enabled, the integration switches the plug back on. This happens at most three times. `advanced_device_shutdown_blocked` fires with `reason: external_off`. - -An external off while WashData reports `paused` or `user_paused` is tolerated and not reversed. - -### One-time lock - -- Turning on the **One-time lock** switch, or calling `lock_shutdown`, arms the lock. The switch uses the default expiry from the options. -- The lock ends at the first switch-off it blocks, at its expiry, when the switch is turned off manually, or when `unlock_shutdown` is called, whichever happens first. -- The lock does not block **Force off**. -- Expiry is stored. A lock whose expiry passed while Home Assistant was stopped is off after the restart. - -### Auto-off - -After the configured time in uninterrupted `standby`, the integration switches the plug off through the normal switch-off path. The one-time lock and the shutdown lock are respected. - -### Problem sensor - -The problem sensor reports these reasons in its `reasons` attribute: - -- `power_missing`: the plug is on and the power sensor is unavailable. -- `cycle_too_long`: the running cycle exceeds the maximum cycle duration. - -### Safety principle - -The integration must not switch a device off unexpectedly. If the state is unclear (missing power data, unavailable sensor, restart during a pending shutdown), the plug stays on. A pending shutdown is discarded on restart. - -### Persistence - -Cycle counter, operating hours, maintenance counter, last cycle values and the one-time lock expiry are stored with Home Assistant's storage helper. They survive restarts. - -Without WashData, a running cycle is stored too, with its start time and the energy up to the last update. After a restart the cycle continues with its original start, and no new cycle starts. The downtime counts towards the duration: if the cycle ends soon after the restart, `duration_s` is measured from the original start. Energy from the last seconds before the restart may be missing. With WashData linked, no cycle is stored, and the cycle state comes from WashData again after a restart. - -### Removing the entry - -When the config entry is removed, the original switch is shown again, but only if it is still hidden by this integration. A switch that you hid yourself stays hidden. - -## WashData - -See the [WashData section in the README](../README.md#washdata). In short: - -- Cycle events and cycle sensors come from WashData when a WashData device is linked. -- The shutdown lock is released only in WashData states `finished`, `clean`, `off` and `idle`. -- Use the original plug switch, not the Advanced Device switch, as WashData's pause/resume switch. -- A linked WashData entry that is not loaded when the device is set up is not used: the device uses its own cycle logic and shows a repair issue. This includes a WashData entry that is still retrying its setup when Home Assistant starts. After WashData is loaded, reload the Advanced Device entry or restart Home Assistant. -- To remove a stale link, open the options and save the **Extras** step.