Author Topic: Few basic questions about creating real-life scenarios  (Read 10135 times)

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Few basic questions about creating real-life scenarios
« Reply #15 on: April 08, 2008, 08:17:40 am »
Hi,

I only wish if we can make some breakthrough in adding events handlers in Ruby ?

ddamron - any chance that this is feasible under current system ?

Thanks in advance,

regards,

Bulek.
Thanks in advance,

regards,

Bulek.

chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Few basic questions about creating real-life scenarios
« Reply #16 on: April 08, 2008, 07:27:23 pm »
I considered writing a GSD device which monitored things like sensors and then sent commands to lights. But  in the end it was easier to just use misterhouse and have it register with the DCE router for plain text events. This way misterhouse exposes all the connected devices to LMCE - MH is the parent device and all my lights sit under it.

Recoding all this to happen natively in LMCE as a GSD would be cool, but I can't get my CM11A working in LMCE, so perhaps when this changes (0710 release?) I'll make a start migrating my MH logic.



bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Few basic questions about creating real-life scenarios
« Reply #17 on: April 08, 2008, 09:29:30 pm »
I considered writing a GSD device which monitored things like sensors and then sent commands to lights. But  in the end it was easier to just use misterhouse and have it register with the DCE router for plain text events. This way misterhouse exposes all the connected devices to LMCE - MH is the parent device and all my lights sit under it.

....
That's great. Are you willing to post your code somewhere. Some time ago I did write dirty mock up code for connecting to Misterhouse, it would be great if that is expanded to better support and integration of LMCE and MH...

I always thought that Misterhouse next generation is to migrate its logic to Ruby and use it under LMCE (there was a lot of discussion about future of MH - I think it is under LMCE)....

Thanks in advance,

regards,

Bulek.
Thanks in advance,

regards,

Bulek.

chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Few basic questions about creating real-life scenarios
« Reply #18 on: April 08, 2008, 10:35:20 pm »
We were working towards a neater version, here: http://forum.linuxmce.org/index.php?topic=3573.0

I didn't really have time though.


Here is what I use right now (it's VERY ugly - I don't know perl!):


Code: [Select]
# Category=Pluto
#
#@ Connection with Pluto DCE Router via TCP port localhost:3450 (mh.ini -> pluto_DCE_router).
#
use strict;
$restartTimer = new Timer;



##############################################################################

sub connect_lmce {
        print_log "Configuring sockets";
        $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');

        print_log "Closing sockets if any left open";
        if (active_now $pluto_device_event_receiver) {stop $pluto_device_event_receiver;}
        if (active_now $pluto_device_command_sender) {stop $pluto_device_command_sender;}

        print_log "Open and setup new sockets";

        start $pluto_device_event_receiver;
        set $pluto_device_event_receiver "COMMAND 78";

        start $pluto_device_command_sender;
        set $pluto_device_command_sender "EVENT 78";
        set $pluto_device_command_sender "PLAIN_TEXT";
#MESSAGET 21
#77 -1000 8 0 5 2 4 84

}

if ($Startup) {
        print_log "Starting connection to LMCE";
        set $restartTimer 10, sub {connect_lmce;};
}

if (inactive_now $pluto_device_event_receiver or inactive_now $pluto_device_command_sender) {
        print_log "Connection to LMCE terminated, restarting";
        set $restartTimer 10, sub {connect_lmce;};
}

if (new_minute 1 and !active $pluto_device_event_receiver or new_minute 1 and !active $pluto_device_command_sender) {
        print_log "Connection to LMCE still terminated, restarting";
        connect_lmce;
}



#my $motion=0;

