-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieColors.json
1 lines (1 loc) · 10.7 KB
/
MovieColors.json
1
[{"id":"ceb93e8d.d8a85","type":"tab","label":"Movie Color","disabled":false,"info":""},{"id":"9e60a024.ed83f","type":"function","z":"ceb93e8d.d8a85","name":"Record Light Color","func":"const gHomeAssistant = global.get('homeassistant').homeAssistant;\n\n\n//edit to match your media player\nvar MovieName = gHomeAssistant.states['media_player.kodi'].attributes.media_title;\nvar CurPos = gHomeAssistant.states['media_player.kodi'].attributes.media_position;\n\n\n//edit to match your light\nvar LiteColor = gHomeAssistant.states['light.movie_color_group'].attributes.rgb_color;\n\n\n//edit this value to create a larger offset if desired\nCurPos = CurPos - 2;\n\nMovieName = MovieName.replace(\".mp4\", \"\");\nMovieName = MovieName.replace(\".avi\", \"\");\nMovieName = MovieName.replace(\".mkv\", \"\");\nMovieName = MovieName.replace(\".mov\", \"\");\n\n\nMovieName = MovieName.replace(/[/\\\\?%*:.,|\"'<>]/g, '');\n\nmsg.filename = '/config/node-red/MovieColor/' + MovieName + '.txt';\n\nmsg.payload = CurPos + ',' + LiteColor[0] + ',' + LiteColor[1] + ',' + LiteColor[2];\n\nvar StatMsg = \"record: \" + msg.payload;\n\nnode.status({fill:\"blue\",shape:\"dot\",text:StatMsg});\n\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":700,"wires":[["38734736.f65c18"]]},{"id":"ee4b1919.a9f9d8","type":"inject","z":"ceb93e8d.d8a85","name":"Hit to Record","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":700,"wires":[["9e60a024.ed83f"]]},{"id":"e6717318.9573d","type":"trigger-state","z":"ceb93e8d.d8a85","name":"Now Playing","server":"abd879d.0389688","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.kodi","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"3pea3ti57gi","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"playing"},{"id":"ps351eqztl8","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"playing"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":130,"y":140,"wires":[["cac25d5e.48c45"],[]]},{"id":"28ad6093.7817f","type":"comment","z":"ceb93e8d.d8a85","name":"Playing Movie","info":"","x":90,"y":40,"wires":[]},{"id":"b046b6eb.cf1388","type":"file in","z":"ceb93e8d.d8a85","name":"Read File","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":740,"y":140,"wires":[["6526bc0a.feeb94"]]},{"id":"6526bc0a.feeb94","type":"csv","z":"ceb93e8d.d8a85","name":"Parse csv","sep":",","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"MPos,R,G,B","skip":"0","strings":true,"x":900,"y":140,"wires":[["16ee40b4.1cc15f"]]},{"id":"c5f6d2cb.6297c","type":"function","z":"ceb93e8d.d8a85","name":"Get CSV File Name","func":"const gHomeAssistant = global.get('homeassistant').homeAssistant;\n\n//--------------------------------------------\n\n\n\n\n//edit reference to match your media player\nvar MovieName = gHomeAssistant.states['media_player.kodi'].attributes.media_title;\n\n\n\n\n\n//--------------------------------------------\n\n\nMovieName = MovieName.replace(\".mp4\", \"\");\nMovieName = MovieName.replace(\".avi\", \"\");\nMovieName = MovieName.replace(\".mkv\", \"\");\nMovieName = MovieName.replace(\".mov\", \"\");\n\n\nMovieName = MovieName.replace(/[/\\\\?%*:.,|\"'<>]/g, '');\n\nmsg.filename = '/config/node-red/MovieColor/' + MovieName + '.txt';\n\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":140,"wires":[["b046b6eb.cf1388"]]},{"id":"f4db4ca8.22091","type":"function","z":"ceb93e8d.d8a85","name":"Function Loop","func":"var Marr = msg.payload.Marr;\nvar Marl = msg.payload.Marl;\nvar MTime = msg.payload.MTime;\nconst gHomeAssistant = global.get('homeassistant').homeAssistant;\n\n// --------------------------------------------------\n\n\n\n\n//Edit these to match your media player\nvar CurPos = gHomeAssistant.states['media_player.kodi'].attributes.media_position;\nvar MPState = gHomeAssistant.states['media_player.kodi'].state;\n\n\n//Edit this to match your light if you dont use this group\nvar LiteColor = gHomeAssistant.states['light.movie_color_group'].attributes.rgb_color;\n\n\n\n\n\n// --------------------------------------------------\n\n//Status Message\nvar StatMsg = MPState + \" time: \" + CurPos;\nvar StatClr = \"green\";\n\n\n// if the time hasnt changed do nothing\nvar NewColor = 'none';\n\nif ((MTime != CurPos) && (LiteColor !== undefined)) {\n\n var CI = 0;\n var i = 0;\n var R1 = Marr[i].R;\n var G1 = Marr[i].G;\n var B1 = Marr[i].B; \n \n while (i < Marl) {\n CI = Marr[i].MPos;\n if (CI <= CurPos) {\n \n R1 = Marr[i].R;\n G1 = Marr[i].G;\n B1 = Marr[i].B; \n \n i++;\n \n } else {\n break;\n }\n }\n \n\n// If the old color was almost the same do nothing.\n\n if ((LiteColor[0]+4 > R1) && (LiteColor[1]+4 > G1) && (LiteColor[2]+4 > B1) && (LiteColor[0]-4 < R1) && (LiteColor[1]-4 < G1) && (LiteColor[2]-4 < B1)) {\n \n NewColor = 'none';\n\n // Stop when template is complete\n \n if (i == (Marl)) {\n NewColor = 'stop';\n StatMsg = \"Template Script Complete\";\n StatClr = \"blue\";\n }\n\n } else {\n \n NewColor = '[' + R1 + ',' + G1 + ',' + B1 + ']';\n\n }\n\n}\n\n\n\n// If media player isn't playing anymore we are done\n\nif (MPState != 'playing') {\n \n NewColor = 'stop';\n StatMsg = MPState;\n StatClr = \"yellow\";\n \n}\n\n\nmsg.payload = {color: NewColor,\n MTime: CurPos,\n Marl: Marl,\n Marr: Marr,\n OldColor: LiteColor,\n MPState: MPState\n};\n\n\nnode.status({fill:StatClr,shape:\"dot\",text:StatMsg});\n\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":240,"wires":[["cd46c607.c04518"]]},{"id":"3a5b2817.b30288","type":"api-call-service","z":"ceb93e8d.d8a85","name":"set color","server":"abd879d.0389688","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"light.movie_color_group","data":"{ \"rgb_color\": {{payload.color}} }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":240,"wires":[["718107a2.687248"]]},{"id":"cd46c607.c04518","type":"switch","z":"ceb93e8d.d8a85","name":"","property":"payload.color","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"},{"t":"eq","v":"none","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":830,"y":240,"wires":[[],["718107a2.687248"],["3a5b2817.b30288"]]},{"id":"f8f45efe.86388","type":"catch","z":"ceb93e8d.d8a85","name":"If No File Found","scope":["b046b6eb.cf1388"],"uncaught":false,"x":760,"y":80,"wires":[[]]},{"id":"b783ee0c.3dc52","type":"comment","z":"ceb93e8d.d8a85","name":"Record Colors","info":"","x":90,"y":640,"wires":[]},{"id":"16ee40b4.1cc15f","type":"function","z":"ceb93e8d.d8a85","name":"Load Array","func":"\nvar Marl = msg.payload.length;\nvar Marr = [...msg.payload];\nMarr.sort(function(a, b) { return a.MPos - b.MPos });\n\nmsg.payload = {\n Marl: Marl,\n Marr: Marr\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":140,"wires":[["f4db4ca8.22091"]]},{"id":"718107a2.687248","type":"delay","z":"ceb93e8d.d8a85","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1140,"y":240,"wires":[["f4db4ca8.22091"]]},{"id":"1e42066b.6c3e3a","type":"api-call-service","z":"ceb93e8d.d8a85","name":"Turn On","server":"abd879d.0389688","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"light.movie_color_group","data":"{\"brightness\":155,\"rgb_color\":[0,0,255]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":260,"y":240,"wires":[["bfaaa1f0.a93a2"]]},{"id":"38734736.f65c18","type":"file","z":"ceb93e8d.d8a85","name":"Write to csv file","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":560,"y":700,"wires":[[]]},{"id":"cac25d5e.48c45","type":"api-current-state","z":"ceb93e8d.d8a85","name":"check light","server":"abd879d.0389688","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.movie_color_group","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":330,"y":140,"wires":[["c5f6d2cb.6297c"],["1e42066b.6c3e3a"]]},{"id":"bfaaa1f0.a93a2","type":"delay","z":"ceb93e8d.d8a85","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":240,"wires":[["cac25d5e.48c45"]]},{"id":"c2c802e4.8d234","type":"api-call-service","z":"ceb93e8d.d8a85","name":"Turn Off Movie Lights","server":"abd879d.0389688","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"light.movie_color_group","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":400,"y":460,"wires":[[]]},{"id":"bdc810dd.0d714","type":"trigger-state","z":"ceb93e8d.d8a85","name":"Media Player is idle","server":"abd879d.0389688","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.kodi","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"wvu06l6cca","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"idle"},{"id":"14hjon5fa5n","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"idle"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":150,"y":460,"wires":[["c2c802e4.8d234"],[]]},{"id":"4c29fdc3.b3e804","type":"comment","z":"ceb93e8d.d8a85","name":"Movie Stopped","info":"","x":100,"y":400,"wires":[]},{"id":"abd879d.0389688","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]