Hi all,
I'm a bit of a lurker and tinkerer, but I think I've figured out how to link from the modem to a Insteon device without doing the button-dance.
First off, thank you Bernd Pfrommer for making the insteon-terminal. It is incredibly powerful.
A bit of background. I've been using MisterHouse to manage my Insteon network, but since I'm slowly transitioning to OpenHab, I needed something else that could do the management. I thought about keeping MisterHouse on since it does a lot of the gruntwork, but having it talk to the Insteon Hub V2 via networking is above my capabilities at this point. insteon-terminal fulfills that role, albeit it being a bit more low-level.
One thing that MisterHouse offers is the ability to link up a device given it's address. This is quite convenient, especially if there are a bunch of devices scattered throughtout the house that have been installed at once, or a modem goes belly-up.
I figured that if MisterHouse could do it, there had to be a way to make insteon-terminal do the same. After searching around on the Internet, poking through Bernd's code and MisterHouse's libraries, reading some of the leaked documentation, and a lot of trial and error, I've come up with this.
NOTE: This is protocol-level stuff. Deciphering some of this may be difficult without digging into the Insteon protocol. Also, I've only tested this on ONE I2CS device. Supposedly, older I2 devices and others are even easier to link up, but I have not tested at this time.
1. Import in the python libraries we'll need:
import message
import querier
2. Set up the messages:
# devAddr is set to the device we wish to add
devAddr = "AA.AA.AA"
# This sets up a communication channel to the device in question
devSend = Querier(InsteonAddress(devAddr))
# This is used to generate effectively a "hello world" message.
helloMsg = message.createStdMsg(InsteonAddress(devAddr),0x0F,0x0d,0x00,-1)
# The magic command, that triggers linking on the device.
linkMsg = message.createExtendedMsg(InsteonAddress(devAddr),0x09,0x01,[])
3. Send the helloMsg to confirm that this is a I2CS device and that we don't have a modem entry at this time.
modem.startWatch()
# We need this to see our response.
devSend.sendMsg(helloMsg)
# You should get a "NACK_OF_DIRECT" response from a unlinked I2CS device. Other devices will respond, according to what I've seen.
modem.stopWatch()
4. Initiate Linking mode on the Modem side, and trigger the linking sequence
modem.linkAsEither(01)
# Put the modem in linking mode
devSend.sendMsg(linkMsg)
#There will be some beeping, and then the device will now be linked.
# You can verify by typing modem.getdb() or <device>.getdb()
5. Continue with manually manipulating the databases as described in the README.
I hope this may help someone. Have fun, and don't nuke your databases! :)