PowerShell/Scripts/switch-shelly1.ps1

29 lines
912 B
PowerShell
Raw Normal View History

2020-12-01 10:54:41 +01:00
#!/snap/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-01-02 11:08:59 +01:00
param([string]$IPaddr = "", [string]$TurnMode = "", [int]$Timer = -999)
2020-12-01 10:54:41 +01:00
try {
2020-12-29 15:14:21 +01:00
if ($IPaddr -eq "") {
2020-12-22 12:06:34 +01:00
[String]$IPaddr = read-host "Enter IP address of the Shelly1 device"
}
2020-12-29 15:14:21 +01:00
if ($TurnMode -eq "") {
2020-12-22 12:06:34 +01:00
[String]$TurnMode = read-host "Enter turn mode (on/off/toggle)"
}
2020-12-29 15:14:21 +01:00
if ($Timer -eq -999) {
2021-01-04 11:35:31 +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)"
write-output "OK - 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
}