How to create a macro with OpenHab?

Hello all,

This is Daniel and I am pretty new to Openhab. I’m trying to get an understanding about the system but it’s taking me a lot of time and it’s driving me crazy.

I think this question is dumb but honestly, although I’ve been playing a while, I don’t know how to do it. My main task is to configure an icon (or something similar) in UI that as soon as I click over it, it will perform several taks in a row. For instance, as I want to automate my home cinema equipment, one example will be:

Turn off the ceiling lights
Turn on the TV
Turn on the Home Cinema Amplifier
Turn on some leds

I have the wifi switches and they are working well in OpenHab. Therefore I can turn them on or off one by one. What I want to accomplish is similar to a “macro”. So first, is this doable with OpenHab? Can someone point me in the right direction?

Thank you very much.

PD: By the way, I’m using openhabian, latest stable release.

You need to use Rules.

Here is the link to the rules tutorial

But basically, and in the context of your requirements,
you need something to trigger your set of rules to do the things you want.
It could be, for example, a switch.

The the rule would look something like this:

rule "Do my cinema stuff"

when
       Item cinemaSwitch changed to ON
then

sendCommand (ceilinglights, ON)
sendCommand (TV, ON)
sendCommand (HomeCinemaAmplifier, ON)
sendCommand (leds, ON)

end

ceilinglights, TV, HomeCinemaAmplifier etc are the item names for those devices.

What you are looking for is a “rule”.
You need a virtual switch to trigger your rule.
This is an idea, how your rule could be done. (Written from head, no testing)

rule "home cinema"
when
	Item switchHomeCinema  received command
then
   if (switchHomeCinema.state == ON) 
   {
       ceilinglights.sendCommand(OFF)
       tv.sendCommand(ON)
       amp.sendCommand(ON)
       leds.sendCommand(ON)
   } 
   else if (switchHomeCinema.state == OFF) 
   {
       ceilinglights.sendCommand(ON)
       tvsendCommand(OFF)
       amp.sendCommand(OFF)
       leds.sendCommand(OFF)
   }
end

Thank you Tom for your prompt answer. That is what I was thinking about but I faced an issue. In order to trigger the rule I guess I need something like a virtual switch (item) and so far, I only know how to create a physical switch by using a binding.

Therefore, Is it possible to create a virtual item, in this case, a switch I can play with but w/o physical entity?

Thank you

This post will explain how to do that: Design Pattern: Unbound Item (aka Virtual Item)

Thank you folks!!

Now it’s time to dig into the material and see what I can do.

You rule.