Best practice / lessons learned for Snips <-> Home Assistant

Hi @all,
to be honest, I am still a newbie in using Snips, that’s also one of the reasons for this topic.
I like to know something regarding best practices for: SNIPS <-> Home Assistant

I started with Snips and Home Assistant - on different Pis - with connectivity to an IP/KNX Router using KNX / XKNX for my Smarthome environment.
I need to say, I have quite a huge KNX environment running incl. Gira Homeserver, visualization, komplex logics etc and the intention for Snips is, to control most of the different entities (lights, cover, heating, cooling, ventilation, media, electronic consumers, etc.) in the near future.

I know, it will be quite a lot of stuff and this is the reason for my upcomming questions. I would like to avoid reengineering and restructuring as much as I can.
So the current status is, the Pis (Snips, HASS etc.) are all running and I am able to control light via Snips->HASS->KNX/XKNX. So, before starting, now the real challenge will be, to create sustainable Snips-Apps and structured entities within HASS.

My questions are: Are there any best-practices for
- Definitions of Intents, Slots, Slot Types (in Snips)
- Contents of the objects above

Home Assistant

  • Sustainable Structures of “namings” of entities within XKNS in HASS
  • Based on the namings of the entities, conceptional structures of the HASS Templates

The reasons for my questions are also based on some of the typical but also unusual properties/characteristics of the german language, especially the characteristic in connecting nouns.
E.g.:
- Hey Snips, switch on the light over the desk in the office.
(Hey Snips, schalte das Licht im Büro über dem Schreibtisch an.)
- Hey Snips, switch on the “desklight” in the office.
(Hey Snips, schalte das Schreibtischlicht im Büro an.)
- Hey Snips, switch on the “desklight”.
(Hey Snips, schalte das Schreibtischlicht.)
- Hey Snips, dim the light at the wall over the desk to 50%.
(Hey Snips, dimme das Licht an der Wand über dem Schreibtisch auf 50%)

So my intention for the Slots in Snips:

  • location (rooms): office (Büro)
  • locationtype (objects within a room): desk, TV, Couch, wall, window, … (Schreibtisch, Fernseher, Sofa, Wand, Fenster)
  • entity (control units): light, “desklight”, “wall-light” (Licht, Schreibtischlicht, Wandlampe, etc)
  • command: on, off, next, previous, … (an, aus, vor, zurück, …)
  • value: 50%, …

The challenge is, that in locationtype and entity you somehow have parts of the same objects, based on the characteristics of the german language.

If now you are going to HASS looking to JSONs objects you need to create the entity names within HASS based on the entities and value, that were delivered, to control the individual objects e.g. light.office_desk_light.
Based on the structure above it will be a huge challenge to realize a template for a number of lights, covers etc.

So, therefore my questions regarding best-practices or any “lessons-learned”.
Any comment is really appreciated.

Ciao
DJ
PS: I have worked out a “concept/structure” wich - looking to the existing snips-apps - seems really quite strange and completely different of how existing apps are realized. Therefore I would like to know, if there are any best practices, because probably my concept doesn’t make sense.

I am working on a project which is to use node-red to have in the same application the commands of the KNX bus and the state of the different devices KNX on the bus, info to Mqtt and info to Mqtt from snips.
A MySQL database serving as a bridge between names and addresses KNX, with their states, and their correspondence with the intents of Snips. The advantage is that it allows each newly installed device to find them directly in MySql.
Today, I already have KNX streams, MQTT and MySql streams, functional in Node-Red but I still have a lot of work left.
Currently I am training ProjectAlice, because I think it will allow me from my data to directly create the Snips assistant adapted to the structure of my home automation.

Probably, the default way would be to use the intent_script component, and create automations based on incoming MQTT messages. Take a look at https://www.home-assistant.io/integrations/intent_script.
I personally have gone another route, by using the HA API directly from within the snips app (
https://console.snips.ai/store/de/skill_Mb2EmQZ332g).
But I guess thats just a matter of personal taste.

Regarding Slots, I recommend that your slot types include a list of possible values (not only strings), as complete as possible. Feel free to clone my app above to take a look. I have added all sorts of room names, with the help of WikiData, which results in around 60 names. This makes it easier for snips to “guess” what you wanted to say, even things sound similar. I don’t have that many rooms/lights, but I havent encountered any issues so far. On the other hand, I did the same for my train stations app, and I have added all station names from a CSV (huge list), and it even understands more complex station names without issues.

Then, maybe it would be worth considering to keep it rather simple than complex. For example, in my app it will control lights by a) snips siteID b) room name c) lamp name. The lamp name will be unique, as I will name my lights something like “Stehlampe”, “Schreibtischlampe” etc, but not “Lampe in der Ecke links”, “Licht auf dem Schreibtisch” etc.
So maybe consider 1) how many different rooms you have 2) how many different lamps in every single room you have and then find a good way of naming those.
I personally just control everything by room name, since I have at most 1 light which is controllable in any room anyway.

Hi,
thanks for your feedback.

@richardpub sounds really interesting, what you are going to realize. I have thought about using Node-Red but I have a huge logic running on a dedicated Gira Homeserver and I do not want to rebuild similar stuff in Node-Red. Especially the maintainance will be to high in my opinion.
To be honest I did not understand exactly the difference and especially the add-on of ProjectAlice compared to Snips - but I only “flew over” the description.
But one question came up: does is make sense to use a db for the mapping and if so, why didn’t you use e.g. Neo4j for it, that would be much more interesting :smiley:?

