Created
November 19, 2018 19:22
-
-
Save pH200/6e60b99816a4cff90e6d089278687e84 to your computer and use it in GitHub Desktop.
Trigger IFTTT webhooks if the device goes into sleep mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Turn of all lights when your PC goes to sleep | |
# | |
# If {Webhooks receive a web request} then {Philips Hue turn off lights} | |
# https://ifttt.com | |
# Change $hook, $from and $to of your preference. | |
$hook = 'https://maker.ifttt.com/trigger/{event}/with/key/{key}' | |
$from = '00:00' | |
$to = '06:00' | |
#Unregister-Event -SourceIdentifier 'SLEEP' | |
Register-WmiEvent -Query 'select * from Win32_PowerManagementEvent within 5 where eventtype = 4' -SourceIdentifier 'SLEEP' -Action { | |
$now = Get-Date | |
if ($(Get-Date $from).TimeOfDay -le $now.TimeOfDay -and $(Get-Date $to).TimeOfDay -ge $now.TimeOfDay) { | |
Invoke-WebRequest -Method POST -Uri $hook | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment