jneilliii / OctoPrint-TPLinkSmartplug

106 stars 57 forks source link

[BUG]:Printer does not turn off after the idle period #361

Open Anathema-Device opened 6 months ago

Anathema-Device commented 6 months ago

Describe the bug Configuring the printer to be turned off after a 30 minute idle time does not seem to result in it being turned off. The printer can be turned off and on with the icon that the plugin puts in the Octoprint toolbar but does not turn off when the printer is idle

To Reproduce Steps to reproduce the behavior:

  1. Enable the checkbox to turn off on idle
  2. Set the idle delay to be 30 minutes
  3. Print something
  4. Wait for it to turn off and nothing happens.

Expected behavior The TPLink smart plug should be turned off after the idle time

Desktop (please complete the following information):

plugin_tplinksmartplug_debug.log

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed if no further activity occurs in 7 days

lethuer commented 5 months ago

Sometimes I also observe that described behaviour, but isn't needed to print something. Just turn on the plug, connect and wait should turn off the printer. My idle time is set to 3min... Also not switching off after a print and reaching idle temperature...

But it's not present everytime, so I can't reproduce it yet. Often after restarting OctoPrint (or System ?!) it's working again... Any recommendations ?

M81 in terminal does not turn off the plug. Shouldn't that be the case ? Lightning button is working as expected. HS110 with Firmware 1.0.6

jneilliii commented 5 months ago

Both of you need to share screenshots of your settings please. For M81 to work you have to include the IP address of the plug you want to turn off.

lethuer commented 5 months ago

Here are my settings. image image

For M81 I included the ip address... But the plug didn't switched off.

In terminal: Send: M81 192.168.178.46 Recv: M106 P0 S0 Recv: //action:notification Artillery Genius (lethuer) OFF. Recv: ok P15 B3 image

In log file: [2024-04-01 16:25:45,237] DEBUG: Received M81 command, attempting power off of 192.168.178.46. [2024-04-01 16:25:45,242] DEBUG: {'autoConnect': True, 'autoConnectDelay': 10, 'autoDisconnect': True, 'autoDisconnectDelay': 0, 'automaticShutdownEnabled': True, 'btnColor': '#808080', 'countdownOffDelay': 1, 'countdownOnDelay': 1, 'currentState': 'off', 'displayWarning': True, 'emeter': {'get_realtime': {'current_ma': 13, 'err_code': 0, 'power_mw': 0, 'total_wh': 358, 'voltage_mv': 231418}}, 'event_on_disconnect': False, 'event_on_error': True, 'event_on_shutdown': False, 'event_on_startup': False, 'event_on_upload': False, 'gcodeCmdOff': False, 'gcodeCmdOn': False, 'gcodeEnabled': False, 'gcodeOffDelay': 0, 'gcodeOnDelay': 0, 'gcodeRunCmdOff': '', 'gcodeRunCmdOn': '', 'icon': 'icon-bolt', 'ip': '192.168.178.46', 'label': '3D Drucker', 'sysCmdOff': False, 'sysCmdOffDelay': 0, 'sysCmdOn': False, 'sysCmdOnDelay': 0, 'sysRunCmdOff': '', 'sysRunCmdOn': '', 'thermal_runaway': True, 'useCountdownRules': False, 'warnPrinting': True} [2024-04-01 16:27:58,798] DEBUG: resetting idle timer due to ClientOpened event.

Log file manual clicking lightning button for turning off (works):

[2024-04-01 16:37:01,151] DEBUG: Turning off 192.168.178.46. [2024-04-01 16:37:01,152] INFO: Turning off 192.168.178.46 at 2024-04-01 16:37:01.150941 [2024-04-01 16:37:01,157] DEBUG: {'autoConnect': True, 'autoConnectDelay': 10, 'autoDisconnect': True, 'autoDisconnectDelay': 0, 'automaticShutdownEnabled': True, 'btnColor': '#808080', 'countdownOffDelay': 1, 'countdownOnDelay': 1, 'currentState': 'off', 'displayWarning': True, 'emeter': {'get_realtime': {'current_ma': 13, 'err_code': 0, 'power_mw': 0, 'total_wh': 358, 'voltage_mv': 231418}}, 'event_on_disconnect': False, 'event_on_error': True, 'event_on_shutdown': False, 'event_on_startup': False, 'event_on_upload': False, 'gcodeCmdOff': False, 'gcodeCmdOn': False, 'gcodeEnabled': False, 'gcodeOffDelay': 0, 'gcodeOnDelay': 0, 'gcodeRunCmdOff': '', 'gcodeRunCmdOn': '', 'icon': 'icon-bolt', 'ip': '192.168.178.46', 'label': '3D Drucker', 'sysCmdOff': False, 'sysCmdOffDelay': 0, 'sysCmdOn': False, 'sysCmdOnDelay': 0, 'sysRunCmdOff': '', 'sysRunCmdOn': '', 'thermal_runaway': True, 'useCountdownRules': False, 'warnPrinting': True} [2024-04-01 16:37:01,284] DEBUG: IP 192.168.178.46 is valid. [2024-04-01 16:37:01,293] DEBUG: Sending command {'system': {'set_relay_state': {'state': 0}}} to 192.168.178.46 [2024-04-01 16:37:01,374] DEBUG: «-ý"system":{"set_relay_state":{"err_code":0}}} [2024-04-01 16:37:01,400] DEBUG: 0 [2024-04-01 16:37:01,401] DEBUG: Checking status of 192.168.178.46.

