How to send a series of commands?

I apologize if this is answered somewhere else.

I want to have a button or switch that I press called “watch TV”, then have it trigger a sequence of commands:

  1. Power on Denon AVR
  2. Power on TV
  3. Power on Cable Box
  4. Switch Denon Input to Cable/Sat
  5. Switch TV to input to 3.
  6. Set TV volume to 55%.
  7. Dim lights

I also want a 200 msec delay between each command.

How do I do this? Rule/Script? Can someone post an example?

Create a virtual item for your “Watch TV” switch, which you show in your sitemap for activation in the UI. Then write a rule which is triggered by that switch and add all the steps you want to perform.

The best way is to start simple and then start building it up. There are plenty of examples in the WIKI and in these forums of how to write rules like this.

2 Likes

Thank you. The Wiki rule examples seem to me to only execute one command, but I found some examples in the forum of how to do this.

Edit: There is another Wiki page with Sample more rules.

Can you share a sample of how you ended up executing multiple commands on the Denon? The only way I managed to do it is to add sleep of 200 to 10000 sleep between the commands depending on which command it is. It takes some time before my Denon finally starts playing the music I want.

Here is an example of a rule to turn on music in my office.

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*

rule "Music Office"
when
        Item Music_Office received command
then
        if(receivedCommand==ON){
                sendCommand(ShinyBow, "POWER 001;")
				Thread::sleep(100)
				sendCommand(ShinyBow, "OUTPUT004 001;")
				Thread::sleep(100)
				sendCommand(DenonZoneTwo, ON)
				Thread::sleep(100)
				sendCommand(DenonZoneTwoInputTuner, ON)
				Thread::sleep(100)
				sendCommand(ShinyBow, "MUTE004 000;")
        }
        else if(receivedCommand==OFF){
				sendCommand(ShinyBow, "OUTPUT004 000;")
				Thread::sleep(100)
				sendCommand(ShinyBow, "MUTE004 000;")
				
        }   
end
1 Like

Thank you, I see you are also using sleep between commands.

Thread::sleep is the common way to produce a short delay (maybe up to 10 seconds or so), where createTimer would be better for long delay, both will fail if openHAB is restarted.