Skip to content

Commit 27f2fa0

Browse files
Merge pull request #6 from quonic/main
Implements Elgato Lighting
2 parents f633163 + 775f8f7 commit 27f2fa0

File tree

7 files changed

+393
-4
lines changed

7 files changed

+393
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
## 0.2.1:
1+
## 0.2.2
2+
3+
Adding KeyLight: Connect-KeyLight, Get-KeyLight, Set-KeyLight, Disconnect-KeyLight
4+
5+
---
6+
7+
## 0.2.1
8+
29
* Set-NanoLeaf: Adding -EffectOption parameter help (#9). Adding examples.
310
* Set-NanoLeaf: Fixing Brightness (#7). Adding Tab Completion (#8). Adding Examples
411
---

Connect-KeyLight.ps1

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
function Connect-KeyLight {
2+
<#
3+
.Synopsis
4+
Connects to a Elgato Key Lighting
5+
.Description
6+
Connects to a Elgato Key Lighting over Wifi
7+
.Example
8+
Connect-KeyLight 1.2.3.4 -PassThru
9+
.Link
10+
Get-KeyLight
11+
#>
12+
[OutputType([Nullable], [PSObject])]
13+
param(
14+
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface.
15+
[Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)]
16+
[Alias('KeyLightIPAddress')]
17+
[IPAddress]
18+
$IPAddress,
19+
20+
# If set, will output the connection information.
21+
[switch]
22+
$PassThru
23+
)
24+
25+
begin {
26+
$PSDefaultParameterValues = @{
27+
"Invoke-RestMethod:ContentType" = "application/json"
28+
}
29+
if ($home) {
30+
$lightScriptRoot = Join-Path $home -ChildPath LightScript
31+
}
32+
}
33+
34+
process {
35+
#region Attempt to Contact the Device
36+
$keyLightConf = Invoke-RestMethod -Method Get -Uri "http://$($IpAddress):9123/elgato/accessory-info"
37+
#endregion Attempt to Contact the Device
38+
39+
40+
if ($keyLightConf) {
41+
$macAddress =
42+
if ($PSVersionTable.Platform -like 'Win*' -or -not $PSVersionTable.Platform) {
43+
Get-NetNeighbor | Where-Object IPAddress -eq $IPAddress | Select-Object -ExpandProperty LinkLayerAddress
44+
}
45+
elseif ($ExecutionContext.SessionState.InvokeCommand.GetCommand('nmap', 'Application')) {
46+
nmap -Pn "$ipAddress" |
47+
Where-Object { $_ -like 'MAC Address:*' } |
48+
ForEach-Object { @($_ -split ' ')[2] }
49+
}
50+
51+
if (-not $macAddress) {
52+
Write-Error "Unable to resolve MAC address for $IpAddress, will not save connection"
53+
return
54+
}
55+
#region Save Device Information
56+
if ($home) {
57+
if (-not (Test-Path $lightScriptRoot)) {
58+
$createLightScriptDir = New-Item -ItemType Directory -Path $lightScriptRoot
59+
if (-not $createLightScriptDir) { return }
60+
}
61+
62+
$keyLightLightsConf = Invoke-RestMethod -Method Get -Uri "http://$($IpAddress):9123/elgato/lights"
63+
$keyLightSettingsConf = Invoke-RestMethod -Method Get -Uri "http://$($IpAddress):9123/elgato/lights/settings" |
64+
Select-Object powerOnBehavior, powerOnBrightness, powerOnTemperature
65+
$keyLightDataFile = Join-Path $lightScriptRoot ".$($keyLightConf.serialNumber).keylight.clixml"
66+
$keyLightConf.pstypenames.clear()
67+
$keyLightConf.pstypenames.add('KeyLight')
68+
$keyLightConf |
69+
Add-Member NoteProperty IPAddress $IPAddress -Force -PassThru |
70+
Add-Member NoteProperty MACAddress $macAddress -Force -PassThru |
71+
Add-Member NoteProperty Lights $keyLightLightsConf.lights -Force -PassThru |
72+
Add-Member NoteProperty Lights $keyLightSettingsConf -Force -PassThru |
73+
Export-Clixml -Path $keyLightDataFile
74+
}
75+
#endregion Save Device Information
76+
if ($PassThru) {
77+
$keyLightConf
78+
}
79+
}
80+
}
81+
}

Disconnect-KeyLight.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Disconnect-KeyLight {
2+
<#
3+
.Synopsis
4+
Disconnects a Elgato Key Lighting
5+
.Description
6+
Disconnects a Elgato Key Lighting, removing stored device info
7+
.Example
8+
Disconnect-KeyLight 1.2.3.4
9+
.Link
10+
Connect-KeyLight
11+
#>
12+
[OutputType([Nullable], [PSObject])]
13+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
14+
param(
15+
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface.
16+
[Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)]
17+
[Alias('KeyLightIPAddress')]
18+
[IPAddress]
19+
$IPAddress
20+
)
21+
22+
begin {
23+
if ($home) {
24+
$lightScriptRoot = Join-Path $home -ChildPath LightScript
25+
}
26+
}
27+
28+
process {
29+
@(Get-ChildItem -Filter *.keylight.clixml -Path $lightScriptRoot) |
30+
Foreach-Object {
31+
$file = $_
32+
$fileInfo = Import-Clixml -LiteralPath $file.FullName
33+
if ($fileInfo.IPAddress -eq $IPAddress -and $PSCmdlet.ShouldProcess("Remove $($fileInfo.serialNumber)")) {
34+
Remove-Item -LiteralPath $file.FullName -Force
35+
}
36+
}
37+
}
38+
}
39+

