Skip to content

Instantly share code, notes, and snippets.

@PaulWieland
Created March 23, 2021 15:48
Show Gist options
  • Save PaulWieland/8fe4ab1ddf995c9a99494e19762b7ee8 to your computer and use it in GitHub Desktop.
Save PaulWieland/8fe4ab1ddf995c9a99494e19762b7ee8 to your computer and use it in GitHub Desktop.
Global Cache Control With NodeRED
[
{
"id":"1eca8288.a05af5",
"type":"debug",
"z":"516ed999.56f778",
"name":"State and source output",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"payload",
"targetType":"msg",
"x":730,
"y":40,
"wires":[
]
},
{
"id":"e7bdc4e5.74f5f",
"type":"homekit-service",
"z":"516ed999.56f778",
"isParent":true,
"bridge":"5848fa57.3c3164",
"parentService":"",
"name":"TV & Stereo",
"serviceName":"Television",
"topic":"",
"filter":false,
"manufacturer":"Marantz",
"model":"SR8001",
"serialNo":"1",
"firmwareRev":"",
"hardwareRev":"",
"softwareRev":"",
"cameraConfigVideoProcessor":"ffmpeg",
"cameraConfigSource":"",
"cameraConfigStillImageSource":"",
"cameraConfigMaxStreams":2,
"cameraConfigMaxWidth":1280,
"cameraConfigMaxHeight":720,
"cameraConfigMaxFPS":10,
"cameraConfigMaxBitrate":300,
"cameraConfigVideoCodec":"libx264",
"cameraConfigAudioCodec":"libfdk_aac",
"cameraConfigAudio":false,
"cameraConfigPacketSize":1316,
"cameraConfigVerticalFlip":false,
"cameraConfigHorizontalFlip":false,
"cameraConfigMapVideo":"0:0",
"cameraConfigMapAudio":"0:1",
"cameraConfigVideoFilter":"scale=1280:720",
"cameraConfigAdditionalCommandLine":"-tune zerolatency",
"cameraConfigDebug":false,
"cameraConfigSnapshotOutput":"disabled",
"cameraConfigInterfaceName":"",
"characteristicProperties":"{}",
"waitForSetupMsg":false,
"outputs":2,
"x":450,
"y":140,
"wires":[
[
"2e681655.f05f02",
"f4c9c4f.a8c70b8",
"1eca8288.a05af5"
],
[
]
]
},
{
"id":"83c80523.3cf0d",
"type":"homekit-service",
"z":"516ed999.56f778",
"isParent":false,
"bridge":"",
"parentService":"e7bdc4e5.74f5f",
"name":"Input 0",
"serviceName":"InputSource",
"topic":"",
"filter":false,
"manufacturer":"Default Manufacturer",
"model":"Default Model",
"serialNo":"Default Serial Number",
"firmwareRev":"",
"hardwareRev":"",
"softwareRev":"",
"cameraConfigVideoProcessor":"ffmpeg",
"cameraConfigSource":"",
"cameraConfigStillImageSource":"",
"cameraConfigMaxStreams":2,
"cameraConfigMaxWidth":1280,
"cameraConfigMaxHeight":720,
"cameraConfigMaxFPS":10,
"cameraConfigMaxBitrate":300,
"cameraConfigVideoCodec":"libx264",
"cameraConfigAudioCodec":"libfdk_aac",
"cameraConfigAudio":false,
"cameraConfigPacketSize":1316,
"cameraConfigVerticalFlip":false,
"cameraConfigHorizontalFlip":false,
"cameraConfigMapVideo":"0:0",
"cameraConfigMapAudio":"0:1",
"cameraConfigVideoFilter":"scale=1280:720",
"cameraConfigAdditionalCommandLine":"-tune zerolatency",
"cameraConfigDebug":false,
"cameraConfigSnapshotOutput":"disabled",
"cameraConfigInterfaceName":"",
"characteristicProperties":"{}",
"waitForSetupMsg":false,
"outputs":2,
"x":440,
"y":180,
"wires":[
[
],
[
]
]
},
{
"id":"4f5fbd12.b77ebc",
"type":"homekit-service",
"z":"516ed999.56f778",
"isParent":false,
"bridge":"",
"parentService":"e7bdc4e5.74f5f",
"name":"Input 1",
"serviceName":"InputSource",
"topic":"",
"filter":false,
"manufacturer":"Default Manufacturer",
"model":"Default Model",
"serialNo":"Default Serial Number",
"cameraConfigVideoProcessor":"ffmpeg",
"cameraConfigSource":"",
"cameraConfigStillImageSource":"",
"cameraConfigMaxStreams":2,
"cameraConfigMaxWidth":1280,
"cameraConfigMaxHeight":720,
"cameraConfigMaxFPS":10,
"cameraConfigMaxBitrate":300,
"cameraConfigVideoCodec":"libx264",
"cameraConfigAudioCodec":"libfdk_aac",
"cameraConfigAudio":false,
"cameraConfigPacketSize":1316,
"cameraConfigVerticalFlip":false,
"cameraConfigHorizontalFlip":false,
"cameraConfigMapVideo":"0:0",
"cameraConfigMapAudio":"0:1",
"cameraConfigVideoFilter":"scale=1280:720",
"cameraConfigAdditionalCommandLine":"-tune zerolatency",
"cameraConfigDebug":false,
"cameraConfigSnapshotOutput":"disabled",
"cameraConfigInterfaceName":"",
"characteristicProperties":"{}",
"outputs":2,
"x":440,
"y":220,
"wires":[
[
],
[
]
]
},
{
"id":"58bf57dc.05281",
"type":"homekit-service",
"z":"516ed999.56f778",
"isParent":false,
"bridge":"",
"parentService":"e7bdc4e5.74f5f",
"name":"Input 2",
"serviceName":"InputSource",
"topic":"",
"filter":false,
"manufacturer":"Default Manufacturer",
"model":"Default Model",
"serialNo":"Default Serial Number",
"firmwareRev":"",
"hardwareRev":"",
"softwareRev":"",
"cameraConfigVideoProcessor":"ffmpeg",
"cameraConfigSource":"",
"cameraConfigStillImageSource":"",
"cameraConfigMaxStreams":2,
"cameraConfigMaxWidth":1280,
"cameraConfigMaxHeight":720,
"cameraConfigMaxFPS":10,
"cameraConfigMaxBitrate":300,
"cameraConfigVideoCodec":"libx264",
"cameraConfigAudioCodec":"libfdk_aac",
"cameraConfigAudio":false,
"cameraConfigPacketSize":1316,
"cameraConfigVerticalFlip":false,
"cameraConfigHorizontalFlip":false,
"cameraConfigMapVideo":"0:0",
"cameraConfigMapAudio":"0:1",
"cameraConfigVideoFilter":"scale=1280:720",
"cameraConfigAdditionalCommandLine":"-tune zerolatency",
"cameraConfigDebug":false,
"cameraConfigSnapshotOutput":"disabled",
"cameraConfigInterfaceName":"",
"characteristicProperties":"{}",
"waitForSetupMsg":false,
"outputs":2,
"x":440,
"y":260,
"wires":[
[
],
[
]
]
},
{
"id":"92deaad9.f1162",
"type":"homekit-service",
"z":"516ed999.56f778",
"isParent":false,
"bridge":"",
"parentService":"e7bdc4e5.74f5f",
"name":"Speaker Controls",
"serviceName":"TelevisionSpeaker",
"topic":"",
"filter":false,
"manufacturer":"Default Manufacturer",
"model":"Default Model",
"serialNo":"Default Serial Number",
"firmwareRev":"",
"hardwareRev":"",
"softwareRev":"",
"cameraConfigVideoProcessor":"ffmpeg",
"cameraConfigSource":"",
"cameraConfigStillImageSource":"",
"cameraConfigMaxStreams":2,
"cameraConfigMaxWidth":1280,
"cameraConfigMaxHeight":720,
"cameraConfigMaxFPS":10,
"cameraConfigMaxBitrate":300,
"cameraConfigVideoCodec":"libx264",
"cameraConfigAudioCodec":"libfdk_aac",
"cameraConfigAudio":false,
"cameraConfigPacketSize":1316,
"cameraConfigVerticalFlip":false,
"cameraConfigHorizontalFlip":false,
"cameraConfigMapVideo":"0:0",
"cameraConfigMapAudio":"0:1",
"cameraConfigVideoFilter":"scale=1280:720",
"cameraConfigAdditionalCommandLine":"-tune zerolatency",
"cameraConfigDebug":false,
"cameraConfigSnapshotOutput":"disabled",
"cameraConfigInterfaceName":"",
"characteristicProperties":"{\"VolumeControlType\":3,\"VolumeSelector\":true}",
"waitForSetupMsg":false,
"outputs":2,
"x":110,
"y":400,
"wires":[
[
],
[
"114705cc.afd342",
"57398b8a.222cfc"
]
]
},
{
"id":"114705cc.afd342",
"type":"debug",
"z":"516ed999.56f778",
"name":"Volume output",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"payload",
"targetType":"msg",
"x":280,
"y":360,
"wires":[
]
},
{
"id":"5c9144fb.2b21dc",
"type":"inject",
"z":"516ed999.56f778",
"name":"TV Setup",
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":"5",
"topic":"",
"payload":"",
"payloadType":"date",
"x":120,
"y":140,
"wires":[
[
"cb35f414.22a5c8"
]
]
},
{
"id":"665f7489.685c9c",
"type":"inject",
"z":"516ed999.56f778",
"name":"Source Setup",
"repeat":"",
"crontab":"",
"once":true,
"onceDelay":"6",
"topic":"",
"payload":"",
"payloadType":"date",
"x":120,
"y":220,
"wires":[
[
"a1b8acd3.775088"
]
]
},
{
"id":"cb35f414.22a5c8",
"type":"function",
"z":"516ed999.56f778",
"name":"Setup TV",
"func":"var name = \"Television\";\n\nmsg.payload = {\n \"ConfiguredName\": name,\n \"ActiveIdentifier\" : 0,\n \"SleepDiscoveryMode\" : 0,\n \"Active\" : 0\n};\nreturn msg;",
"outputs":1,
"noerr":0,
"x":280,
"y":140,
"wires":[
[
"e7bdc4e5.74f5f"
]
]
},
{
"id":"a1b8acd3.775088",
"type":"function",
"z":"516ed999.56f778",
"name":"Setup Inputs",
"func":"// This function will initialize and name inputs\n// it is set to work with 4 inputs\n\n// INPUT SOURCE NAMES\nvar input0 = \"Apple TV\";\nvar input1 = \"Chromecast\";\nvar input2 = \"Switch\";\n\n// INPUT SOURCE TYPES\nvar OTHER = 0;\nvar HOME_SCREEN = 1;\nvar TUNER = 2;\nvar HDMI = 3;\nvar COMPOSITE_VIDEO = 4;\nvar S_VIDEO = 5;\nvar COMPONENT_VIDEO = 6;\nvar DVI = 7;\nvar AIRPLAY = 8;\nvar USB = 9;\nvar APPLICATION = 10;\n\n// Configure your input types based on options above\nvar input0type = HDMI;\nvar input1type = HDMI;\nvar input2type = HDMI;\n\n\n// Duplicate or remove sets if you have more or fewer inputs\nvar msg0={};\nvar msg1={};\nvar msg2={};\n\nmsg0.payload = {\n \"Identifier\": 0,\n \"IsConfigured\" : 1,\n \"ConfiguredName\": input0,\n \"InputSourceType\": input0type\n};\nmsg1.payload = {\n \"Identifier\": 1,\n \"IsConfigured\" : 1,\n \"ConfiguredName\": input1,\n \"InputSourceType\": input1type\n};\nmsg2.payload = {\n \"Identifier\": 2,\n \"IsConfigured\" : 1,\n \"ConfiguredName\": input2,\n \"InputSourceType\": input2type\n};\n\nreturn [msg0,msg1,msg2];",
"outputs":3,
"noerr":0,
"x":290,
"y":220,
"wires":[
[
"83c80523.3cf0d"
],
[
"4f5fbd12.b77ebc"
],
[
"58bf57dc.05281"
]
]
},
{
"id":"57398b8a.222cfc",
"type":"switch",
"z":"516ed999.56f778",
"name":"",
"property":"payload.VolumeSelector",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"0",
"vt":"num"
},
{
"t":"eq",
"v":"1",
"vt":"num"
}
],
"checkall":"true",
"repair":false,
"outputs":2,
"x":290,
"y":400,
"wires":[
[
"9c70ab0e.7d192"
],
[
"72ca1ef7.dd46c8"
]
]
},
{
"id":"2e681655.f05f02",
"type":"switch",
"z":"516ed999.56f778",
"name":"",
"property":"payload.Active",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"0",
"vt":"num"
},
{
"t":"eq",
"v":"1",
"vt":"num"
}
],
"checkall":"true",
"repair":false,
"outputs":2,
"x":630,
"y":100,
"wires":[
[
"7a15f9be.60aab8"
],
[
"c24f9a7d.8595a8"
]
]
},
{
"id":"167461f2.202396",
"type":"switch",
"z":"516ed999.56f778",
"name":"",
"property":"payload.ActiveIdentifier",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"0",
"vt":"str"
},
{
"t":"eq",
"v":"1",
"vt":"str"
},
{
"t":"eq",
"v":"2",
"vt":"str"
}
],
"checkall":"true",
"repair":false,
"outputs":3,
"x":230,
"y":580,
"wires":[
[
"92414428.aeff38"
],
[
"7b3fce0e.20cf1"
],
[
"4b6f36df.3f31b8"
]
]
},
{
"id":"92414428.aeff38",
"type":"change",
"z":"516ed999.56f778",
"name":"DVD/Apple TV",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"SRC:22",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":420,
"y":540,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"7b3fce0e.20cf1",
"type":"change",
"z":"516ed999.56f778",
"name":"VCR1/Chromecast",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"SRC:33",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":410,
"y":580,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"4b6f36df.3f31b8",
"type":"change",
"z":"516ed999.56f778",
"name":"DSS/Switch",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"SRC:55",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":430,
"y":620,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"cfd3b483.ca472",
"type":"comment",
"z":"516ed999.56f778",
"name":"HomeKit Documentation",
"info":"https://github.com/NRCHKB/node-red-contrib-homekit-bridged/wiki/Television-Service",
"x":150,
"y":60,
"wires":[
]
},
{
"id":"43c6a295.a81e5c",
"type":"tcp request",
"z":"516ed999.56f778",
"server":"10.0.1.155",
"port":"4999",
"out":"sit",
"splitc":" ",
"name":"GlobalCache RS232 TV Port",
"x":1360,
"y":100,
"wires":[
[
"338e9a3e.aa8b5e"
]
]
},
{
"id":"3912847d.a3a72c",
"type":"function",
"z":"516ed999.56f778",
"name":"TV On",
"func":"var stx = String.fromCharCode(2);\nvar etx = String.fromCharCode(3);\n\nmsg.payload = new Buffer(`${stx}PON${etx}`,'binary');\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":1150,
"y":120,
"wires":[
[
"43c6a295.a81e5c"
]
]
},
{
"id":"338e9a3e.aa8b5e",
"type":"debug",
"z":"516ed999.56f778",
"name":"",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"true",
"targetType":"full",
"x":1550,
"y":100,
"wires":[
]
},
{
"id":"564e4a45.924dec",
"type":"function",
"z":"516ed999.56f778",
"name":"TV Off",
"func":"var stx = String.fromCharCode(2);\nvar etx = String.fromCharCode(3);\n\nmsg.payload = new Buffer(`${stx}POF${etx}`,'binary');\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":1150,
"y":80,
"wires":[
[
"43c6a295.a81e5c"
]
]
},
{
"id":"190f3e8e.fef6b1",
"type":"tcp request",
"z":"516ed999.56f778",
"server":"10.0.1.155",
"port":"5000",
"out":"sit",
"splitc":" ",
"name":"GlobalCache RS232 Stereo Port",
"x":870,
"y":460,
"wires":[
[
"799732e6.05b6cc"
]
]
},
{
"id":"9c70ab0e.7d192",
"type":"change",
"z":"516ed999.56f778",
"name":"Vol Up",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"VOL:1",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":450,
"y":380,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"72ca1ef7.dd46c8",
"type":"change",
"z":"516ed999.56f778",
"name":"Vol Down",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"VOL:2",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":440,
"y":420,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"29ba49e5.f2f70e",
"type":"function",
"z":"516ed999.56f778",
"name":"Convert",
"func":"var etx = String.fromCharCode(13);\n\nmsg.payload = new Buffer(`@${msg.payload}${etx}`,'binary');\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":660,
"y":460,
"wires":[
[
"190f3e8e.fef6b1"
]
]
},
{
"id":"7a15f9be.60aab8",
"type":"change",
"z":"516ed999.56f778",
"name":"Stereo Off",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"PWR:1",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":770,
"y":80,
"wires":[
[
"29ba49e5.f2f70e",
"564e4a45.924dec"
]
]
},
{
"id":"c24f9a7d.8595a8",
"type":"change",
"z":"516ed999.56f778",
"name":"Stereo On",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"PWR:2",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":760,
"y":120,
"wires":[
[
"29ba49e5.f2f70e",
"3912847d.a3a72c"
]
]
},
{
"id":"7db699ff.5ee96",
"type":"change",
"z":"516ed999.56f778",
"name":"Discrete Vol",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"'VOL:0'&msg.payload",
"tot":"jsonata"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":430,
"y":460,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"f5c4043b.95bc5",
"type":"change",
"z":"516ed999.56f778",
"name":"Get Vol",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"VOL:?",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":440,
"y":500,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"307aa0a.8f4d26",
"type":"inject",
"z":"516ed999.56f778",
"name":"",
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":0.1,
"topic":"",
"payload":"",
"payloadType":"date",
"x":280,
"y":500,
"wires":[
[
"f5c4043b.95bc5"
]
]
},
{
"id":"812750d5.aa113",
"type":"change",
"z":"516ed999.56f778",
"name":"Enable Auto Status Feedback",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"AST:F",
"tot":"str"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":350,
"y":320,
"wires":[
[
"29ba49e5.f2f70e"
]
]
},
{
"id":"8ab4d15e.c1d778",
"type":"inject",
"z":"516ed999.56f778",
"name":"",
"repeat":"",
"crontab":"",
"once":true,
"onceDelay":0.1,
"topic":"",
"payload":"",
"payloadType":"date",
"x":130,
"y":320,
"wires":[
[
"812750d5.aa113"
]
]
},
{
"id":"799732e6.05b6cc",
"type":"function",
"z":"516ed999.56f778",
"name":"Convert",
"func":"msg.payload = msg.payload.toString();\n\n// Split on ETX character (\\r)\nmsg.payload.split(String.fromCharCode(13)).filter(s => s).forEach(s => {\n node.send({\n topic: s.substr(1,3),\n payload: s.substr(5,3),\n raw: s,\n fromMarantz: true\n });\n});",
"outputs":1,
"noerr":0,
"x":1080,
"y":460,
"wires":[
[
"f91d20c4.f4e97"
]
]
},
{
"id":"f91d20c4.f4e97",
"type":"switch",
"z":"516ed999.56f778",
"name":"",
"property":"topic",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"PWR",
"vt":"str"
},
{
"t":"eq",
"v":"VOL",
"vt":"str"
},
{
"t":"eq",
"v":"SRC",
"vt":"str"
},
{
"t":"eq",
"v":"OSD",
"vt":"str"
},
{
"t":"else"
}
],
"checkall":"true",
"repair":false,
"outputs":5,
"x":1210,
"y":460,
"wires":[
[
"32816c00.de3174"
],
[
"1b0dd87a.a6868"
],
[
"ea7df25f.38d93"
],
[
],
[
"d7c24ad3.9cd31"
]
]
},
{
"id":"d7c24ad3.9cd31",
"type":"debug",
"z":"516ed999.56f778",
"name":"",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"true",
"targetType":"full",
"x":1490,
"y":600,
"wires":[
]
},
{
"id":"32816c00.de3174",
"type":"switch",
"z":"516ed999.56f778",
"name":"Power",
"property":"payload",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"1",
"vt":"str"
},
{
"t":"eq",
"v":"2",
"vt":"str"
}
],
"checkall":"true",
"repair":false,
"outputs":2,
"x":1350,
"y":400,
"wires":[
[
"564e4a45.924dec",
"cb29cc03.1633f8"
],
[
"3912847d.a3a72c",
"4ef45e11.17783"
]
]
},
{
"id":"513ee42b.001db4",
"type":"inject",
"z":"516ed999.56f778",
"name":"Switch Input",
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":0.1,
"topic":"",
"payload":"{\"ActiveIdentifier\":2}",
"payloadType":"json",
"x":110,
"y":100,
"wires":[
[
"e7bdc4e5.74f5f"
]
]
},
{
"id":"1b0dd87a.a6868",
"type":"function",
"z":"516ed999.56f778",
"name":"Volume",
"func":"/* stereo scale is -71 to +15.\n/ -ZZ = mute\n/ capping max volume at -15\n*/\n\nlet unscaledNum = parseInt(msg.payload);\nlet maxAllowed = 100;\nlet minAllowed = 0;\n\nlet scaled = 0;\nlet max = -5;\nlet min = -72;\n\nif(msg.payload === '-ZZ') msg.payload = -72;\nif(parseInt(msg.payload) > -15) msg.payload = -15;\n\nscaled = Math.round((maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed);\n\nmsg.payload = {\n \"Brightness\": scaled\n}\n\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":1360,
"y":440,
"wires":[
[
"6ce34f4f.dc6df",
"414f6535.f8605c"
]
]
},
{
"id":"ea7df25f.38d93",
"type":"switch",
"z":"516ed999.56f778",
"name":"Source",
"property":"payload",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"22",
"vt":"str"
},
{
"t":"eq",
"v":"33",
"vt":"str"
},
{
"t":"eq",
"v":"55",
"vt":"str"
}
],
"checkall":"true",
"repair":false,
"outputs":3,
"x":1360,
"y":480,
"wires":[
[
"7cc3a648.458eb"
],
[
"714ac206.cbb4b4"
],
[
"d79522e0.0c0ac"
]
]
},
{
"id":"7cc3a648.458eb",
"type":"change",
"z":"516ed999.56f778",
"name":"DVD/AppleTV",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"{\"ActiveIdentifier\":0}",
"tot":"json"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":1540,
"y":440,
"wires":[
[
"ce9ac8e3.8fd468"
]
]
},
{
"id":"714ac206.cbb4b4",
"type":"change",
"z":"516ed999.56f778",
"name":"VCR1/Chromecast",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"{\"ActiveIdentifier\":1}",
"tot":"json"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":1530,
"y":480,
"wires":[
[
"ce9ac8e3.8fd468"
]
]
},
{
"id":"d79522e0.0c0ac",
"type":"change",
"z":"516ed999.56f778",
"name":"DSS/Nintendo",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"{\"ActiveIdentifier\":2}",
"tot":"json"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":1540,
"y":520,
"wires":[
[
"ce9ac8e3.8fd468"
]
]
},
{
"id":"ce9ac8e3.8fd468",
"type":"link out",
"z":"516ed999.56f778",
"name":"SRC From Stereo",
"links":[
"57b9b3a.2694d4c",
"a34f15de.a39ef",
"1b8bc116.8d2837"
],
"x":1675,
"y":480,
"wires":[
]
},
{
"id":"57b9b3a.2694d4c",
"type":"link in",
"z":"516ed999.56f778",
"name":"To HomeKit",
"links":[
"ce9ac8e3.8fd468",
"f88278ea.95e7e8"
],
"x":315,
"y":100,
"wires":[
[
"fefdbb26.7d3648",
"e7bdc4e5.74f5f"
]
]
},
{
"id":"fefdbb26.7d3648",
"type":"debug",
"z":"516ed999.56f778",
"name":"",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"true",
"targetType":"full",
"x":440,
"y":60,
"wires":[
]
},
{
"id":"f4c9c4f.a8c70b8",
"type":"link out",
"z":"516ed999.56f778",
"name":"From HomeKit",
"links":[
"aa146b3a.459a28"
],
"x":595,
"y":160,
"wires":[
]
},
{
"id":"aa146b3a.459a28",
"type":"link in",
"z":"516ed999.56f778",
"name":"SRC To Stereo",
"links":[
"f4c9c4f.a8c70b8"
],
"x":135,
"y":580,
"wires":[
[
"167461f2.202396"
]
]
},
{
"id":"e7a62a37.dd9f68",
"type":"inject",
"z":"516ed999.56f778",
"name":"Pause Key",
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":0.1,
"topic":"",
"payload":"{\"RemoteKey\":11}",
"payloadType":"json",
"x":220,
"y":180,
"wires":[
[
"e7bdc4e5.74f5f"
]
]
},
{
"id":"498bde4d.395dd",
"type":"homekit-service",
"z":"516ed999.56f778",
"isParent":false,
"bridge":"",
"parentService":"e7bdc4e5.74f5f",
"name":"Vol",
"serviceName":"Lightbulb",
"topic":"",
"filter":false,
"manufacturer":"NRCHKB",
"model":"1.2.0",
"serialNo":"Default Serial Number",
"firmwareRev":"1.2.0",
"hardwareRev":"1.2.0",
"softwareRev":"1.2.0",
"cameraConfigVideoProcessor":"ffmpeg",
"cameraConfigSource":"",
"cameraConfigStillImageSource":"",
"cameraConfigMaxStreams":2,
"cameraConfigMaxWidth":1280,
"cameraConfigMaxHeight":720,
"cameraConfigMaxFPS":10,
"cameraConfigMaxBitrate":300,
"cameraConfigVideoCodec":"libx264",
"cameraConfigAudioCodec":"libfdk_aac",
"cameraConfigAudio":false,
"cameraConfigPacketSize":1316,
"cameraConfigVerticalFlip":false,
"cameraConfigHorizontalFlip":false,
"cameraConfigMapVideo":"0:0",
"cameraConfigMapAudio":"0:1",
"cameraConfigVideoFilter":"scale=1280:720",
"cameraConfigAdditionalCommandLine":"-tune zerolatency",
"cameraConfigDebug":false,
"cameraConfigSnapshotOutput":"disabled",
"cameraConfigInterfaceName":"",
"characteristicProperties":"{\"Brightness\":true}",
"waitForSetupMsg":false,
"outputs":2,
"x":110,
"y":460,
"wires":[
[
"31098766.94de7"
],
[
]
]
},
{
"id":"6ce34f4f.dc6df",
"type":"debug",
"z":"516ed999.56f778",
"name":"",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"true",
"targetType":"full",
"x":1620,
"y":220,
"wires":[
]
},
{
"id":"31098766.94de7",
"type":"function",
"z":"516ed999.56f778",
"name":"Scale Volume",
"func":"/* stereo scale is -71 to +15.\n/ -ZZ = mute\n/ capping max volume at -15\n*/\n\nlet sliderValue = msg.payload.Brightness;\n\nif(isNaN(sliderValue)) return null;\n\n\nlet scaled = 0;\nlet maxAllowed = -5;\nlet minAllowed = -72;\n\nlet unscaledNum = sliderValue;\nlet max = 100;\nlet min = 0;\n\nscaled = Math.round((maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed);\n\nscaled = scaled === -72 ? '-ZZ' : scaled;\n\nmsg.payload = scaled;\n\n\nreturn msg;\n",
"outputs":1,
"noerr":0,
"x":260,
"y":460,
"wires":[
[
"7db699ff.5ee96"
]
]
},
{
"id":"414f6535.f8605c",
"type":"link out",
"z":"516ed999.56f778",
"name":"Vol From Stereo",
"links":[
"d5f4c42f.2b7238"
],
"x":1535,
"y":400,
"wires":[
]
},
{
"id":"d5f4c42f.2b7238",
"type":"link in",
"z":"516ed999.56f778",
"name":"VOL To HomeKit",
"links":[
"414f6535.f8605c"
],
"x":35,
"y":460,
"wires":[
[
"498bde4d.395dd"
]
]
},
{
"id":"10893d28.fc27b3",
"type":"inject",
"z":"516ed999.56f778",
"name":"",
"props":[
{
"p":"payload",
"v":"-15",
"vt":"str"
},
{
"p":"topic",
"v":"",
"vt":"string"
}
],
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":0.1,
"topic":"",
"payload":"-15",
"payloadType":"str",
"x":190,
"y":720,
"wires":[
[
"7db699ff.5ee96"
]
]
},
{
"id":"cb29cc03.1633f8",
"type":"change",
"z":"516ed999.56f778",
"name":"Off",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"{\"Active\":0}",
"tot":"json"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":1510,
"y":320,
"wires":[
[
"f88278ea.95e7e8"
]
]
},
{
"id":"4ef45e11.17783",
"type":"change",
"z":"516ed999.56f778",
"name":"On",
"rules":[
{
"t":"set",
"p":"payload",
"pt":"msg",
"to":"{\"Active\":1}",
"tot":"json"
}
],
"action":"",
"property":"",
"from":"",
"to":"",
"reg":false,
"x":1510,
"y":360,
"wires":[
[
"f88278ea.95e7e8"
]
]
},
{
"id":"f88278ea.95e7e8",
"type":"link out",
"z":"516ed999.56f778",
"name":"PWR From Stereo",
"links":[
"57b9b3a.2694d4c"
],
"x":1615,
"y":340,
"wires":[
]
},
{
"id":"a34f15de.a39ef",
"type":"link in",
"z":"516ed999.56f778",
"name":"",
"links":[
"ce9ac8e3.8fd468"
],
"x":1015,
"y":140,
"wires":[
[
"3912847d.a3a72c"
]
]
},
{
"id":"f022fc17.30726",
"type":"group",
"z":"516ed999.56f778",
"style":{
"stroke":"#999999",
"stroke-opacity":"1",
"fill":"none",
"fill-opacity":"1",
"label":true,
"label-position":"nw",
"color":"#a4a4a4"
},
"nodes":[
"d5d5b505.9ef478",
"7f2987.f35c1678",
"a8ecaeaf.ce18f8",
"cd963cf4.478278"
],
"x":34,
"y":759,
"w":552,
"h":162
},
{
"id":"d5d5b505.9ef478",
"type":"mqtt in",
"z":"516ed999.56f778",
"g":"f022fc17.30726",
"name":"",
"topic":"home/Master Bedroom/Master Bedroom.H/state",
"qos":"2",
"datatype":"json",
"broker":"a59c4793.670798",
"x":240,
"y":840,
"wires":[
[
"a8ecaeaf.ce18f8"
]
]
},
{
"id":"7f2987.f35c1678",
"type":"mqtt in",
"z":"516ed999.56f778",
"g":"f022fc17.30726",
"name":"",
"topic":"home/Kitchen/Kitchen KeypadH/state",
"qos":"2",
"datatype":"json",
"broker":"a59c4793.670798",
"x":210,
"y":880,
"wires":[
[
"a8ecaeaf.ce18f8"
]
]
},
{
"id":"a8ecaeaf.ce18f8",
"type":"switch",
"z":"516ed999.56f778",
"g":"f022fc17.30726",
"name":"",
"property":"payload",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"true",
"vt":"str"
},
{
"t":"else"
}
],
"checkall":"true",
"repair":false,
"outputs":2,
"x":510,
"y":860,
"wires":[
[
],
[
"7a15f9be.60aab8"
]
]
},
{
"id":"cd963cf4.478278",
"type":"comment",
"z":"516ed999.56f778",
"g":"f022fc17.30726",
"name":"Turn off TV&Stereo When H Key is Pressed",
"info":"When the \"H\" key on one of the main insteon keypads is pressed, turn off the TV & Stereo",
"x":220,
"y":800,
"wires":[
]
},
{
"id":"a59c4793.670798",
"type":"mqtt-broker",
"name":"",
"broker":"10.0.1.2",
"port":"1883",
"clientid":"",
"usetls":false,
"compatmode":true,
"keepalive":"60",
"cleansession":true,
"birthTopic":"",
"birthQos":"0",
"birthRetain":"false",
"birthPayload":"",
"closeTopic":"",
"closeRetain":"false",
"closePayload":"",
"willTopic":"",
"willQos":"0",
"willRetain":"false",
"willPayload":""
},
{
"id":"5848fa57.3c3164",
"type":"homekit-bridge",
"bridgeName":"NodeRed",
"pinCode":"111-11-112",
"port":"",
"allowInsecureRequest":false,
"manufacturer":"NRCHKB",
"model":"1.2.0",
"serialNo":"Default Serial Number",
"firmwareRev":"1.2.0",
"hardwareRev":"1.2.0",
"softwareRev":"1.2.0",
"customMdnsConfig":false,
"mdnsMulticast":true,
"mdnsInterface":"",
"mdnsPort":"",
"mdnsIp":"",
"mdnsTtl":"",
"mdnsLoopback":true,
"mdnsReuseAddr":true,
"allowMessagePassthrough":false
}
]
@PaulWieland
Copy link
Author

PaulWieland commented Mar 23, 2021

Screen Shot 2021-03-23 at 11 49 11 AM

This flow Creates a HomeKit Television that has power, input and volume controls. The control works seamlessly (in both directions) with my Marantz SR8001 Receiver and Panasonic Plasma Monitor.

Turning the HomeKit TV on causes the flow to send the necessary RS232 codes to both the TV and Stereo to turn them on. (this can be done with IR as well).

Turning the TV/Stereo on Manually with the remote causes the HomeKit TV to show that it's on - meaning the state is completely sync'd. Even the volume level is synchronized. By turning the volume knob on the stereo, the HomeKit volume level moves in real time. (Note that I am using a lightbulb dimmer because HomeKit does not have a UI based volume control).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment