Skip to content

kavierkoo/Shutdown-Hibernate-PC-via-IFTTT-through-Amazon-Alexa-Deprecated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

Objective

Voice control to shutdown / hibernate PC with combinition of Amazon Alexa, IFTTT, PowerShell script, Task Scheduler, and OneDrive/DropBox

Video Demo

Deprecated

This repository is deprecated.

Instead of using going through the effort through IFTTT, I am now using PCIe Wifi Remote Control On/Off switch for my PCs.

There're plenty of brands out there support it with a relatively cheap cost (Tuya / eWeLink) and is able to directly integrate with IoT Platforms like Home Assitant / Alexa.

Salutation

This script is an modified version of MaxAnderson95's Shutdown-PC-via-IFTTT script by adding in If-Elseif-Else statement so that more use cases can be add in easily.

Currently I am using it to Shutdown and Hibernate my PC.

Prerequisite

  • IFTTT should be already connected Amazon Alexa
  • IFTTT should be already connected to OneDrive/DropBox
  • OneDrive/DropBox should be already logged in and running (synchronizing)

Steps

IFTTT Setup

  1. Login to IFTTT, Click on New Applet

  2. Click on "✚ this"

  3. Search and Choose "Amazon Alexa"

  1. Choose "Say a specific phrase"

  1. What Phrase: Insert your desire phrase to shutdown, Click "Create Trigger"

  1. Click on "✚ that"

  2. Search and Choose "OneDrive" or "DropBox"

  1. Choose "Create text file"

  1. Complete action fields
  • Filename: "shutdown" (If file name changed here, you should change PowerShell script's file name too)
  • Folder Path: Desire path (Will be use in "Computer Setup" Step 2 below.)
  • Content: anything as long as not blank
  • Click Create action

  1. Click Finish

  2. Repeat step 1 to 10 for Hibernating the PC, only change below information

  • Step 5, Change to your desire phrase to hibernate
  • Step 9, Filename: "hibernate" (If file name changed here, you should change PowerShell script's file name too)

Computer Setup

  1. Download and put the PowerShell Script into desire location

  2. Change line 2 to folder that you set in IFTTT (Should be within OneDrive/DropBox directory)

  3. Change line 3 to desire sleeptime between file checks

  4. Open "Task Scheduler"

  5. On right panel, Click Create Task

  6. In "General" Tab, Change/Insert

  • Name: "desire name"
  • Select Run whether user is logged on or not
  • Tick: Run with highest privileges
  • Tick: Hidden
  • Configure for: Windows 10

  1. In "Trigger" Tab, Click "New", Choose/Insert
  • Begin the task: At Logon
  • Tick: Enabled

  1. In "Action" Tab, Click "New", Change/Insert
  • Action: Start a program
  • Program/script: powershell.exe -file "Path_to_downloaded_Powershell_script"

  1. In "Settings" Tab, Select
  • If the task is already running, then the following rules applies: Do not start a new instance
  • Follow below image

  1. Click OK

  2. Click Windows button, type PowerShell, Right click "Run as administrator"

  3. Insert Set-ExecutionPolicy Unrestricted and type A

How it work

  1. Speak the magic phrase

  2. Amazon Alexa will create a file in OneDrive/DropBox

  3. PC will

  4. When PC startup, Task Scheduller will run the PowerShell script

  5. The PowerShell script will scan the folder you inserted in "Computer Setup" Step 2 based on internval set in "Computer Setup" Step 3

  6. When you speak the magic phrase to Alexa

  7. Amazon Alexa will create a file in OneDrive/DropBox

  8. Upon interval time, the PowerShell Script will detect the file

  9. The PowerShell script will read the file name and match with IF-Elseif-Else statment

  10. Lastly, command will be executed based on file name detected

Add in use cases (Optional)

  1. To add in more use cases, you will have to create respective IFTTT applet for it, just change the phrase and filename.

  2. In the script file, Add below

  • After line 7,
Remove-Item -Path "$SearchDirectory\your_new_filename" -Force -ErrorAction SilentlyContinue
  • After line 25,
elseif(Test-Path -Path "$SearchDirectory\your_new_filename")
{
	Remove-Item -Path "$SearchDirectory\your_new_filename"
	YOUR_NEW_COMMAND
	$FileCheck = $True	
}
  1. Restart your computer or go to Task Scheduler, End and Run the task.

Author

Kavier Koo Any queries, please contact me here

License

This project is licensed under the MIT License

Acknowledment