Need Help on Migrating a rule from OpenHab2 to OpenHab3

The following rule is supposed to open my overhead garage door when I speak to one of the amazon echo’s in my home. In the Openhab2 version it would open it if it was currently closed and if it was currently opened the echo would respond with “The garage door is already opened” on the particular amazon echo device I was talking to. I changed the rule in the Openhab3 version for the different item names. The garage door will open, but it was already opened it will not respond with the message that the garage door was already opened.
This is the rule I used:

 rule "Open Garage Door"
 when
         Member of EchoCmds changed to "open the garage door" or
         Member of EchoCmds changed to "open garage door"
 then
       if(Overhead2.state == CLOSED) {
             GarageDoorOpener.sendCommand(ON)
       }    
          if(Overhead2.state == OPEN) {
          val sourceRoom = triggeringItem.name.replace("LastVoiceCommand","")
          val TTS = sourceRoom + "TTS" 
          TTS.sendCommand('<speak>     <voice name="Joey">The Overhead Garage door is already open</voice></speak>')
          }       
 end

I changed it to this in Openhab3:

rule "Open Garage Door"
when
         Member of EchoCmds changed to "open the garage door" or
         Member of EchoCmds changed to "open garage door"
 then
       if(OverheadGarageDoor_ContactState.state == CLOSED) {
             GenericMQTTThing_GarageDoorOpener.sendCommand(ON)
             GenericMQTTThing_GarageDoorOpener.sendCommand(OFF)
       }
          if(OverheadGarageDoor_ContactState.state == OPEN) {
          val sourceRoom = event.itemName.replace("LastVoiceCommand","")
          val TTS = sourceRoom + "Speak"
          TTS.sendCommand('<speak><voice name="Joey">The Overhead Garage door is already      open</voice></speak>')
          }
 end

Any help would be appreciated. Thanks!

So, your TTS doesn’t work? Does the expected Item get the expected string comand? (see your events.log)

That looks like an odd thing to do, it wasn’t in your original rule.

I get the following message on the event log:

 2021-01-30 13:18:04.746 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with           UID 'security-2' failed: The name 'event' cannot be resolved to an item or type; line 27, column 33, length 5 in      security.

Yes, it does look odd. I have a older Pi that I use to control the garage Door. When I turn “On” the switch the garage sends a mqtt message to the older Pi to open the door. The switch doesn’t turn off automatically, so if I try to close the garage door a second time it won’t work. I think I should just use the expire binding to turn it off after a few seconds. But anyways, my main problem is getting the message to play on the amazon echo.

Your original line should work.

It use to work in Openhab2, but not Openhab3. See attached

Have you tried it?
It works in OH3 release version, for Member of triggers.
Release notes

I think I’m getting closer. When I changed the line in the rule to:

val sourceRoom = triggeringItemName.replace(“LastVoiceCommand”,"")

I get this message in the logs:
Item ‘Den_TTS’ does not exist

The full name of the amazon echo is:
Den_LastVoiceCommand, so it should be Den_LastVoiceCommand_TTS I think.

I thought this part of the rule : (“LastVoiceCommand”,"") would add that to the name, but it doesn’t
appear to be working.
Any ideas?

That does the same in OH2 or 3, takes a string and replaces LastVoiceCommand with an empty string.
i.e.start with Den_LastVoiceCommand and end up with Den_ as instructed.

This line should add the LastVoiceCommand, but its not:
val sourceRoom = triggeringItemName.replace(“LastVoiceCommand”,"")

Where did you get that from?
Why do you think a “replace” method would add something? Wouldn’t an “add” method be more appropriate?

Well, no it shouldn’t.
In your original OH2 rule -

          val sourceRoom = triggeringItem.name.replace("LastVoiceCommand","")
          val TTS = sourceRoom + "TTS"

an Item name like Den_LastVoiceCommand will be converted to Den_TTS.

There’s no change in your new rule, it’s doing the same thing. Perhaps it’s the understanding of how to name Items to suit the rule that got mixed up.

Wouldn’t you want the Item representing where to speak to be named Den_TTS? Rather than Den_LastVoiceCommandLastVoiceCommand_TTS.

Yes, I think your right. I was getting a little confused. I finally got it to work with the rule below:

 rule "Open Garage Door"
 when
         Member of EchoCmds changed to "open the garage door" or
         Member of EchoCmds changed to "open garage door"
 then
       if(OverheadGarageDoor_ContactState.state == CLOSED) {
             GenericMQTTThing_GarageDoorOpener.sendCommand(ON)
             GenericMQTTThing_GarageDoorOpener.sendCommand(OFF)
       }
          if(OverheadGarageDoor_ContactState.state == OPEN) {
          val sourceRoom = event.itemName.replace("LastVoiceCommand","")
          val TTS = sourceRoom + "Speak"
          TTS.sendCommand('<speak><voice name="Joey">The Overhead Garage door is already      open</voice></speak>')
          }
 end

Thanks for your help!!!