Skip to content

Commit

Permalink
Merge pull request #3 from jneilliii/dev
Browse files Browse the repository at this point in the history
Initial Release
  • Loading branch information
jneilliii authored Nov 24, 2017
2 parents 2159cb1 + 9b5f56d commit 18e6457
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 72 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Once installed go into settings and enter the ip address for your TP-Link Smartp

## Settings Explained

- **Device**
- The ip or hostname of sonoff device.
- **Index**
- Index number reprensenting the relay to control.
- **Warn**
- The left checkbox will always warn when checked.
- The right checkbox will only warn when printer is printing.
Expand Down
107 changes: 44 additions & 63 deletions extras/tasmota.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,70 @@
---
layout: plugin

id: tplinksmartplug
title: OctoPrint-TPLinkSmartplug
description: Simple plugin to control TP-Link Smartplug
id: tasmota
title: OctoPrint-Tasmota
description: Simple plugin to control sonoff devices that have been flashed with Tasmota.
author: jneilliii
license: AGPLv3

# TODO
date: today's date in format YYYY-MM-DD, e.g. 2015-04-21
date: 2017-11-24

homepage: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug
source: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug
archive: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/archive/master.zip
homepage: https://github.com/jneilliii/OctoPrint-Tasmota
source: https://github.com/jneilliii/OctoPrint-Tasmota
archive: https://github.com/jneilliii/OctoPrint-Tasmota/archive/master.zip

# TODO
# Set this to true if your plugin uses the dependency_links setup parameter to include
# library versions not yet published on PyPi. SHOULD ONLY BE USED IF THERE IS NO OTHER OPTION!
#follow_dependency_links: false

# TODO
tags:
- a list
- of tags
- that apply
- to your plugin
- (take a look at the existing plugins for what makes sense here)
- sonoff
- tasmota
- smartplug
- power

# TODO
screenshots:
- url: url of a screenshot, /assets/img/...
alt: alt-text of a screenshot
caption: caption of a screenshot
- url: url of another screenshot, /assets/img/...
alt: alt-text of another screenshot
caption: caption of another screenshot
- ...

# TODO
featuredimage: url of a featured image for your plugin, /assets/img/...
- url: /assets/img/plugins/tasmota/screenshot.png
alt: Screenshot
caption: Navbar screenshot
- url: /assets/img/plugins/tasmota/settings.png
alt: Settings
caption: Settings screenshot

# TODO
# You only need the following if your plugin requires specific OctoPrint versions or
# specific operating systems to function - you can safely remove the whole
# "compatibility" block if this is not the case.
featuredimage: /assets/img/plugins/tasmota/screenshot.png

compatibility:

# List of compatible versions
#
# A single version number will be interpretated as a minimum version requirement,
# e.g. "1.3.1" will show the plugin as compatible to OctoPrint versions 1.3.1 and up.
# More sophisticated version requirements can be modelled too by using PEP440
# compatible version specifiers.
#
# You can also remove the whole "octoprint" block. Removing it will default to all
# OctoPrint versions being supported.

octoprint:
- 1.2.0

# List of compatible operating systems
#
# Valid values:
#
# - windows
# - linux
# - macos
# - freebsd
#
# There are also two OS groups defined that get expanded on usage:
#
# - posix: linux, macos and freebsd
# - nix: linux and freebsd
#
# You can also remove the whole "os" block. Removing it will default to all
# operating systems being supported.

os:
- linux
- windows
- macos
- freebsd

---
This plugin is to control ITead Sonoff devices that have been flashed with [Sonoff-Tasmota](https://github.com/arendst/Sonoff-Tasmota) via web calls.

## Configuration

Once installed go into settings and enter the ip address for your TP-Link Smartplug device. Adjust additional settings as needed.

## Settings Explained

**TODO**: Longer description of your plugin, configuration examples etc. This part will be visible on the page at
http://plugins.octoprint.org/plugin/tplinksmartplug/
- **Device**
- The ip or hostname of sonoff device.
- **Index**
- Index number reprensenting the relay to control.
- **Warn**
- The left checkbox will always warn when checked.
- The right checkbox will only warn when printer is printing.
- **GCODE**
- When checked this will enable the processing of M80 and M81 commands from gcode to power on/off plug. Syntax for gcode command is M80/M81 followed by hostname/ip and index. For example if your plug is 192.168.1.2 and index of 1 your gcode command would be **M80 192.168.1.2 1**
- **postConnect**
- Automatically connect to printer after plug is powered on.
- Will wait for number of seconds configured in **Auto Connect Delay** setting prior to attempting connection to printer.
- **preDisconnect**
- Automatically disconnect printer prior to powering off the plug.
- Will wait for number of seconds configured in **Auto Disconnect Delay** prior to powering off the plug.
- **Cmd On**
- When checked will run system command configured in **System Command On** setting after a delay in seconds configured in **System Command On Delay**.
- **Cmd Off**
- When checked will run system command configured in **System Command Off** setting after a delay in seconds configured in **System Command Off Delay**.
5 changes: 5 additions & 0 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def turn_on(self, plugip, plugidx):
chk = response["POWER"]
except:
chk = "UNKNOWN"

self._tasmota_logger.debug("Response: %s" % response)

if chk == "ON":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))
Expand All @@ -106,6 +108,8 @@ def turn_off(self, plugip, plugidx):
chk = response["POWER"]
except:
chk = "UNKNOWN"

self._tasmota_logger.debug("Response: %s" % response)

if chk == "ON":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))
Expand All @@ -126,6 +130,7 @@ def check_status(self, plugip, plugidx):
chk = "UNKNOWN"

self._tasmota_logger.debug("%s index %s is %s" % (plugip, plugidx, response))

if chk == "ON":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))
elif chk == "OFF":
Expand Down
15 changes: 8 additions & 7 deletions octoprint_tasmota/static/js/tasmota.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ $(function() {
return;
}

if(self.settings.settings.plugins.tasmota.debug_logging()){
console.log(data);
}

plug = ko.utils.arrayFirst(self.settings.settings.plugins.tasmota.arrSmartplugs(),function(item){
return (item.ip() == data.ip) && (item.idx() == data.idx);
}) || {'ip':data.ip,'idx':data.idx,'currentState':'unknown','btnColor':'#808080'};

if(self.settings.settings.plugins.tasmota.debug_logging()){
console.log('msg received:'+JSON.stringify(data));
console.log('plug data:'+ko.toJSON(plug));
}

if (data.gcodeon && plug.gcodeEnabled()) {
setTimeout(function(){self.turnOn(plug)},plug.gcodeOnDelay()*1000);
Expand All @@ -84,7 +85,7 @@ $(function() {
return false;
}

if (plug.currentState != data.currentState) {
if (plug.currentState != data.currentState) {
plug.currentState(data.currentState)
switch(data.currentState) {
case "on":
Expand All @@ -101,8 +102,8 @@ $(function() {
type: 'error',
hide: true
});
self.settings.saveData();
}
}
self.settings.saveData();
}
};

Expand Down
2 changes: 1 addition & 1 deletion octoprint_tasmota/templates/tasmota_navbar.jinja2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- ko foreach: settings.settings.plugins.tasmota.arrSmartplugs -->
<!-- ko if: $data.ip().length > 0 -->
<a class="pull-right" href=#" data-bind="click: $root.toggleRelay,visible: $root.loginState.loggedIn(),style: {color: $data.btnColor}, attr: {title: $data.ip() + '|' + $data.idx()}" style="display: none;float: left;"><i class="icon-bolt"></i></a>
<a class="pull-right" href=#" data-bind="click: $root.toggleRelay,visible: $root.loginState.loggedIn(),style: {color: $data.btnColor()}, attr: {title: $data.ip() + '|' + $data.idx()}" style="display: none;float: left;"><i class="icon-bolt"></i></a>
<div data-bind="attr: {id: 'tasmota_poweroff_confirmation_dialog_' + $data.ip() + '_' + $data.idx()}" class="modal hide fade">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
Expand Down
Binary file modified settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
plugin_description = """Simple plugin to control TP-Link Smartplug"""
plugin_description = """Simple plugin to control sonoff devices that have been flashed with Tasmota."""

# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
plugin_author = "jneilliii"
Expand Down

0 comments on commit 18e6457

Please sign in to comment.