X10 triggers

Support and queries relating to all previous versions of ZoneMinder
proxorp
Posts: 9
Joined: Wed Feb 23, 2005 8:43 pm

X10 triggers

Post by proxorp » Mon Jun 26, 2006 10:55 pm

Hi,

I'm ready to go to the next level and now use X10 events to trigger my cameras. I've read the documentation and tried to search the forum but haven't found the catalyst to get me going yet. Any advice appreciated.

Here's what I want to do:

I have X10 working on my FC4 box using the X10 universal device drivers found here: http://sourceforge.net/projects/wish. I'm using a SmartHome USB controller. All this is tested and working...

When an X10 event occurs, it can be detected by monitoring /dev/X10 devices (/dev/X10/b1 for example). I'm even able to fire off scripts on events.

Now I just need advice on the best way to have this X10 event trigger a ZM camera.

I thought the zmtrigger.pl would be the best way to work, but can't quite figure it out. It's not obvious from the source code what I should do. Do I need to hardcode into the source, or pass it parameters? (help!)

Also, there's some info in the docs on having X10 trigger directly, but again I'm not sure how to configure for my /dev/x10/ setup. It seems like it's set up to talk to X10 different from my method.

I'm sure I'm missing something obvious, so point me in a general direction and I'm sure I can figure it out.

Thanks!
David.

User avatar
zoneminder
Site Admin
Posts: 5220
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder » Tue Jun 27, 2006 4:06 pm

I've not heard of that driver but it looks interesting. The built-in x.10 support in zmx10.pl expects to talk x.10 over a serial port. What does the new driver expect in and out of the x.10 devices?
Phil

proxorp
Posts: 9
Joined: Wed Feb 23, 2005 8:43 pm

Post by proxorp » Tue Jun 27, 2006 10:02 pm

I'm happy with this X10 module/driver. It supports PowerLinc serial and USB controllers and CM11A serial. However, I've only tested on the PowerLinc USB.

I'm not a driver guy so I don't know the inner workings, but the net result is a /dev/x10 interface to send/receive x10 commands.

To send an X10 command, just pipe a value to the x10 sub-device
example:

Code: Select all

$ echo 1 > /dev/x10/a10    	#Turns on device A10
$ echo 0 > /dev/x10/c3           #Turns off device C3
To read X10 state, just read from the subdevice using cat.
examples:

Code: Select all

$ cat /dev/x10/e11        #Reads the last known status of device E11
$ cat /dev/x10/a           # Reads the last known status of all units on housecode A
$ cat /dev/x10/status    #Reads the last known status of all 256 units in the system
More interesting (for ZM usage), the package comes with a script that will execute a command/script when a X10 event occurs.
For example, I can fire off a script when my motion detector (on device A3) triggers using this:

Code: Select all

$ x10watch /dev/x10/A3 -1 "any_script_u_want.pl"
This will run "any_script_u_want.pl" when the motion detector triggers. This is how I was hoping to use the zmtrigger.pl to force a camera trigger.

So, if I just had a simple script to force a trigger on a camera, I'd be all set. From what I've seen, I think ZM has all the tools in place, I just need to write a perl script to use your APIs.

....or....

From the Docs, it looks like zmtrigger.pl is exactly what I need. But I can't seem to figure out how to use it. Would you show me a simple example of how to force a trigger on say...monitor 1 using this script?:lol: Do I pass it parameters like:

Code: Select all

./zmtrigger.pl 1 on 255 'motion detected' 'front door'
I can't seem to figure it out. Perhaps I need to edit the script somewhere?

FYI, I've got 10 cameras running, most at 640x480. So doing the SW motion detect chews up a bit of cpu bandwidth. Almost all the cameras have X10 based motion detectors nearby that could easily be used to trigger or as a pre-trigger.

Thanks and regards,
David.

proxorp
Posts: 9
Joined: Wed Feb 23, 2005 8:43 pm

Post by proxorp » Fri Jun 30, 2006 6:24 am

Hello,
I think I've figured out what I need to do, so I'm sharing in case someone else is as dumb as me. I'm a victim of my Linux ignorance. :oops:

First, I didn't understand that zmtrigger.pl can use several methods to communicate with external apps/scripts:
- IO Port
- Sockets
- files
- serial

After looking at the source again, I have a better idea of how things work (mostly).

I've so far just tested the io port method of communicating. And it works.

