shbatm / MMM-Carousel

Displays a single magic mirror module at a time, rotating through the list of configured modules in a carousel-like fashion.
MIT License
40 stars 13 forks source link

Alexa/ google integration #9

Closed lodesmets closed 6 years ago

lodesmets commented 6 years ago

This isn't really a issue, but more of a question. Are there any voice assistant modules (you know of) that can controll this. Like I can say Alexa show next?

shbatm commented 6 years ago

It can be controlled by any module that can send Module Notifications which, I think the MagicMirror MMM-Alexa and other voice control modules can use. You will basically have to use the "side door" that is opened for control from the MMM-KeyBindings module.

I personally control it using an Amazon Dot via a 3rd party lighting controller which controls the rest of the house (ISY)--the 3rd-party controller controls it over via URL calls (explained below).

Within MagicMirror locally using notifications between modules: 1) Enable keyBindings in your MMM-Carousel module config section:

keyBindings: {
    NextSlide:"ArrowRight",
    PrevSlide:"ArrowLeft",
    Slide0:"Home"
},

The right half of each line can be called whatever you want--this will be what you tell the other module to send in the notification payload. SlideX is the the X'th slide starting with 0 as the first slide, e.g. to call the 3rd slide "Status" you would put: Slide2: "Status".

2) Configure the other module to send Module Notifications for each of your voice commands of the form:

{ notification: "KEYPRESS", payload: { KeyName: "Home", Sender: "SERVER" } }

Where "Home" is what you provided in the keyBindings config for that action (in this example it would jump to Slide0 or the first slide). Sender is "SERVER" if you're viewing on the same computer as the MagicMirror server (e.g. the screen is connected to the Raspberry Pi) or "LOCAL" if you're viewing it on a web browser on another computer (e.g. you use something besides http://localhost:8080 to access the mirror).

To control remotely via URL (other local controller or something like Alexa-IFTTT interaction): Note You should evaluate the security of opening up the MagicMirror computer/port through your router. The following works fine inside a local network behind a firewall, but no guarantees past that... 1) Complete everything listed above. 2) Install the MMM-KeyBindings module. 3) Update the MMM-KeyBindings config:

{
    module: 'MMM-KeyBindings',
    config: {
        evdev: {
            enabled: false,
        },
        enableNotifyServer: true,
        enableRelayServer: true,
        enableMousetrap: false,
    }
},

This basically disables everything in the KeyBindings module from accepting keys (feel free to explore that module, the wiki on GitHub for more info, and enable the keyboard control if you want--just setting enableMousetrap: true will let you control the Carousel module with the left/right arrow keys).

The important thing here is the Notify / Relay server... When enabled, this will translate calls to a URL into module notifications for other modules:

For Example, sending "Home" as discussed above would be:

http://mirror_ip:8080/MMM-KeyBindings/notify?notification=KEYPRESS&payload=%7B%22KeyState%22%3A%20%22KEY_PRESSED%22%2C%20%22Duration%22%3A%200.0%2C%20%22KeyName%22%3A%20%22Home%22%7D

// payload parameter is a url-encoded JSON string:
{"KeyState": "KEY_PRESSED", "Duration": 0.0, "KeyName": "Home"}

Please let me know if this helps and you get it working.

lodesmets commented 6 years ago

Thanks for the quick answer I will try it in a couple weeks This is a great module