Voicecontroll repeats last voice command

Hey there,

I’m new in the community and I hope you can help me out with the following problem.

I tried to implement rule-based voicecontroll via the Android-App. I can execute the programmed commands, but often the last voice command will be repeated. When I say “lampen an” the lamps switch to “ON”. Then I say “rollo ab” and nothing happens. The log shows me, that a command was received and executed (again “lampen an”).

rule "Voice"
when
Item VoiceCommand received command
then
var String command = VoiceCommand.state.toString.toLowerCase
logInfo("Voice.Rec","VoiceCommand received "+command)

if (command.contains("lampen an")) {
GF_LivingRoom_Light_L.sendCommand(ON)
}
else if (command.contains("lampen aus")) {
GF_LivingRoom_Light_L.sendCommand(OFF)
}


else if (command.contains("rollo ab")) {
FF_GuestRoom_Shutter.sendCommand(DOWN)
}
else if (command.contains("rollo auf")) {
FF_GuestRoom_Shutter.sendCommand(UP)
}


else if (command.contains("rollo wohnzimmer ab")) {
GF_LivingRoom_Shutter.sendCommand(DOWN)
}
else if (command.contains("rollo wohnzimmer auf")) {
GF_LivingRoom_Shutter.sendCommand(UP)
}
end

Might the log show us as well?

That is a race condition. openHAB commands are not states.
Commands might cause a state change … eventually.
If you look in your events.log you’ll probably see this sequence.

But here, grabbing the state of an Item immediately after a command will almost always give you the old state, before the command has any effect on it.

Isn’t it the command you are really interested in, not the state?
That is available to your rule as an implicit variable receivedCommand

Thanks for the quick answer.

2020-01-09 11:51:36.090 [INFO ] [pse.smarthome.model.script.Voice.Rec] - VoiceCommand received lampen an
2020-01-09 11:51:48.819 [INFO ] [pse.smarthome.model.script.Voice.Rec] - VoiceCommand received lampen an

First time I said “Lampen an”, second time I said “Lampen aus”. Received VoiceCommand was in both times “lampen an”.

var String command = VoiceCommand.state.toString.toLowerCase

Do you mean, I have to replace “state” with “receivedCommand”? That didn’t work.

But “Received VoiceCommand” is not the command that the rule received. It is a variable that you just created using the state of an Item.
Commands and states are not the same thing.
Commands do not instantly influence states

It works. Show us what you did.
Hint ; receivedCommand is exactly what it says. It is not an Item, you do not specify an Item name. It is not an Item, you do not take the .state of it. It is the command. You can get a string version of it

var String myCommand = receivedCommand.toString.toLowerCase

As good practice, I’d really avoid naming your variable ‘command’, that’s a reserved word and could give you troubles elsewhere.

2 Likes

That worked!!! Thanks!

1 Like