2024-10-01 15:24:16 +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.
|
2024-08-15 10:09:53 +02:00
|
|
|
|
.PARAMETER host
|
2021-10-16 16:50:10 +02:00
|
|
|
|
Specifies either the hostname or IP address of the Shelly1 device
|
2024-08-15 10:09:53 +02:00
|
|
|
|
.PARAMETER turnMode
|
2021-10-16 16:50:10 +02:00
|
|
|
|
Specifies either 'on', 'off', or 'toggle'
|
2024-08-15 10:09:53 +02:00
|
|
|
|
.PARAMETER timer
|
2021-10-16 16:50:10 +02:00
|
|
|
|
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
|
|
|
|
|
2024-08-15 10:09:53 +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 {
|
2024-08-15 10:09:53 +02:00
|
|
|
|
if ($host -eq "") { $host = Read-Host "Enter the hostname or IP address of the Shelly1 device" }
|
|
|
|
|
if ($turnMode -eq "") { $turnMode = Read-Host "Enter the turn mode (on/off/toggle)" }
|
|
|
|
|
if ($timer -eq -999) { [int]$timer = Read-Host "Enter the timer in seconds (0=endless)" }
|
2021-07-15 15:51:22 +02:00
|
|
|
|
|
2024-08-15 10:09:53 +02:00
|
|
|
|
$result = Invoke-RestMethod "http://$($host)/relay/0?turn=$($turnMode)&timer=$($timer)"
|
2021-02-12 12:28:59 +01:00
|
|
|
|
|
2024-10-01 13:37:53 +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
|
|
|
|
|
}
|