Skip to content

Instantly share code, notes, and snippets.

@pH200
Created November 19, 2018 19:22
Show Gist options
  • Save pH200/6e60b99816a4cff90e6d089278687e84 to your computer and use it in GitHub Desktop.
Save pH200/6e60b99816a4cff90e6d089278687e84 to your computer and use it in GitHub Desktop.
Trigger IFTTT webhooks if the device goes into sleep mode
# 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