Quantcast

Echo and Google Home Local Integration

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Echo and Google Home Local Integration

Wayne Gatlin
Hello everyone and Happy new year!


I've been working on the writing the Hue emulation into Misterhouse to support local direct integration of Alexa/Echo and Google home. I've been testing with the Echo but I don't have Google Home to test with.

Currently working:
 - on,off,dim,brighten,set to %.
 - Discovery, just say discover devices and it finds all configured objects.
 - Supports 120 objects ( 2 TCP sockets )
 
Currently not working:
 - Fix the read/write from at least 3 more sockets so 300 devices is supported.
   - - I'm having issues with looping through the proxy sockets, if I cant figure it out worst case I'll just hard code them.
 - Need to fix rounding the Set %. Hue uses 0 - 252 for brightness and MH uses 0 - 100.
 
To Do:
 - Need to figure out a good way to configure objects and voice commands to present to Echo/GH.
 - - I am thinking maybe add a icon to all objects and voice commands in dev mode that you can click and have a window open to enable and text boxes/drop downs to do the mappings.
 - Add object creation to the mht file.

 If you want to test, my code is in my AlexaBridge.pm branch:
 https://github.com/waynieack/misterhouse/tree/AlexaBridge.pm


Module Config:

mh.private.ini
alexa_enable=1 # To enable the module
alexaHttpPortCount=1 # This is the amount of TCP ports you want the module to open. Only 1 working right now (other than the normal MH web port). 60 Echo/GH commands per tcp port.
alexaHttpPort=8085  # This is the start port, if you enable 4 ports then 8085 - 8089 is created. This port should be higher than the default MH http port so the default is used first. 
alexaHttpIp=192.168.195.37 # This is the IP of the local MH server, its used for the discovery response to the Echo/GH so the Echo/GH knows how to get back to the MH server.


In user code:
$Alexa = new AlexaBridge();  # parent object
$AlexaItems = new AlexaBridge_Item($Alexa);  # child object

$AlexaItems->add('$light1','light1','set','on','off','state');



In order to allow the user to map pretty much anything in MH to a Echo/GH command I created a mapping.

$AlexaItems->add('<actual object name>','<name you want Echo/GH to see>','<sub used to change the object state>','<State mapped to Echo/GH ON command>','<State mapped to Echo/GH OFF command>','<sub used to get the object state>');



$AlexaItems->add('$light1','light1','set','on','off','state');  # This is the same as $AlexaItems->add('$light1')


# To change the name of an object to a more natural name that you would say to the Echo/GH:

$AlexaItems->add('$GarageHall_light_front','Garage_Hall_light');


# To map a voice command, # is replaced by the Echo/GH command (on/off/dim%).
# My actual voice command in MH is "set night mode on", so I configure it like:

$AlexaItems->add('set night mode #','NightMode','run_voice_cmd');   # If I say "Alexa, Turn on Night Mode",  run_voice_cmd("set night mode on") is run in MH.


# To configure a user code sub:
# The actual name (argument 1) can be anything.
# A code ref must be used.
# (on/off/dim%) are passed to the sub as an argument when its run.
$AlexaItems->add('testsub','Test_Sub',\&testsub);  # say "Alexa, Turn on Test Sub",  &testsub("on") is run in MH.


# I have an Insteon thermostat and I configured it like:
$AlexaItems->add('$thermostat','Heat','heat_setpoint',undef,undef,'get_heat_sp');  # say "Alexa, Set Heat to 73%",  $thermostat->heat_setpoint("73") is run in MH.
$AlexaItems->add('$thermostat','Cool','cool_setpoint',undef,undef,'get_cool_sp');

I am going to modify the Insteon thermostat child object so the temp can be set directly as well as up and down and then up can be mapped to 'on' and down can be set to 'off' and the custom subs will not be needed.



Notes:

<actual object name> - This is the only required parameter. If you are good with the defaults, you can add an object like:  $AlexaItems->add('$light1');

<name you want Echo/GH to see> - This defaults to using the <actual object name> with out the $. If want to change the name you say to the Echo/GH to control the object, you can define it here. You can also make aliases for objects so its easier to remember.

<sub used to change the object state> - This defaults to 'set' which works for most objects. You can also put a code reference or 'run_voice_cmd', examples below.

<State mapped to Echo/GH on command> - If you want to set an object to something other than 'on' when you say 'on' to the Echo/GH, you can define it here. Defaults to 'on'.

<State mapped to Echo/GH OFF command> - If you want to set an object to something other than 'off' when you say 'off' to the Echo/GH, you can define it here. Defaults to 'off'.

<sub used to get the object state> - If your object uses a custom sub to get the state, define it here. Defaults to 'state' which works for most objects.


dim% is the actual number you say to Alexa, so if you say "Alexa,Set Light 1 to 75 %" then the dim% value will be 75.


I figured out that the amount of objects per TCP port that the Echo would discover had nothing to do with the amount of object, but actually it has to do with the size of the response. I was able to reduce the response size and now 65 objects per port works, I reduced it to 60 to allow for variances in name length.

_Wayne


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin
I forgot the dependencies in my original email, the only module that you should have to install is Data::UUID but I listed the others just in case.

For Ubuntu "apt-get install libdata-uuid-perl"
Or
cpan install Data::UUID

This is every thing it depends on:
 IO::Socket::INET;
 Socket;
 IO::Socket::Multicast;
 Data::UUID;
 HTTP::Date;


Here's another example that I set up yesterday.

I have a script that I use to control my AV equipment and I can run it via ssh, so I made a voice command in MH:

$v_set_tv_mode = new Voice_Cmd("set tv mode [on,off,hbo,netflix,roku,directtv,xbmc,wii]");
if (my $state = said $v_set_tv_mode) {
        my $output = `/usr/bin/ssh mh\@192.168.1.53 "sudo HomeAVControl/bin/input_change $state"`;
}


I added the following to my MH user code:
$AlexaItems->add('set tv mode #','tv','run_voice_cmd'); # "Alexa, Turn on tv" / "Alexa, Turn off tv" # turns all my AV stuff on or off
$AlexaItems->add('set tv mode #','DirectTv','run_voice_cmd','directtv','directtv'); #"Alexa, Turn on Direct Tv" # turns all my AV stuff on and set the input to direct tv
$AlexaItems->add('set tv mode #','Hbo','run_voice_cmd','hbo','hbo'); #"Alexa, Turn on hbo" # turns all my AV stuff on and set the input to Roku and launches the HBO Go app
$AlexaItems->add('set tv mode #','Netflix','run_voice_cmd','netflix','netflix'); #"Alexa, Turn on Netflix" # turns all my AV stuff on and set the input to Roku and launches the Netflix app
$AlexaItems->add('set tv mode #','Roku','run_voice_cmd','roku','roku');
$AlexaItems->add('set tv mode #','xbmc','run_voice_cmd','xbmc','xbmc');
$AlexaItems->add('set tv mode #','wii','run_voice_cmd','wii','wii');

_Wayne




On Sun, Jan 1, 2017 at 6:02 PM, Wayne Gatlin <[hidden email]> wrote:
Hello everyone and Happy new year!


I've been working on the writing the Hue emulation into Misterhouse to support local direct integration of Alexa/Echo and Google home. I've been testing with the Echo but I don't have Google Home to test with.

Currently working:
 - on,off,dim,brighten,set to %.
 - Discovery, just say discover devices and it finds all configured objects.
 - Supports 120 objects ( 2 TCP sockets )
 
Currently not working:
 - Fix the read/write from at least 3 more sockets so 300 devices is supported.
   - - I'm having issues with looping through the proxy sockets, if I cant figure it out worst case I'll just hard code them.
 - Need to fix rounding the Set %. Hue uses 0 - 252 for brightness and MH uses 0 - 100.
 
To Do:
 - Need to figure out a good way to configure objects and voice commands to present to Echo/GH.
 - - I am thinking maybe add a icon to all objects and voice commands in dev mode that you can click and have a window open to enable and text boxes/drop downs to do the mappings.
 - Add object creation to the mht file.

 If you want to test, my code is in my AlexaBridge.pm branch:
 https://github.com/waynieack/misterhouse/tree/AlexaBridge.pm


Module Config:

mh.private.ini
alexa_enable=1 # To enable the module
alexaHttpPortCount=1 # This is the amount of TCP ports you want the module to open. Only 1 working right now (other than the normal MH web port). 60 Echo/GH commands per tcp port.
alexaHttpPort=8085  # This is the start port, if you enable 4 ports then 8085 - 8089 is created. This port should be higher than the default MH http port so the default is used first. 
alexaHttpIp=192.168.195.37 # This is the IP of the local MH server, its used for the discovery response to the Echo/GH so the Echo/GH knows how to get back to the MH server.


In user code:
$Alexa = new AlexaBridge();  # parent object
$AlexaItems = new AlexaBridge_Item($Alexa);  # child object

$AlexaItems->add('$light1','light1','set','on','off','state');



In order to allow the user to map pretty much anything in MH to a Echo/GH command I created a mapping.

$AlexaItems->add('<actual object name>','<name you want Echo/GH to see>','<sub used to change the object state>','<State mapped to Echo/GH ON command>','<State mapped to Echo/GH OFF command>','<sub used to get the object state>');



$AlexaItems->add('$light1','light1','set','on','off','state');  # This is the same as $AlexaItems->add('$light1')


# To change the name of an object to a more natural name that you would say to the Echo/GH:

$AlexaItems->add('$GarageHall_light_front','Garage_Hall_light');


# To map a voice command, # is replaced by the Echo/GH command (on/off/dim%).
# My actual voice command in MH is "set night mode on", so I configure it like:

$AlexaItems->add('set night mode #','NightMode','run_voice_cmd');   # If I say "Alexa, Turn on Night Mode",  run_voice_cmd("set night mode on") is run in MH.


# To configure a user code sub:
# The actual name (argument 1) can be anything.
# A code ref must be used.
# (on/off/dim%) are passed to the sub as an argument when its run.
$AlexaItems->add('testsub','Test_Sub',\&testsub);  # say "Alexa, Turn on Test Sub",  &testsub("on") is run in MH.


# I have an Insteon thermostat and I configured it like:
$AlexaItems->add('$thermostat','Heat','heat_setpoint',undef,undef,'get_heat_sp');  # say "Alexa, Set Heat to 73%",  $thermostat->heat_setpoint("73") is run in MH.
$AlexaItems->add('$thermostat','Cool','cool_setpoint',undef,undef,'get_cool_sp');

I am going to modify the Insteon thermostat child object so the temp can be set directly as well as up and down and then up can be mapped to 'on' and down can be set to 'off' and the custom subs will not be needed.



Notes:

<actual object name> - This is the only required parameter. If you are good with the defaults, you can add an object like:  $AlexaItems->add('$light1');

<name you want Echo/GH to see> - This defaults to using the <actual object name> with out the $. If want to change the name you say to the Echo/GH to control the object, you can define it here. You can also make aliases for objects so its easier to remember.

<sub used to change the object state> - This defaults to 'set' which works for most objects. You can also put a code reference or 'run_voice_cmd', examples below.

<State mapped to Echo/GH on command> - If you want to set an object to something other than 'on' when you say 'on' to the Echo/GH, you can define it here. Defaults to 'on'.

<State mapped to Echo/GH OFF command> - If you want to set an object to something other than 'off' when you say 'off' to the Echo/GH, you can define it here. Defaults to 'off'.

<sub used to get the object state> - If your object uses a custom sub to get the state, define it here. Defaults to 'state' which works for most objects.


dim% is the actual number you say to Alexa, so if you say "Alexa,Set Light 1 to 75 %" then the dim% value will be 75.


I figured out that the amount of objects per TCP port that the Echo would discover had nothing to do with the amount of object, but actually it has to do with the size of the response. I was able to reduce the response size and now 65 objects per port works, I reduced it to 60 to allow for variances in name length.

_Wayne



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin

First, huge thanks to Brian Klier for all the Google Home debugging!

Updates:
Google Home confirmed fully functional.
Data::UUID is no longer required, it was removed because Google Home did not work with the UUIDs.
MH IP and Mac address are discovered and not required to be defined.

2 new requirements have been added:
  IO::Compress::Gzip
  Net::Address::Ethernet

alexaHttpIp=   #No longer needed - but can still be used to override the discovery

alexaMac=   #New option added - should be the mac address of the local MH server. This is only needed to over ride the discovery.


Google Home Notes:
You must use port 80 for the proxy port, Google Home is locked down to port 80.
The user running MH must be root to run on port 80 or you have to give the MH user rights to use the port.
Current Google Home .ini settings: 
alexaHttpPort=80
alexaHttpPortCount=1

Being that Google Home only supports port 80, I am going to add multiple IP support to allow for more objects to be supported.


Other Notes:
If you were using the old code and update to this, you have to forget all the devices and rediscover because the UUIDs have changed.

The updated code is on Git, let me know if anyone else has tested it and if you have any comments or bugs to report.


_Wayne 


On Mon, Jan 2, 2017 at 8:54 PM, Wayne Gatlin <[hidden email]> wrote:
I forgot the dependencies in my original email, the only module that you should have to install is Data::UUID but I listed the others just in case.

For Ubuntu "apt-get install libdata-uuid-perl"
Or
cpan install Data::UUID

This is every thing it depends on:
 IO::Socket::INET;
 Socket;
 IO::Socket::Multicast;
 Data::UUID;
 HTTP::Date;


Here's another example that I set up yesterday.

I have a script that I use to control my AV equipment and I can run it via ssh, so I made a voice command in MH:

$v_set_tv_mode = new Voice_Cmd("set tv mode [on,off,hbo,netflix,roku,directtv,xbmc,wii]");
if (my $state = said $v_set_tv_mode) {
        my $output = `/usr/bin/ssh mh\@192.168.1.53 "sudo HomeAVControl/bin/input_change $state"`;
}


I added the following to my MH user code:
$AlexaItems->add('set tv mode #','tv','run_voice_cmd'); # "Alexa, Turn on tv" / "Alexa, Turn off tv" # turns all my AV stuff on or off
$AlexaItems->add('set tv mode #','DirectTv','run_voice_cmd','directtv','directtv'); #"Alexa, Turn on Direct Tv" # turns all my AV stuff on and set the input to direct tv
$AlexaItems->add('set tv mode #','Hbo','run_voice_cmd','hbo','hbo'); #"Alexa, Turn on hbo" # turns all my AV stuff on and set the input to Roku and launches the HBO Go app
$AlexaItems->add('set tv mode #','Netflix','run_voice_cmd','netflix','netflix'); #"Alexa, Turn on Netflix" # turns all my AV stuff on and set the input to Roku and launches the Netflix app
$AlexaItems->add('set tv mode #','Roku','run_voice_cmd','roku','roku');
$AlexaItems->add('set tv mode #','xbmc','run_voice_cmd','xbmc','xbmc');
$AlexaItems->add('set tv mode #','wii','run_voice_cmd','wii','wii');

_Wayne




On Sun, Jan 1, 2017 at 6:02 PM, Wayne Gatlin <[hidden email]> wrote:
Hello everyone and Happy new year!


I've been working on the writing the Hue emulation into Misterhouse to support local direct integration of Alexa/Echo and Google home. I've been testing with the Echo but I don't have Google Home to test with.

Currently working:
 - on,off,dim,brighten,set to %.
 - Discovery, just say discover devices and it finds all configured objects.
 - Supports 120 objects ( 2 TCP sockets )
 
Currently not working:
 - Fix the read/write from at least 3 more sockets so 300 devices is supported.
   - - I'm having issues with looping through the proxy sockets, if I cant figure it out worst case I'll just hard code them.
 - Need to fix rounding the Set %. Hue uses 0 - 252 for brightness and MH uses 0 - 100.
 
To Do:
 - Need to figure out a good way to configure objects and voice commands to present to Echo/GH.
 - - I am thinking maybe add a icon to all objects and voice commands in dev mode that you can click and have a window open to enable and text boxes/drop downs to do the mappings.
 - Add object creation to the mht file.

 If you want to test, my code is in my AlexaBridge.pm branch:
 https://github.com/waynieack/misterhouse/tree/AlexaBridge.pm


Module Config:

mh.private.ini
alexa_enable=1 # To enable the module
alexaHttpPortCount=1 # This is the amount of TCP ports you want the module to open. Only 1 working right now (other than the normal MH web port). 60 Echo/GH commands per tcp port.
alexaHttpPort=8085  # This is the start port, if you enable 4 ports then 8085 - 8089 is created. This port should be higher than the default MH http port so the default is used first. 
alexaHttpIp=192.168.195.37 # This is the IP of the local MH server, its used for the discovery response to the Echo/GH so the Echo/GH knows how to get back to the MH server.


In user code:
$Alexa = new AlexaBridge();  # parent object
$AlexaItems = new AlexaBridge_Item($Alexa);  # child object

$AlexaItems->add('$light1','light1','set','on','off','state');



In order to allow the user to map pretty much anything in MH to a Echo/GH command I created a mapping.

$AlexaItems->add('<actual object name>','<name you want Echo/GH to see>','<sub used to change the object state>','<State mapped to Echo/GH ON command>','<State mapped to Echo/GH OFF command>','<sub used to get the object state>');



$AlexaItems->add('$light1','light1','set','on','off','state');  # This is the same as $AlexaItems->add('$light1')


# To change the name of an object to a more natural name that you would say to the Echo/GH:

$AlexaItems->add('$GarageHall_light_front','Garage_Hall_light');


# To map a voice command, # is replaced by the Echo/GH command (on/off/dim%).
# My actual voice command in MH is "set night mode on", so I configure it like:

$AlexaItems->add('set night mode #','NightMode','run_voice_cmd');   # If I say "Alexa, Turn on Night Mode",  run_voice_cmd("set night mode on") is run in MH.


# To configure a user code sub:
# The actual name (argument 1) can be anything.
# A code ref must be used.
# (on/off/dim%) are passed to the sub as an argument when its run.
$AlexaItems->add('testsub','Test_Sub',\&testsub);  # say "Alexa, Turn on Test Sub",  &testsub("on") is run in MH.


# I have an Insteon thermostat and I configured it like:
$AlexaItems->add('$thermostat','Heat','heat_setpoint',undef,undef,'get_heat_sp');  # say "Alexa, Set Heat to 73%",  $thermostat->heat_setpoint("73") is run in MH.
$AlexaItems->add('$thermostat','Cool','cool_setpoint',undef,undef,'get_cool_sp');

