Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
ccc58f9301 | |||
c56b076620 | |||
78f39e82f3 | |||
10702134ee | |||
3e74b23dbc | |||
ebc98694d1 | |||
1ec0b46060 | |||
6b041d7cca | |||
d2e1b00b3f |
27
README.md
27
README.md
@ -2,4 +2,31 @@
|
|||||||
|
|
||||||
This OctoPrint plugin enables the system to control the myStrom switch and read the current Powerconsumption of your system
|
This OctoPrint plugin enables the system to control the myStrom switch and read the current Powerconsumption of your system
|
||||||
|
|
||||||
|
Settings Tab
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Mainscreen
|
||||||
|
You can see the Plugin on the bottom right
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Switch is off
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Switch is on
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
With toggle Button enabled
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Install via the bundled [Plugin Manager](https://github.com/foosel/OctoPrint/wiki/Plugin:-Plugin-Manager)
|
||||||
|
or manually using this URL:
|
||||||
|
|
||||||
|
https://github.com/da4id/OctoPrint-MyStromSwitch/archive/master.zip
|
BIN
fullscreen.png
Normal file
BIN
fullscreen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 167 KiB |
@ -2,6 +2,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import ssl
|
import ssl
|
||||||
|
import time
|
||||||
|
|
||||||
import octoprint.plugin
|
import octoprint.plugin
|
||||||
import requests
|
import requests
|
||||||
@ -25,6 +26,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
|
|
||||||
self._timer = None
|
self._timer = None
|
||||||
|
|
||||||
|
self.energy = 0
|
||||||
|
self.lastTimeStamp = 0
|
||||||
|
|
||||||
self.ctx = ssl.create_default_context()
|
self.ctx = ssl.create_default_context()
|
||||||
self.ctx.check_hostname = False
|
self.ctx.check_hostname = False
|
||||||
self.ctx.verify_mode = ssl.CERT_NONE
|
self.ctx.verify_mode = ssl.CERT_NONE
|
||||||
@ -75,49 +79,73 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
try:
|
try:
|
||||||
request = requests.get(
|
request = requests.get(
|
||||||
'http://{}/report'.format(self.ip), timeout=1)
|
'http://{}/report'.format(self.ip), timeout=1)
|
||||||
data = request.json()
|
if request.status_code == 200:
|
||||||
data["onOffButtonEnabled"] = self.onOffButtonEnabled
|
timestamp = time.time()
|
||||||
self._plugin_manager.send_plugin_message(self._identifier, data)
|
data = request.json()
|
||||||
|
if not self.lastTimeStamp == 0:
|
||||||
|
intervall = timestamp - self.lastTimeStamp
|
||||||
|
# Energy in Wh
|
||||||
|
self.energy = self.energy + (intervall * data["power"] / 3600)
|
||||||
|
self.lastTimeStamp = timestamp
|
||||||
|
data["energy"] = self.energy
|
||||||
|
data["onOffButtonEnabled"] = self.onOffButtonEnabled
|
||||||
|
self._plugin_manager.send_plugin_message(self._identifier, data)
|
||||||
except (requests.exceptions.ConnectionError, ValueError):
|
except (requests.exceptions.ConnectionError, ValueError):
|
||||||
self._logger.info('Connection Error Host: {}'.format(self.ip))
|
self._logger.info('Connection Error Host: {}'.format(self.ip))
|
||||||
else:
|
else:
|
||||||
self._logger.info("Ip is None")
|
self._logger.info("Ip is None")
|
||||||
|
|
||||||
def _setRelaisState(self, newState):
|
def _setRelaisState(self, newState):
|
||||||
try:
|
nbRetry = 0
|
||||||
value = '0'
|
value = '0'
|
||||||
if (newState == True):
|
if (newState == True):
|
||||||
value = '1'
|
value = '1'
|
||||||
request = requests.get(
|
while nbRetry < 3:
|
||||||
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
try:
|
||||||
if not request.status_code == 200:
|
request = requests.get(
|
||||||
self._logger.info("Could not set new Relais State, Http Status Code: {}".format(request.status_code))
|
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
||||||
except requests.exceptions.ConnectionError:
|
if request.status_code == 200:
|
||||||
self._logger.info("Error during set Relais state")
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info(
|
||||||
|
"Could not set new Relais State, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during set Relais state")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
# Sets the switch to a specific inverse newState,
|
# Sets the switch to a specific inverse newState,
|
||||||
# waits for a specified amount of time (max 3h),
|
# waits for a specified amount of time (max 3h),
|
||||||
# then sets the the switch to the newState.
|
# then sets the the switch to the newState.
|
||||||
def _powerCycleRelais(self, newState, time):
|
def _powerCycleRelais(self, newState, time):
|
||||||
try:
|
nbRetry = 0
|
||||||
value = 'on'
|
value = 'on'
|
||||||
if (newState == True):
|
if newState:
|
||||||
value = 'off'
|
value = 'off'
|
||||||
request = requests.post(
|
while nbRetry < 3:
|
||||||
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
try:
|
||||||
if not request.status_code == 200:
|
request = requests.post(
|
||||||
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
||||||
except requests.exceptions.ConnectionError:
|
if request.status_code == 200:
|
||||||
self._logger.info("Error during powerCycle Relais")
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during powerCycle Relais")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def _toggleRelay(self):
|
def _toggleRelay(self):
|
||||||
try:
|
nbRetry = 0
|
||||||
request = requests.get(
|
while nbRetry < 3:
|
||||||
'http://{}/toggle'.format(self.ip), timeout=1)
|
try:
|
||||||
if not request.status_code == 200:
|
request = requests.get(
|
||||||
self._logger.info("Could not toggle Relay State, Http Status Code: {}".format(request.status_code))
|
'http://{}/toggle'.format(self.ip), timeout=1)
|
||||||
except requests.exceptions.ConnectionError:
|
if request.status_code == 200:
|
||||||
self._logger.info("Error during toggle Relais state")
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info("Could not toggle Relay State, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during toggle Relais state")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def on_api_command(self, command, data):
|
def on_api_command(self, command, data):
|
||||||
if command == "enableRelais":
|
if command == "enableRelais":
|
||||||
@ -169,11 +197,16 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
ip=None,
|
ip=None,
|
||||||
intervall=1,
|
intervall=1,
|
||||||
onOffButtonEnabled=False,
|
onOffButtonEnabled=False,
|
||||||
owerOnOnStart=False,
|
powerOnOnStart=False,
|
||||||
powerOffOnShutdown=False,
|
powerOffOnShutdown=False,
|
||||||
powerOffDelay=0
|
powerOffDelay=0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_settings_restricted_paths(self):
|
||||||
|
return dict(admin=[
|
||||||
|
['ip']
|
||||||
|
])
|
||||||
|
|
||||||
def on_settings_save(self, data):
|
def on_settings_save(self, data):
|
||||||
self._logger.info("on_settings_save")
|
self._logger.info("on_settings_save")
|
||||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||||
|
@ -8,6 +8,7 @@ $(function() {
|
|||||||
|
|
||||||
self.onOffButtonEnabled = ko.observable();
|
self.onOffButtonEnabled = ko.observable();
|
||||||
self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue")
|
self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue")
|
||||||
|
self.mystromswitchEnergyValue = document.getElementById("mystromswitchEnergyValue")
|
||||||
|
|
||||||
self.onToggleRelayEvent = function(){
|
self.onToggleRelayEvent = function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -32,6 +33,7 @@ $(function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.onOffButtonEnabled(data.onOffButtonEnabled);
|
self.onOffButtonEnabled(data.onOffButtonEnabled);
|
||||||
|
self.mystromswitchEnergyValue.innerHTML = "Energy: "+data.energy.toFixed(1)+"Wh"
|
||||||
if(data.relay == false){
|
if(data.relay == false){
|
||||||
self.mystromswitchPowerValue.innerHTML = "Relay is off";
|
self.mystromswitchPowerValue.innerHTML = "Relay is off";
|
||||||
} else if (data.power != null) {
|
} else if (data.power != null) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<form class="form-horizontal">
|
<form class="form-horizontal">
|
||||||
<h4>General</h4>
|
<h4>General</h4>
|
||||||
<hr>
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('IP-Address') }}</label>
|
<label class="control-label">{{ _('URL or IP-Address of your switch') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.ip">
|
<input type="text" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.ip">
|
||||||
</div>
|
</div>
|
||||||
@ -13,16 +12,21 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
<div class="input-append">
|
<div class="input-append">
|
||||||
<input type="number" class="input-mini text-right" data-bind="value: settings.plugins.mystromswitch.intervall">
|
<input type="number" class="input-mini text-right" data-bind="value: settings.plugins.mystromswitch.intervall">
|
||||||
<span class="add-on">sec</span>
|
<span class="add-on">seconds</span>
|
||||||
</div>
|
</div>
|
||||||
|
<span class="help-block"><small>{{ _('Intervall in seconds where relays state, power and energy consumption are refreshed') }}</small></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<h4>Octoprint Hardware (Raspberry Pi) is not switched on/off by the relais</h4>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<label class="checkbox">
|
<label class="checkbox">
|
||||||
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.onOffButtonEnabled">Toggle Button Enabled
|
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.onOffButtonEnabled">Toggle Button Enabled
|
||||||
</label>
|
</label>
|
||||||
|
<span class="help-block"><small>{{ _('Shows an on/off Button on the left side to switch the relays on or off. This setting is only recommended if only your printer is switched on/off') }}</small></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -31,21 +35,30 @@
|
|||||||
<label class="checkbox">
|
<label class="checkbox">
|
||||||
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.powerOnOnStart">Turn relais ON on Octoprint start
|
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.powerOnOnStart">Turn relais ON on Octoprint start
|
||||||
</label>
|
</label>
|
||||||
|
<span class="help-block"><small>{{ _('This setting switches your mySwitch on if Octoprint is starting up. Turn relays OFF on Octoprint shutdown could also be interesting for you') }}</small></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<h4>Octoprint Hardware (Raspberry Pi) is switched on/off by the relais</h4>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<label class="checkbox">
|
<label class="checkbox">
|
||||||
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.powerOffOnShutdown">Turn relais OFF on Octoprint shutdown
|
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.powerOffOnShutdown">Turn relais OFF on Octoprint shutdown
|
||||||
</label>
|
</label>
|
||||||
|
<span class="help-block"><small>{{ _('This setting switches your mySwitch off if Octoprint is shutting down. If your Raspberry Pi is also switched by the relays its recommended to use an turn relay off delay of 60 seconds or more. Keep in mind this switches also off if you restart Octoprint service!') }}</small></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('Turn Relais Off Delay') }}</label>
|
<label class="control-label">{{ _('Turn Relais Off Delay') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input type="number" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.powerOffDelay">
|
<div class="input-append">
|
||||||
|
<input type="number" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.powerOffDelay">
|
||||||
|
<span class="add-on">seconds</span>
|
||||||
|
</div>
|
||||||
|
<span class="help-block"><small>{{ _('Delay in seconds after octoprint is shutted down to switch off relays. This settings is recommended to make sure that Raspberry Pi is completely shutted down when you switch power off. Switching off when your Raspberry Pi is running could lead to unrepairable damage to your SD Card!') }}</small></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<div class="sidebar_plugin_mystromswitch">
|
<div class="sidebar_plugin_mystromswitch">
|
||||||
<label class="control-label" id="mystromswitchPowerValue">Powerconsumption 0.0W</label>
|
<label class="control-label" id="mystromswitchPowerValue">Powerconsumption 0.0W</label>
|
||||||
|
<label class="control-label" id="mystromswitchEnergyValue">Energy 0.0Wh</label>
|
||||||
<button class="btn btn-primary" data-bind="click: onToggleRelayEvent, visible : onOffButtonEnabled">{{ _('Toggle Relais') }}</button>
|
<button class="btn btn-primary" data-bind="click: onToggleRelayEvent, visible : onOffButtonEnabled">{{ _('Toggle Relais') }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
BIN
settings_page.png
Normal file
BIN
settings_page.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 159 KiB |
2
setup.py
2
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_mystromswitch"
|
|||||||
plugin_name = "OctoPrint-MyStromSwitch"
|
plugin_name = "OctoPrint-MyStromSwitch"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.3.0"
|
plugin_version = "1.0.1"
|
||||||
|
|
||||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||||
# module
|
# module
|
||||||
|
BIN
sidebar_off.png
Normal file
BIN
sidebar_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.5 KiB |
BIN
sidebar_off_button.png
Normal file
BIN
sidebar_off_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
sidebar_on.png
Normal file
BIN
sidebar_on.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
sidebar_on_button.png
Normal file
BIN
sidebar_on_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user