How To: INSTEON Motion Sensor Remote Configuration

Posted on
Tue May 01, 2012 12:33 pm
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

How To: INSTEON Motion Sensor Remote Configuration

After a number of hours of googling and scanning of various HouseLinc 2, Universal Devices, and Smarthome forum threads, I figured out how to remotely query and configure the Smarthome 2420M SkyLink INSTEON motion sensor without having to remove it from it's mounted location. Note that this is not the same thing as an Indigo "Define and Sync" (though, it'd technically be possible for a future version of Indigo to do that in the same way as well), it's just querying the motion sensor for it's current configuration settings and changing those (if desired).

Background:
I wondered how Smarthome's HouseLinc 2 software maintained synchronization between it's internal link database and that of wireless INSTEON devices. I wondered if it required a user to physically press and hold the SET button on those devices every time they wanted to change settings or device-to-device links. It turns out that you don't have to when using HouseLinc 2 (except for the first time you sync the device). The way they do this is by delaying all link database and device configuration tasks until the device is awoken by some kind of user interaction (e.g. motion detected, causing the device to wake up and send an ON command). The motion sensors and TriggerLincs both stay awake for a very short time after sending any command, which allows another device (like a PowerLinc Modem) to send configuration commands to it while it's still awake. The wireless device will stay awake for as long as it's receiving communication from other devices (plus a few hundred milliseconds after the last received message).

Indigo Solution:
Let's say you want to keep track of the battery level in a frequently used motion sensor. You could wait for the motion sensor to send the Group 3 ON message (indicating low battery), but you might rather monitor the battery voltage on a regular basis.

EDIT: Be sure your motion sensor jumper 5 is connected before doing any of this. That jumper must be connected to do any remote management.

Use the below steps to do that.

  1. Create an Indigo variable to store the motion sensor's battery level info (e.g. "hallway_motion_battery")
  2. Create a new trigger in Indigo, perhaps named something like "hallway motion battery check". In the Trigger tab, specify the Type as "INSTEON Command Received". Select the motion sensor device you wish to monitor. Set the Received command to "On", "Group 1 (motion detected)".
  3. In the Conditions tab, select "Always". The frequency at which Indigo requests battery status can be limited in the next tab.
  4. In the Actions tab, select "Execute Script" as the Type of action. Select the "Embedded" radio button, making sure "Python" is the script type. Enter the following Python code into the text entry area, making sure to replace the actual device name for your motion sensor where "hallway motion" appears in the first line and replacing "hallway_motion_battery" for the variable name you chose in step 1 above.
    Code: Select all
    instnAddr = indigo.devices["hallway motion"].address
    serverBattery = indigo.variables["hallway_motion_battery"]

    indigo.server.log("Checking motion sensor battery level.")

    reply = indigo.insteon.sendRawExtended(instnAddr, [0x2E, 0x00], waitForExtendedReply=True)
    batteryLevel = reply.replyBytes[13]

    indigo.server.log("Battery level (approx. Volts): " + str(float(batteryLevel / 10.0)))

    indigo.variable.updateValue(serverBattery, str(float(batteryLevel / 10.0)))
  5. Click "OK" to save the trigger (We'll get to limiting the battery check frequency in the next steps, but clicking "OK" here is necessary in order for the next steps to work).
  6. Double-click on the trigger you just created ("hallway motion battery check" if you named it like in this example) to edit it.
  7. Click on the Actions tab and click the "Add New" button at the bottom.
  8. Set the new action Type to "Disable Trigger" and select the trigger you're editing ("hallway motion battery check" in this example) as the trigger to disable. Put a check in the box for "Auto-enable after" and enter a delay before the trigger re-enables itself. For a high traffic area, a delay of 120 minutes should keep the Indigo variable updated with the battery level frequently enough.
  9. Click "OK". You're done.

You can duplicate this trigger for other motion sensors, changing the trigger name as well as the device name, variable name, and trigger selection in the Actions tab.

You can also use the same method to query the current ambient light sensor value, change the motion sensor's red LED brightness (or turn it off altogether), change the motion sensor's mode and adjust the motion sensor's timeout period before sending an OFF command, all using the Python code I posted in this thread in place of the above code.

Disclaimer:
Keep in mind that sending the INSTEON extended data command as shown above takes more time than a basic INSTEON ON or OFF command, so whenever this trigger is activated, you may notice a longer delay for other triggers activated by the same motion sensor. That's why the trigger shouldn't be activated for every time a motion sensor is activated.
Last edited by nsheldon on Tue May 01, 2012 8:53 pm, edited 1 time in total.

Posted on
Tue May 01, 2012 3:27 pm
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

Thanks for the trigger and script. What a great way to check the battery. Would be cool if we could do this for smoke alarm batteries (No-Insteon).

I did it for both of my motion sensors. On one I get the following error:

Trigger Sydney Motion Battery Check
Script Checking motion sensor battery level.
Error "Sydney's Motion" raw insteon command; send failed (no acknowledgment)
Script Error embedded script: list index out of range
Script Error Exception Traceback (most recent call shown last):

embedded script, line 7, at top level
IndexError: list index out of range

For the record I ensured the name of the sensor and variable were correct. I pushed the set button on Sydney's Motion to ensure it was awake.

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Posted on
Tue May 01, 2012 4:06 pm
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

Re: How To: INSTEON Motion Sensor Remote Configuration

Hi midd.

The first part of that error
Code: Select all
Error "Sydney's Motion" raw insteon command; send failed (no acknowledgment)

makes sense if the motion sensor couldn't be reached, or if it didn't understand the message being sent to it. The second part of the error
Code: Select all
Script Error embedded script: list index out of range
Script Error Exception Traceback (most recent call shown last):

embedded script, line 7, at top level
IndexError: list index out of range

is simply a result of lazy coding on my part in that I didn't put any error checking in the code. The Python interpreter is just complaining that you're requesting data that doesn't exist (because it couldn't get a reply from the sensor).

