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” ]
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.
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!
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?
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)
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 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).
@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.