Voice Command 'received update' broken after latest Stable 3.1.0 update

Ever since upgrading to the latest 3.1.0, my voice command logic isn’t always working. I’ve concluded that sometimes “Item VoiceCommand received update” will trigger the rule BEFORE the item’s state is actually updated. Here’s my code:

rule “Voice Command Items, Groups of Items, and Rules/Activities”
when

  • Item VoiceCommand received update*
    then
  • var String cmd = VoiceCommand.state.toString.toLowerCase // should already be lowercase.*

The log will show that VoiceCommand was updated, however the ‘cmd’ variable has not changed. And my logic executes the old (prior) command.

Anyone else seeing this? Am I not understanding what ‘received update’ means?

You have concluded correctly. The surprising thing is that this is the first time you have come across this as this has always been the case.

See here for a concise breakdown of why this happens.

Understanding the implicit variables in rules in one of the most common ways around this problem

P.S. It will always be easier for others to help you if you post your rules code in code fences

1 Like

I’m not entirely convinced that is what is going on here. Disregarding the name of the Item involved, the rule trigger is for received state update and NOT for command.

Bear in mind that any update, including to the same value, will trigger the rule.
It’s also possible, but really unlikely in most circumstances, for the state to change in the few milliseconds between triggering the rule and lookin at Item state.

I think we need to see more, logs for example.

Here’s the log entries. What happens is the the ‘cmd’ variable is parsed into certain elements, and that is what is reported in the logs.

From the events log:
2021-10-02 10:48:50.562 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘VoiceCommand’ received command turn on the rec room Roku
2021-10-02 10:48:50.571 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘VoiceCommand’ changed from turn off all the downstairs lights to turn on the rec room Roku
2021-10-02 10:48:50.600 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘voiceparseddesc’ received command downstairs_lights
2021-10-02 10:48:50.602 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘voiceparseditem’ received command gFF
2021-10-02 10:48:50.604 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘voiceparsedcmd’ received command OFF
2021-10-02 10:48:50.605 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘voiceparsedstring’ received command downstairs_lights gFF OFF

From the openhab log:
2021-10-02 10:48:50.599 [INFO ] [penhab.core.model.script.voice.rules] - Voice Command: ‘turn off all the downstairs lights’ parsed to Room: ‘downstairs’, Label: ‘lights’, Description: ‘downstairs_lights’, Item: ‘gFF’, Action: ‘OFF’

From this, it looks like the VoiceCommand item changed from “turn off all the downstairs lights” to “turn on the rec room Roku”, but the ‘cmd’ variable never updated, and it was parsed into the elements making up the “turn off all the downstairs lights” command.

This doesn’t happen all the time, but appears to be more common if voice command hasn’t been used for a while.

If its the parsing that’s troubling you, that’s the rule we need to see.

You can add diagnostics for your theory to the rule fragment you showed us so far -

when
    Item VoiceCommand received update
then
    logInfo("test", "state: " + VoiceCommand.state.toString)

It’s all part of the same rule. It is simply analyzing the the string ‘cmd’ using a series of 'if(cmd.contains(“xyz”) lines, and the log is reporting the results. Based on the results, the ‘cmd’ string is the old, previous state for VoiceCommand. I could add a logInfo line to log the value of cmd to make it clearer.

I changed the code, replacing the ‘received update’ approach with ‘received command’ as follows, and the problem is gone:

when
// Item VoiceCommand received update
Item VoiceCommand received command
then
// var String cmd = VoiceCommand.state.toString.toLowerCase // should already be lowercase.
var String cmd = receivedCommand.toString.toLowerCase

As mentioned in the fist reply, please use code fences if you post rules or log extracts.

when
// Item VoiceCommand received update
Item VoiceCommand received command
then
// var String cmd = VoiceCommand.state.toString.toLowerCase // should already be lowercase.
var String cmd = receivedCommand.toString.toLowerCase

If the issue is resolved, please mark the thread accordingly.

And if you use the code fences as documented, it should look like this …

when
// Item VoiceCommand received update
Item VoiceCommand received command
then
// var String cmd = VoiceCommand.state.toString.toLowerCase // should already be lowercase.
var String cmd = receivedCommand.toString.toLowerCase

I did fix my issue by modifying the code. It doesn’t explain why my original code didn’t work. Seems like there is an issue. Or, I don’t understand how ‘received update’ is supposed to work.

Can’t answer that, we were shown logs but not the code producing them.