Resume play from memory on Chromecast

I made a little sequence that can resume playback of where you stopped.
Say you only see half of a movie, then this sequence will save the position you stopped at and resume at that position - 2 minutes when you cast the same movie again.

The important thing is to stop the playback on the Chromecast, if you only take back the movie to your computer/phone/tablet then it will not be saved.
It also does not save the position if you seen less than 10 minutes, or if you have seen more than [media_duration] - 3 minutes.

The only thing you actually need to change in this sequence is the name of the chromecast in the events state node (top left), and the call service node (top right).
You could possibly add more sensors and have it remember more, but I find 9 more than enough.
If you want to do so then edit the large switch node and add another entity node with the same name convention.

You need to install this custom integration for it to work.

[{"id":"8f160738.cd1e78","type":"server-state-changed","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"media_player.chromecast_vardagsrum","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":300,"y":2540,"wires":[["99474dbf.3a0b4","9b850d6b.479c9","d6f312bc.6dd31"]]},{"id":"99474dbf.3a0b4","type":"switch","z":"94bc1df0.962d9","name":"","property":"data.old_state.state","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"playing","vt":"str"},{"t":"eq","v":"paused","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":610,"y":2540,"wires":[["b296cbeb.2de478"],["eaf27e51.49d42"],["eaf27e51.49d42"]]},{"id":"9b850d6b.479c9","type":"debug","z":"94bc1df0.962d9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":2460,"wires":[]},{"id":"d6f312bc.6dd31","type":"switch","z":"94bc1df0.962d9","name":"","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"eq","v":"idle","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":2640,"wires":[["eaf27e51.49d42"]]},{"id":"b296cbeb.2de478","type":"ha-wait-until","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","outputs":2,"entityId":"media_player.chromecast_vardagsrum","entityIdFilterType":"exact","property":"state","comparator":"is","value":"playing","valueType":"str","timeout":"10","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":780,"y":2500,"wires":[["6a30570e.e13f88"],[]]},{"id":"eaf27e51.49d42","type":"function","z":"94bc1df0.962d9","name":"","func":"if(typeof(msg.data.old_state.attributes.media_title) != \"undefined\"){\n    if(msg.data.old_state.attributes.media_duration - msg.data.old_state.attributes.media_position > 300 & msg.data.old_state.attributes.media_position > 600){\n        return [msg, null];     \n    }else{\n        return [null, msg];\n    }\n}else{\n    \n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":2640,"wires":[["325945ba.75386a"],["df4cd3c4.99061"]]},{"id":"6a30570e.e13f88","type":"ha-get-entities","z":"94bc1df0.962d9","server":"4bbca37b.1700ec","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"sensor.last_watched_","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"list","output_results_count":1,"x":930,"y":2440,"wires":[["d631c14d.469e8"]]},{"id":"325945ba.75386a","type":"ha-get-entities","z":"94bc1df0.962d9","server":"4bbca37b.1700ec","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"sensor.last_watched_","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"list","output_results_count":1,"x":930,"y":2640,"wires":[["c0b5405e.9c7cd"]]},{"id":"df4cd3c4.99061","type":"ha-get-entities","z":"94bc1df0.962d9","server":"4bbca37b.1700ec","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"sensor.last_watched_","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"list","output_results_count":1,"x":930,"y":2740,"wires":[["ee3bf0b9.425d1"]]},{"id":"d631c14d.469e8","type":"function","z":"94bc1df0.962d9","name":"","func":"var position = null;\nmsg.list.forEach(function (value,index){\n    if(value.attributes.media_content_id === msg.data.new_state.attributes.media_content_id){\n        if(value.attributes.app_name === msg.data.new_state.attributes.app_name){\n            position = value.attributes.media_position-120;\n        }\n    }\n});\n\nif(position != null){\n    msg.payload = {\n        data:{\n            \"entity_id\": \"media_player.chromecast_vardagsrum\",\n            \"seek_position\": position,\n        }\n    }\n    \n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1120,"y":2440,"wires":[["6eb95220.beb69c"]]},{"id":"c0b5405e.9c7cd","type":"function","z":"94bc1df0.962d9","name":"","func":"var entity = null;\n\nmsg.list.forEach(function (value,index){\n    if(value.attributes.media_content_id === msg.data.new_state.attributes.media_content_id){\n        if(value.attributes.app_name === msg.data.new_state.attributes.app_name){\n            entity = value.entity_id;\n        }\n    }\n});\n\n\nif(entity != null){\n    msg.entity_target = entity;\n}else{\n    msg.list.forEach(function (value,index){\n        if(value.attributes.media_content_id === \"\" || typeof(value.attributes.media_content_id) === \"undefined\"){\n            if(value.attributes.app_name === \"\" || typeof(value.attributes.app_name) === \"undefined\"){\n                entity = value.entity_id;\n            }\n        }\n    });\n    if(entity != null){\n        msg.entity_target = entity;\n    }\n}\nif(entity != null){\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":2640,"wires":[["30f7a3e4.2bb7ec"]]},{"id":"ee3bf0b9.425d1","type":"function","z":"94bc1df0.962d9","name":"","func":"var entity = null;\nmsg.list.forEach(function (value,index){\n    if(value.attributes.media_content_id === msg.data.old_state.attributes.media_content_id){\n        if(value.attributes.app_name === msg.data.old_state.attributes.app_name){\n            entity = value.entity_id;\n        }\n    }\n});\nif(entity != null){\n    msg.entity_target = entity;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":2740,"wires":[["f13a1458.268878"]]},{"id":"6eb95220.beb69c","type":"delay","z":"94bc1df0.962d9","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1280,"y":2440,"wires":[["5da3ee1e.7cfa4"]]},{"id":"30f7a3e4.2bb7ec","type":"function","z":"94bc1df0.962d9","name":"","func":"\nmsg.payload = {\"state\": msg.data.old_state.attributes.media_title,\n    attributes:{\n        \"media_position\": msg.data.old_state.attributes.media_position,\n        \"media_content_id\": msg.data.old_state.attributes.media_content_id,\n        \"app_name\": msg.data.old_state.attributes.app_name,\n        \"media_duration\": msg.data.old_state.attributes.media_duration\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1220,"y":2640,"wires":[["82556dd4.d15f7"]]},{"id":"f13a1458.268878","type":"function","z":"94bc1df0.962d9","name":"","func":"msg.data.old_state.attributes.media_title = \"\";\nmsg.data.old_state.attributes.media_position =\"\";\nmsg.data.old_state.attributes.media_content_id =\"\";\nmsg.data.old_state.attributes.app_name =\"\";\nmsg.data.old_state.attributes.media_duration = \"\";\n\n\n\nmsg.payload = {\"state\": msg.data.old_state.attributes.media_title,\n    attributes:{\n        \"media_position\": msg.data.old_state.attributes.media_position,\n        \"media_content_id\": msg.data.old_state.attributes.media_content_id,\n        \"app_name\": msg.data.old_state.attributes.app_name,\n        \"media_duration\": msg.data.old_state.attributes.media_duration\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1220,"y":2740,"wires":[["82556dd4.d15f7"]]},{"id":"5da3ee1e.7cfa4","type":"api-call-service","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_seek","entityId":"media_player.chromecast_vardagsrum","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1530,"y":2440,"wires":[[]]},{"id":"82556dd4.d15f7","type":"switch","z":"94bc1df0.962d9","name":"","property":"entity_target","propertyType":"msg","rules":[{"t":"null"},{"t":"eq","v":"sensor.last_watched_1","vt":"str"},{"t":"eq","v":"sensor.last_watched_2","vt":"str"},{"t":"eq","v":"sensor.last_watched_3","vt":"str"},{"t":"eq","v":"sensor.last_watched_4","vt":"str"},{"t":"eq","v":"sensor.last_watched_5","vt":"str"},{"t":"eq","v":"sensor.last_watched_6","vt":"str"},{"t":"eq","v":"sensor.last_watched_7","vt":"str"},{"t":"eq","v":"sensor.last_watched_8","vt":"str"},{"t":"eq","v":"sensor.last_watched_9","vt":"str"}],"checkall":"false","repair":false,"outputs":10,"x":1370,"y":2700,"wires":[[],["7b191636.a22828"],["fad2c31f.ae23f"],["429130a9.5e1a1"],["c53150de.7c7e7"],["28e6817d.df64ee"],["258bc35a.29279c"],["e4cc82c8.7f99c"],["e884f471.2779b8"],["2ad5d927.0275d6"]]},{"id":"830cee3c.0fd3d","type":"function","z":"94bc1df0.962d9","name":"","func":"\nmsg.payload = {\"state\": \"\",\n    attributes:{\n        \"media_position\": \"\",\n        \"media_content_id\": \"\",\n        \"app_name\": \"\",\n        \"media_duration\": \"\"\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1220,"y":2820,"wires":[["82556dd4.d15f7"]]},{"id":"7b191636.a22828","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_1","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_1"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"","stateType":"str","attributes":[{"property":"media_position","value":"","valueType":"str"},{"property":"media_content_id","value":"","valueType":"str"},{"property":"app_name","value":"","valueType":"str"},{"property":"media_duration","value":"","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2520,"wires":[[]]},{"id":"fad2c31f.ae23f","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_2","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_2"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2580,"wires":[[]]},{"id":"429130a9.5e1a1","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_3","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_3"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2640,"wires":[[]]},{"id":"c53150de.7c7e7","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_4","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_4"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2700,"wires":[[]]},{"id":"28e6817d.df64ee","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_5","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_5"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2760,"wires":[[]]},{"id":"258bc35a.29279c","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_6","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_6"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2820,"wires":[[]]},{"id":"e4cc82c8.7f99c","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_7","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_7"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2880,"wires":[[]]},{"id":"e884f471.2779b8","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_8","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_8"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":2940,"wires":[[]]},{"id":"2ad5d927.0275d6","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched_9","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"last_watched_9"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"data.old_state.attributes.media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1620,"y":3000,"wires":[[]]},{"id":"f1b79585.2b3608","type":"inject","z":"94bc1df0.962d9","name":"Clear entity","props":[{"p":"entity_target","v":"sensor.last_watched_6","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1070,"y":2820,"wires":[["830cee3c.0fd3d"]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like