jneilliii commented 5 months ago

@lethuer for gcode to work you have to enable the gcode trigger option.

lethuer commented 5 months ago

Awesome ! That works immediately if I send this manually in terminal :)

Now let me ask: After Idle time I can't observe M81 command in the terminal. If gcode trigger is enabled, is M81 command send automatically and under which conditions ? Is it possible to send M81 command when a desired nozzle temp is reached after a print ?

jneilliii commented 5 months ago

You could do that in your end gcode of your slicer or in OctoPrint's gcode script section. Can't remember if sending the wait for temp command will block until the temp is reached and then allow power off.

lethuer commented 5 months ago

Okay I will try if it is waited until reaching desired nozzle temperature...

Is here the correct location ? image

lethuer commented 5 months ago

I also configured @TPLINKOFF code in section of cancelling a print. Unfortunately I can't observe in terminal that this is sent. Not directly after aborting the print and also not when nozzle is reaching 50 degree again. Maybe because printer has changed it's status to "Operational" directly after "Cancelling" and long before reaching 50 degree ?

Send: N16 M118 P0 A1 action:cancel*14 Recv: //action:cancel Cancelling on request of the printer... Recv: ok N16 P15 B3 Send: N17 M84*41 Recv: ok N17 P15 B3 Send: N18 M104 T0 S0*24 Recv: ok N18 P15 B3 Send: N19 M140 S0*93 Recv: //action:notification Bed Cooling... Recv: ok N19 P15 B3 Send: N20 M106 S0*85 Recv: M106 P0 S0 Recv: ok N20 P15 B3 Changing monitoring state from "Cancelling" to "Operational" [...] Send: M117 L=-/- E=- Recv: ok P15 B3 Connection closed, closing down monitor Changing monitoring state from "Operational" to "Offline"

lethuer commented 5 months ago

I tried again and now received this:

Changing monitoring state from "Printing" to "Cancelling" Send: N15 M108*30 Recv: ok N14 P15 B3 Recv: ok N15 P15 B3 Send: N16 M117 L=-/83 E=-*62 Recv: ok N16 P15 B3 Send: N17 M118 P0 A1 action:cancel*15 Recv: //action:cancel Cancelling on request of the printer... Recv: ok N17 P15 B3 Send: N18 M84*38 Recv: ok N18 P15 B3 Send: N19 M104 T0 S0*25 Recv: ok N19 P15 B3 Send: N20 M140 S0*87 Recv: //action:notification Bed Cooling... Recv: ok N20 P15 B3 Send: N21 M106 S0*84 Recv: M106 P0 S0 Recv: ok N21 P15 B3 Send: N22 M81 192.168.178.46*29 Recv: M106 P0 S0 Recv: //action:notification Artillery Genius (lethuer) OFF. Recv: ok N22 P15 B3

I think the problem was that in my previous post I used @TPLINKOFF 192.168.178.46 instead of M81 192.168.178.46 in gcode section.

So now M81 was sent which I can observe in the terminal. But nethertheless the plug didn't turned off. I thought maybe because temperature was higher than needed for idle but tried also aborting a print when nozzle temp was below 50 degree and got the same result. If I manually type M81 in the terminal the plug switches of immediately, so my assumption is that the plugin does prevent switching off somehow ?

jneilliii commented 5 months ago

Based on your printer response to m81 I suspect the other option of using @TPLINKOFF command would be better. Also, typically what I see with gcode processing is that the delay isn't long enough to allow the final commands from the file to clear the printing buffer. If you want me to assist further I need you to enable debug logging in the plugin's settings and restart OctoPrint. After attempting and it fails share plugin_tplinksmartplug_debug.log. That will help determine what the plugin is doing.

lethuer commented 5 months ago

Based on your printer response to m81 I suspect the other option of using @TPLINKOFF command would be better

But I didn't observe any command is sent if @TPLINKOFF was set up in gcode script section

If you want me to assist further I need you to enable debug logging in the plugin's settings and restart OctoPrint. After attempting and it fails share plugin_tplinksmartplug_debug.log. That will help determine what the plugin is doing.

Logging was active the hole time, here is the file also containing yesterday evening. Can you work with that ? plugin_tplinksmartplug_debug.log

1st try with @TPLINKOFF 2nd try with M81

lethuer commented 5 months ago

I missed that option in plugin settings, so here is another try... image

Nothing configured in gcode script section 14:39 turn on 14:39 start print 14:41 cancel print (nozzle temp in heating phase about 60 degree) 14:45 plug switches off (idle)

terminal:

Recv: echo:busy: processing
[...]
Changing monitoring state from "Printing" to "Cancelling"
Recv: echo:busy: processing
Send: N15 M108*30
Recv: ok N14 P15 B3
Recv: ok N15 P15 B3
Send: N16 M117 L=-/124 E=15:05*20
Recv: ok N16 P15 B3
[...]
Send: N17 M117 L=-/124 E=-*3
Recv: ok N17 P15 B3
Send: N18 M118 P0 A1 action:cancel*0
Recv: //action:cancel
Cancelling on request of the printer...
Recv: ok N18 P15 B3
Send: N19 M84*39
Recv: ok N19 P15 B3
Send: N20 M104 T0 S0*19
Recv: ok N20 P15 B3
Send: N21 M140 S0*86
Recv: //action:notification Bed Cooling...
Recv: ok N21 P15 B3
Send: N22 M106 S0*87
Recv: M106 P0 S0
Recv: ok N22 P15 B3
Changing monitoring state from "Cancelling" to "Operational"
[...]
Send: M117 L=-/- E=-
Recv: ok P15 B3
Connection closed, closing down monitor
Changing monitoring state from "Operational" to "Offline"

M81 configured in gcode script section 14:46 turn on 14:46 start print 14:48 cancel print (nozzle temp in heating phase about 70 degree) 14:52 plug switches off (idle)

terminal:

Recv: echo:busy: processing
[...]
Changing monitoring state from "Printing" to "Cancelling"
Send: N15 M108*30
Recv: ok N14 P15 B2
Recv: ok N15 P15 B3
Send: N16 M117 L=-/124 E=-*2
Recv: ok N16 P15 B3
Send: N17 M118 P0 A1 action:cancel*15
Recv: //action:cancel
Cancelling on request of the printer...
Recv: ok N17 P15 B3
Send: N18 M84*38
Recv: ok N18 P15 B3
Send: N19 M104 T0 S0*25
Recv: ok N19 P15 B3
Send: N20 M140 S0*87
Recv: //action:notification Bed Cooling...
Recv: ok N20 P15 B3
Send: N21 M106 S0*84
Recv: M106 P0 S0
Recv: ok N21 P15 B3
Send: N22 M81 192.168.178.46*29
Recv: M106 P0 S0
Recv: //action:notification Artillery Genius (lethuer) OFF.
Recv: ok N22 P15 B3
[...]
Changing monitoring state from "Cancelling" to "Operational"
[...]
Send: M117 L=-/- E=-
Recv: ok P15 B3
Connection closed, closing down monitor
Changing monitoring state from "Operational" to "Offline"

@TPLINKOFF configured in gcode script section 14:53 turn on 14:53 start print 14:55 cancel print (nozzle temp in heating phase about 60 degree) 14:58 plug switches off (idle)

terminal output: Again I didn't observe any command is sent if @TPLINKOFF was set up in gcode script section

Recv: echo:busy: processing
Changing monitoring state from "Printing" to "Cancelling"
Send: N14 M108*31
Recv: ok N13 P15 B2
Recv: ok N14 P15 B3
Send: N15 M117 L=-/124 E=15:18*27
Recv: ok N15 P15 B3
Send: N16 M117 L=-/124 E=-*2
[...]
Recv: ok N16 P15 B3
Send: N17 M118 P0 A1 action:cancel*15
Recv: //action:cancel
Cancelling on request of the printer...
Recv: ok N17 P15 B3
Send: N18 M84*38
Recv: ok N18 P15 B3
Send: N19 M104 T0 S0*25
Recv: ok N19 P15 B3
Send: N20 M140 S0*87
Recv: //action:notification Bed Cooling...
Recv: ok N20 P15 B3
Send: N21 M106 S0*84
Recv: M106 P0 S0
Recv: ok N21 P15 B3
Changing monitoring state from "Cancelling" to "Operational"
[...]
Send: M117 L=-/- E=-
Recv: ok P15 B3
Connection closed, closing down monitor
Changing monitoring state from "Operational" to "Offline"

The log file: plugin_tplinksmartplug_debug.log

jneilliii commented 5 months ago

ok, so idle timeout is working properly. honestly that's the preferred approach as it will account for temperatures to be below a certain threshold before powering off.

It's normal to not see @ commands in the terminal, because those aren't sent to the printer, they are specifically used internally by OctoPrint. It is strange that it doesn't work as expected. Based on your comment you added that command to OctoPrint's on cancel gcode script?

lethuer commented 5 months ago

ok, so idle timeout is working properly.

Yes this time it worked like it should but in the past I had problems with it... But don't know what was the reason for it. Anyhow, this was the reason I was looking for another possibility to switch off the plug after a print. Let's say kind of redundant if everything is working but double functionality if one approach does not work because of any circumstances :)

Based on your comment you added that command to OctoPrint's on cancel gcode script?

Correct, just like this. image

jneilliii commented 5 months ago

Thanks I'll do some additional testing with gcode scripts being used to trigger. There's a chance that those commands might not go through the processing queue like the file commands do that the plugin is using to do the work.