Connecting snips to openhab

This grabs the item that you want to do something out of the item registry and sends a command to it. So in your example it will send the command “ON” to your item “luce”.

Hello there! I am slowly managing all the stuff… but I run into a big problem…
when i say an intent (or write it in snips web console) snips process the wrong command!
example:
if I have an intent called “resume” and I train it with “resume music”
and have another intent called “pause” trained with " pause music"

if I write or say resume music it always output the “pause” intent!
is it normal? how do I solve this? this problem happen even with other intents like lights control!

Hello everybody!
I found out this topic and seems to solve the problem (but have to do lot of try in intents/slots/training)

Now I run into this new problem:
I can handle with openhab rules snips mqtt data but the system is very very slow… like 30seconds from the speaking to the light on command!!

Using MQTTSPY I see that snips send mqtt data quite fast so the problem should be with openhab…
I use mosquitto broker running on openhab in raspberry n.1 while snips runs on raspberry n.2 …
How can I set correctly snips–>(openhab broker<—openhab)? I would like to use snips satellites in future so the better solution to not overload the network…

I am non very skilled with mqtt configuration, so be gentle! :slight_smile:

thank you!

So the messages by Snips are fast but it takes about 30 seconds before your rule reacts to it, right? Your current setup is that you connected Snips Mosquitto and your OpenHAB Mosquitto via bridging (you edited the config files)? And the about 30 secondsittakes are after the messages arrived at your OpenHAB broker?

Try to integrate your Snips broker like you integrated your other broker into OpenHAB viathe MQTT binding. I did it this way and I have no problems. You could also try to manually send a fitting MQTT message for your OpenHAB rule and see if it also takes that long.

Here I am, after some investigation I assume that the broker configuration should be ok, because I receive snips mqtt message on openhab broker quite fast… the problem is thas openhab process the rule in about 30-40 seconds! really too much! I attach an extract of my rule file…

import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule "Snips"
when
    Item Snips_Intent received update
then
    //logInfo("Snips Intent", Snips_Intent.toString)
    

    var String intentName = 		transform("JSONPATH", "$.intent.intentName", Snips_Intent.state.toString) 
    var String snipsIntent  = 		intentName.split(":").get(1);
    var String snipsSlot1RawValue = transform("JSONPATH", "$.slots[0].rawValue", Snips_Intent.state.toString)
    var String snipsSlot1Value    = transform("JSONPATH", "$.slots[0].value.value", Snips_Intent.state.toString)
	var String snipsSlot2Value    = transform("JSONPATH", "$.slots[1].value.value", Snips_Intent.state.toString)
	var String snipsSlot3Value    = transform("JSONPATH", "$.slots[2].value.value", Snips_Intent.state.toString)
	var String confidence = 		transform("JSONPATH", "$.intent.confidenceScore", Snips_Intent.state.toString)
    

    logInfo("snips.rule", "intent: " + snipsIntent)
    logInfo("snips.rule", "raw value: " + snipsSlot1RawValue)
    logInfo("snips.rule", "slot1: " + snipsSlot1Value)
    logInfo("snips.rule", "slot2: " + snipsSlot2Value)
//end

if (Double::parseDouble(confidence) > 0.5) {  



// ---------------------------------TURN ON -----------------------------------

if (snipsIntent == 'TurnOn') {
   
 if (snipsSlot1Value == "luce"){ 
   	
   	switch (snipsSlot2Value){ 
   	
   		case "sala":{ 
   			sendCommand(Slampher,ON)
   				}
   				
   		case "camera":{
   			sendCommand(cameraled,ON)
   				}
   			
   		case "parete led":{
   				sendCommand(cameraled,ON)
   				}
   		} 
       } 
} 


// ----------------------------------------MUSIC -----------------------------------

if (snipsIntent == 'pause') {

   sendCommand(Music,PAUSE)
   
}


if (snipsIntent == 'nextSong') {
 sendCommand(SpotyMusic,NEXT)
   
}



if (snipsIntent == 'VolumeUp') {
 
   VolumeCasa.sendCommand(INCREASE)
//   new PercentType(50)
   //    VolumeCasa.sendCommand(VolumeCasa+10)
   
}

if (snipsIntent == 'VolumeDown') {

   VolumeCasa.sendCommand(DECREASE)
   //sendCommand(Music,VolumeCasa=VolumeCasa-10)
   
}


if (snipsIntent == 'SetVolume') {
   
   VolumeCasa.sendCommand(new PercentType(snipsSlot3Value))  
}



if (snipsIntent == 'playRadio') {
			playStream("chromecast:audiogroup:Casa","http://ice07.fluidstream.net:8080/KissKiss.mp3")
	        	}

}
end

.item:

Player Music (gAudio) { channel="chromecast:audiogroup:4c810ee9-f28e-473b-8155-3662b4efbfa9:control" }

Dimmer VolumeCasa (gAudio) { channel="chromecast:audiogroup:4c810ee9-f28e-473b-8155-3662b4efbfa9:volume" }

Player SpotyMusic (gAudio) { channel="spotify:device:2ba1d70b:4c82:devicePlayer" }
String Snips_Intent "Snips Intent" { mqtt="<[MQTT:hermes/intent/#:state:default]" }

Now I have another big problem! snips console website is not working anymore! it is always “training”! is it normal?! I tried with different comupere, browser and deleting cookies etc… but always the same screen!

can someone help me?!
Thank you!!

Regarding your first problem:
If you lose the time inside openhab, the only possibility I see is to add some log messages into your rule and check which step needs the time.

Thanks a lot for sharing your thoughts, It’s really a great concept. I am also working on this type of project. Nice thought, great vision.

1 Like

Hello there, I am still working on loosing the time for elaborate commands in openhab, because snips is quite fast to publish messages on openhab broker…
I made this snips.rule: (using telegram bot to have faster debug of rule timing)

import org.eclipse.smarthome.model.script.ScriptServiceUtil


rule "Snips"
when
Item Snips_Intent received update //changed //command
//received update
then
logInfo("Snips Intent riceived", Snips_Intent.toString)
sendTelegram("bot1", "received command!")

 

var String intentName = 		transform("JSONPATH", "$.intent.intentName", Snips_Intent.state.toString) 
var String snipsIntent  = 		intentName.split(":").get(1);
var String snipsSlot1RawValue = transform("JSONPATH", "$.slots[0].rawValue", Snips_Intent.state.toString)
var String snipsSlot1Value    = transform("JSONPATH", "$.slots[0].value.value", Snips_Intent.state.toString)
//	var String snipsSlot1Name    = transform("JSONPATH", "$.slots[0].slotName.value", Snips_Intent.state.toString)
	
	var String snipsSlot2Value    = transform("JSONPATH", "$.slots[1].value.value", Snips_Intent.state.toString)
	var String snipsSlot3Value    = transform("JSONPATH", "$.slots[2].value.value", Snips_Intent.state.toString)
	
	
	var String confidence = 		transform("JSONPATH", "$.intent.confidenceScore", Snips_Intent.state.toString)


logInfo("snips.rule", "intent: " + snipsIntent)
logInfo("snips.rule", "raw value: " + snipsSlot1RawValue)
logInfo("snips.rule", "slot1: " + snipsSlot1Value)
logInfo("snips.rule", "slot2: " + snipsSlot2Value)

and in .item:

String Snips_Intent "Snips Intent" { mqtt="<[MQTT:hermes/intent/#:state:default]" }

how can I find out why rule, sometimes, is very slow? (even 1 minute to receive the command!)

Do you have some example openhab logs?
What time is needed from your first log entry “Snips Intent riceived” to the last one “slot2: …”?