The name 'VoiceCommand' cannot be resolved to an item

I wanted to experiment with voice control. But the VoiceCommand Item can not be accessed, although it obviously has received a command.
Is that command stored somewhere else?

  • Platform information:
    • Hardware: Raspberry Pi 4
    • OS: Linux openhabian 5.10.11-v7l+ armv7l
    • Java Runtime Environment: openjdk 11.0.10 2021-01-19 LTS
      OpenJDK Runtime Environment Zulu11.45+27-CA (build 11.0.10+9-LTS)
      OpenJDK Client VM Zulu11.45+27-CA (build 11.0.10+9-LTS, mixed mode)
    • openHAB version: 3.0.1 - Release Build
openhabian@openhabian:/etc/openhab/rules $ cat voice.rules
rule "Voice control"
when
        Item VoiceCommand received command
then
        var String command = VoiceCommand.state.toString.toLowerCase
        logInfo("Voice.Rec", command)
end

==> /var/log/openhab/openhab.log <==
2021-09-11 23:32:57.739 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'voice.rules'
2021-09-11 23:32:58.838 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'voice.rules'

==> /var/log/openhab/events.log <==
2021-09-11 23:33:10.107 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'VoiceCommand' received command test

==> /var/log/openhab/openhab.log <==
2021-09-11 23:33:10.155 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'voice-1' failed: The name 'VoiceCommand' cannot be resolved to an item or type; line 5, column 30, length 12 in voice

This seems to work:

Can someone try to explain to me why?

I created an items file:

String VoiceCommand

Now both methods work.

This might not give the results you expect.
Command events are often, not always, followed by some effect on the Items state … but it always takes time, even if only a few milliseconds.
Reading Item state after a command trigger like that will probably give you the old state, but it is indeterminate really.

You’ve already found the solution for use with rules triggered by command