Simulate pressing volume down on a Harmony remote button?

My amp doesn’t let you numerically enter in a volume level. You have to press and hold the relevant volume button as the level slowing increases/decreases.

I have the Harmony binding working, but it doesn’t look like there way to simulate continuously pressing a button.

What I am trying to do is send a number to openHAB using Amazon Echo and HA-Bridge. The number received will be used to set how long the button is to be pressed down.

I have it working but it seems a bit janky.

rule "Harmony_Volume_Presses Up"
when
    Item Harmony_Volume_Presses_Up received command
then
        var i = 0
        var Number num_BtnPresses = 10

        num_BtnPresses = receivedCommand

        while((i=i+1) < num_BtnPresses) {
            sendCommand(Harmony_Press_Amp_Up, ON)
        }
end

Is it a bad idea to not use Sleep between each command?

The Smart Remote and the Harmony iOS/Android apps both allow you to press and hold a button, the Hub then continuously spits out the signal until you let go. Would they be doing anything different or do you think they are just repeating the single press over and over?

You aren’t running this for massive periods of time so I wouldn’t worry about it. You could add one if you think it is needed or you see problems. You could also add a Thread::yield which basically give the other threads a chance to execute.

I wouldn’t worry too much about it unless and until you actually see problems.

One would have to sniff the network traffic to see what is happening. The naive implementation would be to just keep sending out the command over and over.

One thing you might consider which may push you to add a sleep is that these commands may get queued up. For example, if you send these commands out as fast as possible, let’s say every 5 msec, but it takes 20 msec for the Harmony to receive and send the IR signal for each command, it could still be processing commands for some time after you stop pressing the UI button causing you to over or undershoot your desired volume level. To determine if and how much of a sleep you need you will have to experiment.