PowerShell/Scripts/switch-shelly1.ps1

30 lines
900 B
PowerShell
Raw Normal View History

2021-02-09 19:30:45 +01:00
#!/bin/powershell
2020-12-29 15:14:21 +01:00
<#
.SYNTAX ./switch-shelly1.ps1 [<IP-address>] [<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-01 10:54:41 +01:00
2021-02-12 12:28:59 +01:00
param($IPaddr = "", $TurnMode = "", [int]$Timer = -999)
2020-12-01 10:54:41 +01:00
try {
2020-12-29 15:14:21 +01:00
if ($IPaddr -eq "") {
2021-02-12 12:28:59 +01:00
$IPaddr = read-host "Enter IP address of the Shelly1 device"
2020-12-22 12:06:34 +01:00
}
2020-12-29 15:14:21 +01:00
if ($TurnMode -eq "") {
2021-02-12 12:28:59 +01:00
$TurnMode = read-host "Enter turn mode (on/off/toggle)"
2020-12-22 12:06:34 +01:00
}
2020-12-29 15:14:21 +01:00
if ($Timer -eq -999) {
2021-02-12 12:28:59 +01:00
[int]$Timer = read-host "Enter timer in seconds (0=endless)"
2020-12-22 12:06:34 +01:00
}
2020-12-01 10:54:41 +01:00
2020-12-22 12:06:34 +01:00
$Result = Invoke-RestMethod "http://$($IPaddr)/relay/0?turn=$($TurnMode)&timer=$($Timer)"
2021-02-12 12:28:59 +01:00
2021-02-10 19:25:48 +01:00
write-host -foregroundColor green "Done - switched Shelly1 device at $IPaddr 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 {
2020-12-22 12:06:34 +01:00
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-09 10:30:55 +01:00
exit 1
}