June 1st, 2017

Not too long ago, I discussed adding the ActiveEye Motion Sensor (outdoor model MS16A) to my home automation system. At the time, the sensor communicated with a CM19A computer interface and the Mochad gateway relayed messages to the Domoticz server. This time around, the sensor will communicate with a RR501 Transceiver Module which will translate the radio frequency messages from the sensor to power line messages that will be picked up by the CM11A computer interface. The Heyu gateway relays these messages to the Domoticz server.

Previous post: Motion sensor using CM19A computer interface

 
This post: Motion sensor using CM11A computer interface

Legend:
MS16A:
X10 ActiveEye Motion and Dusk Sensor.
CM19A:
CM19A USB PC Transceiver.
CM11A:
ActiveHome Computer Interface. No longer available from the manufacturer, but still found in retail channels.
RR501:
RF Based Transceiver Module. Should work with the TM751 Wireless Transceiver Module which I believe works with a single house code.
Raspberry Pi:
Single board computer. Both configurations were tested with the shown Raspberry Pi 3 Model B (latest version of the board), a Raspberry Pi Model B+ (2014) and a Raspberry Pi 1 Model B (2011).
USB:
Wired connection using a Universal Serial Bus cable (version 2.0 for all Raspberry Pi)
RF:
Wireless radio frequency link.
PL:
Power line link over household wiring.
RS232C:
Wired serial connection compatible with RS-232 (Recommended Standard 232). A proprietary cable is used, with a standard DE-9 (DB-9) female connector at the computer end and a telephone type male RJ-11 connector at the CM11A interface.

