Hello friends
I am testing the rules of openhab together voice recognition
At this moment everything works without problems, but I need to understant if have any way to perform the command in more “smarter” way
For example: If I say
Turn ON the Light of Kitchen
The idea is recognize de command (Turn ON), the thing (Light) and the room (Kitchen)
Then the script just concatenate the string and execute the command
- In the rule below I just detect command by command
Works, but for me this can be improved
Someone can help me ?
Sorry, the strings of commands below are in Portuguese
- Another doubt, is possible execute the code more faster ?
Sometimes if I say something, the system have one delay of 15 seconds or more to execute
My rules
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
import java.util.*
//Controle de Voz
rule “Voice control”
when
Item VoiceCommand received command
then
var String command = VoiceCommand.state.toString.toLowerCase
logInfo(“Voice.Rec”,"VoiceCommand received "+command)
//Corredor
if (command.contains(“ligar luz corredor”) || command.contains(“acender luz corredor”))
{
Light_Corredor.sendCommand(ON)
}
else if (command.contains(“desligar luz corredor”) || command.contains(“apagar luz corredor”))
{
Light_Corredor.sendCommand(OFF)
}
//Escada
else if (command.contains(“ligar luz escada”) || command.contains(“acender luz escada”))
{
Light_Escada.sendCommand(ON)
}
else if (command.contains(“desligar luz escada”) || command.contains(“apagar luz escada”))
{
Light_Escada.sendCommand(OFF)
}
//Sala
else if (command.contains(“ligar luz sala”) || command.contains(“acender luz sala”))
{
Light_Sala.sendCommand(ON)
}
else if (command.contains(“desligar luz sala”) || command.contains(“apagar luz sala”))
{
Light_Sala.sendCommand(OFF)
}
else if (command.contains(“ligar ventilador sala”))
{
Ventilador_Sala.sendCommand(ON)
}
else if (command.contains(“desligar ventilador sala”))
{
Ventilador_Sala.sendCommand(OFF)
}
//Sanca
else if (command.contains(“ligar luz sanca”) || command.contains(“acender luz sanca”))
{
Light_Sanca.sendCommand(ON)
}
else if (command.contains(“desligar luz sanca”) || command.contains(“apagar luz sanca”))
{
Light_Sanca.sendCommand(OFF)
}
//Cozinha
else if (command.contains(“ligar luz cozinha”) || command.contains(“acender luz cozinha”))
{
Light_Cozinha.sendCommand(ON)
}
else if (command.contains(“desligar luz cozinha”) || command.contains(“apagar luz cozinha”))
{
Light_Cozinha.sendCommand(OFF)
}
else if (command.contains(“ligar ventilador cozinha”))
{
Ventilador_Cozinha.sendCommand(ON)
}
else if (command.contains(“desligar ventilador cozinha”))
{
Ventilador_Cozinha.sendCommand(OFF)
}
//Hack
else if (command.contains(“ligar luz hack”) || command.contains(“acender luz hack”))
{
Light_Hack.sendCommand(ON)
}
else if (command.contains(“desligar luz hack”) || command.contains(“apagar luz hack”))
{
Light_Hack.sendCommand(OFF)
}
//Escritório
else if (command.contains(“ligar luz escritório”) || command.contains(“acender luz escritório”))
{
Light_Escritorio.sendCommand(ON)
}
else if (command.contains(“desligar luz escritório”) || command.contains(“apagar luz escritório”))
{
Light_Escritorio.sendCommand(OFF)
}
else if (command.contains(“ligar ventilador escritório”))
{
Ventilador_Escritorio.sendCommand(ON)
}
else if (command.contains(“desligar ventilador escritório”))
{
Ventilador_Escritorio.sendCommand(OFF)
}
//Banheiro
else if (command.contains(“ligar luz banheiro”) || command.contains(“acender luz banheiro”))
{
Light_GF_Banheiro.sendCommand(ON)
}
else if (command.contains(“desligar luz banheiro”) || command.contains(“apagar luz banheiro”))
{
Light_GF_Banheiro.sendCommand(OFF)
}
//Filho
else if (command.contains(“ligar luz filho”) || command.contains(“acender luz filho”))
{
Light_Filho.sendCommand(ON)
}
else if (command.contains(“desligar luz filho”) || command.contains(“apagar luz filho”))
{
Light_Filho.sendCommand(OFF)
}
else if (command.contains(“ligar ventilador filho”))
{
Ventilador_Filho.sendCommand(ON)
}
else if (command.contains(“desligar ventilador filho”))
{
Ventilador_Filho.sendCommand(OFF)
}
//Filha
else if (command.contains(“ligar luz filha”) || command.contains(“acender luz filha”))
{
Light_Filha.sendCommand(ON)
}
else if (command.contains(“desligar luz filha”) || command.contains(“apagar luz filha”))
{
Light_Filha.sendCommand(OFF)
}
else if (command.contains(“ligar ventilador filha”))
{
Ventilador_Filha.sendCommand(ON)
}
else if (command.contains(“desligar ventilador filha”))
{
Ventilador_Filha.sendCommand(OFF)
}
//Suíte
else if (command.contains(“ligar luz casal”) || command.contains(“acender luz casal”))
{
Light_Suite.sendCommand(ON)
}
else if (command.contains(“desligar luz casal”) || command.contains(“apagar luz casal”))
{
Light_Suite.sendCommand(OFF)
}
else if (command.contains(“ligar ventilador casal”))
{
Ventilador_Suite.sendCommand(ON)
}
else if (command.contains(“desligar ventilador casal”))
{
Ventilador_Suite.sendCommand(OFF)
}
//Lavanderia
else if (command.contains(“ligar luz lavanderia”) || command.contains(“acender luz lavanderia”))
{
Light_Lavanderia.sendCommand(ON)
}
else if (command.contains(“desligar luz lavanderia”) || command.contains(“apagar luz lavanderia”))
{
Light_Lavanderia.sendCommand(OFF)
}
//Garagem
else if (command.contains(“ligar luz garagem”) || command.contains(“acender luz garagem”))
{
Light_Garagem.sendCommand(ON)
}
else if (command.contains(“desligar luz garagem”) || command.contains(“apagar luz garagem”))
{
Light_Garagem.sendCommand(OFF)
}
//Jardim
else if (command.contains(“ligar luz jardim”) || command.contains(“acender luz jardim”))
{
Light_Jardim.sendCommand(ON)
}
if (command.contains(“desligar luz jardim”) || command.contains(“apagar luz jardim”))
{
Light_Jardim.sendCommand(OFF)
}
//Apagar todas as Luzes
else if (command.contains(“desligar todas as luzes”) || command.contains(“apagar todas as luzes”))
{
Lights.sendCommand(OFF)
}
//Desligar todos os ventiladores
else if (command.contains(“desligar todos os ventiladores”))
{
Heating.sendCommand(OFF)
}
end
// vim: syntax=Xtend