Skip to content

Instantly share code, notes, and snippets.

@ebith

ebith/.env

Created Apr 5, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.