Jasper raspberry pi voice control

having a heck of a time getting this to work i know others have pulled this off but never seem to show any examples of the way the configurations are supposed to be. I have a raspberry pi 3 with jasper and a module that connects jasper to openhab.
jasper works like a charm and will do command line stuff just fine when i tell it but i cannot seem to get it to switch an item that i have set.

I have string VoiceCommand on a line by itself in my home.items and below that a switch set for turning on and off gpio channel 6 on my Pi. I also have a sitemap set and i can verify that the switch item does in fact turn on and off the led light i have on that gpio channel.
I have rules which i took from some very obscure post about using jasper with openhab.

from my home.rules This is just part of my rules which i may have not done properly due to the original code coming from a German article that was very confusing.

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command
import org.openhab.core.types.*
import org.openhab.core.items.GenericItem
import java.util.regex.Matcher
import java.util.regex.Pattern

rule "speak"
when
    Item TTS_Message received command
then
    executeCommandLine("/home/pi/test.sh " + TTS_Message.state.toString )
end

rule "white"
when
    Item light changed from OFF to ON
then
    sendCommand(VoiceCommand,"white")
end
rule "VoiceControl"

when
    Item VoiceCommand received command
then
    var String command = VoiceCommand.state.toString.toLowerCase
    logInfo("Voice.Rec","VoiceCommand received "+command)
    var State newState = null
    // Status herausfinden, ansonsten togglen
    if (command.contains("degrees") || command.contains("percent") || command.contains("dim")) {
        // Wert setzten=> neuer Status als Zahl extrahieren
        var Pattern p = Pattern::compile(".* ([0-9]+) (degrees|percent).*")
        var Matcher m = p.matcher(command)
        if (m.matches()) {
            logInfo("Voice.Rec","found number is "+m.group(1))
            newState = new StringType(m.group(1).trim())
        } else {
            logInfo("Voice.Rec","command does not match")
        }
    } else if (command.contains("off") || command.contains("stop") || command.contains("pause")) {
        newState = OFF
    } else if (command.contains("on") || command.contains("start") || command.contains("play")) {
        newState = ON
    } else if (command.contains("down") || command.contains("close")) {
        newState = DOWN
    } else if (command.contains("up") || command.contains("open")) {
        newState = UP
    }

from my home.items

String VoiceCommand
Switch light{ gpio=“pin:6” }

most of what i find googling is only bits and pieces of this process and I am new to this entire concept. The bugger of this is i know it is being done as I have seen youtube videos of demonstrations of it working but nobody seems to want to share completely how they did it, if they are sharing then my google-fu must be lacking. The hardest part i think is the items setup since most every article i read simply says add string VoiceCommand to items but doesnt explain any syntax or display an example. I would like to get this conversation going to produce some awesomesauce for the raspberry pi home automation community with working voice control.

In fact a lot of articles said you cannot manually install jasper on the Pi 3 and you had to use a special raspbian image which i tried twice and the image did not boot(i used win32diskimager which does not always work right) However I did find out that you can manually install jasper just fine by following the official jasper documentation even though there may be some steps you can skip or have to alter slightly it is not all that complicated if you are a seasoned linux user.

voice control can easily be achieved without openhab but i would like to see it integrated seamlessly so more people can add that functionality since openHAB is pretty awesome and simple to work with rather than having a ton of scripts to run.

2 Likes