Insteon PLM Ruby Code 384

From LinuxMCE
Jump to: navigation, search
Version Status Date Updated Updated By
710 Unknown N/A N/A
810 Unknown N/A N/A
1004 Unknown N/A N/A
1204 Unknown N/A N/A
1404 Unknown N/A N/A
Usage Information
#### Written by Dan Damron
#### #384 Process Receive Command for Child ####
#
#Commands needing implementation
# Climate Events:
# 25 Temperature Changed  Partially working
# 26 Humidity Changed     Partially working
# 27 Thermostat Set Point Changed  Partially working

# Security Commands:
# 746 Disarm Panel
# 758 Get Sensors List
# 19 Set House Mode
# 387 Verify PIN
# Security Events:
# 9 Sensor Tripped
# 16 Security Breach
# 17 Fire Alarm
# 18 Reset Alarm
# 39 Air Quality
# 40 Doorbell
# 41 Monitor Mode
# 42 Movement Detected
# 43 House Mode Changed
# 44 Presence Detected
# 45 Presence Lost
# 67 Alarm Panel Mode Change






deviceID = device_.childdevices_[cmd.devidto_].devdata_[12]
insteonID = deviceID.chomp.split('.')
$cmdID = cmd.id_
$cmdTo = cmd.devidto_
childType = device_.childdevices_[cmd.devidto_].devtemplid_
$cmdFrom = cmd.devidfrom_
$cmdPriority = cmd.priority_
$cmdType = cmd.type_
$cmdParams = cmd.params_
##Used Only for Thermostat Tempruature Changes########
$TempParamSplit =cmd.params_.to_s.split('/') # splits Tempurature string to allow for heat and cool settings
$ConvertTempInt = $TempParamSplit[1].to_i * 2
$ConvertTempHex = $ConvertTempInt.to_s(16) #Converts temp to hex to send to Thermostat
#################################
log('------dce--- cmdID:' + $cmdID.to_s + ', cmdFrom:' + $cmdFrom.to_s + ', cmdTo:' + $cmdTo.to_s + ', cmdType:' + $cmdType.to_s + ', Priority:' + $cmdPriority.to_s)
if $cmdTo == $cmdFrom
log('Detected Command sent to Self!')
return
end
case cmd.id_

when 278 # Set Temp
log('Processing Temp Control command')
#log($cmdParams)
if insteonID.length > 2 then
case $TempParamSplit[0].to_s
when '5C' #sending Heatpoint Tempurature
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6C', # Defines Cool Setpoint
'Parameter6' => $ConvertTempHex} # send Tempurature Value in Hex
$cmdqueue << param
SndIns()

when '5H' #sending Heatpoint Tempurature
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6D', # Defines Heat Setpoint
'Parameter6' => $ConvertTempHex} # send Tempurature Value in Hex
$cmdqueue << param
SndIns()

end
end

when 279 #Fan Control
log('Processing Fan Control command')
log($cmdParams)
if insteonID.length > 2 then

case $cmdParams.to_s
when '81' # Fan ON
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B',
'Parameter6' => '07'} # Sets Fan to ON
log(param)
when '82' # Fan OFF
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B',
'Parameter6' => '08'} # Sets fan OFF
$cmdqueue << param
SndIns()
end
end

when 280 # Heat/Cool/Auto
log('Processing Heat/Cool/Auto command')
#log('Test Param:' +$cmdParams.to_s)
if insteonID.length > 2 then
case $cmdParams.to_s
when '8H' # Heat Command
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B', # Indicates device is a Thermostat
'Parameter6' => '04'} # sets to Heat Mode
$cmdqueue << param
SndIns()

when '8C' # Cool Command
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B',
'Parameter6' => '05'} # Sets to Cool
$cmdqueue << param
SndIns()

when '8A' # Auto Command
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B',
'Parameter6' => '06'} # Sets to Auto

$cmdqueue << param
SndIns()
end
end
when 192 # ON
log('Processing ON command')
if insteonID.length > 2 then
if childType == 2198 then #Used For Thermostat only Sets to Auto, No on command.
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B', # Indicates device is a Thermostat
'Parameter6' => '06'} # sets to Auto
else #Used For Everything else
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '11',
'Parameter6' => 'FF'}
end
$cmdqueue << param
SndIns()
else
log "------dce--- X10 DEVICE!!!"
# Send X10 ON command.
#first, figure out the house code and unit code.
log('DeviceID=' + deviceID)
x10Byte1 = $X10HouseCodes.index(deviceID[0].chr)
x10Byte1 += $X10UnitCodes.index(deviceID[1].chr)
x10cmd = $X10HouseCodes.index(deviceID[0].chr)
x10cmd += '2' # command code for ON
log('X10 Byte1:' + x10Byte1)
param = {'Command' => 'SndX10',
'Parameter1' => x10Byte1,
'Parameter2' => '00'}
$cmdqueue << param
param = {'Command' => 'SndX10',
'Parameter1' => x10cmd,
'Parameter2' => '80'}
$cmdqueue << param
SndIns()
end
reportStatus($children[deviceID], 100)
when 193 #OFF
if insteonID.length > 2 then
if childType == 2198 then #Used For Thermostat only
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B', # Indicates Device is Thermostat
'Parameter6' => '09'} # Sets to Off
else
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '13',
'Parameter6' => '00'}
end
$cmdqueue << param
SndIns()
else
log "------dce--- X10 DEVICE!!!"
log('DeviceID=' + deviceID)

x10Byte1 = $X10HouseCodes.index(deviceID[0].chr)
x10Byte1 += $X10UnitCodes.index(deviceID[1].chr)
x10cmd = $X10HouseCodes.index(deviceID[0].chr)
x10cmd += '3' # command code for OFF
log('X10 Byte1:' + x10Byte1)
param = {'Command' => 'SndX10',
'Parameter1' => x10Byte1,
'Parameter2' => '00'}
$cmdqueue << param
param = {'Command' => 'SndX10',
'Parameter1' => x10cmd,
'Parameter2' => '80'}
$cmdqueue << param
SndIns()

end
reportStatus($children[deviceID], 0)
when 193
if insteonID.length > 2 then
#Needs Work

end

when 184 #SetLevel
# convert from percent to hex
dim_level = percenttohex(cmd.params_[76])
#log("------dce--- Dim Level:" + dim_level.to_s)
if insteonID.length > 2 then

param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '11',
'Parameter6' => dim_level}
$cmdqueue << param
SndIns()
else
# In the PRESET DIM X10 command, the lsbit of the command code is the MSB of the
# dim level, and the house code represents the 4 lsbits of the dim level.
# This is why Pre-Set Dim command is A AND B.
log('Parameter 76 = ' + cmd.params_[76].to_s)
log "X10 DEVICE!!! relative Dimming command"
log('DeviceID=' + deviceID)
x10Byte1 = $X10HouseCodes.index(deviceID[0].chr)
x10Byte1 += $X10UnitCodes.index(deviceID[1].chr)
x10cmd = $X10HouseCodes.index(deviceID[0].chr)
#first, determine if its UP or Down

if $state[deviceID].to_i > hextopercent(dim_level).to_i
# DOWN
x10cmd += $X10CommandCodes.index('Dim')
else
# UP
x10cmd += $X10CommandCodes.index('Bright')
end

log('X10 Byte1:' + x10Byte1)
param = {'Command' => 'SndX10',
'Parameter1' => x10Byte1,
'Parameter2' => '00'}
$cmdqueue << param
param = {'Command' => 'SndX10',
'Parameter1' => x10cmd,
'Parameter2' => '80'}
$cmdqueue << param

SndIns()
log('Dim Level:' + hextopercent(dim_level).to_s)
#now send status info (we should not have to to this, but do)
reportStatus($children[deviceID], hextopercent(dim_level))
end

end