PowerShell/Scripts/switch-shelly1.ps1

35 lines
1.1 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2022-01-30 10:49:30 +01:00
Switches a Shelly1 device
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2022-01-30 10:49:30 +01:00
This PowerShell script switches a Shelly1 device in the local network.
2021-10-16 16:50:10 +02:00
.PARAMETER Host
Specifies either the hostname or IP address of the Shelly1 device
.PARAMETER TurnMode
Specifies either 'on', 'off', or 'toggle'
.PARAMETER Timer
Specifies the timer in seconds (0 = infinite)
2021-07-13 21:10:02 +02:00
.EXAMPLE
2021-09-27 08:35:45 +02:00
PS> ./switch-shelly1 192.168.100.100 toggle 10
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-30 10:49:30 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
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-09-27 08:35:45 +02:00
"✔️ switched Shelly1 device at $Host to $TurnMode for $Timer sec"
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-09 10:30:55 +01:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-09 10:30:55 +01:00
exit 1
}