How to setup rule for Harmony Hub Channel or Item?

  • Platform information: Raspberry Pi Nano

    • Hardware: Raspberry Pi Nano
    • OS: Rasbian image from openHABian
    • Java Runtime Environment:Zulu Embedded OpenJDK Java 8
    • openHAB version: 2
  • Issue of the topic: I am trying to set up rule my Sony AV Receiver. I added the receiver Thing using the Harmony Hub Binding. I linked a SonyAVReceiver_SendButtonPress Item to the harmonyhub:device:HarmonyHub:38426230:buttonPress channel. I can now power on/off the receiver in the Paper UI Control so I know I have that part working. Now I want to create a rule so when the receiver is turned on, my Echo Dot connects to the Bluetooth interface on the stereo.
    I’ve tried using rules based on the channel and based on the Item. The Channel based rule does not work at all. The Item based rule almost works. It runs when I change the Sony Receiver power using the Paper UI. But I’m not getting the value of the button press (PowerOn vs PowerOff) correctly in my rule. How can I write the button press value to the openhab log so I can troubleshoot? Or is SonyAVReceiver_SendButtonPress.state the wrong attribute?

  • Please post configurations (if applicable):

    • Items configuration related to the issue:

    • Sitemap configuration related to the issue n/a

    • Rules code related to the issue


//This rule runs and the else condition occurs so I don't seem to be getting the power state correctly.
rule "Sony Receiver item received command"
when

Item  SonyAVReceiver_SendButtonPress received command

then
	if (SonyAVReceiver_SendButtonPress.state == "PowerOn" ) 
	{
	logInfo("Harmony", "Sony reciever is PowerOn")
	} 
	else 
	{
     logInfo("Harmony", "Sony receiver state is not PowerOn")
	}
end

//This rule does nothing.
rule "Sony Receiver Channel Rule"
when

	Channel "harmonyhub:device:HarmonyHub:38426230:buttonPress" triggered PowerOn

then
	OfficeBot_Remind.sendCommand("Sony receiver Channel triggered PowerOn") 

end


  • Services configuration related to the issue
    HarmonyHub Binding

No errors in the log when I save the rule:

  • If logs where generated please post these here using code fences:
2018-04-03 07:48:08.961 [INFO ] [lipse.smarthome.model.script.Harmony] - Sony re             ceiver state is not PowerOn



Here is what I seed in http://10.0.0.141:8080/rest/channel-types

“UID”:“harmonyhub:hub:HarmonyHub:currentActivity”,“advanced”:false},{“parameters”:[],“parameterGroups”:[],“description”:“Send a button press to device Sony AV Receiver”,“label”:“Send Button Press”,“itemType”:“String”,“kind”:“STATE”,“stateDescription”:{“readOnly”:false,“options”:[{“value”:“PowerOff”,“label”:“Power Off”},{“value”:“PowerOn”,“label”:“Power On”},{“value”:“PowerToggle”,“label”:“Power Toggle”},{“value”:“NumberEnter”,“label”:“Number Enter”},{“value”:“Number0”,“label”:“0”},{“value”:“Number1”,“label”:“1”},{“value”:“Number2”,“label”:“2”},{“value”:“Number3”,“label”:“3”},{“value”:“Number4”,“label”:“4”},{“value”:“Number5”,“label”:“5”},{“value”:“Number6”,“label”:“6”},{“value”:“Number7”,“label”:“7”},{“value”:“Number8”,“label”:“8”},{“value”:“Number9”,“label”:“9”},{“value”:“Mute”,“label”:“Mute”},{“value”:“VolumeDown”,“label”:“Volume Down”},{“value”:“VolumeUp”,“label”:“Volume Up”},{“value”:“DirectionDown”,“label”:“Direction Down”},{“value”:“DirectionLeft”,“label”:“Direction Left”},{“value”:“DirectionRight”,“label”:“Direction Right”},{“value”:“DirectionUp”,“label”:“Direction Up”},{“value”:“Select”,“label”:“Select”},{“value”:“Menu”,“label”:“Menu”},{“value”:“PrevPreset”,“label”:“Prev Preset”},{“value”:“NextPreset”,“label”:“Next Preset”},{“value”:“DirectTune”,“label”:“Direct Tune”},{“value”:“Sleep”,“label”:“Sleep”},{“value”:“Exit”,“label”:“Exit”},{“value”:“Display”,“label”:“Display”},{“value”:“AFD”,“label”:“AFD”},{“value”:“Input5.1Ch”,“label”:“Input5.1Ch”},{“value”:“InputAm”,“label”:“InputAm”},{“value”:“InputCd”,“label”:“InputCd”},{“value”:“InputDVD”,“label”:“InputDVD”},{“value”:“InputFm”,“label”:“InputFm”},{“value”:“InputMd/Tape”,“label”:“InputMd/Tape”},{“value”:“InputMode”,“label”:“InputMode”},{“value”:“InputPhono”,“label”:“InputPhono”},{“value”:“InputTuner”,“label”:“InputTuner”},{“value”:“InputTv/Sat”,“label”:“InputTv/Sat”},{“value”:“InputVideo1”,“label”:“InputVideo1”},{“value”:“InputVideo2”,“label”:“InputVideo2”},{“value”:“InputVideo3”,“label”:“InputVideo3”},{“value”:“SndFldsMovie”,“label”:“SndFldsMovie”},{“value”:“SndFldsMusic”,“label”:“SndFldsMusic”},{“value”:“Stereo”,“label”:“Stereo”},{“value”:“TestTone”,“label”:“TestTone”},{“value”:“TuningDown”,“label”:“TuningDown”},{“value”:“TuningUp”,“label”:“TuningUp”}]},“tags”:[],“UID”:“harmonyhub:device:HarmonyHub:38426230:buttonPress”,“advanced”:false}]

1 Like

Change your first rule:

rule "Sony Receiver item received command"
when

Item  SonyAVReceiver_SendButtonPress received command

then
    if (receivedCommand == "PowerOn" ) {
        logInfo("Harmony", "Sony reciever is PowerOn")
    } else {
        logInfo("Harmony", "Sony receiver state is not PowerOn")
    }
end

And your second rule:

rule "Sony Receiver Channel Rule"
when
    Channel "harmonyhub:device:HarmonyHub:38426230:buttonPress" triggered "PowerOn"
then
    OfficeBot_Remind.sendCommand("Sony receiver Channel triggered PowerOn") 
end