Magic Mirror Control From HA

This Is Mark 1 verson have to start somewhere

Built this verson as a package

can turn screen on/off

sensor to show if its on/off

can reboot it

or

shut it down

#=======================================================================
# Do a FIND REPLACE
# MMIPADDRESS with the the magicMirror ipaddress ???.???.???.???
#=======================================================================
homeassistant:
  customize:
    package.node_anchors:
     customize: &customize
       package: 'Magic Mirror' 

    sensor.mm_display:
      icon: mdi:monitor
      friendly_name: Mirror Display
    switch.mm_display:
      icon: mdi:monitor
      friendly_name: Mirror Display
    script.mm_reboot:
      icon: mdi:lock-reset
    script.mm_shutdown:
      icon: mdi:power

sensor:
  - platform: rest
    resource: http://MMIPADDRESS:8080/remote?action=MONITORSTATUS
    name: mm display
    value_template: '{{ value_json.monitor }}'
#=======================================================================
#
#=======================================================================
switch:
  - platform: command_line
    switches:
      mm_display:
        command_on: "curl -s 'http://MMIPADDRESS:8080/remote?action=MONITORON'"
        command_off: "curl -s 'http://MMIPADDRESS:8080/remote?action=MONITOROFF'"

#=======================================================================
#
#=======================================================================
shell_command:
  mm_reboot: "curl -s 'http://MMIPADDRESS:8080/remote?action=REBOOT'"
  mm_shutdown: "curl -s 'http://MMIPADDRESS:8080/remote?action=SHUTDOWN'"
#=======================================================================
#
#=======================================================================
script:
  mm_reboot:
    alias: Magic Mirror Reboot
    sequence:
    - data: {}
      service: shell_command.mm_reboot
  mm_shutdown:
    alias: Magic Mirror ShutDown
    sequence:
    - data: {}
      service: shell_command.mm_shutdown   

all you need to is put above code into a file inside the package folder

do a find replace MMIPADDRESS with the IPaddress of the Magic Mirror

and the mirror MUST have This module in it

Leaning how to send message to the mirror will update when I know

the lovelace BIT

image

      - type: entities
        show_header_toggle: false
        title: "Magic Mirror"
        entities:
          - switch.mm_display
          - entity: sensor.mm_display
            name: Mirror Display 
          - script.mm_reboot
          - script.mm_shutdown

if you dont know what magic mirror is

https://magicmirror.builders/

using my old PI which was HASS got HASS on real PC now

7 Likes

Been thinking more about this. Think I need to lean some python and write my own plugin
we dont where to start tho

i did get this this working today

import json
import urllib.request
module_data = urllib.request.urlopen('http://IPADDRESS:8080/remote?action=MODULE_DATA')
modules = json.loads(module_data.read())
print(modules)
for module in modules["moduleData"]:
        print(module["name"] )
        print(module["hidden"])

which list the module i have loaded


happy with
was thinking put that into a input select and getting HA to turn hide them

can some point me down the right manual to read

added ====== 27/06/18
found this post

group_entities = hass.states.get('group.all_lights').attributes['entity_id']
all_lights = []
for e in group_entities:
    all_lights.append(e)
service_data = {'entity_id': 'input_select.timer_generico7',
                'options': all_lights}
hass.services.call('input_select', 'set_options', service_data)

run it and it worked
so …
got me thinking

import json
import urllib.request
module_data = urllib.request.urlopen('http://blabla:8080/remote?action=MODULE_DATA')
modules = json.loads(module_data.read())
my_modules = []
for module in modules["moduleData"]:
        my_modules.append(module["name"])
service_data = {'entity_id': 'input_select.mm_modules',
                'options': my_modules}
hass.services.call('input_select', 'set_options', service_data)

all I got was

:frowning:

where the manual when you need it
look like you can’t import modules

so delete the import still not working

one good thing less error lines LOL

after more read found out you can’t import :frowning:

2 Likes

Thanks a lot for this, easily got my mirror controllable from home assistant thanks to you!
Plugin would also be nice but it seems hard to make one without any experience, did you ever get further with that?

Hi @myle,

Sorry to revive an old thread. I am trying to implement this but I’m a newbie in HA and I’d like to ask for your help please.

When I try to add the Lovelace custom card, there’s the error I am receiving:

Can you (or any other member) please help me figure out what I am doing wrong?

This is my magic_mirror.yaml file:

And this is my configuration.yaml file:

let see what you did wrong

I see you have packages

then in the package folder

i have a folder mm

then In side that folder I have paskage data ( the config)

image

and the mm.yaml inside that

than that file has

#=======================================================================
# Do a FIND REPLACE
# MMIPADDRESS with the the magicMirror ipaddress ???.???.???.???
#=======================================================================
homeassistant:
  customize:
    package.node_anchors:
     customize: &customize
       package: 'Magic Mirror' 

    sensor.mm_display:
      icon: mdi:monitor
      friendly_name: Mirror Display
    switch.mm_display:
      icon: mdi:monitor
      friendly_name: Mirror Display
    script.mm_reboot:
      icon: mdi:lock-reset
    script.mm_shutdown:
      icon: mdi:power

sensor:
  - platform: rest
    resource: http://MMIPADDRESS:8080/remote?action=MONITORSTATUS
    name: mm display
    value_template: '{{ value_json.monitor }}'
#=======================================================================
#
#=======================================================================
switch:
  - platform: command_line
    switches:
      mm_display:
        command_on: "curl -s 'http://MMIPADDRESS:8080/remote?action=MONITORON'"
        command_off: "curl -s 'http://MMIPADDRESS:8080/remote?action=MONITOROFF'"

#=======================================================================
#
#=======================================================================
shell_command:
  shell_mm_reboot: "curl -s 'http://MMIPADDRESS:8080/remote?action=REBOOT'"
  shell_mm_shutdown: "curl -s 'http://MMIPADDRESS:8080/remote?action=SHUTDOWN'"
#=======================================================================
#
#=======================================================================
script:
  mm_reboot:
    sequence:
    - data: {}
      service: shell_command.shell_mm_reboot
  mm_shutdown:
    sequence:
    - data: {}
      service: shell_command.shell_mm_shutdown   

if i remember correctly you have to drop alias: out of the scripts part

do you config check if you get the green light reboot and it should be there

Hello @myle,

I also want to shutdown the MM pi via an automation.

I configured this via 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.

I also tried removing the API key from my MM config and then I could run things like monitor on and off but not shutdown

Shutdown It gives me the error that no API key is provided in confg. So I need to use the API Key

Do you have any idea where I need to do that in the HA config? I did not see anything relating to API key in your code.

did you read this

Yes, but did not read the API Readme at least not with a fresh mind yesterday. Now I found the answer and pass the API key along and yes it works.

rest_command:
turn_off_mm_screen:
url: http://192.168.xx.xx:8080/api/monitor/off?apiKey=xxxx

Thanks again for the inspiration with your setup, will tinker with it a bit more but now it works in general that’s awesome