Alexa unRAID voice control How-To


Squid

Recommended Posts

Here is how to get Alexa to control your server (IE: have Alexa start up a VM / docker container etc).  This is all geared towards using a free Dropbox account as the cloud server and Alexa, but the concept would be the same for any other cloud storage providers (provided you can mount the cloud storage location) and Google Assistant.  You probably also need to use the same login as you would for your Alexa account.  (I just used "login via google" for everything listed here, which matches my alexa account)

 

 

image.png.dcc31754989486b0f83361c072f99704.png

 

  • You must however change the host path for the Data Files from it's default of /mnt/user/Dropbox to instead be /mnt/cache/Dropbox (dropbox will not work if it's not pointed directly at a drive), with an access mode of RW:SLAVE

 

image.thumb.png.7109c10f1ca7ea3a83f5b228ef9c4300.png

 

  • Start the dropbox application, and view the logs for it.

image.png

 

 

  • In the logs there will be a line similar to

 

image.png.ebb1ec6c9b52f1129240a9d680112ee8.png

 

  • Go to the URL and connect the server to your account
  • Set Dropbox to autostart
  • Go to https://ifttt.com/join and create a free account
  • Go to Create

 

image.png.c4e2037695e3180248feb71de1a6ba94.png

 

  • Click the Plus sign

 

image.thumb.png.67ba6e0c337a1cdeb02867a5d7497284.png

 

  • Select Amazon Alexa

 

image.png.3e2c54177acdb96ae39d2fc2a4f3d499.png

 

  • Select Say A Specific Phrase

 

image.png.00db6cb8c58bcaf7d4bc07379a43d59b.png

 

  • Tell Alexa what to listen for and create the trigger

 

image.png.be27a714f6ddd660e04fb515976beb3c.png

 

  • Click the Plus Sign

 

image.thumb.png.707c4c32ce1ea29caa449d0f04f1c875.png

 

  • Choose Dropbox and create a text file

 

image.png.5b42ff457e55f7a68c5725593b9af17a.pngimage.png.5c1583cc209c1c8d6a7e075b93646c34.png

 

  • In the box, the "content" is the command to be executed.  If you're running multiple commands, then I would suggest executing them as a script ie: content would be 
/bin/bash /boot/my_scripts/mytestscript.sh
  • Set the dropbox folder path to be unraid_actions  Then click create action  (In this example, we're just going to write "This is a test" into the syslog

 

image.thumb.png.222376339a863c507f4cfbe8be79b546.png

 

 

  • Using the User Scripts plugin (if already installed, then make sure that it's up to date), set up the following script to run at First Array Start Only

 

#!/usr/bin/php
<?
  for ( ;; ) {
    exec("inotifywait /mnt/cache/Dropbox/unraid_actions > /dev/null 2>&1",$out,$err);
    if ($err) { sleep(10); continue; }
    foreach (glob("/mnt/cache/Dropbox/unraid_actions/*.txt") as $file) {
      exec("logger ".escapeshellarg("Executing Voice Command ".file_get_contents($file)));
      passthru("/bin/bash ".escapeshellarg($file));
      unlink($file);
      for ( ;; ) {
       sleep(1);
       if ( ! is_file($file) ) break;
      }
    }
  }
?>

 

  • Enter in the following command at the terminal  (If you don't do this, then it will miss the first trigger ever given)
mkdir -p /mnt/cache/Dropbox/unraid_actions
  • Reboot the server and test what you've created
Quote

Alexa, trigger this is a test

 

Apr 23 08:40:27 unraidA root: Executing Voice Command logger this is a test
Apr 23 08:40:27 unraidA root: this is a test

 

Success!

 

Now you can create any given command you want for Alexa to be able to execute on your server.  IE: you can start a VM with the appropriate virsh commands, start a docker container, etc etc etc.  Enjoy

 

 

DANGER ZONE:

 

DO NOT USE A DROPBOX where other people have write access to it (ie: make sure that no one else can place a file into unraid_actions).  This script will execute ANY file placed into unraid_actions, and if/when your kids get annoyed at you, there is nothing stopping them from deleting the contents of your array.  Only use drop box where you are in 100% complete control of.

 

To avoid this problem, you could expand the user scripts script to actually read what's in the file (say the contents are Start VM) and then it issues the appropriate command itself.  I'll leave the customization up to you guys.  Something akin to

#!/usr/bin/php
<?
  for ( ;; ) {
    exec("inotifywait /mnt/cache/Dropbox/unraid_actions > /dev/null 2>&1",$out,$err);
    if ($err) { sleep(10); continue; }
    foreach (glob("/mnt/cache/Dropbox/unraid_actions/*.txt") as $file) {
      $command = trim(file_get_contents($file));
      exec("logger ".escapeshellarg("Executing Voice Command $command"));
      switch ($command) {
        case "test":
          exec("logger this is a test");
          break;
        case "start VM":
          exec("virsh.....");
          break;
        case "start plex":
          exec("docker start plex");
          break;
        default:
          exec("logger ".escapeshellarg("unknown voice command $command"));
          break;
      }
      unlink($file);
      for ( ;; ) {
        sleep(1);
        if ( ! is_file($file) ) break;
      }
    }
  }
?>

 

  • Like 1
  • Thanks 2
Link to comment
  • 1 year later...
  • 8 months later...

Hi Squid, thanks. 


I actually tried removing the DROPBOX_SKIP_UPDATE value from the container settings. and made sure set the "Dropbox" share set to Cache setting to "No" and just tried restarting the container, and everything worked already. 

 

just circling back to share what was done to make the container work. 

 

Edit: for me this is very helpful because i don't have to do any WOL or VPN in the Server to turn on my windows VM. I can just let the kids know what to say to have the Windows VM start.  

thank you again for the guide.

Edited by baby0nboardInSg
  • Thanks 1
Link to comment
  • 1 year later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.