Hello,
Context
My OH setup strongly relies on AmazonEchoControl LastVoiceCommand (LVC) to locate where voice commands were issued and process them smartly depending on the location. This should be handled by Alexa server side but is so erratic and time-consuming to implement in the Alexa App that I preferred to implement my own logic.
I use 2 levels of proxied items which receive and forward command to items (indeed, there is also a 3rd level of functional proxy but this is not the topic here):
- first level of proxies has 2 functions :
- to âkeep control over Alexaâ: when I am out of the house, commands sent to Alexa items are not forwarded to devices and Alexa just returns a TTS âI am not allowed to control this device at the momentâ,
- to wait for the LVC update so a command can be tagged (using tags in item metadata) with information about where and who triggered it. The âwhoâ gets only filled when the command is sent from a mobile phone (until the binding is able to return userâs voiceprint informationâŠ), the âwhereâ gets filled using the location of the LVC item.
- second level of proxies are attached to the topmost "house location"item for each function such as light, tv, media activity, thermostat, shutter or whatever âfunctionalâ item we can think about. When one of this virtual item receives a command, it forwards the command to the right device in the right room.
I also run a âsmart notification logicâ to return a relevant feeback to the issuer of the command through available ânotification channelsâ available in the room where the command was issued (TTS, color light, OSD, push notification or whatever available).
Use cases
if I request Alexa to turn on my TV with a voice command sent to the Echo device located in the living room:
- I will be locate me in the living room (through Echo LVC item),
- the proxied âgeneric TV itemâ will look for a TV item in the living-room and turn it on if any or will default to the âdefault TV itemâ if any
- will NOT notify me as I am located in the room where I triggered the command (so I basically can see the TV turning on, so no need for a feedback).
if I request the same command from my phone while outside:
-
- I will be located out of the house (I use Tasker and items for each mobile phone for that),
-
- will look for the âdefaultâ or âmasterâ device of the house and turn it on,
-
- will send a push notification to the phone to confirm the TV of the living-room was turned on
So the loss of LVC functionality in AlexaEchoControl just messed up all system and I worked hard to find on a workaround which principles is described here.
Principle of LastVoiceCommand workaround
I have setup a basic packet sniffer for Echo devices on my LAN.
-
the outbound traffic from echo devices is mirrored to a monitoring device
in my case, I could run the following command on my Asus router to create a mirror of Echo packets and route them to my OH server (a Windows PC: might be simpler or more efficient on a Linux setup) -
the âmonitoring deviceâ detects increase of outbound traffic from an Echo and updates the âpacket monitor itemâ (PKT item) related the Echo device in OH
I wrote a short python routine using Scapy library for packet sniffing and requests library to send a postUpdate() using OH API. -
When the PKT item gets updated and an Alexa proxy item (AX) received a command âbarely at the same timeâ, then I update tthe LVC item of the Echo which triggered the network traffic
I store LVC updates and AX commands in Jython queues and when the time difference is low (was 2 secs when LVC was working but with my implementation, 0.5 secs is enough!), I trigger a postUpdate() on LVC item
Advantages: Notifications and commands are dramatically faster: the LVC gets always updated before the command (when AmazonEchoControl LVC was available, LVC item was sometimes updated after my AX item received the command so I had to implement a tricky set of rule to ensure âwait for each otherâ). No longer depends on Alexa API.
Drawbacks (but this was already the case before) : if 2 persons send different voices commands simultaneously to 2 Echos in 2 rooms, things may not run as expected