Read the statement by Michael Teeuw here.
Ways to automate shutdown and startup
-
Hi everyone,
I finally finished my build and the mirror is on the wall :) I can share my build sometime if you are interested.But I have one point I need help with: I want to shutdown the Raspberry Pi at night and when I am not home (energy consumption, safety etc.) and I want to automate this when my house changes it status e.g. from ‘home’ to ‘away’ > shutdown and when i get back then powers up again.
I run my apartment on Home Assistant (running on a different Pi than my mirror) and I have built a Koogeek smart powerstrip into the mirror to which the screen and the Pi are plugged in. I can switch each outlet on and off via HA, which I do with the screen right now, which turns off 5 min after the motion sensor stops detecting movement.
I could do the same with the Pi easily but my fear is that if I regularly just kill the power on the Pi without proper shutdown, that it could mess up something on the memory card or kill the Pi eventually.
Or is this unfounded and it is perfectly ok to just pull the power? As this would be the most easy solution.If killing power is a bad idea, do you have any ideas how to realize this with Home Assistant? Maybe via MQTT or so? I have already done a ton of research if there is a way to control another Pi via HA but nothing useful turned up (no integrations, add-ins, not even in HACS or somewhere on GitHub).
So if anyone has some insights here then I would really appreciate it!
-
@hesspoint it is very bad to power off without shutdown…
can’t answer the HA question.
but I do one of my systems via MMM-AlexaControl. I just add the Shutdown device to an Alexa routine.
if u had MMM-RemoteControl, you could use it’s API to invoke it’s shutdown command
-
@hesspoint
Your HA might be able to turn on/off switch by schedule. If you set cut power of pi off on 23:00 by HA, just execute shutdown script before through cron on pi… every 22:55? -
I use https://www.amazon.com/gp/product/B087FXLZZH/ as a UPS - it has scriptable shutdown and startup operations - and external leads so you can remotely power on device. something like this might work for you, although, the power consumption is so small, other than the monitor, so I wouldn’t worry about shutting it down, just the monitor.
Also, I’ve decided to change it out, I’m going with a PiJuice UPS instead. need more space.
-
@hesspoint You can shut down the operating system BUT you can’t completely shutdown the power to it. The only way to actually have the pi completely off is to unplug it. By running a shutdown command the led on the pi will still be drawing power and showing you it “isn’t running”.
If you just want to shutdown the operating system/mirror etc and don’t care that the pi still has power… Then, you can do it via the operating system. There is a thing called a cron job which you setup on the crontab. You can set it to run every night at the same time.
Here is a link on the raspberry pi forum about retropi (a different project) that will tell you how setup your cron .
https://www.raspberrypi-spy.co.uk/2018/03/raspberry-pi-retropie-shutdown-button/There are some MagicMirror modules that might help you do the same thing via a web url that points to the pi at your house. You would need a fixed ip address at your house, setup your router to allow the outside world to talk directly to your pi, and setup the module too. I haven’t used one of them.
I think there is an Internet of Things IOT module that could probably work via IFTTT too.
-
Wow, I am blown away by the many responses. Thanks so much guys!
Especially thanks @sdetweil, for pointing me in the right direction with MMM-Remote-Control. That module is absolutely awesome. I now figured out the whole thing, so here it is if anyone likes to know:
First I installed https://github.com/Jopyth/MMM-Remote-Control
You need to use the Rest API requests as in the instructions in the moduleI found this for HA: https://community.home-assistant.io/t/controlling-magicmirror2-from-ha/138527
So I need to add each rest api call I want to automate as service in HA. Then I can trigger the service i.e. shutdown in my “leave house” and “night mode” automations.
There are then 2 steps:
- shutting down the Pi via the service/rest api call
- wait a min or two and then kill the power to the pi by switching of the outlet which I can do also in the automation.
When the state change is triggered (e.g. I return home or I start moving in the house in the morning) then the automation just turns the outlet back on and the Pi will boot.
-
@hesspoint Update: There is actually a custom HA integration that is awesome: https://github.com/sindrebroch/ha-magicmirror
So I switched form the REST API to that integration and it is even better