-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from StartAutomating/MoreLightScripting
More light scripting
- Loading branch information
Showing
17 changed files
with
532 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Write-FormatView -TypeName Pixoo.Weather -Property Weather, CurTemp, MaxTemp, MinTemp, Pressure, WindSpeed, Visibility -AutoSize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
Write-formatView -TypeName Pixoo -Property IPAddress, MACAddress, Brightness | ||
|
||
Write-formatView -TypeName Pixoo -Property RotationFlag, GyrateAngle, MirrorFlag -Name Orientation | ||
Write-formatView -TypeName Pixoo -Property IPAddress, MACAddress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
function Watch-HueSensor | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Watches Hue Sensors for changes | ||
.DESCRIPTION | ||
Watches Hue Sensors for changes. | ||
An event will be generated whenever a sensor changes. | ||
.LINK | ||
Get-HueSensor | ||
.EXAMPLE | ||
# Watch for events every minute | ||
Watch-HueSensor -Interval "00:01:00" | ||
# Whenever daylight changes | ||
Register-EngineEvent -SourceIdentifier Daylight.Changed -Action { | ||
if ($event.MessageData.state.Daylight) { | ||
Set-HueLight -Brightness 0.5 | ||
Set-NanoLeaf -Brightness 0.5 | ||
} else { | ||
Set-HueLight -Brightness 1 | ||
Set-NanoLeaf -Brightness 1 | ||
} | ||
} | ||
#> | ||
[OutputType([Management.Automation.Job])] | ||
param( | ||
# The interval hue sensors will be polled. By default, every 2.5 seconds. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[timespan] | ||
$Interval = '00:00:02.5' | ||
) | ||
|
||
process { | ||
#region Define Background Job | ||
$watchJob = [scriptblock]::Create((@" | ||
Import-Module '$($MyInvocation.MyCommand.Module.Path -replace '\.psm1$', '.psd1')' | ||
`$sleepInterval = [Timespan]'$interval' | ||
`$lastSensorCheck = [DateTime]::UTCNow | ||
do { | ||
"@) + { | ||
Register-EngineEvent -Forward -SourceIdentifier Hue.Sensor.Changed | ||
foreach ($sensor in @(Get-HueSensor)) { | ||
if (($sensor.State.lastUpdated -eq 'none') -or ( | ||
$sensor.State.lastUpdated -lt $LastSensorCheck | ||
)) { | ||
continue | ||
} | ||
|
||
New-Event -SourceIdentifier "Hue.Sensor.Changed" -MessageData $sensor | ||
$eventName = "$($sensor.Name -replace '\s').Changed" | ||
Register-EngineEvent -Forward -SourceIdentifier $eventName | ||
New-Event -SourceIdentifier $eventName -MessageData $sensor | ||
} | ||
$LastSensorCheck = [datetime]::UtcNow | ||
Start-Sleep -Milliseconds $sleepInterval.TotalMilliseconds | ||
} + " | ||
} while (`$true)") | ||
|
||
#endregion Define Background Job | ||
|
||
#region Launch Job | ||
$jobExists = Get-Job | Where-Object Name -EQ Watch-HueSensor | ||
if ($jobExists -and $jobExists.Interval -gt $Interval) { | ||
$jobExists | Remove-Job -Force | ||
} | ||
Start-Job -ScriptBlock $watchJob -Name 'Watch-HueSensor' | | ||
Add-Member NoteProperty Interval $Interval -Force -PassThru | ||
#endregion Launch Job | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.