Skip to content

Repository files navigation

Windows Shutdown — Home Assistant Integration

hacs_badge GitHub release License: MIT Quality Scale: Gold

Control your Windows computer directly from Home Assistant. Shut it down, restart it, or log off — with a button, an automation, or a service call.


Features

  • Shut down, restart, or log off via a button in the HA interface
  • Online status sensor — always know if your PC is reachable
  • Automatic discovery via mDNS/Zeroconf — no need to look up IP addresses
  • Configurable delay — the PC waits a specified number of seconds before shutting down
  • Service call — send a shutdown command from an automation
  • Diagnostics — downloadable debug information for troubleshooting
  • Reauth flow — renew the API key without reinstalling the integration

Requirements

The agent is a small application that runs in the system tray and exposes a local HTTP API. Home Assistant communicates exclusively over your local network — nothing goes through the internet.


Installation via HACS

  1. Open HACS in Home Assistant
  2. Go to Integrations → click the menu in the top right → Custom repositories
  3. Add: https://github.com/donserdal/ha-windows-shutdown — category Integration
  4. Search for Windows Shutdown and click Download
  5. Restart Home Assistant

Manual Installation

  1. Download the latest release
  2. Copy the custom_components/windows_shutdown folder to your HA configuration directory
  3. Restart Home Assistant

Setup

Automatic (recommended)

If the agent is running on the same network and mDNS is enabled, Home Assistant will automatically detect the computer. You will receive a notification in the Home Assistant interface.

Manual

  1. Go to Settings → Devices & Services → Add Integration
  2. Search for Windows Shutdown
  3. Choose Manual entry and fill in the IP address and port
  4. Enter the API key generated by the agent

You can find the API key via the agent's system tray icon → Show connection info.


Entities

Entity Type Description
button.windows_pc_shut_down Button Sends the shutdown command to the PC
binary_sensor.windows_pc Binary sensor on if the PC is online, off if it is offline

The button is only available when the PC is online.


Per-device Settings

Via the Configure button (gear icon next to the integration), you can configure per device:

Setting Default Description
Delay 60 seconds How many seconds the PC waits before shutting down
Action type shutdown Choose between shutdown, restart, or logoff

Service: windows_shutdown.shutdown

Use this service in automations to target a specific PC (or all PCs).

action: windows_shutdown.shutdown
data:
  shutdown_type: shutdown   # shutdown | restart | logoff
  delay: 30                 # seconds (optional, default: 60)
  entry_id: abc123          # optional — leave empty for all devices

Example: automatic shutdown at 23:00

automation:
  alias: "Shut down PC at 23:00"
  trigger:
    - platform: time
      at: "23:00:00"
  action:
    - action: windows_shutdown.shutdown
      data:
        shutdown_type: shutdown
        delay: 60

Example: restart after an update

automation:
  alias: "Restart PC after Windows Update"
  trigger:
    - platform: state
      entity_id: binary_sensor.windows_update_pending
      to: "on"
  condition:
    - condition: time
      after: "02:00:00"
      before: "06:00:00"
  action:
    - action: windows_shutdown.shutdown
      data:
        shutdown_type: restart
        delay: 10

How does data updating work?

The integration polls the agent every 30 seconds via GET /status. If the PC is offline, a grace period of 30 seconds is observed to prevent temporary connection interruptions from causing state changes (anti-flapping).

Upon receiving a 401 or 403 response, Home Assistant automatically starts the reauthentication flow.


Troubleshooting

The button is greyed out (unavailable)

  • The PC is offline or unreachable on the network
  • Check that the agent is running (system tray icon)
  • Check that port 8765 is not blocked by a firewall

Cannot set up the integration — connection error

  • Verify the IP address and port
  • Ensure the agent is running and that HA is on the same network

Invalid API key

  • Open the integration → click Reauthenticate and enter the correct key
  • Find the key via the agent's system tray icon

Download diagnostics

  • Go to the integration page → click the device → Download diagnostics
  • Attach the download to a bug report

Contributing

Pull requests are welcome. Please open an issue first to discuss the change.


Licentie

MIT

Releases

Packages

Contributors

Languages