Controlling MagicMirror2 from HA

The integration is quite easy, and can do the most important stuff.
So the module to include in MagicMirror is ‘MMM-Remote-Control’. That opens a REST API for the MM.
With that it’s possible to create restfull commands.
In the config for the remote module you have to allow the HA to access it:

var config = {
        address: "0.0.0.0",
        port: 8080,
        ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1",  "HAIP"],
                {
                        module: 'MMM-Remote-Control',
                        // uncomment the following line to show the URL of the remote control on the mirror
                        // position: 'bottom_left',
                        // you can hide this module afterwards from the remote control itself
                        config: {
                        //      apiKey: ''
                        }
                },

For me the first steps was to turn the screen on and off, and dim and undim it.

rest_command:
  turn_off_mm_screen:
    url: http://IP:8080/api/monitor/off
  turn_on_mm_screen:
    url: http://IP:8080/api/monitor/on
  dim_mm_screen:
    url: http://IP:8080/api/brightness/75
  undim_mm_screen:
    url: http://IP:8080/api/brightness/100

Now I can use these commands in automations:
This will turn on the light at 10%, and turn on the monitor in the magicmirror, and set it to only 75%

- id: '1557033756115'
  alias: Turn on bathroom light at night
  trigger:
  - entity_id: binary_sensor.bathroom_movement
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: '23:00'
    before: '7:59'
    condition: time
  - condition: state
    entity_id: light.spejl
    state: 'off'
  action:
  - data:
      brightness_pct: 10
      entity_id: light.spejl
    service: light.turn_on
  - data: {}
    service: rest_command.turn_on_mm_screen
  - data: {}
    service: rest_command.dim_mm_screen

I think I’m going to try and optimize it a bit, so I can call the rest_commands with a payload that specifies what it should do, instead of having four different, but this works :slight_smile:

1 Like

here is mine

1 Like

Looks cool, so you built an entire package for it. quite advanced.

Most of my Stuff is in Package Make it easyer everything in one file switches sensor scripts automations

Thanks @fribse for the good instructions. I configured the rest_commands but when I run the service calls then nothing happens.

I had also looked up the api page on my install http://ip-of-your-mirror:8080/api/docs where I can also test the calls.

What I noticed is that also there they don’t work unless I authorize them with the API key that I have in my MM config. My guess is that I need to authorize HA with the API key to allow it to call the service.

Do you have any idea where I need to do that in the HA config?

Also in your MM config in your post the apiKey part is commented out. I just tried out to not use an api key and allow all service calls by default without authorization. It works for commands like turn off monitor.

However I also want to shutdown the MM Pi with the ‘shutdown’ call but this does not work. It gives me the error that no API key is provided in confg. Now back to square 1, I need to somehow authorize HA with the API key :frowning:

Hi Hannes

It has gotten a LOT easier now, there is an integration for MagcMirror from HA now.