I am going to modify the Insteon thermostat child object so the temp can be set directly as well as up and down and then up can be mapped to 'on' and down can be set to 'off' and the custom subs will not be needed.



Notes:

<actual object name> - This is the only required parameter. If you are good with the defaults, you can add an object like:  $AlexaItems->add('$light1');

<name you want Echo/GH to see> - This defaults to using the <actual object name> with out the $. If want to change the name you say to the Echo/GH to control the object, you can define it here. You can also make aliases for objects so its easier to remember.

<sub used to change the object state> - This defaults to 'set' which works for most objects. You can also put a code reference or 'run_voice_cmd', examples below.

<State mapped to Echo/GH on command> - If you want to set an object to something other than 'on' when you say 'on' to the Echo/GH, you can define it here. Defaults to 'on'.

<State mapped to Echo/GH OFF command> - If you want to set an object to something other than 'off' when you say 'off' to the Echo/GH, you can define it here. Defaults to 'off'.

<sub used to get the object state> - If your object uses a custom sub to get the state, define it here. Defaults to 'state' which works for most objects.


dim% is the actual number you say to Alexa, so if you say "Alexa,Set Light 1 to 75 %" then the dim% value will be 75.


I figured out that the amount of objects per TCP port that the Echo would discover had nothing to do with the amount of object, but actually it has to do with the size of the response. I was able to reduce the response size and now 65 objects per port works, I reduced it to 60 to allow for variances in name length.

_Wayne




------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Eloy Paris
Hi Wayne,

This is fantastic work; thank you!

I have been happy using our Google Home with MisterHouse via the IFTTT
integration, but I suspect local integration via Hue emulation would
work better so I will be giving that a try soon, especially since the
IFTTT can be left in place at the same time.

The only thing that puts me off is that requirement to use port 80 -- port
80 is already used by Apache on the machine on which I run MisterHouse,
and even if it weren't, I am not keen on running MH as a privileged
user.

One minor comment... if the local integration is achieved via Hue
emulation then would it not make more sense to call the module and
related .ini configuration parameters something with "Hue" in the name
as opposed to Alexa? I was confused at first when I saw all those
alexaXXXX .ini parameters and the module name "AlexaBridge.pm" -- I
thought it was only for Alexa when in reality is for anything that uses
the Hue protocol/API. I realize you have an Alexa but you might want to
consider using a name that gives a better idea of how powerful what you
came up with is. Perhaps hueEmu_enable, hueEmuHttpIp, hueEmuMac, HueBridge.pm, etc.?

Finally, one question -- the limitation of 60 Echo/GH commands per TCP
port comes from the size of the response to the discovery probe, right?
If so, is it not possible to send a response of any arbitrary size by
segmenting the response? Or that is done already? I don't know anything
about the discovery protocol but I find it strange that the protocol
imposes limits on the sizes of the responses, which then creates the
need for a "multiple ports" workaround.

Thanks again for the great work!

Cheers!

Eloy Paris.-

On Mon, Jan 09, 2017 at 09:22:47PM -0600, Wayne Gatlin wrote:

