Kodi and logitech harmony flow

Hello all

So my basic system currently is a Logitech harmony remote, Kodi and Fibaro HC2 platform.
All of these 3 items are working fine in node red...however i want to do some advanced stuff and combine them

I have attached my current flow i'm working on but i have become stuck.

[{"id":"e93fc84b.cb5608","type":"kodi-in","z":"55212914.0911a8","name":"Kodi","controller":"f362c4bb.00cb78","x":110,"y":140,"wires":[["e668d4b0.243f18"]]},{"id":"c2f92b0.e3038d8","type":"debug","z":"55212914.0911a8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":490,"y":40,"wires":[]},{"id":"c4beb359.864b5","type":"switch","z":"55212914.0911a8","name":"","property":"payload.notification","propertyType":"msg","rules":[{"t":"eq","v":"Player.OnResume","vt":"str"},{"t":"eq","v":"Player.OnPause","vt":"str"},{"t":"eq","v":"Player.OnStop","vt":"str"},{"t":"eq","v":"GUI.OnScreensaverActivated","vt":"str"},{"t":"eq","v":"GUI.OnScreensaverDeactivated","vt":"str"}],"checkall":"false","repair":false,"outputs":5,"x":490,"y":120,"wires":[["6979d623.da9ec8"],["bd10a17b.83598"],[],[],[]]},{"id":"8c0729c5.cc1f48","type":"fibaroActor","z":"55212914.0911a8","name":"Simulator D-Box (Games Room)","deviceID":"125","server":"ac1f6e08.f2751","events":true,"outputs":2,"x":950,"y":100,"wires":[[],[]]},{"id":"38f92cc4.19bb34","type":"debug","z":"55212914.0911a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":490,"y":180,"wires":[]},{"id":"bd10a17b.83598","type":"function","z":"55212914.0911a8","name":"Paused/on","func":"// The simplest way\nmsg.payload=true;\nreturn msg;\n","outputs":1,"noerr":0,"x":670,"y":120,"wires":[["8c0729c5.cc1f48"]]},{"id":"6979d623.da9ec8","type":"function","z":"55212914.0911a8","name":"Paused/off","func":"// The simplest way\nmsg.payload=false;\nreturn msg;\n","outputs":1,"noerr":0,"x":670,"y":80,"wires":[["8c0729c5.cc1f48"]]},{"id":"dcf30bc1.5ba7e8","type":"harmonyws-observer","z":"55212914.0911a8","name":"","server":"c117ad76.5414d","startup":true,"toContext":false,"context":"flow","contextKeyActivity":"activity","contextKeyAutomation":"automation","x":100,"y":60,"wires":[["e668d4b0.243f18"]]},{"id":"e668d4b0.243f18","type":"switch","z":"55212914.0911a8","name":"","property":"payload.status","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":290,"y":100,"wires":[[],[],["c4beb359.864b5","c2f92b0.e3038d8","38f92cc4.19bb34"],[]]},{"id":"f362c4bb.00cb78","type":"kodi-controller","z":"","name":"","host":"192.168.0.100","port":"9090"},{"id":"ac1f6e08.f2751","type":"fibaro-server","z":"","name":"HC2","ipaddress":"192.168.0.7"},{"id":"c117ad76.5414d","type":"harmonyws-server","z":"","name":"Harmony Hub","ip":"192.168.0.24","debug":false}]

My issue is that i'm wanting to pause kodi and turn the lights on...but only if the activity is running on the harmony, otherwise do nothing.
I have it working at the moment on the pause/play but my problem is making it only work if the activity from the observer node is running. How can i combine the two nodes?

Regards
Mathew

You could store state in context & check that state when pause is pressed.

See Working with context : Node-RED

Hi Steve

Thank you for your help.

I have updated my flow to get both the activity ID and also the activity status to global context.

