As you can see the code is a total hack in many places and I've been lazy becuase I don't know perl (no case statements, no arrays to map pluto device numbers to x10 codes etc etc). It's ugly but it works!

As I said, it's just to tide me over until the LMCE X10 code is mature, or Z-Wave stuff has become more widely available in the UK, so please don't get mad!

As you can see the code is a total hack in many places and I've been lazy becuase I don't know perl (no case statements, no arrays to map pluto device numbers to x10 codes etc etc). It's ugly but it works!

As I said, it's just to tide me over until the LMCE X10 code is mature, or Z-Wave stuff has become more widely available in the UK, so please don't get mad!

I'm cleaning up your Perl code a little, so it's more maintainable by Perl programmers. But I don't have the MH or other systems set up to debug it, so you'll have to test it and let me know if there's problems.

$pluto_device_event_receiver = new Socket_Item(undef, undef, '192.168.1.1:3450','device_event_receiver','tcp','record'); $pluto_device_command_sender = new Socket_Item(undef, undef, '192.168.1.1:3450','device_command_sender','tcp','record');Is that a hardwired 192.168.1.1 IP# of your core, that should be localhost? Can I just replace that with 127.0.0.1 or something portable?

And what's the context calling that code, so I can look at the functions/vars that the scope you posted inherits?

The connect_lmce sub configures the 2 sockets, closes if any are left running (sometimes LMCE only closes one connection), then initialises them. This sub is run by the following set of if statements.

1. If MH has just be started up ($Startup)

2. If the socket connections have just been closed (inactive_now is only true the first time MH goes through the code loop and sees the is no connection, hence the need for point 3)

3. Every minute, if the socket connections are still closed

I think parse any received messages. Sometimes they are made of 6 values, sometimes 8 if both param1 and param2 are used. The table in the comments shows the possible messages from LMCE.

The part which starts "if ($state = state_now $Kitchen_Motion) {" should really have been put elsewhere in the MH code, not in this plugin, and the lmce_motion or lmce_still called from there. Again, I was being lazy...

if ($state eq MOTION)is MOTION a scalar variable name that's set to a value before entering that line, or is it a filehandle, or some other kind of variable? Or is it a string literal? In other words, should that line really read something like

$inMotion = 'MOTION';$motionless = 'STILL';$locationCode = '184';if($state eq $inMotion){ lmce_motion($locationCode);}elsif($state eq $motionless){ lmce_still(locationCode);}Can state_now return any value other than MOTION or STILL? If so, is there a message for "other", or just silently ignore it?

And are those identifiers like state_now , active_now , inactive_now , new_minute , active , print_log all function names that should end with () when called on an argument list rather shell-script-style on a single argument, separated with a space (eg. "inactive_now $pluto_device_event_receiver" is equivalent to "inactive_now($pluto_device_event_receiver)"?

Can you parenthesize the logic below to make its operator precedence properly explicit, rather than relying on Perl to sort it out?

if(new_minute 1 && !active $pluto_device_event_receiver || new_minute 1 && !active $pluto_device_command_sender)And finally, does that script not need an initial "#!/usr/local/bin/perl" invocation, because it's imported by some other perl script as a string and eval()'d or something?

It occurs to me that we're collaborating on development not only outside SVN, but in a Users forum thread. Will you reply to this post just once more, and I'll reply to that with a link to continuing this thread to a new one in the Developers forum? Thanks (and sorry).

Here's the cleaned up code. I'm suspicious that the %motionStates values are reversed from correct (though that's in your original code), which is sent when calling my factored lmce_motion() with the "tripped" value. Note that I reorganized the main scope with executable commands first, then sub() defs appended. As I said, I can't test (though it does seem to compile with (perl -de mh.prl) ), so please test it and let me know.

I'd like to just make sure my cleaned up Perl code is working correctly before adding anything to it. The main reason to clean it up is to make it more maintainable for improvements like that one you just reported. When it's tested OK, you can upgrade it, or I'll try to get to it.

You can see that it is being sent an ON command. However when triggered as part of a scenario where it is set to "on" LMCE tries to set it's brightness to 100%, which of course fails as dim levels are unsupported on this on/off module. Why is LMCE trying to do this? See below:

I also have a problem trying to figure out how to get MH to report lamp status back to LMCE if they are changed by MH. I'm guessing we need to fire an event but can't seem to find a suitable one in the list on the admin website.

You're right, we should move this to the dev forum. Once I test this code we can start a new post there with the work so far.

Insteon is backwards compatible with X10.Insteon controllers can send and receive X10Insteon devices can be programmed to respond to X10 commandsInsteon devices can be programmed to TRANSMIT X10 (eg. a switch can transmit an X10 command)Insteon devices do NOT repeat X10 commands

HTH

Dan

Logged

The only intuitive interface is the nipple. After that it's all learned.My other computer is your windows box. I'm out of my mind. Back in 5 minutes.Q: What's Red and smells like blue paint?

It occurs to me that we're collaborating on development not only outside SVN, but in a Users forum thread. Will you reply to this post just once more, and I'll reply to that with a link to continuing this thread to a new one in the Developers forum? Thanks (and sorry).

I'd like to just make sure my cleaned up Perl code is working correctly before adding anything to it. The main reason to clean it up is to make it more maintainable for improvements like that one you just reported. When it's tested OK, you can upgrade it, or I'll try to get to it.