Trigger OH 3 Rule via Alexa

Hello guys, thanks to a lot of help from people here I got my alarm now connected to my RPI4 and am able to arm / stay the alarm via rules. (caddx binding)

my next step is to be able to tell alexa to either run a sequence of commands at night time including arming the system.

i.e. Alexa, turn on Goodnight.
Alexa then turns off a set of lights the TV and arms 3 partitions of the alarm.

my understanding is that I create a rule which is triggered by a switch called goodnight, this rule does the on off and probably should call a script for the alarm items.

I would like to have alexa validate the switch activation with an ok.

now i think that the best way to do this is
to install the alexa skill

create a cloud connector account (my understanding is that this cant be avoided if i want to talk to alexa, i.e. amazon cant talk directly to my house, it goes through the openhab cloud servers first.

connect everything and create a virtual switch to do this.

I am stuck on how to create the virtual switch (unless there is a binding ofcourse). my skills are not advanced to understand how to create it / where to create it textually. anyone who can point me in the right direction or tell me a smarter faster way to do the above would be a god/goddess

you are on the right way.
You need to

  1. create an account on
  2. set up the cloud connector to in the settings section of your OH3
  3. install the openHAB alexa skill in your alexa
  4. configure your alexa skill to connect to your cloud account on

then you will have to create a virtual switch. If you want to create it through text files you just need something like this:

Switch VirtualSwitch "My virtual Switch" {alexa="PowerController.powerState"}

if you are using OH3 main UI then you need to create a switch item and add alexa metadata to it, specifying it’s a PowerController.powerState.

When you are done with the above, you need to run your alexa app on your mobile phone or tablet and look for new devices: then VirtualSwitch should be visibile in your alexa app and you should be able to switch it on/off from alexa.

If you want to control the switch through voice commands you have 2 options:

  1. give it a better label than “My virtual switch”, as the label is used in your voice commands, then you need something like “goodnight” to be able to say “alexa, switch goodnight on”. Or…
  2. set up a rule in alexa which responds to 1 or more sentences like “alexa, goodnight” or “alexa, I’m going bed” or “alexa, see you tomorrow”. And then specify in the alexa rule that you want the VirtualSwitch to be switched on.

I prefer the second way as I can add a feedback to the alexa rule, something like “ok, I will switch off all lights and arm the alarm for you, have a nice sleep”.

1 Like

could you pls explain this part (as if to a child :slight_smile: )

Add a new switch item

Then search for your newly created item and edit


got it working @llegovich thanks you!

This was SO helpful @llegovich! I wish you would do a Pages tutorial!