Get-KeyLight.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Get-KeyLight {
2+
<#
3+
.Synopsis
4+
Gets Elgato Key Lighting Devices
5+
.Description
6+
Gets saved Elgato Key Lighting Devices
7+
.Example
8+
Get-KeyLight
9+
.LINK
10+
Connect-KeyLight
11+
.LINK
12+
Set-KeyLight
13+
#>
14+
[CmdletBinding(DefaultParameterSetName = "ListDevices")]
15+
param(
16+
# The IP Address for the Twinkly device. This can be discovered thru the phone user interface.
17+
[Parameter(ValueFromPipelineByPropertyName)]
18+
[Alias('KeyLightIPAddress')]
19+
[IPAddress[]]
20+
$IPAddress
21+
)
22+
23+
begin {
24+
if (-not $script:KeyLightCache) {
25+
$script:KeyLightCache = @{}
26+
}
27+
if ($home) {
28+
$lightScriptRoot = Join-Path $home -ChildPath LightScript
29+
}
30+
}
31+
32+
process {
33+
#region Default to All Devices
34+
if (-not $IPAddress) {
35+
# If no -IPAddress was passed
36+
if ($home) {
37+
# Read all .twinkly.clixml files beneath your LightScript directory.
38+
Get-ChildItem -Path $lightScriptRoot -ErrorAction SilentlyContinue -Filter *.keylight.clixml -Force |
39+
Import-Clixml |
40+
ForEach-Object {
41+
if (-not $_) { return }
42+
$KeyLightConnection = $_
43+
$script:KeyLightCache["$($KeyLightConnection.IPAddress)"] = $KeyLightConnection
44+
}
45+
46+
$IPAddress = $script:KeyLightCache.Keys # The keys of the device cache become the -IPAddress.
47+
}
48+
if (-not $IPAddress) {
49+
# If we still have no -IPAddress
50+
return # return.
51+
}
52+
}
53+
#endregion Default to All Devices
54+
55+
if ($PSCmdlet.ParameterSetName -eq 'ListDevices') {
56+
return $script:KeyLightCache.Values
57+
}
58+
}
59+
}

LightScript.psd1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.2.1'
2+
ModuleVersion = '0.2.2'
33
RootModule = 'LightScript.psm1'
44
Description = 'Smarter Lighting with PowerShell'
55
FormatsToProcess = 'LightScript.format.ps1xml'
@@ -14,7 +14,10 @@
1414
LicenseURI = 'https://github.com/StartAutomating/LightScript/blob/main/LICENSE'
1515
IconURI = 'https://github.com/StartAutomating/LightScript/blob/main/Assets/LightScript.png'
1616
ReleaseNotes = @'
17-
## 0.2.1:
17+
## 0.2.2
18+
Adding KeyLight: Connect-KeyLight, Get-KeyLight, Set-KeyLight, Disconnect-KeyLight
19+
---
20+
## 0.2.1
1821
* Set-NanoLeaf: Adding -EffectOption parameter help (#9). Adding examples.
1922
* Set-NanoLeaf: Fixing Brightness (#7). Adding Tab Completion (#8). Adding Examples
2023
---

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Register-EngineEvent -SourceIdentifier NanoLeaf.Touch.Down -Action {
177177
$event.MessageData | Out-Host
178178
}
179179
180-
~~~PowerShell
180+
~~~
181181

182182
## Twinkly
183183

@@ -260,3 +260,31 @@ Set-Pixoo -Timer "00:01:00" # Set a timer for one minute
260260
261261
Set-Pixoo -RedScore 1 -BlueScore 0 # Keep a scoreboard
262262
~~~
263+
264+
## Elgato Key Lighting
265+
266+
Elgato makes Key Lighting for video recording and streaming.
267+
268+
The Elgato Control Center will show you the IP Address of your Key Lights from the Accessories' settings.
269+
270+
Once you know this, run:
271+
272+
~~~PowerShell
273+
Connect-KeyLight -IPAddress $TheKeyLightIPAddress
274+
~~~
275+
276+
Once authenticated, you can:
277+
278+
~~~PowerShell
279+
# Get information about your lights
280+
Get-KeyLight
281+
282+
# Turn on your Key Light:
283+
Set-KeyLight -On
284+
285+
# Change the brightness and ColorTemperature:
286+
Set-KeyLight -ColorTemperature 270 -Brightness 0.25
287+
288+
# Turn on and change the brightness at the same time:
289+
Set-KeyLight -On -Brightness 0.25
290+
~~~

0 commit comments

Comments
 (0)