Difference between revisions of "Insteon PLM Ruby Code 384"
From LinuxMCE
(Updated to support X10) |
|||
Line 46: | Line 46: | ||
$cmdParams = cmd.params_ | $cmdParams = cmd.params_ | ||
log('------dce--- cmdID:' + $cmdID.to_s + ', cmdFrom:' + $cmdFrom.to_s + ', cmdTo:' + $cmdTo.to_s + ', cmdType:' + $cmdType.to_s + ', Priority:' + $cmdPriority.to_s) | 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 | |
− | case cmd.id_ | + | log('Detected Command sent to Self!') |
− | when 192 # ON | + | return |
− | + | end | |
− | + | case cmd.id_ | |
− | + | when 192 # ON | |
− | + | log('Processing ON command') | |
+ | if insteonID.length > 2 then | ||
− | + | param = {'Command' => 'SndIns', | |
− | + | 'Parameter1' => insteonID[0], | |
− | + | 'Parameter2' => insteonID[1], | |
− | + | 'Parameter3' => insteonID[2], | |
− | + | 'Parameter4' => '0F', | |
− | + | 'Parameter5' => '11', | |
− | + | 'Parameter6' => 'FF'} | |
− | + | $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 | |
− | + | ||
− | + | ||
− | + | ||
− | when 193 #OFF | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | param = {'Command' => 'SndIns', | |
− | + | 'Parameter1' => insteonID[0], | |
− | + | 'Parameter2' => insteonID[1], | |
− | + | 'Parameter3' => insteonID[2], | |
− | + | 'Parameter4' => '0F', | |
− | + | 'Parameter5' => '13', | |
− | + | 'Parameter6' => '00'} | |
− | + | $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 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 | |
− | end | + | # DOWN |
− | </pre> | + | 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</pre> |
Revision as of 01:46, 14 February 2008
#### Written by Dan Damron #### #384 Process Receive Command for Child #### # #Commands needing implementation # Climate commands: # 279 (Set Fan) # 280 (Set Heat/Cool) # 278 (Set Temperature) # Climate Events: # 25 Temperature Changed # 26 Humidity Changed # 27 Thermostat Set Point Changed # 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_ 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 192 # ON log('Processing ON command') if insteonID.length > 2 then param = {'Command' => 'SndIns', 'Parameter1' => insteonID[0], 'Parameter2' => insteonID[1], 'Parameter3' => insteonID[2], 'Parameter4' => '0F', 'Parameter5' => '11', 'Parameter6' => 'FF'} $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 param = {'Command' => 'SndIns', 'Parameter1' => insteonID[0], 'Parameter2' => insteonID[1], 'Parameter3' => insteonID[2], 'Parameter4' => '0F', 'Parameter5' => '13', 'Parameter6' => '00'} $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 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