How to make friends with Alice and HomeBridge

  • Tutorial
image

I have long wanted, in addition to the smart home, a voice assistant who understands and speaks Russian. As a result, I decided to take a chance and take a raw new column of Yandex. Station with a young, but already much beloved Alice. The first impression was great, but when I heard a lot of jokes and had a lot of talk, I began to learn the practical side of the column. I was most interested in the question of Alice’s interaction with the smart home.

Description of the problem
My home is powered by a HomeBridge server . About his setup and use on Habré and other resources, many articles have been written ( one , two , three ), so I will not dwell on this. Not having studied the question thoroughly, I was sure that Alice’s catalog of skills already had a lot of solutions for interacting with smart home control systems. It turned out that at the time of this writing, most of the skills on the subject of “Smart Home” require a device with a display for operation, which is not suitable for the station. The only skill that seemed to meet the requirements and was able to work without a display was Alfred.. Навык не подошел мне по причине того, что он жестко завязан на сервис — IFTTT. Допустим я хочу создать виртуальный переключатель, функционирующий в системе умного дома и позволяющий привязывать сценарии к его текущему состоянию. Альфред использует сервис WebHook для IFTTT с помощью которого можно только воздействовать на триггер создаваемый в апплете IFTTT, но нет возможности получить текущее состояние апплета (можно перевести переключатель в положение вкл или выкл, но нельзя узнать в каком состоянии сейчас переключатель).

To solve the above task, the Alice-HomeBridge service has been created , designed to communicate with the voice assistant of Yandex.Alice and various smart home control systems. Further, we will consider the HomeBridge configuration as examples of settings, but this approach is applicable for other systems such as  Home AssistantopenHAB  and others. 

The service allows users, after registering on the site, to create virtual switches.



You can change or find out the state of the switches using a specially crafted GET request to the service.



In order for the service to interact with the voice assistant "Alice" the skill "Lazy Jimmy" is created.

Lazy jimmy
Tell Alice: “Start the skill lazy Jimmy” and he will offer you to inform the activation code that you can find in your personal account



After activation, you can change the state of your switches using the “Turn On” or “Turn Off” commands. For example, if you say “Turn on the Light”, the state of the “Light” switch will change to positive. If you just say “Light”, the state of the switch will change to the opposite.

In order for the dialogue to sound more natural, there is an opportunity to create switches with more understandable names, for example, “With Utrechkom”, then you can tell Alice “Say Jimmy With Utrechkom” and the state of the switch will change.

It remains to configure the HomeBridge. For example, we will use the extension cmdswitch2. Let's create a switch for HomeKit with the name “Alice Button 1”.

{
  "platform": "cmdSwitch2",
  "name": "CMD Switch",
  "switches": [
    {
      "name": "Alice Button 1",
      "on_cmd": "curl --silent \"http://alicehomebridge.org/alice/switches.php?switch=34&hb=ADB7BYBT728O&state=set&val=true\"",
      "off_cmd": "curl --silent \"http://alicehomebridge.org/alice/switches.php?switch=34&hb=ADB7BYBT728O&state=set&val=false\"",
      "state_cmd": "curl --silent \"http://alicehomebridge.org/alice/switches.php?switch=34&hb=ADB7BYBT728O&state=get\" | grep -oh \"true\"",
      "polling": true,
      "interval": 2
    }
  ]
}

In order not to overload the server with excessive requests, set the interval parameter value for at least 2 seconds.

All is ready.



Now, if you say “Alice tell lazy Jimmy with a morning”, the switch “Alice Button 1” will change state. Here is a demonstration of how everything works in conjunction with customized HomeKit scripts:


The full version of the HomeBridge P.S. configuration file

. Most smart home control systems, such as HomeKit, support scripting. You can create a script that you would like to use in a certain situation, for example, when you wake up and assign it a call to the “Turn On Switch” event.

PS My service is only developing and, to put it mildly, is far from ideal. But Alice refuses to accept certain phrases from time to time. For example, she perfectly conveys the skill phrase "Turn on the light", but the phrase "Good morning" will not pass. I hope Yandex knows about the problem and will soon fix it. Waiting for your comments.

Also popular now: