Integrate Netflix Now Playing sensor in to Media control card?

I created a Node-Red flow that is capable of showing me what is currently playing on Netflix for my account.

I still need to add a loop and switch to trigger this flow when Netflix is active but for now I want to find out if it is possible to use the created sensor as a now playing source in a Media Control card?
Is such thing possible with a Media Control card or any other card?
Use a different sensor as Now Playing source?


If you want to use this flow follow the instructions in this video: https://www.youtube.com/watch?v=Lqo-Lf-iq60 on how to get the needed links/cookie data and add Node-RED Companion Integration using HACS.
When imported edit nodes: http request, change and sensor

All credits for ibleedcubbieblue26 who created the initial flow.

I ran in to some issues that certain Netflix titles contained double information so i stripped it and this is the result.

vivaldi_0Z1Vje48vu

The full node-red flow:
Note: It can probably be optimized but for me it works now.

[{"id":"a7c84c79bae391c2","type":"tab","label":"Netflix Now Playing","disabled":false,"info":"","env":[]},{"id":"fa5a8027e7898f2e","type":"inject","z":"a7c84c79bae391c2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"14400","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["875601fd8ad74584"]]},{"id":"aa8217f31a7bd270","type":"debug","z":"a7c84c79bae391c2","name":"debug 10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":160,"wires":[]},{"id":"875601fd8ad74584","type":"http request","z":"a7c84c79bae391c2","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"<insert netflix viewing activity url here>","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"cookie","valueType":"other","valueValue":"<insert cookie data here>"}],"x":170,"y":160,"wires":[["dc3586b3fab31b48"]]},{"id":"dc3586b3fab31b48","type":"html","z":"a7c84c79bae391c2","name":"","property":"payload","outproperty":"payload","tag":"#appMountPoint > div > div > div > div.bd > div > div > ul","ret":"html","as":"single","x":285,"y":160,"wires":[["a77235aafdf2e7c8"]],"l":false},{"id":"ee290267f7626243","type":"ha-sensor","z":"a7c84c79bae391c2","name":"schumi2004 Netflix Now Playing","entityConfig":"ec75a1e558bbb195","version":0,"state":"schumi2004 Netflix Now Playing","stateType":"str","attributes":[{"property":"data","value":"payload[0]","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":810,"y":100,"wires":[["aa8217f31a7bd270"]]},{"id":"a77235aafdf2e7c8","type":"change","z":"a7c84c79bae391c2","name":"","rules":[{"t":"change","p":"payload[0]","pt":"msg","from":"<span class=\"tooltip\">Hide from viewing history</span>","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"<a class=\"deleteBtn\" href=\"#\">&#x2298;</a>","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"<div class=\"col report\"><a class=\"reportLink\" href=\"/reportproblem/(\\d{8})\">Report a problem</a></div><div class=\"col delete\"></div>","fromt":"re","to":"","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"<a href=\"/","fromt":"str","to":"<a href=\"https://www.netflix.com/","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"<li class=\"retableRow\">","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"</li>","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":160,"wires":[["c339b8b59524e251"]]},{"id":"3a5216fbbda128a3","type":"comment","z":"a7c84c79bae391c2","name":"schumi2004","info":"","x":130,"y":60,"wires":[]},{"id":"c339b8b59524e251","type":"function","z":"a7c84c79bae391c2","name":"Now playing","func":"// Input contains the data\nvar input = msg.payload[0];\n\n// Find the start and end positions of the desired substring\nvar start = input.indexOf('<div class=\"col title\"><a href=\"') + '<div class=\"col title\"><a href=\"'.length;\nvar end = input.indexOf('</a></div>');\n\n// Cut the substring from the input\nvar substring = input.substring(start, end);\n\n// Remove the URL and keep just the title\nsubstring = substring.replace(/https:\\/\\/www\\.netflix\\.com\\/title\\/\\d+\">/, '');\n\n// Remove random duplicates\nsubstring = removeDuplicates(substring);\n\n// Function to remove random duplicates\nfunction removeDuplicates(inputString) {\n    var words = inputString.split(/\\s+/); // Split the string into words\n    var uniqueWords = Array.from(new Set(words)); // Remove duplicates\n    var resultString = uniqueWords.join(' '); // Put the unique words back together\n    return resultString;\n}\n\n// Send the substring as output\nmsg.payload[0] = substring;\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":100,"wires":[["ee290267f7626243"]]},{"id":"ec75a1e558bbb195","type":"ha-entity-config","server":"88a41fe6.efbb1","deviceConfig":"","name":"schumi2004 Netflix Now Playing","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"schumi2004 Netflix Now Playing"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"88a41fe6.efbb1","type":"server","name":"Home Assistant RT","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
2 Likes

I’m interested in this stream but the video is no longer available can you please provide more details on how to make it work? A thousand thanks :slight_smile:

That’s a shame the user made the video private, it showed the steps how to get this data but i tried to type it out for you.
To get the viewing url and cookie information do this. First copy my Node-Red flow and insert in Node-Red, edit http request node.

Navigate to netflix.com, login and go to Account (top right corner).
At the bottom of the screen you can manage profiles, click and select the profile you want.
On the profile page should be a viewing activity button, select and copy the url. This is the url you need for → < insert netflx viewing activity url here >

For < insert cookie data here > go to developer tools, Application, Storage, Cookies and select netflix.com and make it like example below. (It can probably done faster but I cannot recall how i did it myself :smiley: )

Cookie format looks like this:
flwssn=<flwssn_cookie_data>; dsca=<dsca_cookie_data, probably customer>; nfvdid=<nfvdid_cookie_data>; SecureNetflixId=<SecureNetflixId_cookie_data>; NetflixId=<NetflixId_cookie_data>; profilesNewSession=<profilesNewSession_cookie_data, probably 0>; OptanonConsent=<OptanonConsent_cookie_data>

Use this for http request node.

The other nodes is just for how you want the data to be formatted. Just have a play with it to fit your needs.

thanks @schumi2004 I managed to get the sensor to work when I activate the flow it doesn’t give me the film I’m watching in playback but the previous one in fact in the viewing list doesn’t put the film in the list if I don’t close or finish it, so the sensor actually gives me it says the last movie watched on netflix not the one I’m watching is this how it should go? Is there no way to show him what I’m looking at at the moment? thanks a lot :slight_smile:

Maybe something has changed on Netflix end, haven’t really looked at the behavior recently but will check today or tomorrow.

/edit:
Works perfect here when i manual update and viewing my sensor.
I must say that I update my now playing sensor every time a Netflix viewing action happens so it’s always up-to-date.