Table of Contents

  1. What the Sensor Does
  2. What the Sensor Does Not Do
  3. Adding the Sensors in Domoticz
  4. Creating Scripts for the Sensors

  1. What the Sensor Does
  2. The sensor is meant to operate as follows. While the sensor detects motion, it sends wireless "on" messages. The house and device code sent with these messages is programmable. The first of these messages switches the light on, the following do nothing (except clutter the airwave and power line) because the switch is already on. Once the sensor no longer detects motion, it waits for a programmable period of time and then sends a wireless "off" message.

    Presumably, there is a lamp or appliance with the same house and device code that will turn on and off in response to these messages. Since the sensor uses radio frequencies to transmit its messages, there has to be a transceiver such as the RR501 or TM751 to convert them to power line messages.

    The sensor is also a dusk sensor. If enabled, it will send an "on" message when it gets dark at the next house and device code to the one programmed. It will send an "off" message when it gets light. It is also possible to disable the motion messages during daylight.

  3. What the Sensor Does Not Do
  4. The mode of operation described above may not be appropriate. For example,

    Of course, Domoticz can resolve this mess by acting as go between. It will read the incoming message from the sensor via the transceiver and Heyu bridge and it will send out the appropriate power line commands via the Heyu bridge to any number of connected lamps. Since Domoticz knows the state of these lamps when it receives sensor data, it can work out if any should not be turned off after the prescribed delay.

  5. Setting up the sensor
  6. Instructions on setting up the sensor are contained in the product manual. The knowledge base at X10.com has much more information.

    It turns out that when you change the batteries, the sensor will return to the default address: A1. After loosing the settings a few times because of this, I gave up and decided to accept the default. This probably need to be changed, as there is greater likelyhood that neighbours are using X10 hardware with the default address.

    I setup my sensor to report movements day and night and to report dusk and dawn explicitly. By default the latter is done with an on and off message to an address with the same house code as the motion sensor but with a unit code equal to the successor of the motion sensor. This means the sensor will be sending "A2 on" messages to report on that dusk has arrived and and "A2 off" to denote dawn.

    I did not change the default behaviour for the off message. I can use the adjustment screw on the sensor itself to dial in the delay. But it does not really matter, the off message will be almost ignored; the software will take care of turning off the lights.

    Summarizing, I have setup the MS16A so that it looks like two sensors:

  7. Adding the Sensors in Domoticz
  8. Adding the motion sensor is as simple as adding a switch to virtual hardware. However, it is not possible to find the appropriate sensor type among those available for virtual sensors. Instead I added a manual switch in the way I suggested was not appropriate a while back:

    1. Click on the Switches tab.
    2. Click on the Manual Light/Switch at the top left of the page.
    3. Fill in the correct information in the Add Manual Light/Switch Device window.

      In particular
      • Select the hardware; in this case, only Heyu is available.
      • Give the device a name. Showing unbridled imagination, I called it Motion Sensor.
      • Select the switch type: Motion Sensor.
      • It may be necessary to change the House Code and Unit Code if that X10 is already assigned to a virtual device. This address does not have to reflect the physical address of the real sensor.
    4. Finally, click on the Add Device button.

    Adding the dusk sensor is more of the same. Do change the device name and switch type to reflect the nature of the sensor. It will also be necessary to set a different X10 address.

    The default A1 could be changed to A2 for example.

    As Domoticz does not interact directly with X10 hardware, it will be necessary to write scripts to handle the two sensors.

  9. Creating Scripts for the Sensors
  10. The scripts that I created a few weeks ago for using the ActiveEye Motion Sensor with the Mochad gateway, will work with the Heyu gateway.

    First, a user variable needs to be added to the Domoticz database.

    1. Click on the Setup tab.
    2. Click on More Options in the drop-down menu.
    3. Click on User variables is the second-level drop-down menu.
    4. Complete the Edit variable fields:
      • Set the name to Sensor_Delay.
      • Set the variable type to integer.
      • And set the variable value to 4.

    Second, add a hidden virtual switch, called $SensorState, to the Domoticz database.

    1. Click on the Setup tab.
    2. Click on Hardware in the drop-down menu.
    3. Click on the Create Virtual Sensors in the the Heyu hardware.
    4. Name the sensor $SensorState and change its type to switch. Starting the name with a dollar sign '$' hides that switch which will be visible only in the devices list
    5. Click on the OK button.

    Save the following script as a file named script_device_heyu_active_eye.lua in the lua scripts directory /home/pi/domoticz/scripts/lua.

    commandArray = {} MOTION_NAME = 'Motion Sensor' DUSK_NAME = 'Dusk Sensor' LAMP1 = 'Test Lamp' LAMP2 = 'Test Dimmer' VIRTUAL = '$SensorState' DELAY_VAR = 'Sensor_Delay' VERBOSE = 2 -- 0 = quiet, 1 = logs os.execute commands, 2 = debug if devicechanged[MOTION_NAME] then if (VERBOSE > 1) then print('...in active_eye.lua') end change = devicechanged[MOTION_NAME] on_time = uservariables[DELAY_VAR] -- time (min) to turn on LAMP1 and LAMP2 if needed if otherdevices[DUSK_NAME] == 'On' then is_dark = 1 else is_dark = 0 end if (VERBOSE > 1) then print('Device: ' .. MOTION_NAME) print('Change: ' .. change) print('Dusk: ' .. DUSK_NAME) print('is_dark: ' .. is_dark) print('On time: ' .. on_time) end if (change == 'On') then if (is_dark == 1) then if otherdevices[VIRTUAL] == "On" then if (VERBOSE > 1) then print('Motion detected, ignored, lights already on') end else commandArray[VIRTUAL]='On FOR '..on_time if (otherdevices[LAMP1] == 'Off') then commandArray[LAMP1]='On FOR '..on_time end if (otherdevices[LAMP2] == 'Off') then commandArray[LAMP2]='On FOR '..on_time end if (VERBOSE > 0) then print('Motion detected, turned lights on for '..on_time..' min.') end end elseif (VERBOSE > 1) then print('Motion detected, no action, not dark') end elseif (VERBOSE > 1) and (change == 'Off') then print('Motion detection off') end end return commandArray

    All 'Off' messages from the motion sensor are ignored at all times. Motion sensor messages 'On' messages are also ignored unless

    If an 'On' message is not ignored then each desired lamp, that is not already on, is turned on for the specified number of minutes. The user variable Sensor_Delay contains the specified number of minutes that lights should be turned on when motion is detected. It is a simple matter to edit this delay in the Domoticz web site.

    The hidden virtual switch $SensorState is being used as a timer. Once it is turned on for the specified number of minutes all other motion sensor messages are ignored. Since this is the only script that modifies the state of this switch

    The script to be performed by Heyu must be added to the x10config file

    # Script to update Domoticz device on movement detection # A1 off not used by script, but turns off virtual sensor in Web page SCRIPT A1 on rcvi :: curl "http://192.168.0.22:8080/json.htm?type=command&param=udevice&idx=3&nvalue=1" SCRIPT A1 off rcvi :: curl "http://192.168.0.22:8080/json.htm?type=command&param=udevice&idx=3&nvalue=0" # Script to update Domoticz dusk sensor # setting nvalue to 1 --> is dusk, 0 --> is light SCRIPT A2 on rcvi :: curl "http://192.168.0.22:8080/json.htm?type=command&param=udevice&idx=4&nvalue=1" SCRIPT A2 off rcvi :: curl "http://192.168.0.22:8080/json.htm?type=command&param=udevice&idx=4&nvalue=0"

    Note how the lua script ignored A1 off messages but the Heyu script does not. It responds to them by turning the virtual motion detection sensor off in the Domoticz database. How long it takes for this to happen can be controlled by the adjustement screw on the top of the sensor.

    While testing this new setup on the older Raspberry Pi, I had my other home automation system running on the newest single board computer. The CM19A connected to that system was picking up the wireless messages from the motion sensor. I was surprised at the number of garbled messages that the Mochad gateway was unable to decipher. I ended up turning off email notifications of errors, because my mailbox was getting too many messages.

    In the previous post on this subject, I discussed the long time needed for the script to perform its actions. This delay will be longer here because of the extra step done by the RR501 transceiver. Placement of the sensor may be even more critical. It remains to be seen how that will work out in the new home for my old the X10 hardware.