> First, huge thanks to Brian Klier for all the Google Home debugging!
>
> Updates:
> Google Home confirmed fully functional.
> Data::UUID is no longer required, it was removed because Google Home did
> not work with the UUIDs.
> MH IP and Mac address are discovered and not required to be defined.
>
> 2 new requirements have been added:
>   IO::Compress::Gzip
>   Net::Address::Ethernet
>
> alexaHttpIp=   #No longer needed - but can still be used to override the
> discovery
>
> alexaMac=   #New option added - should be the mac address of the local MH
> server. This is only needed to over ride the discovery.
>
>
> Google Home Notes:
> You must use port 80 for the proxy port, Google Home is locked down to port
> 80.
> The user running MH must be root to run on port 80 or you have to give the
> MH user rights to use the port.
> Current Google Home .ini settings:
> alexaHttpPort=80
> alexaHttpPortCount=1
>
> Being that Google Home only supports port 80, I am going to add multiple IP
> support to allow for more objects to be supported.
>
>
> Other Notes:
> If you were using the old code and update to this, you have to forget all
> the devices and rediscover because the UUIDs have changed.
>
> The updated code is on Git, let me know if anyone else has tested it and if
> you have any comments or bugs to report.
>
>
> _Wayne
>
>
> On Mon, Jan 2, 2017 at 8:54 PM, Wayne Gatlin <[hidden email]> wrote:
>
> > I forgot the dependencies in my original email, the only module that you
> > should have to install is Data::UUID but I listed the others just in case.
> >
> > For Ubuntu "apt-get install libdata-uuid-perl"
> > Or
> > cpan install Data::UUID
> >
> > This is every thing it depends on:
> >  IO::Socket::INET;
> >  Socket;
> >  IO::Socket::Multicast;
> >  Data::UUID;
> >  HTTP::Date;
> >
> >
> > Here's another example that I set up yesterday.
> >
> > I have a script that I use to control my AV equipment and I can run it via
> > ssh, so I made a voice command in MH:
> >
> > $v_set_tv_mode = new Voice_Cmd("set tv mode [on,off,hbo,netflix,roku,
> > directtv,xbmc,wii]");
> > if (my $state = said $v_set_tv_mode) {
> >         my $output = `/usr/bin/ssh mh\@192.168.1.53 "sudo
> > HomeAVControl/bin/input_change $state"`;
> > }
> >
> >
> > I added the following to my MH user code:
> > $AlexaItems->add('set tv mode #','tv','run_voice_cmd'); # "Alexa, Turn on
> > tv" / "Alexa, Turn off tv" # turns all my AV stuff on or off
> > $AlexaItems->add('set tv mode #','DirectTv','run_voice_cmd','directtv','directtv');
> > #"Alexa, Turn on Direct Tv" # turns all my AV stuff on and set the input to
> > direct tv
> > $AlexaItems->add('set tv mode #','Hbo','run_voice_cmd','hbo','hbo');
> > #"Alexa, Turn on hbo" # turns all my AV stuff on and set the input to Roku
> > and launches the HBO Go app
> > $AlexaItems->add('set tv mode #','Netflix','run_voice_cmd','netflix','netflix');
> > #"Alexa, Turn on Netflix" # turns all my AV stuff on and set the input to
> > Roku and launches the Netflix app
> > $AlexaItems->add('set tv mode #','Roku','run_voice_cmd','roku','roku');
> > $AlexaItems->add('set tv mode #','xbmc','run_voice_cmd','xbmc','xbmc');
> > $AlexaItems->add('set tv mode #','wii','run_voice_cmd','wii','wii');
> >
> > _Wayne
> >
> >
> >
> >
> > On Sun, Jan 1, 2017 at 6:02 PM, Wayne Gatlin <[hidden email]> wrote:
> >
> >> Hello everyone and Happy new year!
> >>
> >>
> >> I've been working on the writing the Hue emulation into Misterhouse to
> >> support local direct integration of Alexa/Echo and Google home. I've been
> >> testing with the Echo but I don't have Google Home to test with.
> >>
> >> Currently working:
> >>  - on,off,dim,brighten,set to %.
> >>  - Discovery, just say discover devices and it finds all configured
> >> objects.
> >>  - Supports 120 objects ( 2 TCP sockets )
> >>
> >> Currently not working:
> >>  - Fix the read/write from at least 3 more sockets so 300 devices is
> >> supported.
> >>    - - I'm having issues with looping through the proxy sockets, if I
> >> cant figure it out worst case I'll just hard code them.
> >>  - Need to fix rounding the Set %. Hue uses 0 - 252 for brightness and MH
> >> uses 0 - 100.
> >>
> >> To Do:
> >>  - Need to figure out a good way to configure objects and voice commands
> >> to present to Echo/GH.
> >>  - - I am thinking maybe add a icon to all objects and voice commands in
> >> dev mode that you can click and have a window open to enable and text
> >> boxes/drop downs to do the mappings.
> >>  - Add object creation to the mht file.
> >>
> >>  If you want to test, my code is in my AlexaBridge.pm branch:
> >>  https://github.com/waynieack/misterhouse/tree/AlexaBridge.pm
> >>
> >>
> >> Module Config:
> >>
> >> mh.private.ini
> >> alexa_enable=1 # To enable the module
> >> alexaHttpPortCount=1 # This is the amount of TCP ports you want the
> >> module to open. Only 1 working right now (other than the normal MH web
> >> port). 60 Echo/GH commands per tcp port.
> >> alexaHttpPort=8085  # This is the start port, if you enable 4 ports then
> >> 8085 - 8089 is created. This port should be higher than the default MH http
> >> port so the default is used first.
> >> alexaHttpIp=192.168.195.37 # This is the IP of the local MH server, its
> >> used for the discovery response to the Echo/GH so the Echo/GH knows how to
> >> get back to the MH server.
> >>
> >>
> >> In user code:
> >> $Alexa = new AlexaBridge();  # parent object
> >> $AlexaItems = new AlexaBridge_Item($Alexa);  # child object
> >>
> >> $AlexaItems->add('$light1','light1','set','on','off','state');
> >>
> >>
> >>
> >> In order to allow the user to map pretty much anything in MH to a Echo/GH
> >> command I created a mapping.
> >>
> >> $AlexaItems->add('<actual object name>','<name you want Echo/GH to
> >> see>','<sub used to change the object state>','<State mapped to Echo/GH ON
> >> command>','<State mapped to Echo/GH OFF command>','<sub used to get the
> >> object state>');
> >>
> >>
> >>
> >> $AlexaItems->add('$light1','light1','set','on','off','state');  # This
> >> is the same as $AlexaItems->add('$light1')
> >>
> >>
> >> # To change the name of an object to a more natural name that you would
> >> say to the Echo/GH:
> >>
> >> $AlexaItems->add('$GarageHall_light_front','Garage_Hall_light');
> >>
> >>
> >> # To map a voice command, # is replaced by the Echo/GH command
> >> (on/off/dim%).
> >> # My actual voice command in MH is "set night mode on", so I configure it
> >> like:
> >>
> >> $AlexaItems->add('set night mode #','NightMode','run_voice_cmd');   # If
> >> I say "Alexa, Turn on Night Mode",  run_voice_cmd("set night mode on") is
> >> run in MH.
> >>
> >>
> >> # To configure a user code sub:
> >> # The actual name (argument 1) can be anything.
> >> # A code ref must be used.
> >> # (on/off/dim%) are passed to the sub as an argument when its run.
> >> $AlexaItems->add('testsub','Test_Sub',\&testsub);  # say "Alexa, Turn on
> >> Test Sub",  &testsub("on") is run in MH.
> >>
> >>
> >> # I have an Insteon thermostat and I configured it like:
> >> $AlexaItems->add('$thermostat','Heat','heat_setpoint',undef,undef,'get_heat_sp');
> >> # say "Alexa, Set Heat to 73%",  $thermostat->heat_setpoint("73") is run
> >> in MH.
> >> $AlexaItems->add('$thermostat','Cool','cool_setpoint',undef,undef,'get_cool_sp');
> >>
> >>
> >> I am going to modify the Insteon thermostat child object so the temp can
> >> be set directly as well as up and down and then up can be mapped to 'on'
> >> and down can be set to 'off' and the custom subs will not be needed.
> >>
> >>
> >>
> >> Notes:
> >>
> >> <actual object name> - This is the only required parameter. If you are
> >> good with the defaults, you can add an object like:
> >> $AlexaItems->add('$light1');
> >>
> >> <name you want Echo/GH to see> - This defaults to using the <actual
> >> object name> with out the $. If want to change the name you say to the
> >> Echo/GH to control the object, you can define it here. You can also make
> >> aliases for objects so its easier to remember.
> >>
> >> <sub used to change the object state> - This defaults to 'set' which
> >> works for most objects. You can also put a code reference or
> >> 'run_voice_cmd', examples below.
> >>
> >> <State mapped to Echo/GH on command> - If you want to set an object to
> >> something other than 'on' when you say 'on' to the Echo/GH, you can define
> >> it here. Defaults to 'on'.
> >>
> >> <State mapped to Echo/GH OFF command> - If you want to set an object to
> >> something other than 'off' when you say 'off' to the Echo/GH, you can
> >> define it here. Defaults to 'off'.
> >>
> >> <sub used to get the object state> - If your object uses a custom sub to
> >> get the state, define it here. Defaults to 'state' which works for most
> >> objects.
> >>
> >>
> >> dim% is the actual number you say to Alexa, so if you say "Alexa,Set
> >> Light 1 to 75 %" then the dim% value will be 75.
> >>
> >>
> >> I figured out that the amount of objects per TCP port that the Echo would
> >> discover had nothing to do with the amount of object, but actually it has
> >> to do with the size of the response. I was able to reduce the response size
> >> and now 65 objects per port works, I reduced it to 60 to allow for
> >> variances in name length.
> >>
> >> _Wayne
> >>

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin
Eloy,

If you are using Google Home and have Apache installed listening on port 80 then you don't have to run MH on port 80 or use a privileged user because Apache is acting as the proxy from port 80 to the MH port 8080. This is because Google Home ignores the location header in the SSDP response that's telling it to go to port 8080, it only looks at the IP of the sender and does a GET to that IP for /discovery.xml.

For Apache:
Get my latest code from Git
alexa_enable=1
alexaHttpPort=80   # 80 for Google home and any port for Echo
alexaHttpPortCount=0  # Disable the proxy ports I create in the Alexa module.

in the Apache proxy make sure you send any of the requests below to MH:
/discovery.xml
/upnp/*
/api*



As far as the name goes, it started out as being for the Echo/Alexa because that's what I have but after I had most of the code done I realized that Google Home and other things would also work with it. I figured at this point that people may not know what Hue is either so I was just as well leaving it Alexa as long as I put everything in the documentation/Wiki. Not to mention the amount of time it will take to rename everything :)



For the response size, I really have no idea how many objects Google Home supports per port at this point ( I don't have Google Home and it hasn't been tested yet, but Brian said he should have time to test tonight). The 60 objects per port was for the Echo which is what I tested and in my testing I tried gzip with no luck (Google Home does support gzip and it is implemented in the code). I believe the Echo/GH is expecting the entire list of objects (lights) to be sent back in a single json response and the reason I know it has to do with the response size and not the amount of objects included in the response was from reducing the fields per object in the response and watching the response size. When the response got over a certain length, the Echo would not import any of the objects.

What I didn't try was holding the connection open and sending a 60 object json response, then another 60 object json response in the same connection. I expect that the Echo will just close the connection after the first response, but I will try this when I get some time. Thanks for the suggestion.


_Wayne



On Tue, Jan 10, 2017 at 1:01 AM, Eloy Paris <[hidden email]> wrote:
Hi Wayne,

This is fantastic work; thank you!

I have been happy using our Google Home with MisterHouse via the IFTTT
integration, but I suspect local integration via Hue emulation would
work better so I will be giving that a try soon, especially since the
IFTTT can be left in place at the same time.

The only thing that puts me off is that requirement to use port 80 -- port
80 is already used by Apache on the machine on which I run MisterHouse,
and even if it weren't, I am not keen on running MH as a privileged
user.

One minor comment... if the local integration is achieved via Hue
emulation then would it not make more sense to call the module and
related .ini configuration parameters something with "Hue" in the name
as opposed to Alexa? I was confused at first when I saw all those
alexaXXXX .ini parameters and the module name "AlexaBridge.pm" -- I
thought it was only for Alexa when in reality is for anything that uses
the Hue protocol/API. I realize you have an Alexa but you might want to
consider using a name that gives a better idea of how powerful what you
came up with is. Perhaps hueEmu_enable, hueEmuHttpIp, hueEmuMac, HueBridge.pm, etc.?

Finally, one question -- the limitation of 60 Echo/GH commands per TCP
port comes from the size of the response to the discovery probe, right?
If so, is it not possible to send a response of any arbitrary size by
segmenting the response? Or that is done already? I don't know anything
about the discovery protocol but I find it strange that the protocol
imposes limits on the sizes of the responses, which then creates the
need for a "multiple ports" workaround.

Thanks again for the great work!

Cheers!

Eloy Paris.-

On Mon, Jan 09, 2017 at 09:22:47PM -0600, Wayne Gatlin wrote:

> First, huge thanks to Brian Klier for all the Google Home debugging!
>
> Updates:
> Google Home confirmed fully functional.
> Data::UUID is no longer required, it was removed because Google Home did
> not work with the UUIDs.
> MH IP and Mac address are discovered and not required to be defined.
>
> 2 new requirements have been added:
>   IO::Compress::Gzip
>   Net::Address::Ethernet
>
> alexaHttpIp=   #No longer needed - but can still be used to override the
> discovery
>
> alexaMac=   #New option added - should be the mac address of the local MH
> server. This is only needed to over ride the discovery.
>
>
> Google Home Notes:
> You must use port 80 for the proxy port, Google Home is locked down to port
> 80.
> The user running MH must be root to run on port 80 or you have to give the
> MH user rights to use the port.
> Current Google Home .ini settings:
> alexaHttpPort=80
> alexaHttpPortCount=1
>
> Being that Google Home only supports port 80, I am going to add multiple IP
> support to allow for more objects to be supported.
>
>
> Other Notes:
> If you were using the old code and update to this, you have to forget all
> the devices and rediscover because the UUIDs have changed.
>
> The updated code is on Git, let me know if anyone else has tested it and if
> you have any comments or bugs to report.
>
>
> _Wayne
>
>
> On Mon, Jan 2, 2017 at 8:54 PM, Wayne Gatlin <[hidden email]> wrote:
>
> > I forgot the dependencies in my original email, the only module that you
> > should have to install is Data::UUID but I listed the others just in case.
> >
> > For Ubuntu "apt-get install libdata-uuid-perl"
> > Or
> > cpan install Data::UUID
> >
> > This is every thing it depends on:
> >  IO::Socket::INET;
> >  Socket;
> >  IO::Socket::Multicast;
> >  Data::UUID;
> >  HTTP::Date;
> >
> >
> > Here's another example that I set up yesterday.
> >
> > I have a script that I use to control my AV equipment and I can run it via
> > ssh, so I made a voice command in MH:
> >
> > $v_set_tv_mode = new Voice_Cmd("set tv mode [on,off,hbo,netflix,roku,
> > directtv,xbmc,wii]");
> > if (my $state = said $v_set_tv_mode) {
> >         my $output = `/usr/bin/ssh mh\@192.168.1.53 "sudo
> > HomeAVControl/bin/input_change $state"`;
> > }
> >
> >
> > I added the following to my MH user code:
> > $AlexaItems->add('set tv mode #','tv','run_voice_cmd'); # "Alexa, Turn on
> > tv" / "Alexa, Turn off tv" # turns all my AV stuff on or off
> > $AlexaItems->add('set tv mode #','DirectTv','run_voice_cmd','directtv','directtv');
> > #"Alexa, Turn on Direct Tv" # turns all my AV stuff on and set the input to
> > direct tv
> > $AlexaItems->add('set tv mode #','Hbo','run_voice_cmd','hbo','hbo');
> > #"Alexa, Turn on hbo" # turns all my AV stuff on and set the input to Roku
> > and launches the HBO Go app
> > $AlexaItems->add('set tv mode #','Netflix','run_voice_cmd','netflix','netflix');
> > #"Alexa, Turn on Netflix" # turns all my AV stuff on and set the input to
> > Roku and launches the Netflix app
> > $AlexaItems->add('set tv mode #','Roku','run_voice_cmd','roku','roku');
> > $AlexaItems->add('set tv mode #','xbmc','run_voice_cmd','xbmc','xbmc');
> > $AlexaItems->add('set tv mode #','wii','run_voice_cmd','wii','wii');
> >
> > _Wayne
> >
> >
> >
> >
> > On Sun, Jan 1, 2017 at 6:02 PM, Wayne Gatlin <[hidden email]> wrote:
> >
> >> Hello everyone and Happy new year!
> >>
> >>
> >> I've been working on the writing the Hue emulation into Misterhouse to
> >> support local direct integration of Alexa/Echo and Google home. I've been
> >> testing with the Echo but I don't have Google Home to test with.
> >>
> >> Currently working:
> >>  - on,off,dim,brighten,set to %.
> >>  - Discovery, just say discover devices and it finds all configured
> >> objects.
> >>  - Supports 120 objects ( 2 TCP sockets )
> >>
> >> Currently not working:
> >>  - Fix the read/write from at least 3 more sockets so 300 devices is
> >> supported.
> >>    - - I'm having issues with looping through the proxy sockets, if I
> >> cant figure it out worst case I'll just hard code them.
> >>  - Need to fix rounding the Set %. Hue uses 0 - 252 for brightness and MH
> >> uses 0 - 100.
> >>
> >> To Do:
> >>  - Need to figure out a good way to configure objects and voice commands
> >> to present to Echo/GH.
> >>  - - I am thinking maybe add a icon to all objects and voice commands in
> >> dev mode that you can click and have a window open to enable and text
> >> boxes/drop downs to do the mappings.
> >>  - Add object creation to the mht file.
> >>
> >>  If you want to test, my code is in my AlexaBridge.pm branch:
> >>  https://github.com/waynieack/misterhouse/tree/AlexaBridge.pm
> >>
> >>
> >> Module Config:
> >>
> >> mh.private.ini
> >> alexa_enable=1 # To enable the module
> >> alexaHttpPortCount=1 # This is the amount of TCP ports you want the
> >> module to open. Only 1 working right now (other than the normal MH web
> >> port). 60 Echo/GH commands per tcp port.
> >> alexaHttpPort=8085  # This is the start port, if you enable 4 ports then
> >> 8085 - 8089 is created. This port should be higher than the default MH http
> >> port so the default is used first.
> >> alexaHttpIp=192.168.195.37 # This is the IP of the local MH server, its
> >> used for the discovery response to the Echo/GH so the Echo/GH knows how to
> >> get back to the MH server.
> >>
> >>
> >> In user code:
> >> $Alexa = new AlexaBridge();  # parent object
> >> $AlexaItems = new AlexaBridge_Item($Alexa);  # child object
> >>
> >> $AlexaItems->add('$light1','light1','set','on','off','state');
> >>
> >>
> >>
> >> In order to allow the user to map pretty much anything in MH to a Echo/GH
> >> command I created a mapping.
> >>
> >> $AlexaItems->add('<actual object name>','<name you want Echo/GH to
> >> see>','<sub used to change the object state>','<State mapped to Echo/GH ON
> >> command>','<State mapped to Echo/GH OFF command>','<sub used to get the
> >> object state>');
> >>
> >>
> >>
> >> $AlexaItems->add('$light1','light1','set','on','off','state');  # This
> >> is the same as $AlexaItems->add('$light1')
> >>
> >>
> >> # To change the name of an object to a more natural name that you would
> >> say to the Echo/GH:
> >>
> >> $AlexaItems->add('$GarageHall_light_front','Garage_Hall_light');
> >>
> >>
> >> # To map a voice command, # is replaced by the Echo/GH command
> >> (on/off/dim%).
> >> # My actual voice command in MH is "set night mode on", so I configure it
> >> like:
> >>
> >> $AlexaItems->add('set night mode #','NightMode','run_voice_cmd');   # If
> >> I say "Alexa, Turn on Night Mode",  run_voice_cmd("set night mode on") is
> >> run in MH.
> >>
> >>
> >> # To configure a user code sub:
> >> # The actual name (argument 1) can be anything.
> >> # A code ref must be used.
> >> # (on/off/dim%) are passed to the sub as an argument when its run.
> >> $AlexaItems->add('testsub','Test_Sub',\&testsub);  # say "Alexa, Turn on
> >> Test Sub",  &testsub("on") is run in MH.
> >>
> >>
> >> # I have an Insteon thermostat and I configured it like:
> >> $AlexaItems->add('$thermostat','Heat','heat_setpoint',undef,undef,'get_heat_sp');
> >> # say "Alexa, Set Heat to 73%",  $thermostat->heat_setpoint("73") is run
> >> in MH.
> >> $AlexaItems->add('$thermostat','Cool','cool_setpoint',undef,undef,'get_cool_sp');
> >>
> >>
> >> I am going to modify the Insteon thermostat child object so the temp can
> >> be set directly as well as up and down and then up can be mapped to 'on'
> >> and down can be set to 'off' and the custom subs will not be needed.
> >>
> >>
> >>
> >> Notes:
> >>
> >> <actual object name> - This is the only required parameter. If you are
> >> good with the defaults, you can add an object like:
> >> $AlexaItems->add('$light1');
> >>
> >> <name you want Echo/GH to see> - This defaults to using the <actual
> >> object name> with out the $. If want to change the name you say to the
> >> Echo/GH to control the object, you can define it here. You can also make
> >> aliases for objects so its easier to remember.
> >>
> >> <sub used to change the object state> - This defaults to 'set' which
> >> works for most objects. You can also put a code reference or
> >> 'run_voice_cmd', examples below.
> >>
> >> <State mapped to Echo/GH on command> - If you want to set an object to
> >> something other than 'on' when you say 'on' to the Echo/GH, you can define
> >> it here. Defaults to 'on'.
> >>
> >> <State mapped to Echo/GH OFF command> - If you want to set an object to
> >> something other than 'off' when you say 'off' to the Echo/GH, you can
> >> define it here. Defaults to 'off'.
> >>
> >> <sub used to get the object state> - If your object uses a custom sub to
> >> get the state, define it here. Defaults to 'state' which works for most
> >> objects.
> >>
> >>
> >> dim% is the actual number you say to Alexa, so if you say "Alexa,Set
> >> Light 1 to 75 %" then the dim% value will be 75.
> >>
> >>
> >> I figured out that the amount of objects per TCP port that the Echo would
> >> discover had nothing to do with the amount of object, but actually it has
> >> to do with the size of the response. I was able to reduce the response size
> >> and now 65 objects per port works, I reduced it to 60 to allow for
> >> variances in name length.
> >>
> >> _Wayne
> >>


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin
I did a little more testing and I was able to get the Echo to discover 300 MH objects using a single port! Brian tested Google Home and it looks like with gzip will discover at least 170 objects with no modified response (He only tested 170, it will likely discover well over that).

So no wacky multiple port or IP's needed for Google Home or the Echo any more!.

I am having an issue with Google Home not closing connections and over time it will stop polling MH, I tried to make a routine that will disconnect the oldest connection from an IP if it tries to connect again, (basically only 1 connection from an IP would be allowed) I believe this will work but I have not been able to figure out how to close a socket to a specific client (not the whole listening socket all together) and leave the server socket open so the new connection from Google home will remain open. If you want to look at my code, look at the sub check_for_data.

I don't have the stuck connection issue with Alexa, but it also does not poll for the objects like Google Home does.


With the latest code updated today, the .ini settings below should be used. I'm going to make a wiki once everything is wrapped up.



For Google Home and a reverse proxy (Apache/IIS/etc):
alexa_enable = 1
alexaHttpPortCount = 0   # disables all proxy ports
alexaHttpPort = 80       # tells the module to send port 80 in the SSDP response and look for port 80 in the HTTP host header
alexaObjectsPerGet = 300 # Google Home can handle us returning all objects in a single response

For Google Home using the builtin proxy port:
alexa_enable = 1
alexaHttpPortCount = 1   # Open 1 proxy port on port 80 (We default to port 80 so no need to define it)
alexaNoDefaultHttp = 1   # Disable responding on the default MH web port because Google Home will not use it any way.
alexaObjectsPerGet = 300 # Google Home can handle us returning all objects in a single response


For Echo (Chunked method):
alexa_enable = 1
alexaEnableChunked = 1


For Echo (Multi-port method):
# This method should not be needed unless for some reason your Echo does not work with the Chunked method.
alexa_enable = 1
alexaHttpPortCount = 1  # Open 1 proxy port for a total of 2 ports including the default MH web port. We only support 1 for now unless I see a need for more.
alexaHttpPort=8085        # The proxy port will be on port 8085, this port should be higher than the MH web port so it is used first.



alexa_enable        # Enable the module
alexaEnableChunked  # Enable chunked return method (For the Echo)
alexaHttpPortCount  # Amount of proxy ports to open
alexaNoDefaultHttp  # Disable responding on the default MH web port
alexaObjectsPerGet  # Amount of MH objects we return per GET from the Echo/GH
alexaHttpPort        # First proxy port number
alexaMac            # This is used in the SSDP response, We discover it so it does not need to be defined unless something goes wrong
alexaHttpIp            # This is the IP of the local MH server, We discover it so it does not need to be defined unless something goes wrong


_Wayne

On Tue, Jan 10, 2017 at 2:06 PM, Wayne Gatlin <[hidden email]> wrote:
Eloy,

If you are using Google Home and have Apache installed listening on port 80 then you don't have to run MH on port 80 or use a privileged user because Apache is acting as the proxy from port 80 to the MH port 8080. This is because Google Home ignores the location header in the SSDP response that's telling it to go to port 8080, it only looks at the IP of the sender and does a GET to that IP for /discovery.xml.

For Apache:
Get my latest code from Git
alexa_enable=1
alexaHttpPort=80   # 80 for Google home and any port for Echo
alexaHttpPortCount=0  # Disable the proxy ports I create in the Alexa module.

in the Apache proxy make sure you send any of the requests below to MH:
/discovery.xml
/upnp/*
/api*



As far as the name goes, it started out as being for the Echo/Alexa because that's what I have but after I had most of the code done I realized that Google Home and other things would also work with it. I figured at this point that people may not know what Hue is either so I was just as well leaving it Alexa as long as I put everything in the documentation/Wiki. Not to mention the amount of time it will take to rename everything :)



For the response size, I really have no idea how many objects Google Home supports per port at this point ( I don't have Google Home and it hasn't been tested yet, but Brian said he should have time to test tonight). The 60 objects per port was for the Echo which is what I tested and in my testing I tried gzip with no luck (Google Home does support gzip and it is implemented in the code). I believe the Echo/GH is expecting the entire list of objects (lights) to be sent back in a single json response and the reason I know it has to do with the response size and not the amount of objects included in the response was from reducing the fields per object in the response and watching the response size. When the response got over a certain length, the Echo would not import any of the objects.

What I didn't try was holding the connection open and sending a 60 object json response, then another 60 object json response in the same connection. I expect that the Echo will just close the connection after the first response, but I will try this when I get some time. Thanks for the suggestion.


_Wayne



On Tue, Jan 10, 2017 at 1:01 AM, Eloy Paris <[hidden email]> wrote:
Hi Wayne,

This is fantastic work; thank you!

I have been happy using our Google Home with MisterHouse via the IFTTT
integration, but I suspect local integration via Hue emulation would
work better so I will be giving that a try soon, especially since the
IFTTT can be left in place at the same time.

The only thing that puts me off is that requirement to use port 80 -- port
80 is already used by Apache on the machine on which I run MisterHouse,
and even if it weren't, I am not keen on running MH as a privileged
user.

One minor comment... if the local integration is achieved via Hue
emulation then would it not make more sense to call the module and
related .ini configuration parameters something with "Hue" in the name
as opposed to Alexa? I was confused at first when I saw all those
alexaXXXX .ini parameters and the module name "AlexaBridge.pm" -- I
thought it was only for Alexa when in reality is for anything that uses
the Hue protocol/API. I realize you have an Alexa but you might want to
consider using a name that gives a better idea of how powerful what you
came up with is. Perhaps hueEmu_enable, hueEmuHttpIp, hueEmuMac, HueBridge.pm, etc.?

Finally, one question -- the limitation of 60 Echo/GH commands per TCP
port comes from the size of the response to the discovery probe, right?
If so, is it not possible to send a response of any arbitrary size by
segmenting the response? Or that is done already? I don't know anything
about the discovery protocol but I find it strange that the protocol
imposes limits on the sizes of the responses, which then creates the
need for a "multiple ports" workaround.

Thanks again for the great work!

Cheers!

Eloy Paris.-

On Mon, Jan 09, 2017 at 09:22:47PM -0600, Wayne Gatlin wrote:

> First, huge thanks to Brian Klier for all the Google Home debugging!
>
> Updates:
> Google Home confirmed fully functional.
> Data::UUID is no longer required, it was removed because Google Home did
> not work with the UUIDs.
> MH IP and Mac address are discovered and not required to be defined.
>
> 2 new requirements have been added:
>   IO::Compress::Gzip
>   Net::Address::Ethernet
>
> alexaHttpIp=   #No longer needed - but can still be used to override the
> discovery
>
> alexaMac=   #New option added - should be the mac address of the local MH
> server. This is only needed to over ride the discovery.
>
>
> Google Home Notes:
> You must use port 80 for the proxy port, Google Home is locked down to port
> 80.
> The user running MH must be root to run on port 80 or you have to give the
> MH user rights to use the port.
> Current Google Home .ini settings:
> alexaHttpPort=80
> alexaHttpPortCount=1
>
> Being that Google Home only supports port 80, I am going to add multiple IP
> support to allow for more objects to be supported.
>
>
> Other Notes:
> If you were using the old code and update to this, you have to forget all
> the devices and rediscover because the UUIDs have changed.
>
> The updated code is on Git, let me know if anyone else has tested it and if
> you have any comments or bugs to report.
>
>
> _Wayne
>
>
> On Mon, Jan 2, 2017 at 8:54 PM, Wayne Gatlin <[hidden email]> wrote:
>
> > I forgot the dependencies in my original email, the only module that you
> > should have to install is Data::UUID but I listed the others just in case.
> >
> > For Ubuntu "apt-get install libdata-uuid-perl"
> > Or
> > cpan install Data::UUID
> >
> > This is every thing it depends on:
> >  IO::Socket::INET;
> >  Socket;
> >  IO::Socket::Multicast;
> >  Data::UUID;
> >  HTTP::Date;
> >
> >
> > Here's another example that I set up yesterday.
> >
> > I have a script that I use to control my AV equipment and I can run it via
> > ssh, so I made a voice command in MH:
> >
> > $v_set_tv_mode = new Voice_Cmd("set tv mode [on,off,hbo,netflix,roku,
> > directtv,xbmc,wii]");
> > if (my $state = said $v_set_tv_mode) {
> >         my $output = `/usr/bin/ssh mh\@192.168.1.53 "sudo
> > HomeAVControl/bin/input_change $state"`;
> > }
> >
> >
> > I added the following to my MH user code:
> > $AlexaItems->add('set tv mode #','tv','run_voice_cmd'); # "Alexa, Turn on
> > tv" / "Alexa, Turn off tv" # turns all my AV stuff on or off
> > $AlexaItems->add('set tv mode #','DirectTv','run_voice_cmd','directtv','directtv');
> > #"Alexa, Turn on Direct Tv" # turns all my AV stuff on and set the input to
> > direct tv
> > $AlexaItems->add('set tv mode #','Hbo','run_voice_cmd','hbo','hbo');
> > #"Alexa, Turn on hbo" # turns all my AV stuff on and set the input to Roku
> > and launches the HBO Go app
> > $AlexaItems->add('set tv mode #','Netflix','run_voice_cmd','netflix','netflix');
> > #"Alexa, Turn on Netflix" # turns all my AV stuff on and set the input to
> > Roku and launches the Netflix app
> > $AlexaItems->add('set tv mode #','Roku','run_voice_cmd','roku','roku');
> > $AlexaItems->add('set tv mode #','xbmc','run_voice_cmd','xbmc','xbmc');
> > $AlexaItems->add('set tv mode #','wii','run_voice_cmd','wii','wii');
> >
> > _Wayne
> >
> >
> >
> >
> > On Sun, Jan 1, 2017 at 6:02 PM, Wayne Gatlin <[hidden email]> wrote:
> >
> >> Hello everyone and Happy new year!
> >>
> >>
> >> I've been working on the writing the Hue emulation into Misterhouse to
> >> support local direct integration of Alexa/Echo and Google home. I've been
> >> testing with the Echo but I don't have Google Home to test with.
> >>
> >> Currently working:
> >>  - on,off,dim,brighten,set to %.
> >>  - Discovery, just say discover devices and it finds all configured
> >> objects.
> >>  - Supports 120 objects ( 2 TCP sockets )
> >>
> >> Currently not working:
> >>  - Fix the read/write from at least 3 more sockets so 300 devices is
> >> supported.
> >>    - - I'm having issues with looping through the proxy sockets, if I
> >> cant figure it out worst case I'll just hard code them.
> >>  - Need to fix rounding the Set %. Hue uses 0 - 252 for brightness and MH
> >> uses 0 - 100.
> >>
> >> To Do:
> >>  - Need to figure out a good way to configure objects and voice commands
> >> to present to Echo/GH.
> >>  - - I am thinking maybe add a icon to all objects and voice commands in
> >> dev mode that you can click and have a window open to enable and text
> >> boxes/drop downs to do the mappings.
> >>  - Add object creation to the mht file.
> >>
> >>  If you want to test, my code is in my AlexaBridge.pm branch:
> >>  https://github.com/waynieack/misterhouse/tree/AlexaBridge.pm
> >>
> >>
> >> Module Config:
> >>
> >> mh.private.ini
> >> alexa_enable=1 # To enable the module
> >> alexaHttpPortCount=1 # This is the amount of TCP ports you want the
> >> module to open. Only 1 working right now (other than the normal MH web
> >> port). 60 Echo/GH commands per tcp port.
> >> alexaHttpPort=8085  # This is the start port, if you enable 4 ports then
> >> 8085 - 8089 is created. This port should be higher than the default MH http
> >> port so the default is used first.
> >> alexaHttpIp=192.168.195.37 # This is the IP of the local MH server, its
> >> used for the discovery response to the Echo/GH so the Echo/GH knows how to
> >> get back to the MH server.
> >>
> >>
> >> In user code:
> >> $Alexa = new AlexaBridge();  # parent object
> >> $AlexaItems = new AlexaBridge_Item($Alexa);  # child object
> >>
> >> $AlexaItems->add('$light1','light1','set','on','off','state');
> >>
> >>
> >>
> >> In order to allow the user to map pretty much anything in MH to a Echo/GH
> >> command I created a mapping.
> >>
> >> $AlexaItems->add('<actual object name>','<name you want Echo/GH to
> >> see>','<sub used to change the object state>','<State mapped to Echo/GH ON
> >> command>','<State mapped to Echo/GH OFF command>','<sub used to get the
> >> object state>');
> >>
> >>
> >>
> >> $AlexaItems->add('$light1','light1','set','on','off','state');  # This
> >> is the same as $AlexaItems->add('$light1')
> >>
> >>
> >> # To change the name of an object to a more natural name that you would
> >> say to the Echo/GH:
> >>
> >> $AlexaItems->add('$GarageHall_light_front','Garage_Hall_light');
> >>
> >>
> >> # To map a voice command, # is replaced by the Echo/GH command
> >> (on/off/dim%).
> >> # My actual voice command in MH is "set night mode on", so I configure it
> >> like:
> >>
> >> $AlexaItems->add('set night mode #','NightMode','run_voice_cmd');   # If
> >> I say "Alexa, Turn on Night Mode",  run_voice_cmd("set night mode on") is
> >> run in MH.
> >>
> >>
> >> # To configure a user code sub:
> >> # The actual name (argument 1) can be anything.
> >> # A code ref must be used.
> >> # (on/off/dim%) are passed to the sub as an argument when its run.
> >> $AlexaItems->add('testsub','Test_Sub',\&testsub);  # say "Alexa, Turn on
> >> Test Sub",  &testsub("on") is run in MH.
> >>
> >>
> >> # I have an Insteon thermostat and I configured it like:
> >> $AlexaItems->add('$thermostat','Heat','heat_setpoint',undef,undef,'get_heat_sp');
> >> # say "Alexa, Set Heat to 73%",  $thermostat->heat_setpoint("73") is run
> >> in MH.
> >> $AlexaItems->add('$thermostat','Cool','cool_setpoint',undef,undef,'get_cool_sp');
> >>
> >>
> >> I am going to modify the Insteon thermostat child object so the temp can
> >> be set directly as well as up and down and then up can be mapped to 'on'
> >> and down can be set to 'off' and the custom subs will not be needed.
> >>
> >>
> >>
> >> Notes:
> >>
> >> <actual object name> - This is the only required parameter. If you are
> >> good with the defaults, you can add an object like:
> >> $AlexaItems->add('$light1');
> >>
> >> <name you want Echo/GH to see> - This defaults to using the <actual
> >> object name> with out the $. If want to change the name you say to the
> >> Echo/GH to control the object, you can define it here. You can also make
> >> aliases for objects so its easier to remember.
> >>
> >> <sub used to change the object state> - This defaults to 'set' which
> >> works for most objects. You can also put a code reference or
> >> 'run_voice_cmd', examples below.
> >>
> >> <State mapped to Echo/GH on command> - If you want to set an object to
> >> something other than 'on' when you say 'on' to the Echo/GH, you can define
> >> it here. Defaults to 'on'.
> >>
> >> <State mapped to Echo/GH OFF command> - If you want to set an object to
> >> something other than 'off' when you say 'off' to the Echo/GH, you can
> >> define it here. Defaults to 'off'.
> >>
> >> <sub used to get the object state> - If your object uses a custom sub to
> >> get the state, define it here. Defaults to 'state' which works for most
> >> objects.
> >>
> >>
> >> dim% is the actual number you say to Alexa, so if you say "Alexa,Set
> >> Light 1 to 75 %" then the dim% value will be 75.
> >>
> >>
> >> I figured out that the amount of objects per TCP port that the Echo would
> >> discover had nothing to do with the amount of object, but actually it has
> >> to do with the size of the response. I was able to reduce the response size
> >> and now 65 objects per port works, I reduced it to 60 to allow for
> >> variances in name length.
> >>
> >> _Wayne
> >>



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Jon Whitear
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin
if you have an Echo then you need to remove the alexaHttpPort=8086.

_Wayne

On Jan 14, 2017 4:21 PM, "Jon Whitear" <[hidden email]> wrote:
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Jon Whitear
Wayne,

Thank you. I also had a couple of dependencies missing, which I hadn’t noticed when I was just “reloading code”, but when I restarted mh they became obvious. Dependencies you had identified in a  previous email ;-) It’s working fine now.

I’m using Clipsal CBus, and my set() function takes a “set by” argument, although it functions without it. I’m also using raZberry zwave, which takes a “set by” argument and fails without it:

Use of uninitialized value $p_setby in string eq at /usr/local/bin/mrhouse/misterhouse/bin/../lib/raZberry.pm line 645, <GEN300> line 6.

It seems that Alexa doesn’t pass this argument - could you give me an idea of where to look in the code to change that behaviour?

Cheers,

Jon




On 15 Jan 2017, at 9:47 am, Wayne Gatlin <[hidden email]> wrote:

if you have an Echo then you need to remove the alexaHttpPort=8086.

_Wayne

On Jan 14, 2017 4:21 PM, "Jon Whitear" <[hidden email]> wrote:
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin
In my opinion,  that should be fixed in the cbus code. I hardly ever set the set_by arg. But I cant give any pointers on where in my code right now because I am out of town and dont have a computer with me. But you could also have my code look for that object type and add the argument, I have to do some special stuff x10 object.

_Wayne

On Jan 14, 2017 5:55 PM, "Jon Whitear" <[hidden email]> wrote:
Wayne,

Thank you. I also had a couple of dependencies missing, which I hadn’t noticed when I was just “reloading code”, but when I restarted mh they became obvious. Dependencies you had identified in a  previous email ;-) It’s working fine now.

I’m using Clipsal CBus, and my set() function takes a “set by” argument, although it functions without it. I’m also using raZberry zwave, which takes a “set by” argument and fails without it:

Use of uninitialized value $p_setby in string eq at /usr/local/bin/mrhouse/misterhouse/bin/../lib/raZberry.pm line 645, <GEN300> line 6.

It seems that Alexa doesn’t pass this argument - could you give me an idea of where to look in the code to change that behaviour?

Cheers,

Jon




On 15 Jan 2017, at 9:47 am, Wayne Gatlin <[hidden email]> wrote:

if you have an Echo then you need to remove the alexaHttpPort=8086.

_Wayne

On Jan 14, 2017 4:21 PM, "Jon Whitear" <[hidden email]> wrote:
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

H Plato
In reply to this post by Jon Whitear
The razberry shouldn’t require a set_by, I use a set_by argument to set the actual state of the object from the poll.

I think that’s just a warning not an error. In any case what if you add in line 644 in raZberry.pm

 $p_setby = “unknown” unless (defined $p_setby);


On Jan 14, 2017, at 4:54 PM, Jon Whitear <[hidden email]> wrote:

Wayne,

Thank you. I also had a couple of dependencies missing, which I hadn’t noticed when I was just “reloading code”, but when I restarted mh they became obvious. Dependencies you had identified in a  previous email ;-) It’s working fine now.

I’m using Clipsal CBus, and my set() function takes a “set by” argument, although it functions without it. I’m also using raZberry zwave, which takes a “set by” argument and fails without it:

Use of uninitialized value $p_setby in string eq at /usr/local/bin/mrhouse/misterhouse/bin/../lib/raZberry.pm line 645, <GEN300> line 6.

It seems that Alexa doesn’t pass this argument - could you give me an idea of where to look in the code to change that behaviour?

Cheers,

Jon




On 15 Jan 2017, at 9:47 am, Wayne Gatlin <[hidden email]> wrote:

if you have an Echo then you need to remove the alexaHttpPort=8086.

_Wayne

On Jan 14, 2017 4:21 PM, "Jon Whitear" <[hidden email]> wrote:
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Jon Whitear
In reply to this post by Wayne Gatlin
Wayne,

I’m not sure how I could do that its the CBus code, as CBus doesn’t know what’s calling it. For the time being, I’ve changed line 603 of AlexaBridge.pm to include the ‘set by’ argument, like so:

elsif ( $action eq 'set' ) {
    my $end;
    if ( $object->can('state_level') && $state =~ /\d+/ ) { $end = '%'}
           &main::print_log ("[Alexa] Debug: setting object ( $realname ) to state ( $state$end )\n") if $main::Debug{'alexa'};
              $object->$sub($state.$end,’Alexa’); # <— added ‘Alexa” in here
    return;
}

I’m afraid I don’t know if this is the best way to do this, but I can confirm that this passes the “set by” argument to CBus and raZberry, and that they both function with it.

01/15/17 01:42:50 PM [raZberry] Polling initiated
01/15/17 01:42:51 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/2/state ) Body: ( {"on": true} ) Type: ( PUT ) 
01/15/17 01:42:51 PM [Alexa] Debug: MH Got request ( on - true ) to Set device ( 2 ) to ( on )
01/15/17 01:42:51 PM [Alexa] Debug: get_set_state (2 set on) : name: Deck Light  realname: $Deck_Spotlight sub: set state: on
01/15/17 01:42:51 PM [Alexa] Debug: setting object ( $Deck_Spotlight ) to state ( on )
01/15/17 01:42:51 PM [Clipsal_CBus::Group] Deck Spotlight set to state on by Alexa
01/15/17 01:42:51 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/2 ) Body: ( {"on": true} ) Type: ( GET ) 
01/15/17 01:42:51 PM [Alexa] Debug: get_set_state (2 get ) : name: Deck Light  realname: $Deck_Spotlight sub: set state: 
01/15/17 01:42:51 PM [Alexa] Debug: get_state (actual object state: on) - (object type: Clipsal_CBus::Group) -  returning - "on":true,"bri":254
01/15/17 01:42:55 PM [raZberry] Polling initiated
01/15/17 01:42:59 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/1/state ) Body: ( {"on": false} ) Type: ( PUT ) 
01/15/17 01:42:59 PM [Alexa] Debug: MH Got request ( on - false ) to Set device ( 1 ) to ( off )
01/15/17 01:42:59 PM [Alexa] Debug: get_set_state (1 set off) : name: lounge_lamps  realname: $lounge_lamps sub: set state: off
01/15/17 01:42:59 PM [Alexa] Debug: setting object ( $lounge_lamps ) to state ( off )
01/15/17 01:42:59 PM [raZberry] Setting 2-0-37 to off
01/15/17 01:42:59 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/1 ) Body: ( {"on": false} ) Type: ( GET ) 
01/15/17 01:42:59 PM [Alexa] Debug: get_set_state (1 get ) : name: lounge_lamps  realname: $lounge_lamps sub: set state: 
01/15/17 01:42:59 PM [Alexa] Debug: get_state (actual object state: on) - (object type: raZberry_switch) -  returning - "on":true,"bri":254
01/15/17 01:43:00 PM: Saving object states ... done
01/15/17 01:43:00 PM [Clipsal_CBus::Group] Kitchen Bench Downlights set to state on by cbus unit: Kitchen_Multi_Sensor
01/15/17 01:43:01 PM [raZberry] Polling initiated
01/15/17 01:43:01 PM [raZberry] Found:ZWayVDev_zway_2-0-37 with level off and updated 1484448179.
01/15/17 01:43:01 PM [raZberry_switch] Setting value to off. Level is 0

Cheers,

Jon



On 15 Jan 2017, at 9:47 am, Wayne Gatlin <[hidden email]> wrote:

if you have an Echo then you need to remove the alexaHttpPort=8086.

_Wayne

On Jan 14, 2017 4:21 PM, "Jon Whitear" <[hidden email]> wrote:
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Echo and Google Home Local Integration

Wayne Gatlin
The problem is that if the object uses the second argument for something else other than set_by, I can see where statically setting it like that could be an issue at some point. Being that the module is very generic and is supposed to be able to be used with basically any type of object and any sub in that object.

 1. We could fix the modules
 2. Add another option in the add like:
    $AlexaItems->add(realname, name, sub, on, off, statesub, setby);

 3. Add mappings in the AlexaBridge for different object types as they come along like:
      if ( lc($type) =~ /clipsal_cbus/ ) { $object->$sub($state,'Alexa') }

I know that I am going to have to add some code to set and get the proper state for some objects just as I have done with the x10 module. I don't use the set_by for anything, but if its important then we should probably just add the option in #2.

_Wayne
 



 

On Sat, Jan 14, 2017 at 8:46 PM, Jon Whitear <[hidden email]> wrote:
Wayne,

I’m not sure how I could do that its the CBus code, as CBus doesn’t know what’s calling it. For the time being, I’ve changed line 603 of AlexaBridge.pm to include the ‘set by’ argument, like so:

elsif ( $action eq 'set' ) {
    my $end;
    if ( $object->can('state_level') && $state =~ /\d+/ ) { $end = '%'}
           &main::print_log ("[Alexa] Debug: setting object ( $realname ) to state ( $state$end )\n") if $main::Debug{'alexa'};
              $object->$sub($state.$end,’Alexa’); # <— added ‘Alexa” in here
    return;
}

I’m afraid I don’t know if this is the best way to do this, but I can confirm that this passes the “set by” argument to CBus and raZberry, and that they both function with it.

01/15/17 01:42:50 PM [raZberry] Polling initiated
01/15/17 01:42:51 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/2/state ) Body: ( {"on": true} ) Type: ( PUT ) 
01/15/17 01:42:51 PM [Alexa] Debug: MH Got request ( on - true ) to Set device ( 2 ) to ( on )
01/15/17 01:42:51 PM [Alexa] Debug: get_set_state (2 set on) : name: Deck Light  realname: $Deck_Spotlight sub: set state: on
01/15/17 01:42:51 PM [Alexa] Debug: setting object ( $Deck_Spotlight ) to state ( on )
01/15/17 01:42:51 PM [Clipsal_CBus::Group] Deck Spotlight set to state on by Alexa
01/15/17 01:42:51 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/2 ) Body: ( {"on": true} ) Type: ( GET ) 
01/15/17 01:42:51 PM [Alexa] Debug: get_set_state (2 get ) : name: Deck Light  realname: $Deck_Spotlight sub: set state: 
01/15/17 01:42:51 PM [Alexa] Debug: get_state (actual object state: on) - (object type: Clipsal_CBus::Group) -  returning - "on":true,"bri":254
01/15/17 01:42:55 PM [raZberry] Polling initiated
01/15/17 01:42:59 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/1/state ) Body: ( {"on": false} ) Type: ( PUT ) 
01/15/17 01:42:59 PM [Alexa] Debug: MH Got request ( on - false ) to Set device ( 1 ) to ( off )
01/15/17 01:42:59 PM [Alexa] Debug: get_set_state (1 set off) : name: lounge_lamps  realname: $lounge_lamps sub: set state: off
01/15/17 01:42:59 PM [Alexa] Debug: setting object ( $lounge_lamps ) to state ( off )
01/15/17 01:42:59 PM [raZberry] Setting 2-0-37 to off
01/15/17 01:42:59 PM [Alexa] Debug: Port: ( 8080 ) URI: ( /api/Zd0zG7YKFT1jr7tuYgmg9Gxqy6LCBj2QGfABo6sw/lights/1 ) Body: ( {"on": false} ) Type: ( GET ) 
01/15/17 01:42:59 PM [Alexa] Debug: get_set_state (1 get ) : name: lounge_lamps  realname: $lounge_lamps sub: set state: 
01/15/17 01:42:59 PM [Alexa] Debug: get_state (actual object state: on) - (object type: raZberry_switch) -  returning - "on":true,"bri":254
01/15/17 01:43:00 PM: Saving object states ... done
01/15/17 01:43:00 PM [Clipsal_CBus::Group] Kitchen Bench Downlights set to state on by cbus unit: Kitchen_Multi_Sensor
01/15/17 01:43:01 PM [raZberry] Polling initiated
01/15/17 01:43:01 PM [raZberry] Found:ZWayVDev_zway_2-0-37 with level off and updated 1484448179.
01/15/17 01:43:01 PM [raZberry_switch] Setting value to off. Level is 0

Cheers,

Jon



On 15 Jan 2017, at 9:47 am, Wayne Gatlin <[hidden email]> wrote:

if you have an Echo then you need to remove the alexaHttpPort=8086.

_Wayne

On Jan 14, 2017 4:21 PM, "Jon Whitear" <[hidden email]> wrote:
This is great stuff - unfortunately I’m having problems getting going.

I have updated my working mh with the http_server.pl, bin/mh, and AlexaBridge.pm files from Wayne’s git repo. My mh.private.ini  includes:-

alexa_enable=1
alexaEnableChunked=1
alexaHttpPort=8086

and I have some user code (alexa.pl) like this:-

$Alexa = new AlexaBridge();
$AlexaItems = new AlexaBridge_Item($Alexa);
$AlexaItems->add('$lounge_lamps’);

but when I reload code, all I get in the print.log is "Error in user code.”

I feel like I’ve missed something basic ;-) I’d appreciate some help

Cheers,

Jon




------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users

Loading...