Zum Hauptinhalt springen

Shutdown PC Smart-Home-Integration, kostenlos und Open Source

Shutdown PC-Integration für Gladys Assistant

Shut down your Windows and Linux computers over SSH from a dashboard or a scene.

Info

Die Dokumentation dieser Integration wird von ihrem Autor geschrieben und ist bisher nur auf Englisch verfügbar.

Shut down your Windows and Linux computers from Gladys: a button on the dashboard, a dedicated widget or a scene action ("shut the office PC down at 11 pm", "turn everything off when I leave"…).

The integration connects to the computer over SSH and runs the shutdown command. Nothing to install: the SSH server is built into Windows 10 and 11, and available on every Linux distribution.

1. Prepare the computer​

Give the computer a fixed IP address (a DHCP reservation in your router): the integration reaches it at that address.

Windows 10 / 11​

Open PowerShell as administrator and run:

## Install and start the SSH server, at every Windows startup too
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

## Check that the firewall lets port 22 in (rule created by the install)
Get-NetFirewallRule -Name *OpenSSH-Server* | Select-Object Name, Enabled

Use an administrator account of the computer. With a Microsoft account, the user is the name of the C:\Users\<name> folder and the password is the Microsoft account password (not the PIN).

Linux​

sudo apt install openssh-server # or your distribution's equivalent

Unless you use root, allow the chosen user (here john) to power the machine off without a password, and nothing else:

echo "john ALL=(root) NOPASSWD: $(command -v systemctl) poweroff" | sudo tee /etc/sudoers.d/gladys-shutdown
sudo chmod 440 /etc/sudoers.d/gladys-shutdown

2. Choose the authentication​

Public key (recommended). The integration generates its own SSH key. Click Show the public key in the Configuration tab and copy the ssh-ed25519 … gladys-shutdown-pc line to the computer. No password of the computer is stored in Gladys then.

  • Windows, administrator account: the key goes into a file shared by every administrator, which must be protected (PowerShell as administrator):

    Add-Content -Force -Path "$env:ProgramData\ssh\administrators_authorized_keys" -Value 'ssh-ed25519 AAAA… gladys-shutdown-pc'
    icacls.exe "$env:ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "*S-1-5-32-544:F" /grant "*S-1-5-18:F"
  • Linux: add the line to the user's ~/.ssh/authorized_keys.

Password. Just enter the account password when adding the computer. It is stored in the integration's data volume, readable by the integration only, and never sent back to the interface. With a password set, the key is still tried first.

3. Add the computers​

In the integration's Configuration tab:

  1. Add a computer: name, IP address or host name, SSH port (22), user, system, optional password. The integration saves the computer, then tests the connection right away (without shutting it down) and shows the result.
  2. Open the Discovery tab and create the device in a room.
  3. Repeat for every computer.

Options:

  • Force applications to close (Windows, on by default): otherwise an unsaved document can block the shutdown.
  • Custom command: replaces the default command, e.g. shutdown /h to hibernate on Windows, or sudo -n systemctl suspend on Linux (with the matching sudoers rule).

The other buttons:

  • Test the connection: connects to the chosen computer and checks the rights, without shutting it down. On Linux it also checks the sudoers rule.
  • Edit a computer: enter all the values again. Leave the password empty to keep the current one, or tick Remove the stored password to switch to the key only. Rename the device in Gladys itself.
  • Remove a computer: delete its device in Gladys, the integration forgets it at once.

The SSH connection timeout setting is how long to wait for a computer (10 s by default).

4. Shut down​

  • Dashboard: every computer is a device with a Shut down button, shown in its room's widget.
  • "Shutdown PC" widget: add it to a dashboard and choose the computer in its settings. It shows whether the computer is reachable and offers a Shut down button that asks for confirmation.
  • Scenes (Integrations category): the Shut down a computer action returns success (true/false), which the following actions can test. The standard "Control devices" action on the computer's button works too.

Security​

  • On the first successful connection, the integration remembers the fingerprint of the computer's host key. It then refuses to connect to a machine presenting another key (IP address spoofing). After reinstalling the computer, use Edit a computer to trust it again.
  • Neither the passwords nor the private key ever appear in the logs.

Troubleshooting​

MessageWhat to do
no answerThe computer is off or asleep, or sshd is not running (Get-Service sshd).
unreachableCheck the IP address, the port and the computer's firewall.
authentication refusedCheck the user and the password, or the public key and the rights of administrators_authorized_keys (the icacls command).
sudo asks for a passwordAdd the sudoers rule of step 1.
the SSH host key changedWas the computer reinstalled? Use Edit a computer. Otherwise, be careful.
the command failed (exit code 5)"Access is denied" on Windows: use an administrator account.

The integration logs (Gladys interface or docker logs) detail every attempt.

Konfigurationseinstellungen​

Diese Einstellungen fragt Shutdown PC in seinem Konfigurationsbildschirm in Gladys ab.

EinstellungTypPflichtfeldBeschreibung
Getting startedsectionNeinEnable the SSH server on each computer (built into Windows 10 and 11), then add the computers with the buttons below and create them from the Discovery tab. Each computer becomes a device with a "Shut down" button.
SSH connection timeout (s)numberNeinHow long to wait for a computer before giving up.

So installierst du Shutdown PC in Gladys​

  1. Öffne in Gladys Integrationen: Shutdown PC erscheint im Katalog neben den nativen Integrationen, mit einem Community-Badge.
  2. Klicke auf Installieren. Gladys lädt das Docker-Image (ghcr.io/luckys7evin/gladys-shutdown-pc:2.0.1) herunter, startet es in einer vom Kern isolierten Sandbox und erzeugt die Oberfläche der Integration (Geräte, Erkennung und Konfiguration).
  3. Öffne den Bildschirm Konfiguration der Integration, fülle die Einstellungen aus und speichere.
  4. Du kannst sie auch direkt über die URL ihres Repositorys installieren: https://github.com/LuckyS7evin/gladys-shutdown-pc.

Shutdown PC benötigt Gladys >=5.1.0. Der Katalog in Gladys wird stündlich aktualisiert, eine neue Version ist also spätestens eine Stunde nach ihrer Veröffentlichung verfügbar.

Du nutzt Gladys noch nicht? Es ist kostenlos und Open Source: folge der Installationsanleitung, um loszulegen.

Über externe Integrationen​

Shutdown PC ist eine externe Integration: eine Community-Integration, die als Docker-Container verpackt und auf GitHub veröffentlicht wird. Gladys installiert sie mit einem Klick und führt sie in einer vom Kern isolierten Sandbox aus. Sie wird von LuckyS7evin veröffentlicht und gepflegt, nicht vom Gladys-Kernteam.

Abonniere den Newsletter von Gladys Assistant

Ein paar E-Mails im Monat zu neuen Releases und Neuigkeiten aus dem Projekt. Verschickt von Pierre-Gilles Leymarie, dem Gründer des Projekts. Jederzeit abbestellbar 🙂