Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 28 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<img src="https://raw.githubusercontent.com/Developer-Simon/ha-advanced-device/main/custom_components/advanced_device/brand/icon.png" alt="Advanced Device icon" width="88" align="right">
<img src="https://raw.githubusercontent.com/Developer-Simon/ha-advanced-device/main/custom_components/advanced_device/brand/icon.png" alt="Advanced Device icon" width="96" align="right">

# 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.
<img src="https://raw.githubusercontent.com/Developer-Simon/ha-advanced-device/main/docs/assets/AddDeviceDialog.png" alt="Add device dialog in Home Assistant" width="380">

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:

<img src="https://raw.githubusercontent.com/Developer-Simon/ha-advanced-device/main/docs/assets/ConfiguredDevice.png" alt="Device page of a configured Advanced Device" width="640">

## Installation

Expand All @@ -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

Expand Down
Binary file modified custom_components/advanced_device/brand/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 11 additions & 7 deletions custom_components/advanced_device/brand/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified custom_components/advanced_device/brand/icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file added docs/assets/AddDeviceDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/ConfiguredDevice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/ExtrasDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/PowerThresholdDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/ShutdownLockDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions docs/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions docs/behaviour.md
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading