Switching off power

I'm using Tasmota (0.8.8)


and [Sonoff-Tasmota 6.7.1] on the sonoff

Oops, looks like I didn't change the call out for the gcode off command and it's pulling the time from ther backlog on delay. Since you have that set at 0 it's happening instantly. Can you do me a favor and set the on delay to 300 just to confirm?

When setting the on delay countdown to 300, the sonoff show RESULT = {"Delay":3000} and after 5 minutes, POWER = OFF. Like it should so it's working perfectly now

I pushed an update to my current development branch that fixes this. Will be in next release.

1 Like

thank you for everything

Hi jneilliii,
I've just installed you tasmota plugin but have some trouble.

What do I want to do:

  • the printer power including the (octo)pi + klipper is switched by a sonoff basic with tasmota 8.1
  • the pi needs to be shutdown before switching off
  • if the heated bed (750W) temperature rise above a limit (120°), switch the printer off
  • if the hotend temperature rise above a limit (280°), switch the printer off
  • if the print is complete (controlled by gcode), switch the printer off

What I've got working:

  • switching the sonoff with the 'flash' icon in the control bar, the delay works.
  • status polling works
  • thermal runaway monitoring, I've set the bed limit to 60° and heated the bed to 70°, switch after the tasmota delay, no system command before off.

What I've not got working:

  • system command before off. The 'sudo shutdown' with 30s delay seems to start the delay, after the 40s tasmota delay has expired and the tasmota has switched off (for testing still not connected to printer power). So the shutdown happen after power off (more than 30s).
  • gcode switching works direct, but no tasmota delay. system command (shutdown) is processed after power off..

Any hints?
Regards,
Markus

Are you using the backlog option for the tasmota power off command? If not, I don't think any of this will work because if the shutdown occurs prior to the command being sent to the tasmota, it can't send it because it's powered off. Post a screenshot of your plug's settings please. There very well could be some logic here that isn't working right on thermal runaway, it was kind of thrown together on a whim.

I've used the blacklog option during my first tests with shell scripts - that has worked. I'm your opinion, backlog is the only way for activity beyond shutdown.
I think your tasmota plugin use backlogs, there are input fields for the IP and a delay? I could not find a way to start scripts.

Starting scripts for shutdown and thermal runaway would be great - is this already possible (at least for shutdown, maybe by the system or other plugins)?
Is there a central shutdown script for octoprint where I can add a curl for the tasmota?

The tasmota settings are almost default. Power is always on, on startup. I can post the settings when I've access to my printer.

There very well could be some workflow logic problems in the current implementation, but in theory the following settings should work. Sorry I had the wording wrong of what's displayed in the settings. Backlog is the Countdown Timers option.

Here's the setting and plugin_tasmota_debug.log for bed overheat , delayed switch off , if shutdown is called, always after power off....

[2020-02-12 20:23:27,318] DEBUG: Using authentication for 192.168.178.142.
[2020-02-12 20:23:27,320] DEBUG: Checking status of 192.168.178.142 index .
[2020-02-12 20:23:27,400] DEBUG: 192.168.178.142 index response: <Response [200]>
[2020-02-12 20:23:27,401] DEBUG: 192.168.178.142 index is ON
[2020-02-12 20:24:27,320] DEBUG: {u'username': u'admin', u'ip': u'192.168.178.142', u'password': u'', u'command': u'checkStatus', u'idx': u'1'}
[2020-02-12 20:24:27,321] DEBUG: Using authentication for 192.168.178.142.
[2020-02-12 20:24:27,323] DEBUG: Checking status of 192.168.178.142 index .
[2020-02-12 20:24:27,387] DEBUG: 192.168.178.142 index response: <Response [200]>
[2020-02-12 20:24:27,388] DEBUG: 192.168.178.142 index is ON
[2020-02-12 20:25:00,680] DEBUG: Max bed temp reached, shutting off plugs.
[2020-02-12 20:25:00,684] DEBUG: Turning off 192.168.178.142 index .
[2020-02-12 20:25:00,756] DEBUG: Response: {'POWER': 'OFF'}
[2020-02-12 20:25:00,759] DEBUG: Turning off 192.168.178.142 index .
[2020-02-12 20:25:00,810] DEBUG: Response: {'POWER': 'OFF'}
[2020-02-12 20:25:27,318] DEBUG: {u'username': u'admin', u'ip': u'192.168.178.142', u'password': u'', u'command': u'checkStatus', u'idx': u'1'}

Thanks, that's what I needed to see. The issue is any server side power off; thermal based, gcode based, or action command based don't call the system commands like they should. The system command logic is isolated to the client/javascript side from the button only. That was changed around in some of my other power plugins, but never got changed in this one. I'll mark that correction for the next release.

Ok, thank you.
In the meantime I'll use a hard coded
self._printer.disconnect() and os.system("sudo shudown -h")
at the end of turn_off()
Seems to work, is that ok?

