Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ebith
Created April 5, 2019 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebith/24162f87189d3325422e1c0e8834d9ad to your computer and use it in GitHub Desktop.
Save ebith/24162f87189d3325422e1c0e8834d9ad to your computer and use it in GitHub Desktop.
OctoPrintとスマートプラグをオンオフするスクリプト
PLUG_HOST=192.168.0.30
OCTOPI_HOST=octopi.local
API_KEY=
{
"name": "3dPrinter",
"version": "0.1.0",
"main": "index.js",
"author": "ebith",
"license": "MIT",
"private": true,
"dependencies": {
"dotenv": "^7.0.0",
"httpie": "^1.1.1",
"tplink-smarthome-api": "^1.2.0"
},
"xo": {
"space": true,
"prettier": true,
"rules": {
"capitalized-comments": 0
},
"env": [
"node"
]
},
"prettier": {
"printWidth": 120
}
}
require('dotenv').config();
const {post} = require('httpie');
const tpLink = new (require('tplink-smarthome-api')).Client();
(async () => {
const plug = tpLink.getPlug({host: process.env.PLUG_HOST});
const response = await post(`http://${process.env.OCTOPI_HOST}/api/system/commands/core/shutdown`, {
headers: {'X-Api-Key': process.env.API_KEY}
});
setTimeout(async () => {
await plug.setPowerState(false);
}, 30 * 1000);
})();
require('dotenv').config();
const tpLink = new (require('tplink-smarthome-api')).Client();
(async () => {
const plug = tpLink.getPlug({host: process.env.PLUG_HOST});
await plug.setPowerState(true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment