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

[Question]: Is it possible to power on the smart plug when Octoprint starts? #204

Closed
Alwinator opened this issue Aug 17, 2020 · 15 comments · Fixed by #220
Closed

[Question]: Is it possible to power on the smart plug when Octoprint starts? #204

Alwinator opened this issue Aug 17, 2020 · 15 comments · Fixed by #220
Labels
enhancement New feature or request solved workaround documented or fix applied
Milestone

Comments

@Alwinator
Copy link

It would be very convenient. By the way thank you for your great plugin! Thank you in advance.

@Alwinator Alwinator added the enhancement New feature or request label Aug 17, 2020
@jneilliii
Copy link
Owner

There is a way, although a little convoluted. Create a new file called startup.sh in /home/pi/.octoprint/scripts/ and put this into it, replacing the API KEY (you can get that from your user settings) and plug's ip address.

#!/bin/bash
curl -s -H "Content-Type: application/json" -H "X-Api-Key: PUTYOUTAPIKEYHERE" -X POST -d '{"command":"turnOn", "ip":"PUTYOURPLUGSIPHERE"}' https://127.0.0.1/api/plugin/tplinksmartplug

after creating the file you need to run this command to make it executable.

chmod +x /home/pi/.octoprint/scripts/startup.sh

and then edit your config.yaml to include the startup event by adding this.

events:
    subscriptions:
    -   command: /home/pi/.octoprint/scripts/startup.sh
        event: Startup
        type: system

@Alwinator
Copy link
Author

Alwinator commented Aug 17, 2020

Thanks a lot for your answer! But it doesn't work yet.

#!/bin/bash
curl -s -H "Content-Type: application/json" -H "X-Api-Key: PUTYOUTAPIKEYHERE" -X POST -d '{"command":"turnOn", "ip":"PUTYOURPLUGSIPHERE"}' https://127.0.0.1/api/plugin/tplinksmartplug

Works after removing the S from HTTPS. Now it turns on my printer like it should.

events:
subscriptions:
- command: /home/pi/.octoprint/scripts/startup.sh
event: Startup
type: system

When I add this lines to my config.yaml and restart Octoprint it crashes. The status is active (exited). Nothing written to ~/.octoprint/logs/octoprint.log

Do you have an idea why?

@jneilliii
Copy link
Owner

The space indentation of those lines are extremely important in config.yaml. Just make sure that you match up the space indentation in the areas around it. Some config.yam files use 2 spaces, others use 4. Just make sure it matches the way it looks elsewhere.

@Alwinator
Copy link
Author

Thank you, now everything works!

I replaced the tabs with 4 spaces and this fixed the problem.

Then it showed the following error in the logs:

2020-08-18 13:42:43,555 - octoprint.events - WARNING - Command failed with return code 7: Command '/home/pi/.octoprint/scripts/startup.sh' returned non-zero exit status 7

I fixed it by adding sleep 5 in the startup.sh before the turn on command. It is definitely not the best way to solve this, but it works.

@jneilliii Is it possible to add this directly to the plugin? That you have a checkbox for every object in the web interface: Power on when Octoprint starts

@jneilliii
Copy link
Owner

Yes, it's possible. I was just giving you a temporary solution until I'm able to get around to making the change.

@jneilliii jneilliii reopened this Aug 18, 2020
@Alwinator
Copy link
Author

@jneilliii Thank you a lot! I am looking forward to the feature.

jneilliii added a commit that referenced this issue Sep 3, 2020
@jneilliii
Copy link
Owner

Startup event monitoring implemented in the above commit and will be included in next release. If you want to try it out you can install by copying/pasting the URL below in plugin manager > get more > ...from URL and clicking install.

https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/archive/0.9.25.zip

@jneilliii jneilliii added the solved workaround documented or fix applied label Sep 3, 2020
@jneilliii jneilliii added this to the 0.9.25 milestone Sep 3, 2020
@Alwinator
Copy link
Author

Thank you a lot for implementing, but I have just tested it and it does not work. When I just restart Octoprint it works, but when I restart my whole Raspberry Pi it does not work. I had exactly the same problem with my script. I have solved it with adding sleep 5 before the turn on command, but maybe there is a better way to solve this.

@jneilliii
Copy link
Owner

Interesting, I'll have to do some additional testing with a full power up. I was just testing by restarting octoprint from the system menu.

@Alwinator
Copy link
Author

Okay, thank you!

@jneilliii jneilliii mentioned this issue Nov 12, 2020
@Alwinator
Copy link
Author

@jneilliii Thank you for your work, but I still have this problem:

Thank you a lot for implementing, but I have just tested it and it does not work. When I just restart Octoprint it works, but when I restart my whole Raspberry Pi it does not work. I had exactly the same problem with my script. I have solved it with adding sleep 5 before the turn on command, but maybe there is a better way to solve this.

@jneilliii jneilliii reopened this Nov 13, 2020
@jneilliii
Copy link
Owner

Sorry @Alwinator I forgot to test a full power on. Probably just need to move the stuff into a different startup event section.

@jneilliii jneilliii removed the solved workaround documented or fix applied label Nov 13, 2020
@jneilliii
Copy link
Owner

I think I got this startup issue really resolved now. I have tested with my pi here going from a cold boot and it works as expected here. If you want to test it out you can copy/paste the URL below into plugin manager > get more > ...from URL and clicking install.

https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/archive/0.9.26rc2.zip

@jneilliii jneilliii added the solved workaround documented or fix applied label Nov 14, 2020
@Alwinator
Copy link
Author

Alwinator commented Nov 16, 2020

@jneilliii Thank you a lot! It works perfectly!

@jneilliii
Copy link
Owner

Great news, thanks for reporting back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request solved workaround documented or fix applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants