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
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.
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.
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