PowerShell/Scripts/switch-shelly1.ps1

23 lines
892 B
PowerShell
Raw Normal View History

2021-04-16 20:01:38 +02:00
#!/usr/bin/pwsh
2020-12-29 15:14:21 +01:00
<#
2021-04-07 15:17:49 +02:00
.SYNTAX switch-shelly1.ps1 [<host>] [<turn-mode>] [<timer>]
2021-03-22 20:10:18 +01:00
.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)
2021-04-07 15:17:49 +02: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-04-16 20:01:38 +02:00
write-host -foregroundColor green "✔️ Shelly1 device at $Host switched 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
}