MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Ways to automate shutdown and startup

    Scheduled Pinned Locked Moved Hardware
    raspberry pishutdownautomationhome assistant
    7 Posts 5 Posters 1.8k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      hesspoint
      last edited by

      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!

      S M BKeyportB kayakbabeK 4 Replies Last reply Reply Quote 0
      • S Away
        sdetweil @hesspoint
        last edited by sdetweil

        @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

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • M Offline
          MMRIZE @hesspoint
          last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • BKeyportB Offline
            BKeyport Module Developer @hesspoint
            last edited by BKeyport

            @hesspoint

            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.

            The "E" in "Javascript" stands for "Easy"

            1 Reply Last reply Reply Quote 0
            • kayakbabeK Offline
              kayakbabe @hesspoint
              last edited by kayakbabe

              @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.

              1 Reply Last reply Reply Quote 0
              • H Offline
                hesspoint
                last edited by

                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 module

                I 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:

                1. shutting down the Pi via the service/rest api call
                2. 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.

                H 1 Reply Last reply Reply Quote 1
                • H Offline
                  hesspoint @hesspoint
                  last edited by

                  @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

                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy
                    OSZAR »