LinuxMCE Forums

General => Users => Topic started by: bulek on March 21, 2008, 09:04:38 am

Title: Few basic questions about creating real-life scenarios
Post by: bulek on March 21, 2008, 09:04:38 am
Hi,

I'm creating first few scenarios in my new house and in a lack of any experience have few basic questions how to :

- create scenario to play some music for X mins ...

- do something when bluetooth phone appears in range (Wiki talks about bluetooth phone coming/going but couldn't find it on preselectable pull down menu....) ?

- can I run another scenario from new scenario ?

- create scenario, where actions appear over time (for instance wake up: start slowly music, after 5 mins slowly come up with lights, after 10mins start coffe machine, then tell weather forecast, etc....) ?

- when I have wake up scenario - how to easily setup wake up time on daily basis (from Orbiter maybe) ?

- can I schedule power down of core at night ? (I can easily make him wake up in the morning by BIOS)...

- it's mentioned that Ruby can be used for event handling. Anyone tried that ?

Any advices ?

I'd also like to hear about popular scenarios you're using at your homes....

Thanks in advance,

regards,

Bulek.
Title: Re: Few basic questions about creating real-life scenarios
Post by: jondecker76 on March 21, 2008, 09:44:00 am
Scenarios are nothing more than defined buttons that appear on the orbiter. For example, creating a "Bathroom" scenario for your bedroom orbiter will create a button (under lighting if thats where you defined it) with the text "Bathroom" on it. You might have this scenario set up to turn all lights between your bedroom and your bathroom on to 50% (I have these set up on my kids' orbiters, so they can hit one button in the middle of the night and the lights going from their room to the bathroom will light up for them).

I think what you are looking to do is "respond to events", check it out in the web admin, a lot of it is self-explainitory.
Title: Re: Few basic questions about creating real-life scenarios
Post by: bulek on March 22, 2008, 01:18:38 pm
Scenarios are nothing more than defined buttons that appear on the orbiter. For example, creating a "Bathroom" scenario for your bedroom orbiter will create a button (under lighting if thats where you defined it) with the text "Bathroom" on it. You might have this scenario set up to turn all lights between your bedroom and your bathroom on to 50% (I have these set up on my kids' orbiters, so they can hit one button in the middle of the night and the lights going from their room to the bathroom will light up for them).

I think what you are looking to do is "respond to events", check it out in the web admin, a lot of it is self-explainitory.
Hi, thanks of response.

What I was after are problems in how to implement such things. I don't think those things are so self explanatory (just two examples) - but could be easily that I'm missing something - that's why I wrote post:

- I can't find corresponding event to respond to in case of detection of Mobile phone in Bluetooth range

- It's not clear to me how to start music and end it after some time (Event handle has mostly "do this at this time", but not "do this after xxx mins"

- Scenarios (AFAIK) don't have "run this after x mins" support, so I'm curious if anyone tried something similar already...


Thanks in advance,

regards,

Bulek.
 

Title: Re: Few basic questions about creating real-life scenarios
Post by: caiman on March 29, 2008, 09:57:15 am
Hi Bulek,

For BT device detection, go to menu Advanced -> Configuration -> Events. Click "create advanced event" and you will find ¨Bluetooth dongle -> Mobile orbiter detected"in the list. I have just tried it and had a message displayed on the orbiter when my phone was in range.

For the timer, you can do this. In the commands you enter to respond to the event, send a command to DCERouter. You will have there the option to send a "delay"command. Enter the value in milliseconds (I think). I have used this to have a light stay on for a few minutes when movement was detected in a room.

Sam
Title: Re: Few basic questions about creating real-life scenarios
Post by: bulek on March 29, 2008, 09:52:03 pm
Hi Bulek,

For BT device detection, go to menu Advanced -> Configuration -> Events. Click "create advanced event" and you will find ¨Bluetooth dongle -> Mobile orbiter detected"in the list. I have just tried it and had a message displayed on the orbiter when my phone was in range.

Hi,

thanks for response. We're moving ahead.... Aaah, that "create advanced event" was the trick... Have found it - can you distinguish which mobile orbiter is detected or you just have response to any mobile orbiter detected ?

For the timer, you can do this. In the commands you enter to respond to the event, send a command to DCERouter. You will have there the option to send a "delay"command. Enter the value in milliseconds (I think). I have used this to have a light stay on for a few minutes when movement was detected in a room.

Sam

I've added delay command, but I'm not sure if I follow your explanation... ok, you put 1000 (fpor 1 sec) and add Delay command. What happens now ? How do you specify what will happen after 1000 msec ?

It seems you've done few interesting scenarios. Can you please post to Wiki about scenarios you created ? I'd love to read more..

Thanks in advance,

regards,

Bulek.
Title: Re: Few basic questions about creating real-life scenarios
Post by: caiman on March 30, 2008, 01:09:56 am
Hi Bulek,

good catch for the identification of the mobile orbiter. I had a look and I don't see how to specify the phone/mobile orbiter. When the orbiter is detected, we can see in the DCErouter logs some interesting parameters:
Code: [Select]
07      03/30/08 0:48:15.226            Received Message from 30 (Bluetooth Dongle / Salon TV) to -1001 (unknown / ), type 2 id 4 Event:Mobile orbiter detected, retry none, parameters: <0x841ccb90>
07      03/30/08 0:48:15.226              Parameter 5(Mac Address): 00:17:E5:04:xx:xx <0x841ccb90>
07      03/30/08 0:48:15.226              Parameter 6(Signal Strength): 0 <0x841ccb90>
07      03/30/08 0:48:15.226              Parameter 7(ID): Lembas <0x841ccb90>
but I do not see many useful options in the "criteria"  menu. Let's keep on searching...

For the delay, the idea is the following. Assume you have a sensor which detects presence in a room. You want a light to be turned on during 10 minutes when that sensor is triggered. What you need to do is create a event handler for sensor tripped, and define 3 actions:
1) turn the light on
2) send a delay of 600000 ms to dcerouter
3) turn off the light
This works fine for me. I agree, itś not intuitive :)

