PowerShell/Scripts/switch-shelly1.ps1

29 lines
950 B
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
switch-shelly1.ps1 [<host>] [<turn-mode>] [<timer>]
.DESCRIPTION
Switches a Shelly1 device in the local network
.EXAMPLE
PS> .\switch-shelly1.ps1 192.168.100.100 toggle 10
.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-07-15 15:51:22 +02:00
param([string]$Host = "", [string]$TurnMode = "", [int]$Timer = -999)
2020-12-01 10:54:41 +01:00
2021-02-18 08:50:55 +01:00
try {
2021-07-15 15:51:22 +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)" }
2021-02-18 08:50:55 +01:00
$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-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-09 10:30:55 +01:00
exit 1
}