@s710 I have seen your Github project and the description sounds really to what I am looking for. I have also tested a couple of things in the last days, coming to the conclusion that everything should work based on

  • location (rooms etc.)
  • entity (Licht, Deckenlicht etc)
  • value

So more or less what you metioned and also documented on Github. I will try to realize such kind of structures in the next days/weeks or whatever.
Ciao
DJ

For KNX, in ETS5 I have 18 pages of group addresses and 6 pages of equipment. This is the reason why I prefer to go through a database because ETS5 allows me to directly export all these addresses and equiments in XML with nearly 2000 lines … And this will facilitate maintenance in case of evolution.
I do not know Neo4j, I’m going to inquire …
Personally, I use Lifedomus as a supervisor but since its purchase, I have doubts about its durability.
In addition I try to have a home automation as independent as possible with respect to external connections. And at the same time, I’ve developed a number of features on arduino, ESP and Raspberry, which run in overlay, like the OneWire weather station, the Husqvarna robotic lawnmower, which goes into hiding before watering. … On Node-red there is a lot of addons for TV, HIFI, etc …

I also tested the Snpis assistant for Jeedom, and I quickly found the limits to its structure … with confusions and the inability to differentiate the level in the house, the room, the location in the room, the equipment concerned, the action and the % of the action …

OK, I agree, that makes sense! Neo4j is a graphical db, quite easy to get into and really cool for such requirements. It should be easy to import your mysql structure into a useful Neo4j structure.

As mentioned before, I also have a large-scaling logic for KNX and therefore I would like to reduce the snips and HA environment really for voice control. For media I am using SONOS. I have realized logic and graphical implementation for Sonos in Gira HS (based an the http-api of jishi https://github.com/jishi/node-sonos-http-api). An example of my result you can find here: https://knx-user-forum.de/forum/öffentlicher-bereich/knx-eib-forum/1114605-neue-version-3-0-des-player-moduls-für-sonos-gira-hs?p=1257672#post1257672
So I just need the basic commands for voice control and if there should be requirements to also create voice commands to start a special playlist or favorite or TuneIn Radio I think it should also be possible to start it through the http api. But - to be honest - currently I do not know if this will be necessary.

Following your advice I followed some tutorial on Neo4j. I discovered the graph databases … Really powerful … Thank you for this discovery. I still have to continue and import my data in XML to Neo4j. But there may be a way to directly retrieve data from the KNX bus, which is the major source of my home automation data. Do you already have experience in this field ???

Hi @richardpub,

I knew, you would like it :slight_smile: It’s great!

Based on the fact, that I do not know exactly your intention in using a db for your knx-addresses, it is not as easy as it seems to make a recommendation. As far as I understood, you are using it for a mapping of your devices and knx-points.
The important fact in working with a graph DB is, you need to define 3 major topics: nodes, relationships and properties

So, what do you want to depict? Which information is the most important?

Mostly the structures in ETS are:

  • Topology of the environment: House, Garage, …
  • Unions (Actors, Detectors, Switches, Interfaces …)
  • Lines (typically for floors etc.)
  • Group-Adresses
    These are very often categorized in entities
    * light
    * heating
    * cover
    * detector
    * media
    * …

Based on these information a structure could be (only an example).
Nodes:
- Topology
- Location
- Unions
- Lines
- Category/entities

Relationship Types:
- Installation (installed in)
- Usage (used for)
- Connection (connected to)
- …

Property Keys
- Address
- Description
- Supplier
- …

This is only an example, as mentioned. To get a structure, you can also use your model in your MySQL db.

  1. Take the names of your “master data tables” (in german: Stammdaten-Tabellen) and use the names for your nodes.

  2. Take the names of your “transaction data tables” (in german: Bewegungsdaten-Tabellen) and use the names for your relationship.

  3. Take the properties of your tables and use them for your property keys.

This could be a starting point, otherwise you need to update or change it however you need it.
Ciao
DJ

Sorry I forgot.
How do you get the data from your knx bus? You can save the data from your knx bus into a csv file and then importing it via batch.
To be honest, I prefer to work with json or csv. XML I use only if necessary.

In fact, everything is not stopped yet …
I started two years ago, trying to use the App for ETS5, KNX Web Service. I could also use .csv exports. It is he who generates the global export of my project in XML. Behind there is an image file to use the export on Raspberry, but this one is really basic.
Then I started to use Snips, and I tested the assistant developed for Jeedom. I quickly found the limits with a structure of slots that is insufficiently structured. But that allowed to test by passing commands in http to my box Lifedomus. I realized that I would have to manually make a purchase order, ie 2 orders for one of the lights in my office. Given the number of rooms and devices in the house it was going to make a really large number, not to mention the difficulty of maintenance with each new device or change.
I then discovered Node-Red that I did not know, with its modules KNX, Mqtt, Mysql … The KNX module returns each change on the KNX Bus, hence the idea to analyze all these messages that pass constantly to maintain the state of the devices as well as the appearance of unknown addresses.
I would like to compare the characteristics of these data to bring them closer to the Snips commands a bit like a translation between what goes through KNX and the messages from Snips that go through Mqtt.
I am and I test the ProjectAlice of Psycho, because that would allow with a well built and dynical database to generate with ProjectAlice, the assistant for Snips
Sorry for my English.
cordially