I haven't done so many scenarios, as much as I would love to because automation is still very unreliable: my home is half x10 half zwave.

X10 has never worked well if there are sensors around because of the bad checksum bug http://mantis.linuxmce.org/view.php?id=3845 (http://mantis.linuxmce.org/view.php?id=3845) (except for a nasty workaround with heyu that I suggested in an earlier post). I have seen with delight that this has been fixed but not in beta4, I am now in the process of installing a dev environment to try to compile the cm11a driver for a 32 bits arch. Fingers crossed.

Zwave is unreliable because it looses half of my devices at each router reload: [url][http://mantis.linuxmce.org/view.php?id=3614/url] which is unresolved. I have ordered a seluxis dongle hoping its driver will be better but I have doubts.

So you see, my setup remains experimental :(

But I disgress... some typical scenarios I have are:
- turn off all devices at late night, to be sure I haven left anything on
- react on Sunset event and add 1.5 hour. Then only, light outside lamps at 30% (power save...)
- turn lights on when I enter a room, but only during the day
- etc etc
So still quite basic :)

Hope this helps
Title: Re: Few basic questions about creating real-life scenarios
Post by: jondecker76 on March 30, 2008, 01:14:05 am
Caiman-

You should drop into #linuxmce on IRC, we can hve youre dev environment up and running in no time... Also, I put an entry in the wiki on setting up a development environment. I'd like to help you get your CM11A up and stable for you - if I had a 32 bit setup I'd compile it for you. Either way, I think you will be impressed with how stable the CM11A is now
Title: Re: Few basic questions about creating real-life scenarios
Post by: jondecker76 on March 30, 2008, 01:24:15 am
Regarding the delay command....  I haven't had time to test it myself, but does anyone know if it actually schedules the command to be sent at a later time (without blocking any other commands between _now and _now+delay?

For example, if I create a scenario which ends up turning a light on, then doing a delay for 5 minutes before a command to turn the lights back off.. During that 5 minutes, will other commands sent to that light still have an effect, or, will it jump to the end of the line and get executed after the command that gets executed after the 5 minutes expires?
Title: Re: Few basic questions about creating real-life scenarios
Post by: caiman on March 30, 2008, 02:07:57 pm
Hi jondecker76,

thanks. I am doing the first "svn update" right now :)
I have seen your posts regarding the new cm11 driver and I cannot wait !

