It's in PowerShell, but this might help you understand how to send direct commands through the Insteon hub.
Couple things, I actually pull the list of devices from a network UNC that runs houselinc (I use this to populate the PowerShell dynamic parameter InsteonDeviceName). A PowerShell dynamic parameter can pull device names in many ways.
Search and replace the following strings below, then drop the function in a PowerShell module or script.
insert_computer_name_here -> your computername
insert_hub_ip_here -> your hub ip address
insert_hub_local_user_name -> your hub local username
insert_password_in_clear_text_here -> your hub local password
# Set Power-Level (which includes on/off and brightness if the Insteon device is a dimmer).
function Set-InsteonDevicePowerLevel {
[CmdLetBinding()]
[OutputType([string])]
Param (
[Parameter(Mandatory = $true, Position = 1)]
[ValidateSet("Off", "10", "25", "50", "50", "55", "60", "65", "70", "75", "90", "On")]
[string]$PowerLevel
)
DynamicParam {
# InsteonDeviceName
# Set the dynamic parameters' name
$ParameterName = 'InsteonDeviceName'
# Create the dictionary
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParamet erDictionary
# Create the collection of attributes
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
# Create and set the parameters' attributes
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $true
$ParameterAttribute.Position = 0
# Add the attributes to the attributes collection
$AttributeCollection.Add($ParameterAttribute)
# Generate and set the ValidateSet
$houseLincSettings = [xml](Get-Content "\\insert_computer_name_here\users\Public\Smar tLab s\HouseLinc\Settings\HouseLinc.settings.xml")
$insteonDevices = $houseLincSettings.settings.insteon.active_devices .device
$deviceArrSet = $insteonDevices | Select-Object -Property displayName
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute( $deviceArrSet.displayName)
# Add the ValidateSet to the attributes collection
$AttributeCollection.Add($ValidateSetAttribute)
# Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParamet er($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary
}
begin {
$PowerLevels = @{
Off = '00';
10 = '19';
25 = '40';
50 = '7F';
55 = '8C';
60 = '99';
65 = 'A5';
70 = 'B2';
75 = 'BF';
90 = 'E6';
On = 'FF'
}
# Bind the parameter to a friendly variable
$InsteonDeviceName = $PsBoundParameters[$ParameterName]
$SelectedPowerLevel = ($PowerLevels | ForEach-Object getEnumerator | Where-Object key -eq $PowerLevel).Value
}
process {
[string]$DeviceID = ($insteonDevices | Where-Object displayName -eq $InsteonDeviceName).insteonID
$InsteonDeviceID = $DeviceID.Replace(".", "")
$InsteonUserName = "insert_hub_local_user_name"
$InsteonPassword = ConvertTo-SecureString "insert_password_in_clear_text_here" -AsPlainText -Force
$insteonCred = New-Object Management.Automation.PSCredential ($InsteonUserName, $InsteonPassword)
if ($PSVersionTable.PSVersion.Major -eq 5) {
$response = Invoke-WebRequest "http://insert_hub_ip_here:25105/3?0262$($InsteonDeviceID)0F11$($SelectedPowerLevel )=I=3" `
-Credential $insteonCred
}
elseif ($PSVersionTable.PSVersion.Major -eq 7) {
$response = Invoke-WebRequest "http://insert_hub_ip_here:25105/3?0262$($InsteonDeviceID)0F11$($SelectedPowerLevel )=I=3" `
-Credential $insteonCred -AllowUnencryptedAuthentication
}
}
end {
return $response.StatusCode
}
}
Enjoy!
Couple things, I actually pull the list of devices from a network UNC that runs houselinc (I use this to populate the PowerShell dynamic parameter InsteonDeviceName). A PowerShell dynamic parameter can pull device names in many ways.
Search and replace the following strings below, then drop the function in a PowerShell module or script.
insert_computer_name_here -> your computername
insert_hub_ip_here -> your hub ip address
insert_hub_local_user_name -> your hub local username
insert_password_in_clear_text_here -> your hub local password
# Set Power-Level (which includes on/off and brightness if the Insteon device is a dimmer).
function Set-InsteonDevicePowerLevel {
[CmdLetBinding()]
[OutputType([string])]
Param (
[Parameter(Mandatory = $true, Position = 1)]
[ValidateSet("Off", "10", "25", "50", "50", "55", "60", "65", "70", "75", "90", "On")]
[string]$PowerLevel
)
DynamicParam {
# InsteonDeviceName
# Set the dynamic parameters' name
$ParameterName = 'InsteonDeviceName'
# Create the dictionary
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParamet erDictionary
# Create the collection of attributes
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
# Create and set the parameters' attributes
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $true
$ParameterAttribute.Position = 0
# Add the attributes to the attributes collection
$AttributeCollection.Add($ParameterAttribute)
# Generate and set the ValidateSet
$houseLincSettings = [xml](Get-Content "\\insert_computer_name_here\users\Public\Smar tLab s\HouseLinc\Settings\HouseLinc.settings.xml")
$insteonDevices = $houseLincSettings.settings.insteon.active_devices .device
$deviceArrSet = $insteonDevices | Select-Object -Property displayName
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute( $deviceArrSet.displayName)
# Add the ValidateSet to the attributes collection
$AttributeCollection.Add($ValidateSetAttribute)
# Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParamet er($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary
}
begin {
$PowerLevels = @{
Off = '00';
10 = '19';
25 = '40';
50 = '7F';
55 = '8C';
60 = '99';
65 = 'A5';
70 = 'B2';
75 = 'BF';
90 = 'E6';
On = 'FF'
}
# Bind the parameter to a friendly variable
$InsteonDeviceName = $PsBoundParameters[$ParameterName]
$SelectedPowerLevel = ($PowerLevels | ForEach-Object getEnumerator | Where-Object key -eq $PowerLevel).Value
}
process {
[string]$DeviceID = ($insteonDevices | Where-Object displayName -eq $InsteonDeviceName).insteonID
$InsteonDeviceID = $DeviceID.Replace(".", "")
$InsteonUserName = "insert_hub_local_user_name"
$InsteonPassword = ConvertTo-SecureString "insert_password_in_clear_text_here" -AsPlainText -Force
$insteonCred = New-Object Management.Automation.PSCredential ($InsteonUserName, $InsteonPassword)
if ($PSVersionTable.PSVersion.Major -eq 5) {
$response = Invoke-WebRequest "http://insert_hub_ip_here:25105/3?0262$($InsteonDeviceID)0F11$($SelectedPowerLevel )=I=3" `
-Credential $insteonCred
}
elseif ($PSVersionTable.PSVersion.Major -eq 7) {
$response = Invoke-WebRequest "http://insert_hub_ip_here:25105/3?0262$($InsteonDeviceID)0F11$($SelectedPowerLevel )=I=3" `
-Credential $insteonCred -AllowUnencryptedAuthentication
}
}
end {
return $response.StatusCode
}
}
Enjoy!
Comment