Sure, if it works it works. I'll probably work on the updates tonight, might be able to release soon thereafter.

Great, I'm looking forward for it.

I just pushed updates to my current development branch. If you want to try it out you can install using the URL below. I have decided to remove the SingleRelay option, so in order for the plugin to work you may need to make sure to set your index to 1 and on the Tasmota make sure SetOption26 is ON. I may eventually add a link in the plugin's settings to do that automatically for you, but it's easy enough for now to run the command in the web console of Tasmota for testing.

https://github.com/jneilliii/OctoPrint-Tasmota/archive/0.8.9.zip

Thank you, I've installed the software over the released one and adjusted the settings. The sonoff basic is now handled in the same way as the S20.

I've made 2 tests:

1 ) clicking on the flash button in octoprint, works:

Tasmota Sonoff log:
19:15:19 RSL: STATUS11 = {"StatusSTS":{"Time":"2020-02- ...
19:15:27 RSL: RESULT = {"Delay":1100}
19:16:19 RSL: STATUS = {"Status":{"Module":1,"FriendlyName": ...
19:16:19 RSL: RESULT = {"POWER1":"OFF"}
19:16:19 RSL: POWER1 = OFF

No coresponding entry in Tasmota plugin log:
????

The sonoff has switched after the selected delay.

  1. Shutdown Printer Plugin Test-Button (M81) pressed:

Tasmota-Plugin.log:
[2020-02-14 18:24:22,890] DEBUG: 192.168.178.140 index 1 is ON
[2020-02-14 18:24:39,316] DEBUG: Received M81 command, attempting power off of 192.168.178.140 index 1.
[2020-02-14 18:25:22,895] DEBUG: Checking status of 192.168.178.140 index 1.
[2020-02-14 18:25:22,898] DEBUG: {'label_extended': '', 'autoConnect': False, 'ip': '192.168.178.140', 'backlog_on_delay': 0, '
...
[2020-02-14 18:25:23,032] DEBUG: 192.168.178.140 index 1 is ON
[2020-02-14 18:26:06,725] DEBUG: {u'username': u'admin', u'idx': u'1', u'ip': u'192.168.178.140', u'command': u'turnOff', u'backlog_delay': u'110', u'password': u''}
[2020-02-14 18:26:06,726] DEBUG: Turning off 192.168.178.140 index 1.
[2020-02-14 18:26:06,868] DEBUG: Response: {'POWER1': 'OFF'}
[2020-02-14 18:26:23,037] DEBUG: Checking status of 192.168.178.140 index 1.

OctoPrint.log:
2020-02-14 18:28:15,047 - octoprint.plugins.shutdownprinter - INFO - start thread
2020-02-14 18:28:15,049 - octoprint.plugins.shutdownprinter - INFO - Shutting down printer with command: M81 192.168.178.140 1
2020-02-14 18:28:15,050 - octoprint.plugins.shutdownprinter - INFO - eventView

the logs looks like it works, but the sonoff does not switch ... no entry in the sonoff.log

Please share a screenshot of the settings for the plug with ip 192.168.178.140. I probably didn't adjust something correctly in the gcode processing side.

BTW: I'll probably be integrating the automatic power off toggle similar to the Shutdown Printer plugin like I've done with my TPLinkSmartplug plugin prior to next release of this one. Will be working on it throughout the weekend.

Ok, I think I have success now.

Plugin debug log:

[2020-02-15 00:43:46,829] DEBUG: Received M81 command, attempting power off of 192.168.0.126 index 1.
[2020-02-15 00:43:56,832] DEBUG: Sending gcode off
[2020-02-15 00:43:56,832] DEBUG: Sending turn off for 192.168.0.126 index 1
[2020-02-15 00:43:56,832] DEBUG: Turning off {'label_extended': '192.168.0.126', 'autoConnect': True, 'ip': '192.168.0.126', 'backlog_on_delay': 0, 'off_color': '#FF0000', 'autoDisconnectDelay': 0, 'sysCmdOff': True, 'gcodeEnabled': True, 'backlog_off_delay': '20', 'gcodeOnDelay': 0, 'label': '192.168.0.126', 'warnPrinting': False, 'thermal_runaway': False, 'gcodeOffDelay': '10', 'sysCmdOnDelay': 0, 'username': 'admin', 'sysRunCmdOff': 'notepad.exe>nul', 'use_backlog': True, 'autoDisconnect': True, 'sysRunCmdOn': '', 'unknown_color': '#808080', 'password': '', 'icon': 'icon-bolt', 'idx': '1', 'displayWarning': False, 'sensor_identifier': 'DHT11', 'autoConnectDelay': 10, 'sysCmdOn': False, 'on_color': '#00FF00', 'currentState': 'on', 'sysCmdOffDelay': '10'} 
[2020-02-15 00:43:56,832] DEBUG: Using backlog commands with a delay value of 200
[2020-02-15 00:43:56,832] DEBUG: Sending command http://192.168.0.126/cm?user=admin&password=&cmnd=backlog%20delay%20200%3BPower1%20off%3B
[2020-02-15 00:43:57,000] DEBUG: Running system command: notepad.exe>nul in 10
[2020-02-15 00:43:57,003] DEBUG: Disconnnecting from printer
[2020-02-15 00:43:57,025] DEBUG: Response: {'POWER1': 'OFF'}

Tasmota log:

06:43:57 MQT: sonoff/stat/RESULT = {"Delay":200}
06:44:17 MQT: sonoff/tele/STATE = {"Time":"2020-02-15T06:44:17","Uptime":"0T00:06:16","UptimeSec":376,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"OFF","Wifi":{"AP":1,"SSId":"TS-HQ","BSSId":"50:C7:BF:62:07:A7","Channel":11,"RSSI":80,"Signal":-60,"LinkCount":1,"Downtime":"0T00:00:09"}}
06:44:17 MQT: sonoff/stat/RESULT = {"POWER1":"OFF"}
06:44:17 MQT: sonoff/stat/POWER1 = OFF

And notepad started before the plug turned off. Pushing to the dev branch now.

Integrating the automatic power off toggle similar to the Shutdown Printer plugin is a good idea, because the shutdown will run in a separate thread , delayed.

OK here are the actual settings of the plugin, commands are disabled:

And the settings of the sonoff:

06:30:26 CMD: status 0
06:30:26 RSL: stat/tasmota/STATUS = {"Status":{"Module":1,"FriendlyName":["Tasmota"],"Topic":"tasmota","ButtonTopic":"0","Power":1,"PowerOnState":1,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
06:30:26 RSL: stat/tasmota/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://thehackbox.org/tasmota/release/tasmota.bin","RestartReason":"Power on","Uptime":"0T00:09:35","StartupUTC":"2020-02-15T05:20:51","Sleep":50,"CfgHolder":4617,"BootCount":20,"SaveCount":113,"SaveAddress":"FB000"}}
06:30:26 RSL: stat/tasmota/STATUS2 = {"StatusFWR":{"Version":"8.1.0.6(tasmota)","BuildDateTime":"2020-02-08T17:18:44","Boot":7,"Core":"2_6_1","SDK":"2.2.2-dev(38a443e)","Hardware":"ESP8285","CR":"316/699"}}
06:30:26 RSL: stat/tasmota/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["MAD WLAN 7360",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["04008009","2805C8000100060000005A00000000000000","00000000","00000000"]}}
06:30:26 RSL: stat/tasmota/STATUS4 = {"StatusMEM":{"ProgramSize":569,"Free":432,"Heap":26,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"144051","FlashMode":3,"Features":["00000809","8FDAE397","043683A0","22B617CD","01001BC0","00007881"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,29","Sensors":"1,2,3,4,5,6,7,8,9,10,14,15,17,18,20,22,26,34"}}
06:30:26 RSL: stat/tasmota/STATUS5 = {"StatusNET":{"Hostname":"tasmota-0585","IPAddress":"192.168.178.142","Gateway":"192.168.1.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.1","Mac":"xxxxxxxxxxxxxx","Webserver":2,"WifiConfig":4,"WifiPower":17.0}}
06:30:26 RSL: stat/tasmota/STATUS6 = {"StatusMQT":{"MqttHost":"","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_F7E249","MqttUser":"DVES_USER","MqttCount":0,"MAX_PACKET_SIZE":1000,"KEEPALIVE":30}}
06:30:26 RSL: stat/tasmota/STATUS7 = {"StatusTIM":{"UTC":"Sat Feb 15 05:30:26 2020","Local":"Sat Feb 15 06:30:26 2020","StartDST":"Sun Mar 29 02:00:00 2020","EndDST":"Sun Oct 25 03:00:00 2020","Timezone":"+01:00","Sunrise":"07:59","Sunset":"18:09"}}
06:30:26 RSL: stat/tasmota/STATUS10 = {"StatusSNS":{"Time":"2020-02-15T06:30:26"}}
06:30:26 RSL: stat/tasmota/STATUS11 = {"StatusSTS":{"Time":"2020-02-15T06:30:26","Uptime":"0T00:09:35","UptimeSec":575,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"POWER1":"ON","Wifi":{"AP":1,"SSId":"xxxxxxx","BSSId":"44:4E:6D:3A:E7:C0","Channel":1,"RSSI":62,"Signal":-69,"LinkCount":1,"Downtime":"0T00:00:06"}}}
06:30:51 APP: Serial logging disabled

Not sure if you saw my last post or not since I think we were typing at the same time, but I pushed an update that I believe will resolve the timing issue with the GCODE triggers. I still plan to incorporate the automatic off after print complete option, but if you could test current workflow timing on the dev branch that would be great.