[{"id":"e93fc84b.cb5608","type":"kodi-in","z":"55212914.0911a8","name":"Kodi","controller":"f362c4bb.00cb78","x":110,"y":140,"wires":[["c4beb359.864b5"]]},{"id":"c2f92b0.e3038d8","type":"debug","z":"55212914.0911a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":930,"y":40,"wires":[]},{"id":"c4beb359.864b5","type":"switch","z":"55212914.0911a8","name":"","property":"payload.notification","propertyType":"msg","rules":[{"t":"eq","v":"Player.OnResume","vt":"str"},{"t":"eq","v":"Player.OnPause","vt":"str"},{"t":"eq","v":"Player.OnStop","vt":"str"},{"t":"eq","v":"GUI.OnScreensaverActivated","vt":"str"},{"t":"eq","v":"GUI.OnScreensaverDeactivated","vt":"str"}],"checkall":"false","repair":false,"outputs":5,"x":450,"y":120,"wires":[["6979d623.da9ec8"],["bd10a17b.83598"],[],[],[]]},{"id":"8c0729c5.cc1f48","type":"fibaroActor","z":"55212914.0911a8","name":"Simulator D-Box (Games Room)","deviceID":"125","server":"ac1f6e08.f2751","events":true,"outputs":2,"x":1030,"y":140,"wires":[[],[]]},{"id":"bd10a17b.83598","type":"function","z":"55212914.0911a8","name":"Paused/on","func":"if (global.activitystatus = 2) {\n    msg.payload=true;\n}\nelse {\n    return null;\n}\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":160,"wires":[["8c0729c5.cc1f48","c2f92b0.e3038d8"]]},{"id":"6979d623.da9ec8","type":"function","z":"55212914.0911a8","name":"Paused/off","func":"if (global.activitystatus = 2) {\n    msg.payload=false;\n}\nelse {\n    return null;\n}\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":120,"wires":[["8c0729c5.cc1f48","c2f92b0.e3038d8"]]},{"id":"dcf30bc1.5ba7e8","type":"harmonyws-observer","z":"55212914.0911a8","name":"","server":"c117ad76.5414d","startup":true,"toContext":false,"context":"flow","contextKeyActivity":"activity","contextKeyAutomation":"automation","x":100,"y":200,"wires":[["753eb846.4190f8","bce5e01e.8088"]]},{"id":"bce5e01e.8088","type":"change","z":"55212914.0911a8","name":"","rules":[{"t":"set","p":"activityid","pt":"global","to":"payload.activity","tot":"msg"},{"t":"set","p":"activitystatus","pt":"global","to":"payload.status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":200,"wires":[[]]},{"id":"753eb846.4190f8","type":"debug","z":"55212914.0911a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":290,"y":260,"wires":[]},{"id":"f362c4bb.00cb78","type":"kodi-controller","z":"","name":"","host":"192.168.0.100","port":"9090"},{"id":"ac1f6e08.f2751","type":"fibaro-server","z":"","name":"HC2","ipaddress":"192.168.0.7"},{"id":"c117ad76.5414d","type":"harmonyws-server","z":"","name":"Harmony Hub","ip":"192.168.0.24","debug":false}]

The issue i'm having now is finding the right function node if statement to match against the global vars i have set. If they match then do X or if they don't match then do nothing.

Just using the activity status (keeping it simple at the moment) i have this code but it still seems to pass through it even though the activity status is not set to 2 (not running)

if (global.activitystatus = 2) {
    msg.payload=true;
}
else {
    return null;
}
return msg;

Thanks for your help!

You are setting global.activitystatus to 2

Equality is checked with ==

Hmm, So it's still not working. Here is my function node.

st = global.activitystatus

if (st == 2) {
    msg.payload=true;
}
else {
    msg.payload="wrong" ;
}
return msg;

I can confirm the global.activitystatus is set to 2 as per the context data window, However it still does the else part of the statement and does not match the 2 from the activitystatus.

Thanks for your help!

what do you see in debug sidebar if you add the below code to the top your function...

node.warn("global.activitystatus = " + global.activitystatus);

Additionally, it is generally recommended that you use global.get("activitystatus")

Lastly, JavaScript is case sensitive, are you 100% certain activitystatus is spelled and cased correctly?

Also are you sure the status is numeric 2 and not string "2"?

Using the code at the top of my function it says in the debug window "global.activitystatus = undefined"
However in the context data panel it says it has a value of 2 attached to it.

I tried your global.get("activitystatus") instead and it works!

Thanks for your help!

And yes colin, It was a numeric 2 not a string :slight_smile:

1 Like

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