[SOLVED] Adding a Rule that can be called from Alexa

I’m new, only started this OpenHAB Raspberry PI thing about 2 weeks ago. However, so far, I have managed to install a number of Switches and my Honeywell thermostat into items, interface those items so they show as devices in Alexa, and write a couple of very primitive rules in the rules cfg file (i.e. cron and Astro sunset).

This post and my goal is open and close my garage door.

In a previous life, I installed a Z-Wave Plug-In Outlet in the garage. Using other Z-Wave software, I created a Scene that turned on the Plug-In outlet and then immediately turn off the power. Next, I plugged a Relay circuit into the outlet. When the relay saw power it closed the contacts, when power was immediately removed, the contacts opened. Then I wired this momentary closed/open circuit to the garage door switch. Thus the momentary closed circuit triggered the door to open if it was close or close if it was open.

OpenHAB is a bit different from my previously Z-Wave GUI software and I need some basic direction or point me to the proper readings so I can create a similar Rule.

2 Questions

Frist question, when writing an openHAB Rule what would be an appropriate ‘WHEN’ trigger. I only want to manually call this rule. A fixed time/CRON would not work in this case, nor would an ASTRO Sunset help me out here. So, what can I use for the WHEN Trigger?

Second (and final question), What Tag do I need to enter in a Rule so Alexa will discover the rule? Can I use the same [LIGHTING] tag I used with my light switches?

Thanks for your time read this as I made a short story long.

Hoping to hear from someone

Create a virtual switch that when turned on will trigger the rule…then you can tag the switch with a [SWITCHABLE] tag that Alexa can control…

Here’s an example of one of mine…

Switch VIR_IN_HolidaySwitch "Indoor Holiday Mode" [ "Switchable" ]
rule "Indoor Holiday Mode On"
    Time cron "0 0 6 1/1 * ? *"
logInfo("sunriseholiday.rules", "The Indoor Holiday rule has triggered ON")
if (VIR_IN_HolidaySwitch.state == ON)

Let us know if you have any questions.

Good Luck!


1 Like

Of course that rule could be triggered like this as well:

rule "Indoor Holiday Mode On"
    Item VIR_IN_HolidaySwitch changed to ON
logInfo("sunriseholiday.rules", "The Indoor Holiday rule has triggered ON")

Very true…but I don’t want my Christmas lights on until 6am :stuck_out_tongue:

THANK YOU Squid & opus. I appreciate your reply’s.

I had never thought about a Virtual Switch. The second you mentioned it, It was like a light bulb going off.
if (VIR_IN_GarageDoorSwitch.state == ON)

Is there any type of wait command or loop I can create to give a second or two between sending an ON and an OFF?



You can use the EXPIRE binding to do just that.!!!

If my suggestion helped, please check the solution mark under the post so that others can see the solution.


EXPIRE 10 — Is it a second parameter that needs to be passed?
Or should I add a time+10 seconds for the EXPIRE?

Also, I thought about this right as I hit the reply button.
Should I add a change state parameter to the Virtual switch? for example;
VIR_IN_GarageDoorSwitch.state == OFF


For the expire binding read Here.

OK, folks Some thoughts please…
I edited up the ITEMs file to include

Switch VIR_IN_GarageDoorSwitch “Garage Door” [ “Switchable” ]


Switch Switch_GarageS “Garage Door Switch” [“Lighting”] {channel=“zwave:device:c4664bf8:node8:switch_binary”, expire=“10s,command=OFF”}

The rule now looks like this;

rule “Trigger Garage Door”
Item VIR_IN_GarageDoorSwitch changed to ON
VIR_IN_GarageDoorSwitch.state == OFF
logInfo(“Trigger Garage Door.rules”, “Garage Door rule has triggered”)

Now after savng the files, reboot the RaspberryPI and I ask Alexa to search for new devices she does NOT find Switch_GarageS.
If however, I remove the expire syntax Alexa has no problem at all seeing Switch_GarageS

What’s going on?
Could Alexa not accept the expire binding?

Anything at all might help.
Thank You

Have yo installed the expire binding? You may also need to allow 1.x legacy bindings in OH2

As an alternative to the expire binding, you can use createTimer in your rule:

createTimer(now.plusSeconds(10)) [Switch_GarageS.sendCommand(OFF)]

I would also suggest removing the “ON” from your when statement:

    Item VIR_IN_GarageDoorSwitch changed

This way, the rule will trigger whenever you toggle your virtual switch, and you can use it to represent whether your garage door is open or closed in your sitemap. You can then use map transformation to translate ON into “Open” and OFF into “Closed” (or the other way around).

Hi Bill
I too have two honeywell thermostats that I would like to incorporate into OH. Do you have any information as to how you did that?


Bill -

Please use the code fences for your code, makes it much easier to read…

I have had no issues with Alexa not seeing items with the expire binding…

Here’s one of mine…

Switch RtGarageDr "Right Garage Door" [ "Switchable" ] { channel="zwave:device:xxxxxxxxx:nodex:switch_binary",expire="1s,command=OFF",autoupdate="false" }



Good Day folks,
Thanks for all your help. I did not mean to leave anyone hanging yesterday when I did not respond, but I have been working on trying to find what is going on.

It appears I have, or had, multiple problems. One the most stupid was I kept enabling EXPIRE through the PaperUI GUI. Then to make sure I did not have any bad information in the buffers, I would reboot the Raspberry-PI and try to figure out why EXPIRE was not working and not installed. All I want to say now is EXPIRE is now edited into my Binding line.

The next problem, I came across was an old implementation. I had previously mention I used other zwave software prior to openHAB. Will I had setup ‘Routines’ in my Alexa mobile app. Those old routines were getting the way as I tried to get the garage door to open/close. They were calling for switches that had been renamed in the process of changing to openHAB. Guess what, the Routines are gone now.

I have not gotten the Garage Door to open and close through openHAB/Alexa, but I think I am closer.

Thanks for EVERYONE’s suggestions. I experimented with each and every one of the ideas and those definitely helped me to teach this old dog new tricks and narrow down my multiple problems.
I will update when I have more to add. I am really hoping it is good news!

1 Like