Difference between revisions of "Insteon PLM Ruby Code 384"

From LinuxMCE
Jump to: navigation, search
 
(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)
#$cmdParams.keys.each {|p| log('------dce--- Param_[' + p.to_s + ']=' + $cmdParams[p])}
+
if $cmdTo == $cmdFrom
case cmd.id_
+
log('Detected Command sent to Self!')
when 192 # ON
+
return
  log('Processing ON command')
+
end
  if $ignorecmdon == false
+
case cmd.id_
    log('$ignorecmdon = false')
+
when 192 # ON
    if insteonID.length > 2 then
+
log('Processing ON command')
 +
  if insteonID.length > 2 then
 
 
      param = {'Command' => 'SndIns',  
+
    param = {'Command' => 'SndIns',  
        'Parameter1' => insteonID[0],  
+
      'Parameter1' => insteonID[0],  
        'Parameter2' => insteonID[1],
+
      'Parameter2' => insteonID[1],
        'Parameter3' => insteonID[2],
+
      'Parameter3' => insteonID[2],
        'Parameter4' => '0F',  
+
      'Parameter4' => '0F',  
        'Parameter5' => '11',
+
      'Parameter5' => '11',
        'Parameter6' => 'FF'}
+
      'Parameter6' => 'FF'}
      $cmdqueue << param
+
    $cmdqueue << param
      SndIns()
+
    SndIns()
    else
+
  else
      log "------dce--- X10 DEVICE!!!"
+
    log "------dce--- X10 DEVICE!!!"
      # Send X10 ON command.
+
# Send X10 ON command.
      #first, figure out the house code and unit code.
+
#first, figure out the house code and unit code.
      log('DeviceID=' + deviceID)
+
log('DeviceID=' + deviceID)
      x10Byte1 = $X10HouseCodes[deviceID[0].chr]
+
x10Byte1 = $X10HouseCodes.index(deviceID[0].chr)
      x10Byte1 +=$X10UnitCodes[deviceID[1].chr]
+
x10Byte1 += $X10UnitCodes.index(deviceID[1].chr)
      x10cmd = $X10HouseCodes[deviceID[0].chr]
+
x10cmd = $X10HouseCodes.index(deviceID[0].chr)
      x10cmd += '2' # command code for ON
+
x10cmd += '2' # command code for ON
      log('X10 Byte1:' + x10Byte1)
+
log('X10 Byte1:' + x10Byte1)
      param = {'Command' => 'SndX10',  
+
param = {'Command' => 'SndX10',  
        'Parameter1' => x10Byte1,
+
        'Parameter1' => x10Byte1,
        'Parameter2' => '00'}
+
        'Parameter2' => '00'}
      $cmdqueue << param
+
$cmdqueue << param
      param = {'Command' => 'SndX10',
+
param = {'Command' => 'SndX10',
        'Parameter1' => x10cmd,
+
'Parameter1' => x10cmd,
        'Parameter2' => '80'}
+
'Parameter2' => '80'}
      $cmdqueue << param
+
$cmdqueue << param
      SndIns()
+
    SndIns()
    end
+
  end
    reportStatus($children[deviceID], 100)
+
  reportStatus($children[deviceID], 100)
  else
+
when 193 #OFF
    $ignorecmdon = false
+
  if insteonID.length > 2 then
    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',
+
    param = {'Command' => 'SndIns',
        'Parameter1' => insteonID[0],  
+
      'Parameter1' => insteonID[0],  
        'Parameter2' => insteonID[1],
+
      'Parameter2' => insteonID[1],
        'Parameter3' => insteonID[2],
+
      'Parameter3' => insteonID[2],
        'Parameter4' => '0F',  
+
      'Parameter4' => '0F',  
        'Parameter5' => '13',
+
      'Parameter5' => '13',
        'Parameter6' => '00'}
+
      'Parameter6' => '00'}
      $cmdqueue << param
+
    $cmdqueue << param
      SndIns()
+
    SndIns()
    else
+
  else
      log "------dce--- X10 DEVICE!!!"
+
    log "------dce--- X10 DEVICE!!!"
      x10Byte1 = $X10HouseCodes[deviceID[0].chr]
+
log('DeviceID=' + deviceID)
      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
+
x10Byte1 = $X10HouseCodes.index(deviceID[0].chr)
when 184 #SetLevel
+
x10Byte1 += $X10UnitCodes.index(deviceID[1].chr)
  if $ignoresetlevel == false
+
x10cmd = $X10HouseCodes.index(deviceID[0].chr)
    log('$ignoresetlevel = false')
+
x10cmd += '3' # command code for OFF
    # convert from percent to hex
+
log('X10 Byte1:' + x10Byte1)
    dim_level = percenttohex(cmd.params_[76])
+
param = {'Command' => 'SndX10',  
    #log("------dce--- Dim Level:" + dim_level.to_s)
+
        'Parameter1' => x10Byte1,
    if insteonID.length > 2 then
+
        'Parameter2' => '00'}
+
$cmdqueue << param
      param = {'Command' => 'SndIns',
+
param = {'Command' => 'SndX10',
        'Parameter1' => insteonID[0],  
+
'Parameter1' => x10cmd,
        'Parameter2' => insteonID[1],
+
'Parameter2' => '80'}
        'Parameter3' => insteonID[2],
+
$cmdqueue << param
        'Parameter4' => '0F',  
+
    SndIns()
        'Parameter5' => '11',
+
        'Parameter6' => dim_level}
+
      $cmdqueue << param
+
      SndIns()
+
    else
+
      log "X10 DEVICE!!! relative Dimming command"
+
 
 
      SndIns()
+
  end
      log('Dim Level:' + hextopercent(dim_level).to_s)
+
  reportStatus($children[deviceID], 0)
      #now send status info (we should not have to to this, but do)
+
when 184 #SetLevel
      reportStatus($children[deviceID], hextopercent(dim_level))
+
  # convert from percent to hex
    end
+
  dim_level = percenttohex(cmd.params_[76])
  else
+
  #log("------dce--- Dim Level:" + dim_level.to_s)
    $ignoresetlevel = false
+
  if insteonID.length > 2 then
    log('$ignoresetlevel = true')
+
    log('Setting $ignoresetlevel == false')
+
    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
  
  end
+
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