PowerShell/Scripts/switch-shelly1.ps1

30 lines
897 B
PowerShell
Raw Normal View History

2021-02-09 19:30:45 +01:00
#!/bin/powershell
2020-12-29 15:14:21 +01:00
<#
2021-03-22 20:10:18 +01:00
.SYNTAX ./switch-shelly1.ps1 [<host>] [<turn-mode>] [<timer>]
.DESCRIPTION switches a Shelly1 device in the local network
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
2020-12-29 15:14:21 +01:00
#>
2020-12-01 10:54:41 +01:00
2021-02-18 08:50:55 +01:00
param($Host = "", $TurnMode = "", [int]$Timer = -999)
2020-12-01 10:54:41 +01:00
2021-02-18 08:50:55 +01:00
if ($Host -eq "") {
$Host = read-host "Enter hostname or IP address of the Shelly1 device"
}
if ($TurnMode -eq "") {
$TurnMode = read-host "Enter turn mode (on/off/toggle)"
}
if ($Timer -eq -999) {
[int]$Timer = read-host "Enter timer in seconds (0=endless)"
}
2020-12-01 10:54:41 +01:00
2021-02-18 08:50:55 +01:00
try {
$Result = Invoke-RestMethod "http://$($Host)/relay/0?turn=$($TurnMode)&timer=$($Timer)"
2021-02-12 12:28:59 +01:00
2021-02-18 08:50:55 +01:00
write-host -foregroundColor green "Done - switched Shelly1 device at $Host to $TurnMode for $Timer second(s)"
2020-12-01 10:54:41 +01:00
exit 0
2020-12-09 10:30:55 +01:00
} catch {
2021-02-16 10:03:20 +01:00
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-09 10:30:55 +01:00
exit 1
}