Skip to content

🌩️ Turn on and off power to an electrical outlet using an HTTP API request

License

Notifications You must be signed in to change notification settings

Aldaviva/PowerOverInternet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

🌩️ PowerOverInternet

GitHub Actions Testspace Coveralls

Web service with an HTTP API for turning smart power outlets on and off

  1. Prerequisites
  2. Installation
  3. Usage
  4. API Reference

Prerequisites

Installation

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.

IIS

  1. Install the .NET Core Hosting Bundle for IIS.
  2. Copy the build files from the latest release of this project to a folder on your server.
  3. In IIS Manager, add a new Website to your server's Sites.
  4. Choose a name and binding for the site.
  5. 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.

Add Website

Standalone

  1. Copy the build files from the latest release of this project to a folder on your server.
  2. 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\

Usage

Turn on an outlet

PUT /power?outletHostname=192.168.1.100&turnOn=true
Host: myserver.com

Turn off an outlet

PUT /power?outletHostname=192.168.1.100&turnOn=false
Host: myserver.com

Turn off an outlet after 30 seconds

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 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
}, "");

Phone charger control

This 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

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.

Automate flow

API Reference

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 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.

About

🌩️ Turn on and off power to an electrical outlet using an HTTP API request

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

Languages