Stuck on programatically creating voice commands

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Stuck on programatically creating voice commands

Jon Whitear
Hi guys,

When I’m creating a new object, I want to create the voice command to match, and then tie the items and the events. I’m trying to do this through eval-ing the commands, but I’m not having much luck. Here’s an example from the existing output of the CBus code:-

 $cbus_Guest_Bedroom_Cupboard_Light = new Generic_Item;
 $cbus_Guest_Bedroom_Cupboard_Light -> set_label('Guest Bedroom Cupboard Light');
 $cbus_Guest_Bedroom_Cupboard_Light -> set_states(split ',','on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%');

 

 $v_cbus_Guest_Bedroom_Cupboard_Light = new Voice_Cmd 'Guest Bedroom Cupboard Light [on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%]';
 $v_cbus_Guest_Bedroom_Cupboard_Light -> set_info ('Item Guest Bedroom Cupboard Light');
 tie_items $v_cbus_Guest_Bedroom_Cupboard_Light  $cbus_Guest_Bedroom_Cupboard_Light;
 tie_event $cbus_Guest_Bedroom_Cupboard_Light
 'cbus_set("//HOME/254/56/9", $state, $cbus_Guest_Bedroom_Cupboard_Light->{set_by})’;

In my code, I’m calling the object’s new() method to do the same thing, like this:-

sub new {
    my ( $class, $address, $name, $label ) = @_;
    my $self = new Generic_Item();

    

    bless $self, $class;

    

    my $object_name = "\$". $name;
    my $object_name_v = $object_name . '_v';

    

    &::print_log ("[Clipsal CBus] New group object $object_name at $address");

    

    $self->set_states(split ',','on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%');
    $self->set_label($label);
    $$self{ramp_speed} = $::config_parms{cbus_ramp_speed};
    $$self{address} = $address;

    #Add this object to the CBus object hash.
    $Clipsal_CBus::Groups{$address}{object_name} = $object_name;
    $Clipsal_CBus::Groups{$address}{name} = $name;
    $Clipsal_CBus::Groups{$address}{label} = $label;
    $Clipsal_CBus::Groups{$address}{note} = "Added at object creation";

    

    eval "$object_name_v = new Voice_Cmd '$label [on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%]';";
    eval "$object_name_v->set_info('$label');";
    eval "tie_items $object_name_v $object_name;";
    eval "tie_event $object_name '$object_name->set(\"$address\", \$state, \$object_name->{set_by})';";

    

    return $self;
}

I’ve got the feeling I’m going about this the wrong way. I would appreciate any pointers on how I can do this.

Cheers,

Jon

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|

Re: Stuck on programatically creating voice commands

Jon Whitear
Answering my own question here, but that’s OK ;-)

I looked through the insteon code, and copied that. I added a post reload hook to a generate_voice_commands() method in my base class, and added a get_voice_cmds() method to my Group class. Seems to be working OK now, generating code like so:

use vars '$Guest_Bedroom_Cupboard_Light_v';
$Guest_Bedroom_Cupboard_Light_v  = new Voice_Cmd 'Guest Bedroom Cupboard Light [set off,set on]';
$Guest_Bedroom_Cupboard_Light_v -> tie_event('$Guest_Bedroom_Cupboard_Light->cbus_set( 0 , $Guest_Bedroom_Cupboard_Light->{set_by})', 'set off');
$Guest_Bedroom_Cupboard_Light_v -> tie_event('$Guest_Bedroom_Cupboard_Light->cbus_set( 100 , $Guest_Bedroom_Cupboard_Light->{set_by})', 'set on');
&main::register_object_by_name('$Guest_Bedroom_Cupboard_Light_v',$Guest_Bedroom_Cupboard_Light_v);
$Guest_Bedroom_Cupboard_Light_v->{category} = "Clipsal CBus";
$Guest_Bedroom_Cupboard_Light_v->{filename} = "Clipsal_CBus_commands";
$Guest_Bedroom_Cupboard_Light_v->{object_name} = '$Guest_Bedroom_Cupboard_Light_v';

