entrippy / OctoPrint-OctoHue

Illuminate your print job and signal its status using a Philips Hue lights.
GNU Affero General Public License v3.0
18 stars 4 forks source link

Allow lights to turn off after a configurable time after a status change #18

Open entrippy opened 4 years ago

entrippy commented 4 years ago

A user prefers that the light does not stay on continuously when a status changes, instead preferring that it turns off after X seconds.

Add a lights on time limit to status customisations.

terrorhai commented 4 years ago

It would be awesome to shutdown a light after a configurable time, because I use Osram Smart Plugs with my Hue bridge which shutdown the printer.

entrippy commented 4 years ago

I've flagged this for 0.5.0, in principle it sounds like a straight forward feature (adding a sleep between event and status update), and will be made easier by the new settings structure.

I'll need to do a little homework, as I need to make sure the delay doesn't cause everything else to pause until the trigger is pulled.

I haven't seen how it might interact with octoprint, but I'm thinking a sleeping thread and callback.

philipptrenz commented 4 years ago

Hey there, some ideas from my side:

My Pi with Octoprint is powered by the printers PSU, so that Octoprint starts when I power up the printer. Also my printer is connected via a Zigbee smart socket, so I can turn it on remotely. As the Pi should shutdown safely and turn off the power afterwards, I modified the shutdown command in Octoprint to use the API of my bridge (its a deCONZ, but should be compatible to Hue) to schedule a delayed power off of the smart socket. By this the Pi has 30 seconds to shut down before power gets disconnected.

The Server > Shutdown system command looks like this:

curl --header "Content-Type: application/json" --request POST --data '{     "autodelete": true,     "command": {       "address": "/api/XXXXXXXXXX/lights/5/state",       "method": "PUT",       "body": {         "on": false       }      },     "name": "shutdown OctoPi and printer",     "time": "PT00:00:30" }' http://phoscon.local:80/api/XXXXXXXXXX/schedules && sudo shutdown -h now

As this approach works, but is not very pretty, I'd very like to see this feature implemented within this plugin.

So I would suggest to hand over the delay to the bridge in form of a schedule (see here), as this can then be used to power off the printer as well and might even be easier as to implement several threads.

As I then will have one light and one smart socket, support for more than one entity would also be great in the future 😉