File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 Switches a Shelly1 device
44. DESCRIPTION
55 This PowerShell script switches a Shelly1 device in the local network.
6- . PARAMETER Host
6+ . PARAMETER host
77 Specifies either the hostname or IP address of the Shelly1 device
8- . PARAMETER TurnMode
8+ . PARAMETER turnMode
99 Specifies either 'on', 'off', or 'toggle'
10- . PARAMETER Timer
10+ . PARAMETER timer
1111 Specifies the timer in seconds (0 = infinite)
1212. EXAMPLE
1313 PS> ./switch-shelly1 192.168.100.100 toggle 10
1717 Author: Markus Fleschutz | License: CC0
1818#>
1919
20- param ([string ]$Host = " " , [string ]$TurnMode = " " , [int ]$Timer = -999 )
20+ param ([string ]$host = " " , [string ]$turnMode = " " , [int ]$timer = -999 )
2121
2222try {
23- if ($Host -eq " " ) { $Host = read-host " Enter hostname or IP address of the Shelly1 device" }
24- if ($TurnMode -eq " " ) { $TurnMode = read-host " Enter turn mode (on/off/toggle)" }
25- if ($Timer -eq -999 ) { [int ]$Timer = read-host " Enter timer in seconds (0=endless)" }
23+ if ($host -eq " " ) { $host = Read-Host " Enter the hostname or IP address of the Shelly1 device" }
24+ if ($turnMode -eq " " ) { $turnMode = Read-Host " Enter the turn mode (on/off/toggle)" }
25+ if ($timer -eq -999 ) { [int ]$timer = Read-Host " Enter the timer in seconds (0=endless)" }
2626
27- $Result = Invoke-RestMethod " http://$ ( $Host ) /relay/0?turn=$ ( $TurnMode ) &timer=$ ( $Timer ) "
27+ $result = Invoke-RestMethod " http://$ ( $host ) /relay/0?turn=$ ( $turnMode ) &timer=$ ( $timer ) "
2828
29- " ✔️ switched Shelly1 device at $Host to $TurnMode for $Timer sec"
29+ " ✔️ Switched Shelly1 device at $host to $turnMode for $timer sec. "
3030 exit 0 # success
3131} catch {
3232 " ⚠️ Error in line $ ( $_.InvocationInfo.ScriptLineNumber ) : $ ( $Error [0 ]) "
You can’t perform that action at this time.
0 commit comments