Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSU Switch needed for remote shutdown the 3d printer #88142

Closed
VikeHsu opened this issue Feb 14, 2023 · 17 comments
Closed

PSU Switch needed for remote shutdown the 3d printer #88142

VikeHsu opened this issue Feb 14, 2023 · 17 comments

Comments

@VikeHsu
Copy link

VikeHsu commented Feb 14, 2023

The problem

PSU Switch needed for remote shutdown the 3d printer

What version of Home Assistant Core has the issue?

2023.2.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Octoprint

Link to integration documentation on our website

https://www.home-assistant.io/integrations/octoprint/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

Hey there @rfleming71, mind taking a look at this issue as it has been labeled with an integration (octoprint) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of octoprint can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign octoprint Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


octoprint documentation
octoprint source
(message by IssueLinks)

@rfleming71
Copy link
Contributor

Are you using a plugin to expose the power switch? I don't see anything on the octoprint API that exposes this functionality. I think there is a shutdown command, but that is for the OS and not the physical switch.

@VikeHsu
Copy link
Author

VikeHsu commented Feb 16, 2023

Are you using a plugin to expose the power switch? I don't see anything on the octoprint API that exposes this functionality. I think there is a shutdown command, but that is for the OS and not the physical switch.

Hi I am refering to add control to PSU control plugin for Octoprint.
Here is the API to turn on/off the printer with out shutdown the Octprint server.

@Didel
Copy link

Didel commented Mar 16, 2023

@VikeHsu I assume you might have resolved your problem already, but still this might be helpful to you and/or others:

Using the PSU control HomeAssistant sub-plugin you can actually do the exact opposite: Define which switch in HomeAssistant should be toggled by Octopi when turning the PSU Control toggle on or off. So instead of home assistant calling an API within Octopi, this makes Octopi call the API of HomeAssistant (and will use polling to make sure that if if you toggle the switch from within HomeAssistant, the PSU state within Octopi is shown properly). It has been working great so far for me!

@fribse
Copy link

fribse commented May 4, 2023

@Didel and @VikeHsu As far as I can see, that only works for an external switch, ie. a powerplug where the printer is plugged in?
I (and I think @VikeHsu ) have a relay operated by octopi, and thus the power plugin is inside octoprint.
Having it handled directly from inside octoprint, makes it possible to just send a print, and it will turn on the printer automatically.
You can of course make your own REST switch by using the curl commands, but that seems almost moronic when there is already an integration availab.e

@fribse
Copy link

fribse commented May 4, 2023

This is of course also relevant to know for the code owner @rfleming71 :-)

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@JohnathonMohr
Copy link

Hi, I’m also interested in having this functionality enabled in the integration (i.e. control the power state of the printer via API calls to OctoPrint, made available via the PSU Control plugin linked to by @VikeHsu). This scenario is the primary reason I want to have the OctoPrint integration in HA, so not supporting this yet is a bit of a bummer.

@github-actions github-actions bot removed the stale label Aug 5, 2023
@rfleming71
Copy link
Contributor

Given the plugin supplies an API, this should be pretty straight forward to add. However, my instances of Octoprint at not supported given how I run them, so I am unable to test against a working instance. PRs are always welcome 😄

@JohnathonMohr
Copy link

JohnathonMohr commented Aug 7, 2023

As much as I'd love to implement this myself, I just don't have time to learn the Home Assistant dev platform right now. 🙁

From what I can tell, I'm guessing adding this support would require adding an additional "switch" entity, where hitting the PSU Control API controls the switch's on/off state. There doesn't appear to be a great way to retrieve updated state if controlled outside HA (other than polling), but maybe a PR could add an option to PSU Control to POST to a custom endpoint when power is controlled? Just thinking out loud.

If someone else can add the functionality, I may be able to help test it, and I could probably do some amount of debugging if something doesn't quite work.

@JohnathonMohr
Copy link

I could possibly (hopefully) add a bug fix too, if necessary.

@Didel
Copy link

Didel commented Aug 7, 2023

