OH3 M2 Groovy Script not recognizing item names


I have a simple groovy script to say the current time over my Amazon Echo:

    import java.text.SimpleDateFormat

            var SimpleDateFormat df = new SimpleDateFormat( "h:mm a" )
            var String Timestamp
            var String ChimeMessage
            Timestamp = df.format( new Date() )
            ChimeMessage = "It's " + Timestamp

However, whenever I run it, I get the following error in the openhab.log file:

2020-11-07 00:11:35.895 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'bf7402e1fc' failed: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: NeosEcho_Speaker for class: Script1

Any idea what’s going on? Is there something wrong with the Groovy engine or is it human error?


Items are not included in the default scope, as they are in the rules DSL. You also wont find sendCommand and postUpdate as methods of the Items and will need to get to it through the events object.

events.sendCommand("NeosEcho_Speaker", ChimeMessage)

The helper library documentation may be helpful for things like this (select the Groovy tab)…