CodingTheUnknown / OctoPrint-Tplinkautoshutdown

A plugin designed to be used within OctoPrint and OctoPi to control TP-Link kasa devices.
https://github.com/CodingTheUnknown/OctoPrint-Tplinkautoshutdown.git
9 stars 7 forks source link

'Turn Off!' turns off all 3 sockets on TP303 strip, make this configurable #47

Closed ppriest closed 3 years ago

ppriest commented 3 years ago

I have a brand new KP303 (1.0.4 Build 200828 Rel.165029), and I'm in Ireland if it matters (I know they were rolling out divergent firmware in the UK).

I currently have the three sockets configured thusly: 1) Octoprint/RPI - Running two instances of Octoprint on port 80 and 81 ('Custom') 2) Printer 1 ('Printer' + 'Auto-shutdown enabled' on the :80 instance) 3) Printer 2 ('Printer' + 'Auto-shutdown enabled' on the :81 instance)

I have configured the plugin on both instances (is this supported? do they need exclusive control?) And on each I have set the relevant socket as being the one to 'auto shutdown'.

Clicking "Turn Off!" turns off the entire strip - both printers and the raspberry pi itself. I had presumed it would only be the sockets selected to 'auto shutdown'.

Whenever I go back into the plugin I have to reselect that it's a 'Smart Strip' though as it re-defaults to 'Smart Plug' in the dialog. Could that be the root of my issues? Also the device name shows as 'undefined'. Perhaps that's the reason it flips back?

ppriest commented 3 years ago

Also, nothing happened at the end of the print. I didn't see any messages, and the printer didn't turn off. Is there any debug logs I can get at?

ppriest commented 3 years ago

Plugin is 1.0.2

CodingTheUnknown commented 3 years ago

In terms of manual buttons that is correct it turns the whole strip off/on. I have never tried this before but imagine that it is possible.

The dropdown will re-default to smart Plug but as long as you click smart Strip then set the settings and then save it will update and store it within a config.yaml page. This is something i aim to fix in time to avoid confusion.

Can you send screenshots of your settings with headings of which pi it is so i can see the configuration. I presume you have also restarted the server as per the instructions otherwise this will be your problem.

In answer to your question though, in theory they do not require exclusive control

CodingTheUnknown commented 3 years ago

Debug logs can be found within settings > octoprint.log

Also can you show me your config.yaml. For this you need to ssh into the pi.

Looking at the current log it looks as if the configs haven't been saved into the config file. Have a look at the config.yaml file within .octoprint. In there you should see plugins: then under that TpLinkAutoShutdown. This will list all the settings you have set/changed from the defaults

CodingTheUnknown commented 3 years ago

Should look like

image

CodingTheUnknown commented 3 years ago

Just published a fix to what i believe is your issue. Uninstall and try again. Should now work when setup again.

CodingTheUnknown commented 3 years ago

will be version 1.0.3

ppriest commented 3 years ago

Can you send screenshots of your settings with headings of which pi it is so i can see the configuration. I presume you have also restarted the server as per the instructions otherwise this will be your problem.

I had restarted both Octoprint instances, prior to restarting Octoprint it hadn't picked up the firmware version. Subsequently due to clicking 'Turn Off!' I had restarted the OS too a couple of times and hit 'Save' on the plugin settings several times.

Here's the relevant bit of the first OP instance:

    TpLinkAutoShutdown:
        command: update
        smartPlug:
            auto: false
        smartStrip:
            deviceThree:
                auto: true
                movieDone: true
                printer: true
        type: smartStrip
        url: 192.168.0.239

From within the second instance (runs under docker):

    TpLinkAutoShutdown:
        command: update
        smartStrip:
            deviceTwo:
                auto: true
                movieDone: true
                printer: true
        type: smartStrip
        url: 192.168.0.239

Initially, upon opening the plugin settings I see: image

If I choose 'Smart Strip' and click 'show configuration' then I get (first instance): image

second instance: image

I tried messing with the 'Wait for timelapse to render' or not, and setting 'Socket Use' for the other sockets, or not.

I'll check the debug logs.

ppriest commented 3 years ago

Just published a fix to what i believe is your issue. Uninstall and try again. Should now work when setup again.

Thanks. In the middle of a print atm, will try later. Looking at the commit this just fixes it not correctly binding the dropdown to the persisted state for the Plug/Strip? I guess that won't help with it not disabling the plug post-print?

I found this in the Octoprint log, but I'm unsure if this was before I restarted the Ocotoprint instance. I'll see what I get after this print completes:


2021-03-17 17:04:23,710 - octoprint.server.api - ERROR - Error while executing SimpleApiPlugin TpLinkAutoShutdown
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/server/api/__init__.py", line 146, in pluginCommand
    response = api_plugin.on_api_command(command, data)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1890, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_TpLinkAutoShutdown/__init__.py", line 102, in on_api_command
    self.conn.shutdown_btn()
AttributeError: 'TpLinkAutoShutdown' object has no attribute 'conn'
2021-03-17 17:04:23,732 - tornado.access - ERROR - 500 POST /api/plugin/TpLinkAutoShutdown (::ffff:192.168.0.252) 36.77ms```
CodingTheUnknown commented 3 years ago

By setting the bind setting it will also ensure that it is updated within the settings on save as well. Whereas it originally seemed to work 50/50. For some it worked others it didn't. Now the settings should be saved which on startup should then get the autoshudown feature working.

ppriest commented 3 years ago

@jamesmccannon02 - 1.0.3 fixed the plugin settings not reflecting the 'type' of Strip. Initially I just upgraded, went through the settings again and resaved, restarted and it didn't appear to work. So I fully uninstalled and reinstalled it as you said, and this time it did work! So thanks a lot.

There was nothing in the Octoprint logs from the plugin - just the complaint about the serial connection when the printer turned off.

I only used the 'Auto-shutdown enabled' and not the 'time-lapse'. I'm not clear exactly on how the time lapse works - I don't see anything to configure what the delay should be. I'm also not clear what the 'Socket Use' is for, other than metadata.

I can create some enhancement tickets, but what would suite me would be:

Thanks again this got me going for now at least.

CodingTheUnknown commented 3 years ago

Thanks for the feedback and will look at implementing this when i get time. In terms of the serial port complaining, this is normal. Also, the time-lapse turn-off feature wits for the event within the server to be triggered when all rendering of the image file is completed and then turns the plug off. This is there for users who wish to use one plug that powers both the printer and the server. Else if it turns off the time-lapse may be lost.

mcmillanb commented 3 years ago

Just hit this as well, I also had my OctoPi plugged into the strip so it went off as well, I'll move it for now!

Definitely +1 to control the individual plugs

CodingTheUnknown commented 3 years ago

@ppriest @mcmillanb I would like to make you aware that within update 1.2.0 is the requested feature. Hope this is what you are looking for.

mcmillanb commented 3 years ago

Amazing, works a treat. Thank you

ppriest commented 3 years ago

Finally got around to testing/configuring this, works great. Thanks. Although the time delay before attempting to auto-connect is nowhere near long enough factoring in the time taken for the power strip to respond (relates to https://github.com/jamesmccannon02/OctoPrint-Tplinkautoshutdown/pull/55 I guess)