Help with Siri and Harmony Hub, almost there!

Hi everyone!

I’m trying to get Siri to work with my Logitech Harmony Hub. At the moment I can turn on dummy switches with Siri but only manually turn on the Harmony Hub activities (powerOff and Samsung KS7005) with my mapped keys in the sitemap.

Here how my ITEMS file looks like:
//Fake switches
Switch Dummy “Dummy switch” [ “Switchable” ]

//HarmonyHub
String HarmonyHub “Current Activity [%s]” (gMain) { channel="harmonyhub:hub:HarmonyHub:currentActivity” }

Here’s my SITEMAP:

sitemap home label=“My house”
{

Frame label=“Fake switches”
{
Switch item=Dummy
}

Frame label=“Harmony Hub”
{
Switch item=HarmonyHub mappings=[PowerOff=“PowerOff”,“Samsung KS7005”="Samsung KS7005”]
}
}

What’ should I do next?
I tried adding a [ “Switchable” ] tag to the harmony hub string but that didn’t work.

Do I need to create a rule for this and make a dummy switch to trigger the actions of the harmony?

I’m very new to all this but yesterday I decided to finally start working with openHAB and it’s great!

//Victor

Hi!
I use rules for that, a switchable tag in a string item cannot do anything (what is it supposed to switch it to?) and the sitemap doesn’t do anything regarding this either.

Heres how I do it:

Items:

// Groups
Group:Switch gHarmonyDummy

// Harmony Hub
String harmonyLivingActivity_current "Harmony current activity" (gHistory) {channel="harmonyhub:hub:HarmonyHub:currentActivity"}

// Dummy Items for Alexa
Switch dummyLivingActivity_kodi "Heimkino" (gHarmonyDummy, gHistory) ["Switchable"]
Switch dummyLivingActivity_ps4 "Playstation" (gHarmonyDummy, gHistory) ["Switchable"]

Rules:

import org.eclipse.xtext.xbase.lib.Functions

// Functions
// dummy2harmony
val Functions$Function3<GenericItem, GenericItem, String, Boolean> dummy2harmony = [ harmonyActivity_current, dummyItem, activityName |

	var desiredActivity = ( if (dummyItem.state == ON) activityName else "PowerOff" )
    logDebug("HarmonyActivityControl", "dummy2harmony: " + dummyItem.name + " received command, calling harmony hub witch activity " + desiredActivity)
    harmonyActivity_current.sendCommand(desiredActivity)
    true //not sure if neccesary
]


rule "Harmony Kodi start or stop"
when
	Item dummyLivingActivity_kodi received command
then
	dummy2harmony.apply(harmonyLivingActivity_current, dummyLivingActivity_kodi, "Kodi")
end

rule "Harmony Playstation start or stop"
when
	Item dummyLivingActivity_ps4 received command
then
	dummy2harmony.apply(harmonyLivingActivity_current, dummyLivingActivity_ps4, "Playstation")
end


// harmony2dummy

rule "Harmony state mapping to OpenHAB"
when
	Item harmonyLivingActivity_current received update
then
	var currentActivity = harmonyLivingActivity_current.state
	logDebug("Harmony", "Harmony activity update detected, now: " + currentActivity)
	postUpdate(dummyLivingActivity_kodi,  if (currentActivity == "Kodi") ON else OFF )
	postUpdate(dummyLivingActivity_ps4,  if (currentActivity == "Playstation") ON else OFF )
end

Dont be confused by the function, you can implement the functionality directly into the rule just as well.

Thank you so much, it worked! :ok_hand:
Although I just copy and pasted your code and changed some names to match my setup, I didn’t understand much when it comes to the function part.
When you said, "Don’t be confused by the function, you can implement the functionality directly into the rule just as well."
Does that mean you can do it in an easier way?

I’m just started learning openHAB so coding is not my strong side, sorry. Can you recommend any websites/videos that explains this kind of coding, for me to learn?

Thanks again Nicolas! I really appreciate it!

I glad it worked for you!
easier is relative. This one is easy for me because I can easily add more activities as I need them without having to rewrite (or copy paste) the debug messages and the if loop… And if I want to add functionality I only have to do it once for all the rules.
You could just as well call the if statement and the logging and so on directly in the rule (basically copy all the stuff that is in the function directly into the rule):

rule "Harmony Kodi start or stop"
when
	Item dummyLivingActivity_kodi received command
then
	var desiredActivity = ( if (dummyLivingActivity_kodi == ON) "Kodi" else "PowerOff" )
    logDebug("HarmonyActivityControl", "dummy2harmony: " + dummyLivingActivity_kodi.name + " received command, calling harmony hub witch activity " + desiredActivity)
    harmonyActivity_current.sendCommand(desiredActivity)
end

*note: did not test this, maybe theres a typo somewhere

I am not aware of any good videos or websites that explain the openHAB rule syntax like step by step (AFAIK it is xtend so some sort of javascript) but if you are completely new to programming in general I would start to learn some python or javascript maybe to grasp the basic concepts of loops, functions, methods and so on. Theres even a rule engine available in openhab using jython (which i want to test sooner or later!)
There are some good tutorials out there for those more common languages (and the basic concepts are the same everywhere)

Aha, I know what you mean now with the function part.

Thanks again! I’ll have a look at javascript/python to start somewhere. Again, thanks Nicolas!

hi, does this still work with OH2? I tried and devices used are switching on but the avr Input channel defined within the harmony Actions/sequences does not Change :frowning: Actions can be changed via direct harmony Control and also via PaperUI Harmony Hub entry, but alexa doesn’t Change the Input channel. Additionally, not all activities do work (device not reachable).

As you are an owner of a ps4 as well.
Are you able to start the ps4 with Harmony?

The Harmony App says it’s not possible (allowed by Sony).
So how did you manage this?
Thanks in advance.

@ostfriesenkopp
Sorry for the (really) late reply, I have been out of country for the last couple of months…
I do not use this rule anymore actually… I implemented it in jython, because adding activities becomes a lot easier. (see here: Jython: harmony to dummy for use with alexa)
It used to work with OH2 though and I know of a friend where it still works (@Rickecho)

@NCO
When I got my Harmony around a year ago it was able to start the PS4 (or at least wake it from the power save state). I cannot confirm it to you right now because I opted to just start the PS4 with the controller. The steps it took to send it into the powersave mode just have been to wonky for me. So the activity just selects the proper input.

Thanks a lot - that’s a good hint.
I will play around with it while it’s in powersafe mode.