I also want to have a look at the source of the zwave plugin to see why we loose devices when there is a gap in the sequence.

For the delay, I am not sure, but I believe you are right saying there will be some sort of locking. See this old post: http://forum.linuxmce.org/index.php?topic=136.0 (http://forum.linuxmce.org/index.php?topic=136.0). I would expect that you can still send commands to the device during the delay period (to be verified) but it seems you cannot "reset" the timer.

See you soon on IRC...

Sam

Title: Re: Few basic questions about creating real-life scenarios
Post by: chrisbirkinshaw on March 31, 2008, 11:45:07 am
So isn't there going to be a problem in that if you enter a room the timer is set up for 10 mins, but if you stay in there and are moving around the light will still turn off after 10 mins because it is not possible to keep extending the timer whenever movement is detected? This would mean every 10 mins the light would go off and then back on again, which would be quite annoying.

Is there a way around this?

Chris

Title: Re: Few basic questions about creating real-life scenarios
Post by: caiman on March 31, 2008, 09:55:43 pm
Chris,

that is correct. Maybe we could reach out to aaron.b from plutohome to ask if it has been implemented in the meantime.
http://plutohome.com/support/phpbb2/viewtopic.php?t=136&highlight=x10+timed+events (http://plutohome.com/support/phpbb2/viewtopic.php?t=136&highlight=x10+timed+events)

Sam
Title: Re: Few basic questions about creating real-life scenarios
Post by: chrisbirkinshaw on April 01, 2008, 03:16:03 pm
Good work finding that post. Do you know how we can get hold of Aaron?
Title: Re: Few basic questions about creating real-life scenarios
Post by: caiman on April 07, 2008, 02:27:12 pm
No idea. In the meantime I found some possible leads.

This post: http://wiki.linuxmce.org/index.php/Make_things_happen_at_set_times_or_intervals (http://wiki.linuxmce.org/index.php/Make_things_happen_at_set_times_or_intervals) talks about the possibility to use ruby code to create advanced events. While I understand how this could be done with standalone ruby scripts connecting to the DCErouter, I didn't find in the GUI the possibility to enter "snippets of code".

In the events editor, using the "Advanced Wizard", one can send a "delay" message to DCE router as I explained above. Now I see two other message types that can be sent to DCE router: "Execute command group" and "Stop pending command group". If the latter is what I think, it could be used to reset the timer associated to a presence sensor each time the sensor is triggered. I haven't tried though, and we would need to find how to obtain the command group ID (and how to create command groups for that matter)

Sam
Title: Re: Few basic questions about creating real-life scenarios
Post by: bulek on April 07, 2008, 02:36:42 pm
Hi,

not sure if any help, but command groups are also custom scenarios that you create to appear on Orbiters. I have found no other way of searching them beside digging directly in sql database.... I use them to trigger LMCE scenarios from lower level automation system...

Regards,

Bulek.
Title: Re: Few basic questions about creating real-life scenarios
Post by: caiman on April 07, 2008, 02:48:43 pm
Bulek,

thank you !
I could indeed find them in the DB in the table CommandGroup (surprise surprise :) )

Sam
Title: Re: Few basic questions about creating real-life scenarios
Post by: bulek 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.
Title: Re: Few basic questions about creating real-life scenarios
Post by: chrisbirkinshaw 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.


Title: Re: Few basic questions about creating real-life scenarios
Post by: bulek 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.
Title: Re: Few basic questions about creating real-life scenarios
Post by: chrisbirkinshaw 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.
Title: Re: Few basic questions about creating real-life scenarios
Post by: bulek 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.
Title: Re: Few basic questions about creating real-life scenarios
Post by: chrisbirkinshaw 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