So, you followed the instructions above to create the trigger. Then you pressed the SET button in the motion sensor to force an ON message? I hadn't tried that scenario in my testing. I figured that if I had the back off of the motion sensor to press the SET button, I wouldn't need to create a trigger (I could just put the sensor in linking mode (press and hold SET for 5 sec) then run the script from an Action Group or from the Indigo plug-in command-line).

Try this. Don't press the SET button to force the trigger to activate. Instead, activate the motion sensor by moving your hand in front of it. I'm not sure that really makes any difference, but it's the only method I used when testing the script and trigger, so I know it works.

Another thing to consider is motion sensor firmware version. All of my motion sensors are version 34 (they show rev. 2.0 on the back). If you're using the older version 1.x motion sensor, I'm not sure the raw extended command will work with that version.

Posted on
Tue May 01, 2012 5:43 pm
matt (support) offline
Site Admin
User avatar
Posts: 18801
Joined: Jan 27, 2003
Location: Texas

Re: How To: INSTEON Motion Sensor Remote Configuration

Great idea, and thanks again for sharing your technique and scripts.

FYI, the Indigo Plugin SDK examples (download here) has a plugin example that shows how a plugin can catch all incoming INSTEON (or X10) messages. So in theory a plugin could automate this process. :-) You could have it check the battery level only once per day, or once every few hours. And the plugin could email out to the user whenever the battery levels get low a list of the devices that need to be changed.

Image

Posted on
Tue May 01, 2012 6:40 pm
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

Thanks for the tip. Both of my sensors are version 2.0. Still can't get Sydney's to give me what I need. It turns on the bedroom light when its supposed to. I'll try doing a full reset on the sensor.

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Posted on
Tue May 01, 2012 8:50 pm
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

Re: How To: INSTEON Motion Sensor Remote Configuration

matt (support) wrote:
Great idea, and thanks again for sharing your technique and scripts.

My pleasure Matt!
So in theory a plugin could automate this process. :-) You could have it check the battery level only once per day, or once every few hours. And the plugin could email out to the user whenever the battery levels get low a list of the devices that need to be changed.

Hmmm.... that's a cool idea. More reading and experimenting. Might be fun!

midd wrote:
Thanks for the tip. Both of my sensors are version 2.0. Still can't get Sydney's to give me what I need. It turns on the bedroom light when its supposed to. I'll try doing a full reset on the sensor.

Have you tried the trigger and script with your other motion sensor? Oh! One other thing that I neglected to mention in the initial post is that your motion sensors HAVE to have jumper 5 connected. D'oh! That's a pretty important omission on my part. So yea, check jumper 5 to make sure it's connected in the motion sensor, otherwise you can't do any remote management.

Posted on
Wed May 02, 2012 3:18 am
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

Yep the other sensor is working fine with the script and trigger. Both have jumper five connected to both pins.


I must have had some noise in my line because I see Sydney's battery registered a value at 3:00am. The variable is showing a value of 9 where prior to 10pm it said "no value".


Thanks.

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Posted on
Wed May 02, 2012 3:42 am
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

Re: How To: INSTEON Motion Sensor Remote Configuration

Glad you got them both working. I've done some more testing with the various motion sensors I have around the house (I have 13 in all) and have found that the above communication fails rather frequently, especially if 1) the battery voltage is lower than 8.0 V and 2) there is a lot of other INSTEON communication going on around the same time. I'm sure range from the nearest dual-band INSETON device and/or RF interference is another factor. I'll have to see if I can find out how to wrap the code in the above trigger into some kind of error handling so it exits more gracefully when no response is received.

Posted on
Fri May 04, 2012 11:26 am
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

Re: How To: INSTEON Motion Sensor Remote Configuration

So, I've reworked the trigger (whose code is listed in the first post). I think this version of the trigger is better, but your effectiveness may vary.

  1. Create an Indigo variable to store the motion sensor's battery level info (e.g. "hallway_motion_battery").
  2. Create another Indigo variable to keep track of the most recent time the trigger was executed (e.g. "last_motion_sensor_battery_check"). This is most useful in situations where you have lots of motion sensors that are all waiting for the next time it's awake to be checked. Because they're so finicky about responding to the extended command and often don't respond, they can cause significant server hangs while the PowerLinc Modem is waiting for a non-responsive sensor to reply. By logging the most recent trigger execution time in this variable, other copies of the trigger won't attempt to run if another copy of the trigger was recently executed, thus (hopefully) avoiding cascading no acknowledgement errors.
  3. Create a new trigger in Indigo, perhaps naming it "hallway motion battery check". The below code requires the trigger name to be "<motion sensor name> battery check," otherwise it will error out. In the Trigger tab, specify the Type as "INSTEON Command Received". Select the motion sensor device you wish to monitor. Set the Received command to "Off", "Group 1 (motion detected)". By using the "Off" command as the trigger source, should the sensor be unresponsive to the battery check, the delay caused by this unresponsiveness may be less noticeable.
  4. In the Conditions tab, select "If script returns true". In the text entry area, enter the code
    Code: Select all
    set thisTime to time of (current date)
    set lastTime to (value of variable "last_motion_sensor_battery_check") as number
    if thisTime + 60 > lastTime then
       return true
    else
       return false
    end if
  5. In the Actions tab, select "Execute Script" as the Type of action. Select the "Embedded" radio button, making sure "Python" is the script type. Enter the following Python code into the text entry area, making sure to replace the device name "hallway motion" for your motion sensor name and replacing "hallway_motion_battery" for the variable name you chose in step 1 above.
    Code: Select all
    # Change these for each device trigger.

    devName      = "hallway motion"
    battVarName  = "hallway_motion_battery"

    ######################################
    import time
    trigName = devName + " battery check"
    sensorAddr = indigo.devices[devName].address
    trigObj = indigo.triggers[trigName]

    # Set the secondes since midnight.
    thisTime = int(time.localtime().tm_hour * 3600 + time.localtime().tm_min * 60 + time.localtime().tm_sec)

    lastTimeVar   = indigo.variables["last_motion_sensor_battery_check"]
    serverBattery = indigo.variables[battVarName]

    indigo.server.log("Checking motion sensor \"" + devName + "\" battery levels.")
    indigo.variable.updateValue(lastTimeVar, str(thisTime))

    try:
       reply = indigo.insteon.sendRawExtended(sensorAddr, [0x2E, 0x00], waitForExtendedReply=True)
       batteryLevel = reply.replyBytes[13]   
       
    except:
       indigo.server.log("\"" + devName + "\" invalid response: " + str(reply.replyBytes))
       
    else:
       indigo.server.log("Battery Level (apporx. Volts): " + str(float(batteryLevel / 10.0)))
       indigo.variable.updateValue(serverBattery, str(float(batteryLevel / 10.0)))
       indigo.trigger.enable(trigObj, False, duration=7200)
    This code updates the "last_motion_sensor_battery_check" variable then attempts to send the extended command to the motion sensor to get it's battery level. If that command is successful, the "hallway_motion_battery" variable is updated with the current motion sensor battery level and the trigger is disabled, set to automatically re-enable itself in 2 hours. If the command fails, the trigger remains enabled so it'll try the next time an "Off" command is received by the motion sensor.
  6. Click the "Compile" button at the top right of the text entry area to make sure there are no errors. If there are no errors, click "OK".

