-
-
Save ebith/24162f87189d3325422e1c0e8834d9ad to your computer and use it in GitHub Desktop.
OctoPrintとスマートプラグをオンオフするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLUG_HOST=192.168.0.30 | |
OCTOPI_HOST=octopi.local | |
API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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