Control Harmmony HUB on OpenHab

Hi all,

i am a new user on OpenHab

I have a question about working with Harmony.

I connected Harmony and I can see all my devices.

One of the devices is a DVR which I transmit the channels on TV.

I want to make a list of channels and control them through the app.

How do I execute the process?

I need to make a Rule because it is about sending 2 or more commands

I see the device itself as follows:

harmonyhub:device:homecohen:37575602:buttonPress

This is the detail I get from Rest api

{
“parameters”: ,
“parameterGroups”: ,
“description”: “Send a button press to device Yes DVR”,
“label”: “Send Button Press”,
“itemType”: “String”,
“kind”: “STATE”,
“stateDescription”: {
“readOnly”: false,
“options”: [
{
“value”: “PowerToggle”,
“label”: “Power Toggle”
},
{
“value”: “Number0”,
“label”: “0”
},
{
“value”: “Number1”,
“label”: “1”
},
{
“value”: “Number2”,
“label”: “2”
},
{
“value”: “Number3”,
“label”: “3”
},

As you can see, I have orders of numbers here.

For example, I want to create a list of channels through which I will control the app

(012,013,088,010 for example)

I tried to make that RULE but I’m not sure I did it well:

rule “Yes_Channel”

when

Item Yes received update ON

then

Yes.sendCommand ("1")

Yes.sendCommand ("2")

end

I created Rule in Rule Engine in ui and the channel did move properly

Another question, do I need to subscribe for each channel individually?
Is there an option to create one Rule, then to create a list of channels in the SIETMAP file?

Thank you so much!

1 Like

Welcome to the forums.

No, this can be accomplished with just a single string item to track the channel selection and a single string item linked to the buttonPress channel.

Yes, if I understand what you’re asking, then in conjunction with one string item to track the channel, you can have this all under one rule.

You’ve already figured out how to create the item linked to the buttonPress channel. Now you also need to create another string item for the tv channel you’re recording (but not linked to any OH channel), either in an item file:

String DVR_Channel "Channel Selector"

or through the UI:

Then, in your sitemap you want to have a selection item that sets the value of your DVR_Channel item using mappings where ItemValue=“Some button label”:

Selection item=DVR_Channel mappings=["Yes"="Yes Network", "FoxSp"="Fox Sports", "ESPN"="ESPN"]

Lastly, your rule will want to trigger on any changes in the DVR_Channel item and use a switch statement to check for the various options:

rule "Set DVR Channel"
    when
        Item DVR_Channel changed
    then
        switch DVR_Channel.state.toString)
            {
            case "Yes": {
                yourButtonPressItem.sendCommand ("1")
                yourButtonPressItem.sendCommand ("2")                }
            }
            case "FoxSp": {
                yourButtonPressItem.sendCommand ("whatever")
                yourButtonPressItem.sendCommand ("whatever")                }
            }
            case "ESPN": {
                yourButtonPressItem.sendCommand ("whatever")
                yourButtonPressItem.sendCommand ("whatever")                }
            }
end

The logic here is now, whenever you use the sitemap to change the channel setting for the DVR the rule runs and compares the new DVR channel value against the set list you’ve given it via the switch statement.

Couple additional thoughts:

  • There are physical limitations how fast devices can process IR commands. If you send 1,2 in direct succession it might be too fast for the device to handle. If some keys get “lost” in the device intermittently add a sleep time (typically in the 100s of milliseconds; I am using 400ms for most of my devices). You will need to experiment. The joys of IR!
  • Every device is different, but based on your REST output it appears to send numbers you need to send “Number0”, “Number1” etc. So sendCommand (“1”) would be sendCommand (“Number1”).
  • You might have to send the ok/return button press after sending the numbers. Depends on your device. If not required it might still speed up how fast your DVR responds to the channel change. Just try with your remote and then emulate from the rule.

I haven’t looked at the Harmony app in awhile, but I think it might be possible to set up the delay in the hub, so that it knows not to send multiple commands to a device in rapid succession.

I expected that, too, but sadly they don’t. You can configure a delay per device, but Harmony uses that only for activities one defines within Harmony. I.e. if you define an activity to send “1,2,enter” and then trigger the activity from OpenHAB the delay is enforced. But single key presses are fired as fast as they arrive.
I have been working on a basic framework to abstract this and more importantly the power management, where Harmony gets confused if one turns a device on or off manually. Hopefully I’ll find time later this year to share those ideas/frameworks.

Thank you so much for responding

I now understood the logic of the process

I have a small problem, I copied the Rule you wrote here

I changed the values but I get 2 errors in VS

rule "Set DVR Channel"

    when

        Item DVR_Channel changed

    then

        switch DVR_Channel.state.toString)

            {

            case "Yes": {

                Yes_DVR.sendCommand ("1")

                Yes_DVR.sendCommand ("2")                }

            }

            case "FoxSp": {

                Yes_DVR.sendCommand ("whatever")

                Yes_DVR.sendCommand ("whatever")                }

            }

            case "ESPN": {

                Yes_DVR.sendCommand ("whatever")

                Yes_DVR.sendCommand ("whatever")                }

            }

end

I apologize, I am just learning the system right now and have no experience writing code

Thank you again!!

Summary

This text will be hidden

Sorry, in my haste to edit a version of my own rule in the reply I left a few typos that are causing the errors you see.

In coding, there’s almost never a cause to have an unmatched parentheses. So in line 5, where you see toString) that should be a matched pair: toString().

Similarly, some cut and paste errors have left the { and } also unmatched. There should be one set for the switch statement and one set each for each case statement. If you count them up, there are 4 { and 6 }, so VSC is warning you about those two extra }.

For the cleanest looking rule, delete the three } that are way off at the ends of lines 9, 13, and 17. Then you will need to add one more } on its own line between the last } and the end.

Make sure at the end, that every case statement has its own pair of curly brackets that enclose every command you want that value to trigger and that the switch statement has a single pair of curly brackets that encloses all the case statements.

There are some very good basic tutorials on this site and in the openHab documentation that cover how to write DSL rules, so spend sometime just poking around and you’ll learn quite a bit. If you want to get an even more formal understanding you can learn about Xtend, the scripting language the DSL rules are based on:

https://www.eclipse.org/xtend/documentation/index.html

Thanks so much for responding
Everything works perfectly !!!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.