My next challenge is how to get ia7 working - the objects are shown, but e.g. switching a light on has no effect.

Cheers,

Jon

On 22 Mar 2016, at 10:06 PM, Jon Whitear <[hidden email]> wrote:

Hi guys,

When I’m creating a new object, I want to create the voice command to match, and then tie the items and the events. I’m trying to do this through eval-ing the commands, but I’m not having much luck. Here’s an example from the existing output of the CBus code:-

 $cbus_Guest_Bedroom_Cupboard_Light = new Generic_Item;
 $cbus_Guest_Bedroom_Cupboard_Light -> set_label('Guest Bedroom Cupboard Light');
 $cbus_Guest_Bedroom_Cupboard_Light -> set_states(split ',','on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%');
 
 $v_cbus_Guest_Bedroom_Cupboard_Light = new Voice_Cmd 'Guest Bedroom Cupboard Light [on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%]';
 $v_cbus_Guest_Bedroom_Cupboard_Light -> set_info ('Item Guest Bedroom Cupboard Light');
 tie_items $v_cbus_Guest_Bedroom_Cupboard_Light  $cbus_Guest_Bedroom_Cupboard_Light;
 tie_event $cbus_Guest_Bedroom_Cupboard_Light
 'cbus_set("//HOME/254/56/9", $state, $cbus_Guest_Bedroom_Cupboard_Light->{set_by})’;

In my code, I’m calling the object’s new() method to do the same thing, like this:-

sub new {
    my ( $class, $address, $name, $label ) = @_;
    my $self = new Generic_Item();
    
    bless $self, $class;
    
    my $object_name = "\$". $name;
    my $object_name_v = $object_name . '_v';
    
    &::print_log ("[Clipsal CBus] New group object $object_name at $address");
    
    $self->set_states(split ',','on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%');
    $self->set_label($label);
    $$self{ramp_speed} = $::config_parms{cbus_ramp_speed};
    $$self{address} = $address;

    #Add this object to the CBus object hash.
    $Clipsal_CBus::Groups{$address}{object_name} = $object_name;
    $Clipsal_CBus::Groups{$address}{name} = $name;
    $Clipsal_CBus::Groups{$address}{label} = $label;
    $Clipsal_CBus::Groups{$address}{note} = "Added at object creation";
    
    eval "$object_name_v = new Voice_Cmd '$label [on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%]';";
    eval "$object_name_v->set_info('$label');";
    eval "tie_items $object_name_v $object_name;";
    eval "tie_event $object_name '$object_name->set(\"$address\", \$state, \$object_name->{set_by})';";
    
    return $self;
}

I’ve got the feeling I’m going about this the wrong way. I would appreciate any pointers on how I can do this.

Cheers,

Jon
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users



------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|

Re: Stuck on programatically creating voice commands

Jon Whitear
Thank you - that was just the tip I needed!


On 24 Mar 2016, at 12:34 AM, H Plato wrote:

IA7 uses this http_server command to trigger state changes:

<a href="http://mhip:port/SET;none?select_item='+entity+'&amp;select_state='+new_state" class="">http://mhip:port/SET;none?select_item='+entity+'&select_state='+new_state

So for example <a href="http://mhip:port/SET;none?select_item=test_item&amp;select_state=on" class="">http://mhip:port/SET;none?select_item=test_item&select_state=on

Does your object have a set method? I notice from your voice commands you have a custom method to set the object, cbus_set

On Wed, Mar 23, 2016 at 6:13 AM, Jon Whitear wrote:
Answering my own question here, but that’s OK ;-)

I looked through the insteon code, and copied that. I added a post reload hook to a generate_voice_commands() method in my base class, and added a get_voice_cmds() method to my Group class. Seems to be working OK now, generating code like so:

