This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 857d37f
Showing
10 changed files
with
844 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.{md,asciidoc}] | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.DS_Store | ||
node_modules/ | ||
/dist/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
/test/unit/coverage/ | ||
/test/e2e/reports/ | ||
selenium-debug.log | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Sergio Luis Scarnatto | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# node-red-contrib-tplink-smarthome | ||
|
||
TP-Link Smart Home is a collection of node-red nodes that allow you control smart plugs and bulbs from the TP-Link smart home ecosystem. | ||
|
||
Under the hood, each node uses the awesome https://github.com/plasticrake/tplink-smarthome-api API library. | ||
|
||
# Installation | ||
|
||
Run the following command in the root directory of your Node-RED install | ||
|
||
`$ npm install node-red-contrib-tplink-smarthome` | ||
|
||
or you can use the Palette Manager in Node-RED. | ||
|
||
# Parameters | ||
|
||
Name: Type in the name of the host manually or keep the default device name | ||
|
||
Device IP: Type in the Device IP address manually or press the button to retreive all locally available plug devices | ||
|
||
Poll interval: Interval that is used to poll active nodes for changes (min 500ms / recommended between 3000ms and 5000ms) | ||
|
||
# Inputs | ||
|
||
## payload: string | boolean | ||
|
||
### On/Off | ||
|
||
true: Turn on the device. | ||
|
||
false: Turn off the device. | ||
|
||
### Commands | ||
|
||
getInfo: Fetch the device information. | ||
|
||
getMeterInfo: Fetch the current device consumption. | ||
|
||
clearEvents: Unsubscribe events. | ||
|
||
eraseStats: Clear all the meter statistics. | ||
|
||
### Events | ||
|
||
getMeterEvents: Subscribe to meter information events. | ||
|
||
getInfoEvents: Subscribe to information events. | ||
|
||
getPowerUpdateEvents: Subscribe to power on/off events. | ||
|
||
getInUseEvents: Subscribe to device usage events. | ||
|
||
getOnlineEvents: Subscribe to online/offline events. | ||
|
||
Multiple events can be used as a list separated with the `|` character. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "node-red-contrib-tplink-smarthome", | ||
"version": "0.0.1", | ||
"description": "A collection of node-red nodes for tp-link smart home devices", | ||
"author": "Sergio Scarnatto", | ||
"license": "MIT", | ||
"node-red": { | ||
"nodes": { | ||
"smart-plug": "smart-plug.js", | ||
"smart-bulb": "smart-bulb.js" | ||
} | ||
}, | ||
"keywords": [ | ||
"node-red", | ||
"tplink", | ||
"tp-link", | ||
"kasa", | ||
"iot", | ||
"hs100", | ||
"hs105", | ||
"hs110", | ||
"hs200", | ||
"lb100", | ||
"lb110", | ||
"lb120", | ||
"lb130", | ||
"home", | ||
"smart", | ||
"smartplug", | ||
"smartswitch", | ||
"smartbulb" | ||
], | ||
"dependencies": { | ||
"moment": "^2.20.1", | ||
"numeral": "^2.0.6", | ||
"tplink-smarthome-api": "^0.20.1" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": {}, | ||
"engines": { | ||
"node": ">=4.8.0", | ||
"npm": ">=3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('smart-bulb', { | ||
category: 'output', | ||
color: '#FFF0F0', | ||
defaults: { | ||
name: { value: '' }, | ||
device: { value: '', required: true}, | ||
interval: { | ||
value: 5000, | ||
required: true, | ||
validate: function(v) { | ||
return (/^[0-9]+/.test(v) && parseInt(v,10) >= 500); | ||
} | ||
} | ||
}, | ||
inputs: 1, | ||
outputs: 1, | ||
icon: 'icon.png', | ||
align: 'right', | ||
paletteLabel: 'smart bulb', | ||
label: function () { | ||
return this.name || 'smart_bulb'; | ||
}, | ||
oneditprepare: function() { | ||
function manualDeviceIP () { | ||
var current = $('#node-input-device').val(); | ||
$('#node-input-device').replaceWith('<input type="text" id="node-input-device" style="width: 60%;"/>'); | ||
$('#node-input-device').val(current); | ||
} | ||
|
||
function searchAndSelectDevice() { | ||
var current = $('#node-input-device').val(); | ||
$('#node-input-device').replaceWith('<select id="node-input-device" style="width: 60%;"></select>'); | ||
$('#node-input-device').append('<option selected="selected" value="null">searching…</option>'); | ||
|
||
$.get('smarthome/bulbs') | ||
.done( function(data) { | ||
var devices = JSON.parse(data); | ||
|
||
if(devices.length <= 0) { | ||
RED.notify("No TP-Link smart bulb found.", "error"); | ||
} | ||
|
||
// reset options | ||
$('#node-input-device').empty(); | ||
|
||
// Set devices as options | ||
devices.forEach(function(ip) { | ||
$('#node-input-device').append('<option value="' + ip + '">' + ip + '</option>'); | ||
}); | ||
|
||
// select current value | ||
$('#node-input-device').val(current); | ||
}) | ||
.fail(function() { | ||
RED.notify("Something went wrong. Please retry.", "error"); | ||
}); | ||
} | ||
|
||
$(document).on('change', '#node-input-device', function() { | ||
var currentDeviceIP = $('#node-input-device').val(); | ||
if(currentDeviceIP.length > 6) { | ||
$.get('smarthome/bulb', { ip: currentDeviceIP } ) | ||
.done( function(data) { | ||
$('#node-input-name').val(data); | ||
}) | ||
.fail(function(err) { | ||
RED.notify("Sorry. Your selected device is invalid!", "error"); | ||
}); | ||
} | ||
}); | ||
|
||
$('#node-input-scan').click(function() { | ||
if($('#node-input-device').prop("tagName") === "INPUT") { | ||
searchAndSelectDevice(); | ||
} else { | ||
manualDeviceIP(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
</script> | ||
|
||
<script type="text/x-red" data-template-name="smart-bulb"> | ||
<div class="form-row"> | ||
<label for="node-input-name"><i class="icon-tag"></i> Name</label> | ||
<input type="text" id="node-input-name" placeholder="Name"> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-device"><i class="fa fa-server"></i> Device IP</label> | ||
<input type="text" id="node-input-device" placeholder="192.168.0.100" style="width: 60%;"> | ||
<a id="node-input-scan" class="editor-button"><i class="fa fa-search"></i></a> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-interval"><i class="fa fa-clock-o"></i> Poll interval</label> | ||
<input type="text" placeholder="5000" id="node-input-interval"> | ||
</div> | ||
</script> | ||
|
||
<script type="text/x-red" data-help-name="smart-bulb"> | ||
<p>This node controls a TP-Link Smart Bulb</p> | ||
|
||
<p>Parameters:</p> | ||
|
||
<h3>Name</h3> | ||
<p>Type in the name of the host manually or keep the default device name</p> | ||
|
||
<h3>Device IP</h3> | ||
<p>Type in the Device IP address manually or press the button to retreive all locally available bulb devices</p> | ||
|
||
<h3>Poll interval</h3> | ||
<p>Interval that is used to poll active nodes for changes (min 500ms / recommended between 3000ms and 5000ms)</p> | ||
|
||
<h3>Inputs</h3> | ||
<dl class="message-properties"> | ||
<dt>payload | ||
<span class="property-type">string | boolean</span> | ||
</dt> | ||
|
||
<p> | ||
<p><b>On/Off</b></p> | ||
<p>true: Turn on the device.</p> | ||
<p>false: Turn off the device.</p> | ||
|
||
<p><b>Commands</b></p> | ||
<p>getInfo: Fetch the device information.</p> | ||
<p>clearEvents: Unsubscribe events.</p> | ||
|
||
<p><b>Events</b></p> | ||
<p>getInfoEvents: Subscribe to information events.</p> | ||
<p>getPowerUpdateEvents: Subscribe to power on/off events.</p> | ||
<p>getOnlineEvents: Subscribe to online/offline events.</p> | ||
|
||
<p>Multiple events can be used as a list separated with the `|` character.</p> | ||
</p> | ||
</script> |
Oops, something went wrong.