The zmtrigger.pl needs to be edited to map your desired IO port to the desired camera (see "User Section" ). I stuck with the existing port 6802 and changed the Name field to match my camera name. (I don't understnad why the name field is there since I'm communication via ID, but I'll worry about that later)

Then to test, I just telneted in: telnet myserver 6802
then enter the following in the telnet console:

1|on+60|255

This will force a trigger on my camera ID 1 for 60 seconds, then reset the trigger.

FYI, I can enter "1|on|255" to force an indefinite trigger, but can't get it to reset with a "1|off" command...but that's a minor issue. I plan to trigger for a fixed duration once my X10 motion detector triggers.

So, I now have the building blocks I needed. Now I can write scripts that are executed with X10 motion sensors trigger and communicate with zmtrigger.pl to force a ZM trigger.

This should keep me busy for while. Then I might look into the ZoneMinder::SharedMem perl module and solve this in a more elegant way.

Phil, thanks for the external control tools (zmtrigger.pl, etc...). It opens up ZM to a lot of cool customization ideas. Very powerful.

Cheers,
David.

User avatar
zoneminder
Site Admin
Posts: 5220
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder » Mon Jul 03, 2006 11:30 am

Thanks for posting your followup, and sorry that you got there before I did!

Let us know how you get on. I'd like to update the X.10 stuff at some point to use the new interface as the existing X.10 perl modules are far from ideal and a bit old and flaky.
Phil

proxorp
Posts: 9
Joined: Wed Feb 23, 2005 8:43 pm

Post by proxorp » Wed Jul 19, 2006 10:52 pm

I've now converted over to using X10 to trigger my cameras and it seems to be working pretty well.

Here's some misc comments for those who have nothing better to do....

I've written various bash scripts to handle X10 events and trigger ZM. The basic concept is that when an X10 event occurs the x10watch daemon calls my custom script(s) which in turn use ZM's zmtrigger.pl daemon to trigger cameras.

The scripts will ultimately do the following command to the desired camera:

Code: Select all

    echo "$1|on+10|255|$2|X10|X10" >/dev/tcp/localhost/6802
See Phil's documentation on the zmtrigger.pl on what this does, but it basically triggers camera $1 for 10 seconds. $2 is just a label for the trigger event. I then go to sleep for 10 seconds and check to see if the X10 event is still active...if so, trigger for another 10 sec, etc... The result is one event in ZM for the entire duration of the X10 event.

I also do stuff like turn on lights, sound a chime and what-not via X10 in the scripts.

So now I've got 8 cameras being triggered off X10 motion detectors. I'm using the wireless motion detectors that run off AAA batteries. A receiver plugged into a wall socket will receive the motion sensor signal and send the X10 code. More info on the x10 motion detectors here:
http://www.smarthome.com/prodindex.asp?catid=7 Also, X10.com has bundle deals, but the website is annoying with lots of flash and popups.

The load on my linux box is now very low compared to when I had all 8 cameras using SW motion detect. Also, the false alarms are significantly lower since the motion detect hardware is less affected by shadows and wind. Also, I use 2 motion detectors in critical areas making it so that both need to go active to generate a ZM event.

However, keep in mind that X10 can be a pain. It sometimes doesn't work across different circuits in your house. I had to experiment a lot to get it reliable. I also don't trust it to turn off things. So for the cameras I use the X10 to trigger the ZM camera, but then use time to turn off the ZM event. Otherwise, you may end up triggering a camera that never un-triggers. For a hobbiest, X10 is ok, but I wouldn't use it for anything critical.

Another thing I'm noticing is that there is a delay from when the motion detctors detect and when the x10watch script calls my scripts. It can be a second or so. Since ZM buffers, it's ok, but keep that in mind. I'm pretty sure the delay is in the X10 driver, but haven't investigated very far.

My next steps are to move the code from bash to perl. I don't think it will make much difference, but I used this opportunity to teach myself better bash programming. (I prefer perl). I also need to add more configurability to the scripts. I tried not to hardcode things in and keep it flexible, but there are places where I took shortcuts in order to prove this concept out.

So Phil, I think that even if ZM had better native X10 support built in, I'd probably still use the zmtrigger approach rather than ZM's built in X10 trigger. Writing my own scripts enabled me to be much more flexible and configurable when it comes to using x10 events.

Rgds,
David.

User avatar
zoneminder
Site Admin
Posts: 5220
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder » Thu Jul 20, 2006 3:00 pm

That's really what zmtrigger is for, to allow people to customise triggers to interfaces as yet undreamt of. Plus of course giving people the excuse to pick up a bit of extra coding experience! :lol:
Phil

wfmerchant
Posts: 6
Joined: Tue Jun 06, 2006 4:30 pm
Location: Reston, VA USA
Contact:

What I am trying to do..

Post by wfmerchant » Wed Aug 30, 2006 12:31 am

Hi David,

I am attempting to do extactly what you have already down. I have been tring to get X10 triggers to start recording using the ZM x10 interface. Your approch is much cleaner and I would love to just repeat what you have already done. No sense re-creating the wheel.

So, to start with I need to get the SmartHome USB controler.

132CU POWERLINC CONTROLLER & SMARTHOME MANAGER ESSENTIAL SOFTWARE

There seem to be a number of X10 motion sensors and I would guess any of them would work?

Your post is pretty detailed but if you have any instructions and scripts you would like to share it would be much appreciated.

Bill

whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Re: X10 triggers

Post by whatboy » Wed Aug 10, 2011 5:34 pm

Bought a 2413u from smarthome, but the linux detects the device as /dev/ttyUSB0 using FTDI drivers, not USBHID /dev/usb/hiddevX as the program plusbd wants it (/usr/sbin/plusbd -device /dev/usb/hiddev0), and if I use the serial pld (/usr/sbin/pld -device /dev/ttyUSB0) then the pld complains that the Powerlinc is not ready...

Code: Select all

#modprobe x10
#/usr/sbin/pld -device /dev/ttyS0
#/usr/sbin/x10logd

Aug 10 11:09:49 computer pld[3563]: starting. api-device=/dev/x10/.api, pidfile=/var/run/x10d.pid
Aug 10 11:09:49 computer pld[3563]: Successfully opened X10 API device /dev/x10/.api
Aug 10 11:09:50 computer pld[3564]: Transmit thread starting
Aug 10 11:09:52 computer pld[3564]: Connecting to Powerlinc Serial Interface on /dev/ttyUSB0
Aug 10 11:09:52 computer pld[3564]: PowerLinc serial module found, but not ready
Aug 10 11:09:52 computer pld[3564]: transmitter connected

#$ echo 1 > /dev/x10/a1
Aug 10 11:12:32 computer pld[3564]: unable to communicate with PowerLinc Transceiver

#/etc/init.d/x10.pl stop
Aug 10 11:13:12 computer pld[3564]: exiting on signal 1
Aug 10 11:13:12 computer pld[3564]: killing all children
Aug 10 11:13:12 computer pld[3564]: closing all files and exiting
Aug 10 11:13:12 computer kernel: x10: X10 driver unloaded

I even changed the baud rates on daemons/pl_xcvr.c and daemons/pl2_xcvr.c files... from 9600 to 19200 and 115200 and nothing!!!

Code: Select all

setline(serial,CS8,B115200);  // specific to the device

whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Re: X10 triggers

Post by whatboy » Thu Aug 11, 2011 12:01 am

Seems like My PLM (2413u) does work, if I use the rs232 program http://sjinn.sourceforge.net/ and use this command

To turn it on!!!

Code: Select all

rs232 -d /dev/ttyUSB0 -b 19200 -s "\h02 62 XX XX XX 0F 13\n" --hex --verbose -r9 --wait .4
/dev/ttyUSB0 19200 8n1 +dtr -rts -cts -dsr 
send <hex>(2)(62)(XX)(XX)(XX)(f)(13)<lf>
wait 0.400000 seconds
read 9 characters
bc ba  e 40  0  0  0  0  0
To turn it off!!!

Code: Select all

rs232 -d /dev/ttyUSB0 -b 19200 -s "\h02 62 XX XX XX 0F 13\n" --hex --verbose -r9 --wait .4
/dev/ttyUSB0 19200 8n1 +dtr -rts -cts -dsr 
send <hex>(2)(62)(XX)(XX)(XX)(f)(11)<lf>
wait 0.400000 seconds
read 9 characters
bc  a  1 40  0  0  0  0  0


where XX XX XX is the ID of the device I want to turn on/off it does work!!!

but not with the wish program...

bbenne
Posts: 1
Joined: Wed Sep 07, 2011 9:53 pm

Re: X10 Devices

Post by bbenne » Wed Sep 07, 2011 9:56 pm

I have ZM installed and running but I want to run it with my cameras alone. Not the whole Home automation. I am using a VA12a USB video capture device and I am trying to locate a driver for it. OS is Ubuntu 11.04. HELP PLEASE!

kloger
Posts: 6
Joined: Tue Aug 23, 2011 2:16 am

Re: X10 triggers

Post by kloger » Tue May 15, 2012 6:08 am

That's actually what zmtrigger is for, to permit men and women to customise triggers to interfaces as nonetheless undreamt of.

CSmyre64
Posts: 1
Joined: Wed May 15, 2013 7:04 pm

Re: X10 triggers

Post by CSmyre64 » Wed May 15, 2013 7:21 pm

I know it's been a while since the post by bbenne on the VA12A but i'm currently in that same situation Just started using ZM and have a VA12A that i bought a few years back, along with some analog camera's and would like to get them working with ZM. I'm running Ubuntu 12.04 with the newest version of ZoneMinder. Thanks

hatrickpatrick
Posts: 2
Joined: Wed May 29, 2013 6:14 am

Re: X10 triggers

Post by hatrickpatrick » Wed Jun 12, 2013 6:03 am

Hi Folks,
I've just got my zoneminder up and running, but I'm wondering if this 8 year old post is still relevant. :) Is the powerlink USB still a good transceiver? Is the Wish project still the best way to go?

I'm just getting started and I know almost nothing. :(
Thanks
-pat

sammyice
Posts: 1
Joined: Wed Aug 21, 2013 2:59 pm

Re: X10 triggers

Post by sammyice » Wed Aug 21, 2013 3:08 pm

Any tips from anyone here who has managed to enable zmtrigger.pl without X10. Sorry, i know this thread is for X10 but i would like to write a custom trigger even from bash etc.

Thank you

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests