https://github.com/aldaviva/poweroverinternet
🌩️ Turn on and off power to an electrical outlet using an HTTP API request
https://github.com/aldaviva/poweroverinternet
home-automation smart-outlets smart-plug smarthome smartplug
Last synced: 3 months ago
JSON representation
🌩️ Turn on and off power to an electrical outlet using an HTTP API request
- Host: GitHub
- URL: https://github.com/aldaviva/poweroverinternet
- Owner: Aldaviva
- License: apache-2.0
- Created: 2022-06-04T08:22:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T01:33:31.000Z (over 1 year ago)
- Last Synced: 2025-03-24T07:08:33.464Z (3 months ago)
- Topics: home-automation, smart-outlets, smart-plug, smarthome, smartplug
- Language: C#
- Homepage:
- Size: 385 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: License.txt
Awesome Lists containing this project
README
🌩️ PowerOverInternet
===[](https://github.com/Aldaviva/PowerOverInternet/actions/workflows/dotnet.yml) [](https://aldaviva.testspace.com/spaces/192613) [](https://coveralls.io/github/Aldaviva/PowerOverInternet?branch=master)
*Web service with an HTTP API for turning smart power outlets on and off*
1. [Prerequisites](#prerequisites)
1. [Installation](#installation)
1. [Usage](#usage)
1. [API Reference](#api-reference)- [ASP.NET Core Runtime 6 or later](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
- [Kasa smart outlet](https://www.kasasmart.com/us/products/smart-plugs)
- Verified with [EP10](https://www.kasasmart.com/us/products/smart-plugs/kasa-smart-plug-mini-ep10) and [KP125](https://www.kasasmart.com/us/products/smart-plugs/kasa-smart-plug-slim-energy-monitoring-kp125)
- Probably [compatible](https://github.com/Aldaviva/Kasa#prerequisites) with most other modelsFor 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](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/?view=aspnetcore-6.0).
### IIS
1. Install the [.NET Core Hosting Bundle](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-6.0) for IIS.
1. Copy the build files from the [latest release of this project](https://github.com/Aldaviva/PowerOverInternet/releases/latest) to a folder on your server.
1. In IIS Manager, add a new Website to your server's Sites.
1. Choose a name and binding for the site.
1. Choose that folder as the site's physical path.For more information, refer to [Host ASP.NET Core on Windows with IIS](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-6.0) and [Publish an ASP.NET Core app to IIS](https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-6.0&tabs=netcore-cli).

### Standalone
1. Copy the build files from the [latest release of this project](https://github.com/Aldaviva/PowerOverInternet/releases/latest) to a folder on your server.
1. In that folder, run `PowerOverInternet.exe`.```ps1
> .\PowerOverInternet.exeinfo: 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\
```### Turn on an outlet
```http
PUT /power?outletHostname=192.168.1.100&turnOn=true
Host: myserver.com
```### Turn off an outlet
```http
PUT /power?outletHostname=192.168.1.100&turnOn=false
Host: myserver.com
```### Turn off an outlet after 30 seconds
```http
PUT /power?outletHostname=192.168.1.100&turnOn=false&delaySec=30
Host: myserver.com
```### Shut down and power off Cisco endpoint using macro
This [Cisco macro](https://gist.github.com/Aldaviva/bccd766099e2d7807da086feacf2c18a#file-shutdown-button-js-L22) cuts power to the endpoint after a confirmation prompt and a 33 second graceful shutdown delay.
```js
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
}, "");
```### Phone charger control
This [Automate](https://llamalab.com/automate/) flow turns off a phone charger when the phone is ≥80% charged, and turns it back on when it's ≤20% charged.
[**Download flow**](.github/files/charging-limiter.flo)
This flow requires the [Automate legacy extension](https://llamalab.com/automate/doc/extensions.html) 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.
### `PUT /power`
|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`](https://nmap.org/) 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.