Voice control to shutdown / hibernate PC with combinition of Amazon Alexa, IFTTT, PowerShell script, Task Scheduler, and OneDrive/DropBox
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.
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.
- 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)
-
Login to IFTTT, Click on New Applet
-
Click on "โ this"
-
Search and Choose "Amazon Alexa"
- Choose "Say a specific phrase"
- What Phrase: Insert your desire phrase to shutdown, Click "Create Trigger"
-
Click on "โ that"
-
Search and Choose "OneDrive" or "DropBox"
- Choose "Create text file"
- 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
-
Click Finish
-
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)
-
Download and put the PowerShell Script into desire location
-
Change line 2 to folder that you set in IFTTT (Should be within OneDrive/DropBox directory)
-
Change line 3 to desire sleeptime between file checks
-
Open "Task Scheduler"
-
On right panel, Click Create Task
-
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
- In "Trigger" Tab, Click "New", Choose/Insert
- Begin the task: At Logon
- Tick: Enabled
- In "Action" Tab, Click "New", Change/Insert
- Action: Start a program
- Program/script: powershell.exe -file "Path_to_downloaded_Powershell_script"
- In "Settings" Tab, Select
- If the task is already running, then the following rules applies: Do not start a new instance
- Follow below image
-
Click OK
-
Click Windows button, type PowerShell, Right click "Run as administrator"
-
Insert Set-ExecutionPolicy Unrestricted and type A
-
Speak the magic phrase
-
Amazon Alexa will create a file in OneDrive/DropBox
-
PC will
-
When PC startup, Task Scheduller will run the PowerShell script
-
The PowerShell script will scan the folder you inserted in "Computer Setup" Step 2 based on internval set in "Computer Setup" Step 3
-
When you speak the magic phrase to Alexa
-
Amazon Alexa will create a file in OneDrive/DropBox
-
Upon interval time, the PowerShell Script will detect the file
-
The PowerShell script will read the file name and match with IF-Elseif-Else statment
-
Lastly, command will be executed based on file name detected
-
To add in more use cases, you will have to create respective IFTTT applet for it, just change the phrase and filename.
-
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
}
- Restart your computer or go to Task Scheduler, End and Run the task.
Kavier Koo Any queries, please contact me here
This project is licensed under the MIT License