use vars '$Guest_Bedroom_Cupboard_Light_v';
$Guest_Bedroom_Cupboard_Light_v  = new Voice_Cmd 'Guest Bedroom Cupboard Light [set off,set on]';
$Guest_Bedroom_Cupboard_Light_v -> tie_event('$Guest_Bedroom_Cupboard_Light->cbus_set( 0 , $Guest_Bedroom_Cupboard_Light->{set_by})', 'set off');
$Guest_Bedroom_Cupboard_Light_v -> tie_event('$Guest_Bedroom_Cupboard_Light->cbus_set( 100 , $Guest_Bedroom_Cupboard_Light->{set_by})', 'set on');
&main::register_object_by_name('$Guest_Bedroom_Cupboard_Light_v',$Guest_Bedroom_Cupboard_Light_v);
$Guest_Bedroom_Cupboard_Light_v->{category} = "Clipsal CBus";
$Guest_Bedroom_Cupboard_Light_v->{filename} = "Clipsal_CBus_commands";
$Guest_Bedroom_Cupboard_Light_v->{object_name} = '$Guest_Bedroom_Cupboard_Light_v';

My next challenge is how to get ia7 working - the objects are shown, but e.g. switching a light on has no effect.

Cheers,

Jon

On 22 Mar 2016, at 10:06 PM, Jon Whitear <[hidden email]> wrote:

Hi guys,

When I’m creating a new object, I want to create the voice command to match, and then tie the items and the events. I’m trying to do this through eval-ing the commands, but I’m not having much luck. Here’s an example from the existing output of the CBus code:-

 $cbus_Guest_Bedroom_Cupboard_Light = new Generic_Item;
 $cbus_Guest_Bedroom_Cupboard_Light -> set_label('Guest Bedroom Cupboard Light');
 $cbus_Guest_Bedroom_Cupboard_Light -> set_states(split ',','on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%');
 
 $v_cbus_Guest_Bedroom_Cupboard_Light = new Voice_Cmd 'Guest Bedroom Cupboard Light [on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%]';
 $v_cbus_Guest_Bedroom_Cupboard_Light -> set_info ('Item Guest Bedroom Cupboard Light');
 tie_items $v_cbus_Guest_Bedroom_Cupboard_Light  $cbus_Guest_Bedroom_Cupboard_Light;
 tie_event $cbus_Guest_Bedroom_Cupboard_Light
 'cbus_set("//HOME/254/56/9", $state, $cbus_Guest_Bedroom_Cupboard_Light->{set_by})’;

In my code, I’m calling the object’s new() method to do the same thing, like this:-

sub new {
    my ( $class, $address, $name, $label ) = @_;
    my $self = new Generic_Item();
    
    bless $self, $class;
    
    my $object_name = "\$". $name;
    my $object_name_v = $object_name . '_v';
    
    &::print_log ("[Clipsal CBus] New group object $object_name at $address");
    
    $self->set_states(split ',','on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%');
    $self->set_label($label);
    $$self{ramp_speed} = $::config_parms{cbus_ramp_speed};
    $$self{address} = $address;

    #Add this object to the CBus object hash.
    $Clipsal_CBus::Groups{$address}{object_name} = $object_name;
    $Clipsal_CBus::Groups{$address}{name} = $name;
    $Clipsal_CBus::Groups{$address}{label} = $label;
    $Clipsal_CBus::Groups{$address}{note} = "Added at object creation";
    
    eval "$object_name_v = new Voice_Cmd '$label [on,off,5%,10%,20%,30%,40%,50%,60%,70%,80%,90%]';";
    eval "$object_name_v->set_info('$label');";
    eval "tie_items $object_name_v $object_name;";
    eval "tie_event $object_name '$object_name->set(\"$address\", \$state, \$object_name->{set_by})';";
    
    return $self;
}

I’ve got the feeling I’m going about this the wrong way. I would appreciate any pointers on how I can do this.

Cheers,

Jon
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users



------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users





------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users