From what I can tell, I'm guessing adding this support would require adding an additional "switch" entity, where hitting the PSU Control API controls the switch's on/off state.

But isn't that exactly what is provided by the PSU control HomeAssistant sub-plugin ? To quote my earlier reply:

Using the PSU control HomeAssistant sub-plugin you can actually do the exact opposite: Define which switch in HomeAssistant should be toggled by Octopi when turning the PSU Control toggle on or off.

It works 2 ways: controlling the configured switch in home assistant will also toggle PSU control if needed, and enabling PSU control will toggle the switch in HA if needed.

In my opinion, it should be up to Octoprint / PSU-control to make sure the correct plugin will be triggered to actually supply power, the HA plugin should only communicate an on/off state to a switch in HA (as it currently does)

@JohnathonMohr
Copy link

JohnathonMohr commented Aug 7, 2023

Thanks @Didel, but as @fribse noted above, this seems to only work when the power is controlled by an external device. The plugin's "sensing method" must be set to "plugin" for the integration to work, but when the power is controlled via a relay (controlled via GPIO on a raspberry pi, for example) the sensing method has to be set to GPIO or Internal. So for @fribse and me, that plugin won't do the job, and we're back to needing an integration that can invoke the API endpoints exposed by PSU Control directly.

@Didel
Copy link

Didel commented Aug 10, 2023

Hhm. @JohnathonMohr I think I get the problem. But then I don't think that this should be solved within Home Assistant. Instead, I think that the right place to solve this would be in the OctoPrint PSU Control plugin .

There are 3 different things that need to happen:

  • Read the current state ('sensing' in PSU Control's wording). Could be either from GPIO, Internal, HA Sensor, ...
  • Write/set the desired state (in order to turn the printer on when it is off, and vice versa). Again, could be either by means of GPIO, Internal, HA sensor to trigger
  • Expose the current state according to PSU Control to Home Assistant and Octoprint (icon in toolbar)

In my opinion, the problem is that when using the Home Assistant PSU Control plugin, all three of those change to 'Home Assistant'. However, you are running in to the problem that you want to e.g. read and write using GPIO, but still want to have that exposed to Home Assistant (e.g. showing the current state, derived from GPIO, in HA, and being able to toggle the power via HA which will trigger PSU Control to send the correct signal over to GPIO). I think that should require a change in the setup of the PSU Control plugin for Octoprint, and not in the Octoprint plugin for Home Assistant.

Edit: By the way, I also feel I should state that I am by no means associated with neither Home Assistant nor Octoprint (or any of its plug-ins). I'm just a fanatic user of both, and I happen to be a software developer myself with a 'strong' opinion on some topics. If one of the maintainers decides on another path, then I'll follow along 🙂

Edit 2: It also feels fair to hear @edekeijzer (developer of the PSU Control Home assistant plugin for Octoprint) about their opinion on the matter.

@JohnathonMohr
Copy link

Thanks @Didel for your thoughts! I had also looked into how this plugin worked, and took a look at the Octoprint package it was relying on (pyoctoprintapi), and the more I understood, the more I was coming to the same conclusion - having the integration here wasn't the best logical choice (even if it was the place of least effort).

Instead, I decided to work around this manually using a combination of the REST Command integration, an automation with a helper toggle for a trigger, and a web hook trigger called from OctoPrint on Connecting and Disconnected events (in my case, the power being on and OctoPrint being connected are always correlated) so I can keep everything in sync. Not the most elegant, but it solves my use case.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2023
@edekeijzer
Copy link

Edit 2: It also feels fair to hear @edekeijzer (developer of the PSU Control Home assistant plugin for Octoprint) about their opinion on the matter.
This is not within the scope of my plugin as that is designed to switch HA entities from Octoprint. The main PSUControl already exposes itself, as the OctoRemote app supports it.
As a workaround, you could publish your OctoPrint to HA over MQTT, some dude built PSUControl into that (yes, this does allow you to use HA to toggle the OctoPrint PSU which will then toggle an HA entity :D)

@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants