Insteon PLM Ruby Code 384

From LinuxMCE
Revision as of 01:30, 6 January 2008 by Ddamron (Talk | contribs)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
#### 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)
#$cmdParams.keys.each {|p| log('------dce--- Param_[' + p.to_s + ']=' + $cmdParams[p])}
case cmd.id_
when 192 # ON
  log('Processing ON command')
  if $ignorecmdon == false
    log('$ignorecmdon = false')
    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[deviceID[0].chr]
      x10Byte1 +=$X10UnitCodes[deviceID[1].chr]
      x10cmd = $X10HouseCodes[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)
  else
    $ignorecmdon = false
    log('$ignorecmdon = true')
    log('Setting $ignorecmdon == false')
  end
when 193 #OFF
  if $ignorecmdoff == false
    log('$ignorecmdoff = false')

    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!!!"
      x10Byte1 = $X10HouseCodes[deviceID[0].chr]
      x10Byte1 +=$X10UnitCodes[deviceID[1].chr]
      x10cmd = $X10HouseCodes[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)
  else
    $ignorecmdoff = false
    log('$ignorecmdoff = true')
    log('Setting $ignorecmdoff == false')

  end
when 184 #SetLevel
  if $ignoresetlevel == false
    log('$ignoresetlevel = false')
    # 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
      log "X10 DEVICE!!! relative Dimming command"
	
      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
  else
    $ignoresetlevel = false
    log('$ignoresetlevel = true')
    log('Setting $ignoresetlevel == false')

  end
end