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.

    Switching the Magic Mirror display on/off

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    10 Posts 3 Posters 1.8k Views 3 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
      Hilt
      last edited by Hilt

      What you’re describing in Home Assistant sounds like a switch, not a button. They have different behaviours. This is important for what follows.

      Initially I had our mirror turning on/off on a schedule using crontab. But when I rebuilt it recently, I too wanted some Home Assistant integration to make this a little more intelligent ( turn on/off with the alarm system for e.g. )

      I went a different route and installed an SSH integration in Home Assistant ( there are enough modules on the long suffering Pi 3B+ ! )

      Using this integration, any SSH command can be turned into button like so :

      Screenshot (1).png

      If you’re using a Pi, you can use the following in the configuration options of the integration :

      Screenshot (2).png

      The actual code for your ease of use :

      - command: sudo shutdown -h now
        name: Turn off
        key: turn_off
      - command: sudo reboot
        name: Restart
        key: restart
      - command: vcgencmd display_power 0
        name: Turn Screen Off
        key: turn_offf
      - command: vcgencmd display_power 1
        name: Turn Screen On
        key: turn_on
      

      That vcgencmd display_power command should work on pretty much an HDMI monitor

      This results in a bunch of buttons that you can use in your Home Assistant automations

      Screenshot (3).png

      S 1 Reply Last reply Reply Quote 0
      • S Do not disturb
        sdetweil @Hilt
        last edited by

        @Hilt vcgencmd no longer works on Bullseye (last release) or Bookworm (this release) of PI os

        @Hilt said in Switching the Magic Mirror display on/off:

        vcgencmd

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        H 1 Reply Last reply Reply Quote 0
        • H Offline
          Hilt @sdetweil
          last edited by Hilt

          @sdetweil

          Thanks for the heads up Sam.

          I’m currently running Bullseye with kernel 6.1.21-v7+ and it still works in this revision. Admittedly I didn’t try with Bookworm as when I originally tried it ( Bookworm ) at launch, the VNC server had gone away on account of Wayland and alternatives were…interesting back then ( didn’t do too much research at the time to be fair ). So for this rebuild I just stuck with Bullseye.

          2 quick questions for my own edification :

          1. For Bookworm. Could the commands I listed for vcgencmd simply be replaced with wlr-randr --output HDMI-A-1 --on and wlr-randr --output HDMI-A-1 --off ( assuming HDMI port 1 ) for the same result ?

          2. Another option according the the almighty but not always correct ChatGPT is to switch to X11 and then vcgencmd would work as expected ?

          I have a spare Pi I could test on. I won’t however have time to tinker in the next few weeks. Curse having to adult !!

          Really appreciate your input

          S 1 Reply Last reply Reply Quote 0
          • S Do not disturb
            sdetweil @Hilt
            last edited by

            @Hilt said in Switching the Magic Mirror display on/off:

            Another option according the the almighty but not always correct ChatGPT is to switch to X11 and then vcgencmd would work as expected ?

            no, this is incorrect, as vcgencmd is no more , altho I see it on my bookworm system , it is not supposed to support display anymore…

            as for point 1,
            when running wayland you can use the wlr-randr command
            when running x11 you can use the xrandr command

            I don’t know the specifics of what each command needs.

            all linux commands come with help built in

            wlr-randr --help

            many provide more detailed info in the man page
            man wlr-randr
            I see the man page for vcgencmd is there too

            Sam

            How to add modules

            learning how to use browser developers window for css changes

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

              First of all, thank you for your tips.

              So, I use the module from ambarusa

              origin  https://github.com/ambarusa/MMM-HomeAssistant/ (fetch)
              origin  https://github.com/ambarusa/MMM-HomeAssistant/ (push)
              

              And use the following config

                                 module: “MMM-HomeAssistant”,
                                 config: {
                                      mqttServer: “mqtt://192.168.100.xx”,
                                      mqttPort: 1883,
                                      username: “mqttxxxx”,
                                      password: “xxxxx”,
                                      deviceName: “MagicMirror xxxx”,
                                      autodiscoveryTopic: “homeassistant”,
                                      monitorControl: true,
                                      brightnessControl: true,
                                      moduleControl: true,
                                      monitorStatusCommand: “xrandr --query | awk \”/Screen/ {print ($8 > 320) ? ‘true’ : ‘false’}\“”,
                                      monitorOnCommand: “wlr-randr --output HDMI-A-1 --on --transform 90”,
                                      monitorOffCommand: “wlr-randr --output HDMI-A-1 --off”,
              //                      monitorOnCommand: “xrandr -d :0 --output HDMI-1 --auto --rotate right”,
              //                      monitorOffCommand: “xrandr -d :0 --output HDMI-1 --off”,
                                      pm2ProcessName: “mm”,
                                  }
              

              As you can see, I use wlr-randr for on/off and rotate the monitor 90 degrees when switching it on.

              1 Reply Last reply Reply Quote 0
              • K Offline
                Klinge
                last edited by

                I think you’re right in calling it a switch. You can see it clearly in the screenshot at the arrow.

                Zwischenablage01s.jpg

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Hilt @sdetweil
                  last edited by

                  @sdetweil

                  Many thanks for the input. I’ll have a tinker when I find a gap and explore the commands and their respective soft switches. Just so that I’m future proof !

                  1 Reply Last reply Reply Quote 0
                  • 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