Skip to content

Amazon Echo and Google Home local integration using MH native Hue Emulation

Rick Steeves edited this page Jan 20, 2021 · 1 revision

Misterhouse now natively supports Philips Hue emulation, so in theory any thing that supports the Hue is supported by the Misterhouse Hue emulation module.

Hue emulation uses /mh/lib/AlexaBridge.pm. The dev version can be found here: https://raw.githubusercontent.com/waynieack/misterhouse/AlexaBridge/lib/AlexaBridge.pm

Currently the only things that have been tested is Google Home and Amazon Alexa Echo.

PreReqs:

  • Net::Address::Ethernet (dependency on Regexp::Common, Net::Ifconfig::Wrapper)
  • UPnP/SSDP broadcasts between MH and the Echo/Home device (should be true if on the same subnet)
  • Current read_table_A.pl

mh.private.ini Configuration

Note: You must use port 80 for Google Home, it 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.

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

Notes: Your reverse proxy must be listening on port 80. In the Apache proxy make sure you send any of the requests below to MH unauthenticated: /discovery.xml /api* Being that there is no authentication, you can allow only the the Google Home IP to the directories above.

For Google Home by changing the MH web port (preferred method for Google Home):

alexa_enable = 1
http_port = 80   # Set the Misterhouse web port to 80
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 Alexa Echo (Chunked method):

alexa_enable           = 1
alexaEnableChunked     = 1
alexaHttpIp            = 192.168.100.57   # This is the IP of the local MH server, We discover it so it does not need to be defined unless something goes wrong
                                          #this is the LAN IP of MH, NOT the Alexa device                                                
#debug                 = alexa:5
alexaForceLongFormat = 1

For Echo (Multi-port method):

This method should not be used.

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.

Items.MHT configuration

ALEXA_BRIDGE, Alexa
ALEXABRIDGE_ITEM, AlexaItems, Alexa

The most important part of the configuration is mapping the MisterHouse objects/code you want to present to the module (Echo/Google Home/Etc.). This allows the user to map pretty much anything in MisterHouse to a Echo/GH command.

ALEXABRIDGE_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>

  • "actual object name" - This is the only required parameter. It is the actual name you gave to an object such as a Insteon or X10 light in MisterHouse. If you are good with the defaults, you can add an object like:

ALEXABRIDGE_ADD, AlexaItems, light1

  • "name you want Echo/GH to see" - This defaults to using the "actual object name" without 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 it's 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'.

  • "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.

  • The 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.

Implementation:

Once you have set mh up, you need to go to the Alexa app on your phone or the web page and add ‘other’ devices there, that launches the discovery. You can then test it in the app.

Voice syntax is Alexa turn xxx on

Installation and Enabling Hints:

This was one of the harder things to get working in Misterhouse, for me in some time, so I thought I would add some hints. Some maybe only relevant to mh-rev-4.2.

password_allow_clients

In order for Alexa to access your devices, she needs access. You must edit you mh.private.ini and at a minimum add your Echo devices IP to the list of allowed clients. It is common to configure this parameter to allow access for all local LAN clients.

password_allow_clients uses regexp and as it is not completely intuitive. A quick google of password_allow_clients will get you what you need. Quick example: password_allow_clients = 127.0.0.1,192.168.2..+,239.255.255.250

Net::Address::Ethernet

Net::Address::Ethernet perl module is used by AlexaBridge.pm but installation wasn't simple. The package has a dependency on Regexp::Common that didn't auto install nor would it install via CPAN. I fixed this on Ubuntu 12.04.5 LTS via

>>apt-file search Regexp/Common
libregexp-common-perl
>>sudo apt-get install libregexp-common-perl
>>sudo cpan Net::Address::Ethernet

Aside- While I used cpan to install Net::Address::Ethernet you might be able to get it from apt via the libnet-address-ip-local-perl package

>>apt-file search Net/Address
libnet-address-ip-local-perl: /usr/share/perl5/Net/Address/IP/Local.pm

my_alexa.pl

The mh-rev-4.2 (fixed in 4.3) has a bug in AlexaBridge.pm that does not build items.mhp from items.mht correctly. I was not able to specify Alexa items in items.mht. I created ./code/my_alexa.pl. In it I specified the full alexa bridge exposure. Here is a simple example. See AlexaBridge.pm for more complex examples.

use AlexaBridge;
$Alexa = new AlexaBridge();  # parent object
$AlexaItems =  new AlexaBridge_Item($Alexa);
$AlexaItems -> add('$KitchenLights','Kitchen_Lights','','','','',);
$AlexaItems -> add('$KitchenCabinet','Kitchen_Cabinet_Lights','','','','',);
$AlexaItems -> add('$FamilyRoomLamp','Family_Room_Lights','','','','',);
$AlexaItems -> add('$HolidayLightsOutside','Outside_Christmas_Lights','','','','',);
$AlexaItems -> add('$HolidayLightsIndoor','Inside_Christmas_Lights','','','','',);
$AlexaItems -> add('$FrontPorchLight','Front_Porch_Lights','','','','',);

Smart Home Skills (Echo)

You do not need to have the Hue skill enabled to get mh working with Alexa.

Device scan and multiple accounts in Household (Echo)

Amazon has recently made it impossible to simply scan for your devices by saying 'Alexa scan for new devices', because they cache all of the devices it discovers, so each time you make a change to your MisterHouse configuration you need to do the following;

  1. Delete all of your devices via the Amazon Echo phone App or the web interface
  2. If you have more than one Echo power them all down but one.
  3. Factory reset this Echo here are some instructions
  4. Add this Echo back using the Alexa phone App
  5. Now use the app or web interface to re-scan for your MisterHouse devices.

NOTE: Be especially careful if you have more than one account registered as household members in the device settings, each echo becomes set to the account that registered it.

alexaHttpIp

  • Part1 - Depending on if Net::Address::Ethernet is installed, AlexaBridge.pm may not divine the address for alexaHttpIp correctly. You can specify alexaHttpIp in mh.private.ini. Without it mh doesn't broadcast its URL to Alexa correctly.
  • Part2 - (Oh duh! level) The name of alexaHttpIp is a bit confusing. This is parameter is the LAN IP of your misterhouse box NOT the IP of your Echo.

debug=alexa:5

If you have trouble add 'debug=alexa:5' to your ini file. That will expose a lot of details to assist in the debug.

For more see the MisterHouse local documentation by navigating to the following on your local MisterHouse installation: Home > Mr. House Home > Browse Categories > MisterHouse > Update the Documentation

Clone this wiki locally