If anyone tries this new trigger/code, I'd be interested to hear how it works for them.
Last edited by nsheldon on Wed May 09, 2012 5:33 pm, edited 1 time in total.

Posted on
Sat May 05, 2012 5:44 am
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

I'll check it out and let you know. Thanks!

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Posted on
Wed May 09, 2012 5:00 pm
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

I get an invalid syntax error for the python script here:

Code: Select all
indigo.trigger.enable(trigObj, False, duration=7200


Added the closed ) and it compiled.

Question: SInce I have two sensors, do I need two different variables of Last_motion_sensor_battery_ check? Or can I use just one?

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Posted on
Wed May 09, 2012 5:43 pm
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

Re: How To: INSTEON Motion Sensor Remote Configuration

midd wrote:
I get an invalid syntax error for the python script here:

Code: Select all
indigo.trigger.enable(trigObj, False, duration=7200


Added the closed ) and it compiled.

Wow. I don't know how I missed that end parenthesis. I've corrected my original post.
Question: SInce I have two sensors, do I need two different variables of Last_motion_sensor_battery_ check? Or can I use just one?

There should only be one "last_motion_sensor_battery_check" variable regardless of how many sensors you have. You don't need a different "last_motion_sensor_battery_check" variable for each sensor. The idea of having that one variable is that if you have lots of triggers trying to send status requests in quick succession, if that "last_motion_sensor_battery_check" variable indicates that another trigger performed a battery check recently, subsequent triggers won't try (to try to avoid consecutive communication failures).

In any case, sorry for the typo up there.

Posted on
Fri May 11, 2012 12:56 pm
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

I only used that Last motion sensor battery check variable once for the two motion sensors I use. Can u tell me about it. Just curious about the value. Right now my value for it says 85469. What is the value referring to?

Thanks.

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Posted on
Sun May 13, 2012 2:01 am
nsheldon offline
Posts: 1977
Joined: Aug 09, 2010
Location: CA

Re: How To: INSTEON Motion Sensor Remote Configuration

That's simply the number of seconds since midnight. Not the most elegant way of checking for recent activity over a multi-day period. Let me know if it helps for your setup or not. I'm not sure it'd help improve anything for your situation.

Posted on
Sun May 13, 2012 5:53 am
midd offline
Posts: 346
Joined: Apr 18, 2010

Re: How To: INSTEON Motion Sensor Remote Configuration

ok thanks for the input. Yeah I really don't see a difference. In fact I have only seen one of the motion sensors battery's checked and not the other.

Thanks for making the trigger and script available. Like I said before I wish this could be done on smoke detectors and everything else in the house that runs off a battery!

Indigo 7, Mountain Lion , on a dedicated 2011 Mac Mini Server.

Who is online

Users browsing this forum: No registered users and 7 guests

cron