if (my $msg = said $pluto_device_event_receiver) {
        print_log "Pluto Device Message received: $msg\n";

        $msg =~ s/[\"\']//g;    # remove quotes before splitting on whitespace

        if ($msg =~/(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)/ or $msg =~/(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)/
                        or $msg =~/(\w*)\s(\w*)\s(\w*)\s(\w*)/ ) {
                print_log "DeviceFrom: $1";
                print_log "DeviceTo: $2";
                print_log "MsgType: $3 (1=Command, 2=Event)";
                print_log "MsgId: $4";
                if (defined $5) { print_log "param1id: $5";}
                if (defined $6) { print_log "param2value: $6";}
                if (defined $7) { print_log "param2id: $7";}
                if (defined $8) { print_log "param2value: $8";}

                #############################################################
                # $1    $2      $3      $4      $5      $6      $7      $8
                # from  to      msgtype msgid   p1id    p1val   p2id    p2val
                # Example command from orbiter
                # 69    206     1       192     97      ""      98      ""
                # 69    206     1       193     97      ""
                # 69    205     1       184     76      "100"
                # 69    218     1       193
                # Example command from admin site
                # 0     204     1       760     10      "C2"    154     "192"
                # 0     204     1       760     10      "C2"    154     "193"
                #############################################################

                my $target;
                my $x10_id;

                if ($2 == '71') { $x10_id = 'A5'; } # BR Table *
                if ($2 == '79') { $x10_id = 'A3'; } # Hall
                if ($2 == '80') { $x10_id = 'B1'; } # Triple Spot
                if ($2 == '81') { $x10_id = 'A8'; } # LR Reading *
                if ($2 == '82') { $x10_id = 'B3'; } # LR Red
                if ($2 == '84') { $x10_id = 'C1'; } # LR AV
                if ($2 == '83') { $x10_id = 'A10'; } # Landing
                if ($2 == '85') { $x10_id = 'A9'; } # Kitchen
                if ($2 == '72') { $x10_id = 'A6'; } # BR Mirror
                if ($2 == '73') { $x10_id = 'A4'; } # BR AV

                if (defined $x10_id) { $target = new X10_Item("$x10_id");}

                if ($4 == '760' ) { $target = new X10_Item("$6");}

                if ($8 == '192' or $4 == '192') {
                  print_log "Turn device $x10_id ON";
                  set $target ON;
                }
                if ($8 == '193' or $4 == '193') {
                  print_log "Turn device $x10_id OFF";
                  set $target OFF;
                }
                if ($4 == '184') {
                  print_log "Setting device $x10_id to $6%";
                  set $target "$6%";
                }
        }
}

sub send_pluto_message {
        my($message) = @_;
        set $pluto_device_command_sender "MESSAGET " . length ($message);
        set $pluto_device_command_sender $message;
}
 
sub update_temp {
        # Example message@
        # 167=temp sensor ID, 2=event, 25=event ID (temp changed), 30=value, temperature (string)
        # my $message = sprintf("167 -1000 2 25 30 %d.2",$random_number);

        my($sensor, $temp) = @_;
        my $lmce_device;

        ### map iButtons to lmce device numbers - there are better ways of doing this! ###
        if ($sensor == 0) { $lmce_device = 166; }
        if ($sensor == 1) { $lmce_device = 167; }

        my $message = sprintf("$lmce_device -1000 2 25 30 %d.2",$temp);
        send_pluto_message($message);
        print_log "Updating sensor $lmce_device $temp";
}
 
sub lmce_motion {
        my($device_id) = @_;
        # 6780=Detector ID, 2=event, 9=event ID (tripped), 25=tripped value, 0=value (tripped OFF)
        my $message = "$device_id -1000 2 9 25 0";
        send_pluto_message($message);
}

sub lmce_still {
        my($device_id) = @_;
        # 6780=Detector ID, 2=event, 9=event ID (tripped), 25=tripped value, 1=value (tripped ON)
        my $message = "$device_id -1000 2 9 25 1";
        send_pluto_message($message);
}

if ($state = state_now $Kitchen_Motion) {
  if ($state eq MOTION) {
        lmce_motion(76);
  }
  if ($state eq STILL) {
        lmce_still(76);
  }
}

if ($state = state_now $Landing_Motion) {
  if ($state eq MOTION) {
        lmce_motion(75);
  }
  if ($state eq STILL) {
        lmce_still(75);
  }
}

if ($state = state_now $Hall_Motion) {
  if ($state eq MOTION) {
        lmce_motion(74);
  }
  if ($state eq STILL) {
        lmce_still(74);
  }
}

Edit: Just noticed that message values for still and motion seem to be the wrong way round? Btw I haven't been able to clear a tripped security sensor from a DCE message, it seems from looking at the admin site that there is no command to do this.
« Last Edit: April 08, 2008, 10:38:30 pm by chrisbirkinshaw »

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Few basic questions about creating real-life scenarios
« Reply #19 on: April 09, 2008, 04:52:01 am »
We were working towards a neater version, here: http://forum.linuxmce.org/index.php?topic=3573.0

...

Edit: Just noticed that message values for still and motion seem to be the wrong way round? Btw I haven't been able to clear a tripped security sensor from a DCE message, it seems from looking at the admin site that there is no command to do this.

Not sure if this is what you're looking for, but sensor tripped event has two values (1 ON, 0 Off)...
$device_id -1000 2 9 25 0     sensor tripped off....

Regards,

Bulek.
Thanks in advance,

regards,

Bulek.

chrisbirkinshaw

  • Guru
  • ****
  • Posts: 431
    • View Profile
Re: Few basic questions about creating real-life scenarios
« Reply #20 on: April 14, 2008, 01:05:07 pm »

Things have changed a little bit and my system setup is now:

Motion Sensors --> MR26A X10 RF receiver --> Misterhouse --> LMCE DCE

MH sends a tripped event with value 1 to LMCE when motion is detected and sets an internal timer. More motion refreshes the timer. When the timer expires a tripped event with value 0 is sent to LMCE. I could find no way to program this logic in LMCE, and also there is no support for the MR26A, so MH is the best option right now.

I then setup LMCE to turn lights on and off based on the security sensors.

I have some X10 wall switches which I have defined as lights. I then setup respond to events to do things when the light is turned on or off.

What I am missing:

There is no way to say in the advanced criteria page "Do this, if this sensor is tripped, and nobody is watching media in the room, or if this device is on" as there is no way to add more than one event for the criteria. I wanted to have an override switch I could use to enable and disable motion operated lights - hence the last part of my desired criteria.

I also can't find a way to say "if it is 2 hours before sunset" in the criteria. Is this possible?

I wondered what Room Mode was in the criteria - perhaps this would let me do the "if nobody is watching media in the room"?

Also how can I do "if the house is not in sleep mode"?

Regards,

Chris