Web service with an HTTP API for turning smart power outlets on and off
- ASP.NET Core Runtime 6 or later
- Kasa smart outlet
- Verified with EP10 and KP125
- Probably compatible with most other models
For additional hosting and deployment scenarios not covered in this section, such as HTTP.sys
and Windows services, refer to Host and deploy ASP.NET Core.
- Install the .NET Core Hosting Bundle for IIS.
- Copy the build files from the latest release of this project to a folder on your server.
- In IIS Manager, add a new Website to your server's Sites.
- Choose a name and binding for the site.
- Choose that folder as the site's physical path.
For more information, refer to Host ASP.NET Core on Windows with IIS and Publish an ASP.NET Core app to IIS.
- Copy the build files from the latest release of this project to a folder on your server.
- In that folder, run
PowerOverInternet.exe
.
> .\PowerOverInternet.exe
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Program Files\PowerOverInternet\
PUT /power?outletHostname=192.168.1.100&turnOn=true
Host: myserver.com
PUT /power?outletHostname=192.168.1.100&turnOn=false
Host: myserver.com
PUT /power?outletHostname=192.168.1.100&turnOn=false&delaySec=30
Host: myserver.com
This Cisco macro cuts power to the endpoint after a confirmation prompt and a 33 second graceful shutdown delay.
await xapi.Command.HttpClient.Put({
Url: "https://thor.aldaviva.com:8444/power?outletHostname=sx20.outlets.aldaviva.com&turnOn=false&delaySec=33" //it takes the SX20 about 28 seconds to shut down
}, "");
This Automate flow turns off a phone charger when the phone is ≥80% charged, and turns it back on when it's ≤20% charged.
This flow requires the Automate legacy extension app to be installed so that it can show the battery percentage in the status bar while it's charging, and hide it when it's discharging.
Parameter | Required | Location | Example | Description |
---|---|---|---|---|
outletHostname |
🛑 required | ❔ query | 192.168.1.100 |
The IP address or FQDN of your smart outlet, visible in router DHCP list or nmap scan. |
turnOn |
🛑 required | ❔ query | true |
true to turn the outlet on, or false to turn it off. |
delaySec |
🟢 optional | ❔ query | 30 |
Number of seconds to wait after receiving the request before changing the outlet's power state. Defaults to 0 if omitted. |
Response status: 204 No Content
The response is sent immediately, not after waiting for delaySec
seconds.