Guest User

google home resume helper

a guest
Nov 28th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 35.73 KB | None | 0 0
  1. {
  2.   "trace": {
  3.     "last_step": "sequence/1/then/8/then/1/choose/3/sequence/1",
  4.     "run_id": "d878ecd2b3eeb8ab7b23b8aaff4534f0",
  5.     "state": "stopped",
  6.     "script_execution": "error",
  7.     "timestamp": {
  8.       "start": "2022-11-25T13:54:08.779838+00:00",
  9.       "finish": "2022-11-25T13:54:16.891039+00:00"
  10.     },
  11.     "domain": "script",
  12.     "item_id": "google_home_resume_helper",
  13.     "error": "Failed to get device id from Spotify",
  14.     "trace": {
  15.       "sequence/0": [
  16.         {
  17.           "path": "sequence/0",
  18.           "timestamp": "2022-11-25T13:54:08.781224+00:00",
  19.           "changed_variables": {
  20.             "this": {
  21.               "entity_id": "script.google_home_resume_helper",
  22.               "state": "off",
  23.               "attributes": {
  24.                 "last_triggered": "2022-11-25T13:51:27.346421+00:00",
  25.                 "mode": "parallel",
  26.                 "current": 0,
  27.                 "max": 30,
  28.                 "icon": "mdi:cast-audio",
  29.                 "friendly_name": "00 - Google Home Resume - Helper Script"
  30.               },
  31.               "last_changed": "2022-11-25T13:51:38.917067+00:00",
  32.               "last_updated": "2022-11-25T13:51:38.917067+00:00",
  33.               "context": {
  34.                 "id": "01GJQGXRD52Q5V1DBWJPW1ABJN",
  35.                 "parent_id": null,
  36.                 "user_id": null
  37.               }
  38.             },
  39.             "start_time": "2022-11-25 15:54:06.087338+02:00",
  40.             "player": {
  41.               "data_source": "resume_script",
  42.               "entity_id": "media_player.ufficio_milena",
  43.               "state": "playing",
  44.               "type": "no screen",
  45.               "members": [],
  46.               "app_name": "Spotify",
  47.               "volume_level": 0.3,
  48.               "media_content_id": "spotify:track:7wfxf9QXBIWgBx1aG5QWhR",
  49.               "media_position": 134.11,
  50.               "spotcast": "milena_dacheva"
  51.             },
  52.             "member_data": [],
  53.             "players_to_resume": [
  54.               "media_player.ufficio_milena"
  55.             ],
  56.             "event_script": false,
  57.             "resume": true,
  58.             "ytube_resume": false,
  59.             "action_type": "resume",
  60.             "resume_delay": {
  61.               "seconds": 20
  62.             },
  63.             "context": {
  64.               "id": "01GJQH284421RHYVGRM3VGKPSY",
  65.               "parent_id": null,
  66.               "user_id": "2a298aebc80446749be35680bdc494b1"
  67.             }
  68.           }
  69.         }
  70.       ],
  71.       "sequence/1": [
  72.         {
  73.           "path": "sequence/1",
  74.           "timestamp": "2022-11-25T13:54:08.781278+00:00",
  75.           "changed_variables": {
  76.             "version": "2022.11.8"
  77.           },
  78.           "error": "Failed to get device id from Spotify",
  79.           "result": {
  80.             "choice": "then"
  81.           }
  82.         }
  83.       ],
  84.       "sequence/1/if": [
  85.         {
  86.           "path": "sequence/1/if",
  87.           "timestamp": "2022-11-25T13:54:08.781311+00:00",
  88.           "result": {
  89.             "result": true
  90.           }
  91.         }
  92.       ],
  93.       "sequence/1/if/condition/0": [
  94.         {
  95.           "path": "sequence/1/if/condition/0",
  96.           "timestamp": "2022-11-25T13:54:08.781328+00:00",
  97.           "result": {
  98.             "result": true,
  99.             "entities": []
  100.           }
  101.         }
  102.       ],
  103.       "sequence/1/then/0": [
  104.         {
  105.           "path": "sequence/1/then/0",
  106.           "timestamp": "2022-11-25T13:54:08.781520+00:00"
  107.         }
  108.       ],
  109.       "sequence/1/then/1": [
  110.         {
  111.           "path": "sequence/1/then/1",
  112.           "timestamp": "2022-11-25T13:54:08.781661+00:00",
  113.           "changed_variables": {
  114.             "image": false,
  115.             "dashboard_cast": false
  116.           },
  117.           "result": {
  118.             "wait": {
  119.               "remaining": 30,
  120.               "completed": true
  121.             }
  122.           }
  123.         }
  124.       ],
  125.       "sequence/1/then/2": [
  126.         {
  127.           "path": "sequence/1/then/2",
  128.           "timestamp": "2022-11-25T13:54:08.781863+00:00",
  129.           "changed_variables": {
  130.             "wait": {
  131.               "remaining": 30,
  132.               "completed": true
  133.             }
  134.           }
  135.         }
  136.       ],
  137.       "sequence/1/then/3": [
  138.         {
  139.           "path": "sequence/1/then/3",
  140.           "timestamp": "2022-11-25T13:54:08.781980+00:00",
  141.           "changed_variables": {
  142.             "state_changed": true,
  143.             "current_volume": 0.8,
  144.             "data_volume": 0.3
  145.           },
  146.           "result": {
  147.             "params": {
  148.               "domain": "group",
  149.               "service": "set",
  150.               "service_data": {
  151.                 "object_id": "resume_active_ghresume_01gjqh284421rhyvgrm3vgkpsy",
  152.                 "name": "Entities which will be resumed by the Google Home Resume script",
  153.                 "icon": "mdi:autorenew",
  154.                 "entities": [
  155.                   "media_player.ufficio_milena"
  156.                 ]
  157.               },
  158.               "target": {}
  159.             },
  160.             "running_script": false,
  161.             "limit": 10
  162.           }
  163.         }
  164.       ],
  165.       "sequence/1/then/4": [
  166.         {
  167.           "path": "sequence/1/then/4",
  168.           "timestamp": "2022-11-25T13:54:08.783586+00:00",
  169.           "result": {
  170.             "wait": {
  171.               "remaining": null,
  172.               "completed": true
  173.             }
  174.           }
  175.         }
  176.       ],
  177.       "sequence/1/then/5": [
  178.         {
  179.           "path": "sequence/1/then/5",
  180.           "timestamp": "2022-11-25T13:54:13.721279+00:00",
  181.           "changed_variables": {
  182.             "wait": {
  183.               "remaining": null,
  184.               "completed": true
  185.             }
  186.           }
  187.         }
  188.       ],
  189.       "sequence/1/then/5/if": [
  190.         {
  191.           "path": "sequence/1/then/5/if",
  192.           "timestamp": "2022-11-25T13:54:13.721320+00:00",
  193.           "result": {
  194.             "result": false
  195.           }
  196.         }
  197.       ],
  198.       "sequence/1/then/5/if/condition/0": [
  199.         {
  200.           "path": "sequence/1/then/5/if/condition/0",
  201.           "timestamp": "2022-11-25T13:54:13.721335+00:00",
  202.           "result": {
  203.             "result": false,
  204.             "entities": []
  205.           }
  206.         }
  207.       ],
  208.       "sequence/1/then/6": [
  209.         {
  210.           "path": "sequence/1/then/6",
  211.           "timestamp": "2022-11-25T13:54:13.721408+00:00",
  212.           "result": {
  213.             "choice": "then"
  214.           }
  215.         }
  216.       ],
  217.       "sequence/1/then/6/if": [
  218.         {
  219.           "path": "sequence/1/then/6/if",
  220.           "timestamp": "2022-11-25T13:54:13.721428+00:00",
  221.           "result": {
  222.             "result": true
  223.           }
  224.         }
  225.       ],
  226.       "sequence/1/then/6/if/condition/0": [
  227.         {
  228.           "path": "sequence/1/then/6/if/condition/0",
  229.           "timestamp": "2022-11-25T13:54:13.721440+00:00",
  230.           "result": {
  231.             "result": true,
  232.             "entities": []
  233.           }
  234.         }
  235.       ],
  236.       "sequence/1/then/6/then/0": [
  237.         {
  238.           "path": "sequence/1/then/6/then/0",
  239.           "timestamp": "2022-11-25T13:54:13.722430+00:00"
  240.         }
  241.       ],
  242.       "sequence/1/then/6/then/0/repeat/sequence/0": [
  243.         {
  244.           "path": "sequence/1/then/6/then/0/repeat/sequence/0",
  245.           "timestamp": "2022-11-25T13:54:13.722662+00:00",
  246.           "changed_variables": {
  247.             "repeat": {
  248.               "first": true,
  249.               "index": 1,
  250.               "last": true,
  251.               "item": "media_player.ufficio_milena"
  252.             }
  253.           },
  254.           "result": {
  255.             "params": {
  256.               "domain": "media_player",
  257.               "service": "volume_set",
  258.               "service_data": {
  259.                 "volume_level": 0.3,
  260.                 "entity_id": [
  261.                   "media_player.ufficio_milena"
  262.                 ]
  263.               },
  264.               "target": {
  265.                 "entity_id": [
  266.                   "media_player.ufficio_milena"
  267.                 ]
  268.               }
  269.             },
  270.             "running_script": false,
  271.             "limit": 10
  272.           }
  273.         }
  274.       ],
  275.       "sequence/1/then/7": [
  276.         {
  277.           "path": "sequence/1/then/7",
  278.           "timestamp": "2022-11-25T13:54:13.724481+00:00"
  279.         }
  280.       ],
  281.       "sequence/1/then/7/if": [
  282.         {
  283.           "path": "sequence/1/then/7/if",
  284.           "timestamp": "2022-11-25T13:54:13.724523+00:00",
  285.           "result": {
  286.             "result": false
  287.           }
  288.         }
  289.       ],
  290.       "sequence/1/then/7/if/condition/0": [
  291.         {
  292.           "path": "sequence/1/then/7/if/condition/0",
  293.           "timestamp": "2022-11-25T13:54:13.724537+00:00",
  294.           "result": {
  295.             "result": false,
  296.             "entities": []
  297.           }
  298.         }
  299.       ],
  300.       "sequence/1/then/8": [
  301.         {
  302.           "path": "sequence/1/then/8",
  303.           "timestamp": "2022-11-25T13:54:13.724620+00:00",
  304.           "error": "Failed to get device id from Spotify",
  305.           "result": {
  306.             "choice": "then"
  307.           }
  308.         }
  309.       ],
  310.       "sequence/1/then/8/if": [
  311.         {
  312.           "path": "sequence/1/then/8/if",
  313.           "timestamp": "2022-11-25T13:54:13.724641+00:00",
  314.           "result": {
  315.             "result": true
  316.           }
  317.         }
  318.       ],
  319.       "sequence/1/then/8/if/condition/0": [
  320.         {
  321.           "path": "sequence/1/then/8/if/condition/0",
  322.           "timestamp": "2022-11-25T13:54:13.724652+00:00",
  323.           "result": {
  324.             "result": true,
  325.             "entities": []
  326.           }
  327.         }
  328.       ],
  329.       "sequence/1/then/8/then/0": [
  330.         {
  331.           "path": "sequence/1/then/8/then/0",
  332.           "timestamp": "2022-11-25T13:54:13.724833+00:00"
  333.         }
  334.       ],
  335.       "sequence/1/then/8/then/1": [
  336.         {
  337.           "path": "sequence/1/then/8/then/1",
  338.           "timestamp": "2022-11-25T13:54:13.725021+00:00",
  339.           "changed_variables": {
  340.             "ytube_music": false,
  341.             "spotify": true,
  342.             "youtube": false,
  343.             "podcast": false,
  344.             "stream": false,
  345.             "mass": false
  346.           },
  347.           "error": "Failed to get device id from Spotify",
  348.           "result": {
  349.             "choice": 3
  350.           }
  351.         }
  352.       ],
  353.       "sequence/1/then/8/then/1/choose/0": [
  354.         {
  355.           "path": "sequence/1/then/8/then/1/choose/0",
  356.           "timestamp": "2022-11-25T13:54:13.725046+00:00",
  357.           "result": {
  358.             "result": false
  359.           }
  360.         }
  361.       ],
  362.       "sequence/1/then/8/then/1/choose/0/conditions/0": [
  363.         {
  364.           "path": "sequence/1/then/8/then/1/choose/0/conditions/0",
  365.           "timestamp": "2022-11-25T13:54:13.725058+00:00",
  366.           "result": {
  367.             "result": false,
  368.             "entities": []
  369.           }
  370.         }
  371.       ],
  372.       "sequence/1/then/8/then/1/choose/1": [
  373.         {
  374.           "path": "sequence/1/then/8/then/1/choose/1",
  375.           "timestamp": "2022-11-25T13:54:13.725106+00:00",
  376.           "result": {
  377.             "result": false
  378.           }
  379.         }
  380.       ],
  381.       "sequence/1/then/8/then/1/choose/1/conditions/0": [
  382.         {
  383.           "path": "sequence/1/then/8/then/1/choose/1/conditions/0",
  384.           "timestamp": "2022-11-25T13:54:13.725117+00:00",
  385.           "result": {
  386.             "result": false,
  387.             "entities": []
  388.           }
  389.         }
  390.       ],
  391.       "sequence/1/then/8/then/1/choose/2": [
  392.         {
  393.           "path": "sequence/1/then/8/then/1/choose/2",
  394.           "timestamp": "2022-11-25T13:54:13.725158+00:00",
  395.           "result": {
  396.             "result": false
  397.           }
  398.         }
  399.       ],
  400.       "sequence/1/then/8/then/1/choose/2/conditions/0": [
  401.         {
  402.           "path": "sequence/1/then/8/then/1/choose/2/conditions/0",
  403.           "timestamp": "2022-11-25T13:54:13.725168+00:00",
  404.           "result": {
  405.             "result": false,
  406.             "entities": []
  407.           }
  408.         }
  409.       ],
  410.       "sequence/1/then/8/then/1/choose/3": [
  411.         {
  412.           "path": "sequence/1/then/8/then/1/choose/3",
  413.           "timestamp": "2022-11-25T13:54:13.725208+00:00",
  414.           "result": {
  415.             "result": true
  416.           }
  417.         }
  418.       ],
  419.       "sequence/1/then/8/then/1/choose/3/conditions/0": [
  420.         {
  421.           "path": "sequence/1/then/8/then/1/choose/3/conditions/0",
  422.           "timestamp": "2022-11-25T13:54:13.725218+00:00",
  423.           "result": {
  424.             "result": true,
  425.             "entities": []
  426.           }
  427.         }
  428.       ],
  429.       "sequence/1/then/8/then/1/choose/3/sequence/0": [
  430.         {
  431.           "path": "sequence/1/then/8/then/1/choose/3/sequence/0",
  432.           "timestamp": "2022-11-25T13:54:13.725349+00:00"
  433.         }
  434.       ],
  435.       "sequence/1/then/8/then/1/choose/3/sequence/1": [
  436.         {
  437.           "path": "sequence/1/then/8/then/1/choose/3/sequence/1",
  438.           "timestamp": "2022-11-25T13:54:13.725476+00:00",
  439.           "changed_variables": {
  440.             "service_data": {
  441.               "entity_id": "media_player.ufficio_milena",
  442.               "force_playback": true
  443.             },
  444.             "account_data": {
  445.               "account": "milena_dacheva"
  446.             }
  447.           },
  448.           "error": "Failed to get device id from Spotify",
  449.           "result": {
  450.             "params": {
  451.               "domain": "spotcast",
  452.               "service": "start",
  453.               "service_data": {
  454.                 "entity_id": "media_player.ufficio_milena",
  455.                 "force_playback": true,
  456.                 "account": "milena_dacheva"
  457.               },
  458.               "target": {}
  459.             },
  460.             "running_script": false,
  461.             "limit": 10
  462.           }
  463.         }
  464.       ]
  465.     },
  466.     "config": {
  467.       "alias": "00 - Google Home Resume - Helper Script",
  468.       "description": "Helper script for the Google Home Resume script",
  469.       "icon": "mdi:cast-audio",
  470.       "mode": "parallel",
  471.       "max": 30,
  472.       "sequence": [
  473.         {
  474.           "alias": "Variable for version number",
  475.           "variables": {
  476.             "version": "2022.11.8"
  477.           }
  478.         },
  479.         {
  480.           "if": "{{ action_type == 'resume' }}",
  481.           "then": [
  482.             {
  483.               "variables": {
  484.                 "image": "{{\n  state_attr(player.entity_id, 'media_content_id') is not none\n  and (\n        'jpg' in state_attr(player.entity_id, 'media_content_id') | lower\n        or 'jpeg' in state_attr(player.entity_id, 'media_content_id') | lower\n        or 'png' in state_attr(player.entity_id, 'media_content_id') | lower\n        or 'gif' in state_attr(player.entity_id, 'media_content_id') | lower\n        or 'webp' in state_attr(player.entity_id, 'media_content_id') | lower\n      )\n}}\n",
  485.                 "dashboard_cast": "{{ is_state_attr(player.entity_id, 'app_name', 'Home Assistant Lovelace') }}"
  486.               }
  487.             },
  488.             {
  489.               "alias": "State changed since script started?",
  490.               "wait_template": "{{\n  event_script\n  or ytube_resume\n  or (\n      (states[player.entity_id].last_changed > as_datetime(start_time))\n      and expand([player.entity_id] + player.members)\n            | selectattr('state', 'eq', 'playing')\n            | list | count > 0\n    )\n  or image\n  or dashboard_cast\n}}\n",
  491.               "timeout": "00:00:30"
  492.             },
  493.             {
  494.               "variables": {
  495.                 "state_changed": "{{ wait.completed }}",
  496.                 "current_volume": "{{ state_attr(player.entity_id, 'volume_level') | round(2, default=0) }}",
  497.                 "data_volume": "{{ player.volume_level | round(2, default=0) }}"
  498.               }
  499.             },
  500.             {
  501.               "alias": "Add entity to the restore active group",
  502.               "service": "group.set",
  503.               "data": {
  504.                 "object_id": "resume_active_ghresume_{{ context.id | lower }}",
  505.                 "name": "Entities which will be resumed by the Google Home Resume script",
  506.                 "icon": "mdi:autorenew",
  507.                 "entities": "{%- set g = 'group.resume_active_ghresume_' ~ context.id | lower %} {%- set current = state_attr(g, 'entity_id') %} {%- set current = [] if current == none else current | list %} {{ ( current + [ player.entity_id ] ) | unique | list }}\n"
  508.               }
  509.             },
  510.             {
  511.               "alias": "Wait until player is idle again, and all other scripts are finished",
  512.               "wait_template": "{%- set current = expand(states.group\n                    | selectattr('entity_id', 'search', 'group.resume_script_target_')\n                    | rejectattr('entity_id', 'search', context)\n                    | map(attribute='entity_id')\n                    | list) | map(attribute='entity_id') | list\n%} {%- set checklist = [player.entity_id] + player.members %} {{\n  dashboard_cast or\n  expand(checklist) | rejectattr('state', 'in', ['idle', 'off', 'paused']) | list | count == 0\n  and current | select('eq', player.entity_id) | list | count == 0\n}}\n"
  513.             },
  514.             {
  515.               "if": "{{ image or dashboard_cast }}",
  516.               "then": [
  517.                 {
  518.                   "delay": "{{ resume_delay }}"
  519.                 }
  520.               ]
  521.             },
  522.             {
  523.               "alias": "Restore volume in case volume has changed",
  524.               "if": "{{ data_volume != current_volume }}",
  525.               "then": [
  526.                 {
  527.                   "alias": "Restore volume",
  528.                   "repeat": {
  529.                     "for_each": "{{ player.members if player.type == 'group' else [ player.entity_id ] }}",
  530.                     "sequence": [
  531.                       {
  532.                         "alias": "Set volume back to old state",
  533.                         "service": "media_player.volume_set",
  534.                         "target": {
  535.                           "entity_id": "{{ repeat.item }}"
  536.                         },
  537.                         "data": {
  538.                           "volume_level": "{%- if player.type == 'group' %}\n  {{ member_data | selectattr('entity_id', 'eq', repeat.item) | map(attribute='volume_level') | join }}\n{%- else %}\n  {{ data_volume }}\n{%- endif %}\n"
  539.                         }
  540.                       }
  541.                     ]
  542.                   }
  543.                 }
  544.               ]
  545.             },
  546.             {
  547.               "alias": "Google Home with screen back to idle screen",
  548.               "if": "{{ player.type == 'screen' and not resume }}",
  549.               "then": [
  550.                 {
  551.                   "alias": "Turn Google Home off to return to idle mode (photo display)",
  552.                   "service": "media_player.turn_off",
  553.                   "target": {
  554.                     "entity_id": "{{ player.entity_id }}"
  555.                   }
  556.                 }
  557.               ]
  558.             },
  559.             {
  560.               "alias": "Resume needed?",
  561.               "if": "{{ ytube_resume or (state_changed and resume) }}",
  562.               "then": [
  563.                 {
  564.                   "alias": "Set variables",
  565.                   "variables": {
  566.                     "ytube_music": "{{ player.app_name == 'Ytube Music Player' }}\n",
  567.                     "spotify": "{{ player.app_name == 'Spotify' }}\n",
  568.                     "youtube": "{{ player.app_name in ['YouTube', 'YouTube Music'] }}\n",
  569.                     "podcast": "{{ player.app_name == 'Google Podcasts' }}\n",
  570.                     "stream": "{{\n  player.media_content_id is defined\n  and player.media_content_id.startswith('http')\n}}\n",
  571.                     "mass": "{{ player.get('mass_playing') | default(false, true) }}"
  572.                   }
  573.                 },
  574.                 {
  575.                   "alias": "Resume playing",
  576.                   "choose": [
  577.                     {
  578.                       "alias": "Music Assistant?",
  579.                       "conditions": "{{ mass }}",
  580.                       "sequence": [
  581.                         {
  582.                           "service": "mass.queue_command",
  583.                           "data": {
  584.                             "command": "snapshot_restore"
  585.                           },
  586.                           "target": {
  587.                             "entity_id": "{{ player.mass_sync }}"
  588.                           }
  589.                         }
  590.                       ]
  591.                     },
  592.                     {
  593.                       "alias": "Ytube Music?",
  594.                       "conditions": "{{ ytube_music }}",
  595.                       "sequence": [
  596.                         {
  597.                           "variables": {
  598.                             "player_ytube": "{{ player.yt_player }}"
  599.                           }
  600.                         },
  601.                         {
  602.                           "service": "ytube_music_player.call_method",
  603.                           "data": {
  604.                             "entity_id": "{{ player_ytube }}",
  605.                             "command": "interrupt_resume"
  606.                           }
  607.                         },
  608.                         {
  609.                           "alias": "Wait until song is playing",
  610.                           "wait_template": "{{ iif(state_attr(player_ytube, '_media_id')) and iif(state_attr(player_ytube, 'media_position')) }}\n",
  611.                           "timeout": "00:00:10"
  612.                         },
  613.                         {
  614.                           "alias": "Go to the right position in the track when resume is performed",
  615.                           "if": "{{ wait.completed }}",
  616.                           "then": [
  617.                             {
  618.                               "alias": "Seek",
  619.                               "service": "media_player.media_seek",
  620.                               "target": {
  621.                                 "entity_id": "{{ player_ytube }}"
  622.                               },
  623.                               "data": {
  624.                                 "seek_position": "{{ player.media_position }}"
  625.                               }
  626.                             }
  627.                           ]
  628.                         }
  629.                       ]
  630.                     },
  631.                     {
  632.                       "alias": "YouTube?",
  633.                       "conditions": "{{ player.type == 'screen' and youtube }}",
  634.                       "sequence": [
  635.                         {
  636.                           "alias": "Play video",
  637.                           "service": "media_player.play_media",
  638.                           "target": {
  639.                             "entity_id": "{{ player.entity_id }}"
  640.                           },
  641.                           "data": {
  642.                             "media_content_type": "cast",
  643.                             "media_content_id": "{{ dict(app_name=\"youtube\", media_id=player.media_content_id) | to_json }}"
  644.                           }
  645.                         },
  646.                         {
  647.                           "alias": "Wait until video is playing",
  648.                           "wait_template": "{{\n  is_state_attr(player.entity_id, 'media_content_id', player.media_content_id)\n  and iif(state_attr(player.entity_id, 'media_position'))\n}}\n",
  649.                           "timeout": "00:00:10"
  650.                         },
  651.                         {
  652.                           "alias": "Go to the right position in the track when resume is performed",
  653.                           "if": "{{ wait.completed }}",
  654.                           "then": [
  655.                             {
  656.                               "alias": "Seek",
  657.                               "service": "media_player.media_seek",
  658.                               "target": {
  659.                                 "entity_id": "{{ player.entity_id }}"
  660.                               },
  661.                               "data": {
  662.                                 "seek_position": "{{ [0, player.media_position - 3] | max }}\n"
  663.                               }
  664.                             }
  665.                           ]
  666.                         }
  667.                       ]
  668.                     },
  669.                     {
  670.                       "alias": "Spotify?",
  671.                       "conditions": "{{ spotify }}",
  672.                       "sequence": [
  673.                         {
  674.                           "variables": {
  675.                             "service_data": {
  676.                               "entity_id": "{{ player.entity_id }}",
  677.                               "force_playback": true
  678.                             },
  679.                             "account_data": {
  680.                               "account": "{{ player.spotcast }}"
  681.                             }
  682.                           }
  683.                         },
  684.                         {
  685.                           "alias": "Resume spotify",
  686.                           "service": "spotcast.start",
  687.                           "data": "{{ service_data if player.spotcast == 'primary_account' else dict(service_data, **account_data) }}\n"
  688.                         },
  689.                         {
  690.                           "alias": "Wait until song is playing",
  691.                           "wait_template": "{{ is_state_attr(player.entity_id, 'app_name', 'Spotify') and iif(state_attr(player.entity_id, 'media_position')) }}\n",
  692.                           "timeout": "00:00:10"
  693.                         },
  694.                         {
  695.                           "alias": "Go t the right position in the track when resume is performed",
  696.                           "if": "{{ wait.completed }}",
  697.                           "then": [
  698.                             {
  699.                               "alias": "Seek",
  700.                               "service": "media_player.media_seek",
  701.                               "target": {
  702.                                 "entity_id": "{{ player.entity_id }}"
  703.                               },
  704.                               "data": {
  705.                                 "seek_position": "{{ player.media_position }}"
  706.                               }
  707.                             }
  708.                           ]
  709.                         }
  710.                       ]
  711.                     },
  712.                     {
  713.                       "alias": "Google Podcast?",
  714.                       "conditions": "{{ podcast }}",
  715.                       "sequence": [
  716.                         {
  717.                           "variables": {
  718.                             "picture_url": "{{ player.fixed_picture if player.fixed_picture is defined else player.entity_picture }}",
  719.                             "metadata": {
  720.                               "metadataType": 3,
  721.                               "title": "{{ player.media_title }}",
  722.                               "artist": "{{ player.media_artist }}"
  723.                             },
  724.                             "picture": {
  725.                               "images": [
  726.                                 {
  727.                                   "url": "{{ picture_url }}"
  728.                                 }
  729.                               ]
  730.                             }
  731.                           }
  732.                         },
  733.                         {
  734.                           "alias": "Resume stream",
  735.                           "service": "media_player.play_media",
  736.                           "target": {
  737.                             "entity_id": "{{ player.entity_id }}"
  738.                           },
  739.                           "data": {
  740.                             "media_content_id": "{{ player.media_content_id }}",
  741.                             "media_content_type": "{{ player.media_content_type }}",
  742.                             "extra": {
  743.                               "metadata": "{{ metadata if picture_url == 'no pic' else dict(metadata, **picture) }}\n"
  744.                             }
  745.                           }
  746.                         },
  747.                         {
  748.                           "alias": "Wait until media_content_id is available",
  749.                           "wait_template": "{{ is_state_attr(player.entity_id, 'media_content_id', player.media_content_id) }}",
  750.                           "timeout": "00:00:10"
  751.                         },
  752.                         {
  753.                           "alias": "Go to the right position in the track when resume is performed",
  754.                           "if": "{{ wait.completed }}",
  755.                           "then": [
  756.                             {
  757.                               "alias": "Play (avoids long delay)",
  758.                               "service": "media_player.media_play",
  759.                               "target": {
  760.                                 "entity_id": "{{ player.entity_id }}"
  761.                               }
  762.                             },
  763.                             {
  764.                               "alias": "Seek",
  765.                               "service": "media_player.media_seek",
  766.                               "target": {
  767.                                 "entity_id": "{{ player.entity_id }}"
  768.                               },
  769.                               "data": {
  770.                                 "seek_position": "{{ player.media_position }}"
  771.                               }
  772.                             }
  773.                           ]
  774.                         }
  775.                       ]
  776.                     },
  777.                     {
  778.                       "alias": "Stream?",
  779.                       "conditions": "{{ stream }}",
  780.                       "sequence": [
  781.                         {
  782.                           "variables": {
  783.                             "picture_url": "{{ player.entity_picture }}",
  784.                             "metadata": {
  785.                               "metadataType": 3,
  786.                               "title": "{{ player.media_title }}",
  787.                               "artist": "{{ player.media_artist }}"
  788.                             },
  789.                             "picture": {
  790.                               "images": [
  791.                                 {
  792.                                   "url": "{{ picture_url }}"
  793.                                 }
  794.                               ]
  795.                             }
  796.                           }
  797.                         },
  798.                         {
  799.                           "alias": "Resume stream",
  800.                           "service": "media_player.play_media",
  801.                           "target": {
  802.                             "entity_id": "{{ player.entity_id }}"
  803.                           },
  804.                           "data": {
  805.                             "media_content_id": "{{ player.media_content_id }}",
  806.                             "media_content_type": "{{ player.media_content_type }}",
  807.                             "extra": {
  808.                               "metadata": "{{ metadata if picture_url == 'no pic' else dict(metadata, **picture) }}\n"
  809.                             }
  810.                           }
  811.                         },
  812.                         {
  813.                           "alias": "Wait until media_content_id is available",
  814.                           "wait_template": "{{ is_state_attr(player.entity_id, 'media_content_id', player.media_content_id) }}",
  815.                           "timeout": "00:00:10"
  816.                         },
  817.                         {
  818.                           "alias": "Go to the right position in the track when resume is performed",
  819.                           "if": "{{ wait.completed }}",
  820.                           "then": [
  821.                             {
  822.                               "alias": "Play (avoids long delay)",
  823.                               "service": "media_player.media_play",
  824.                               "target": {
  825.                                 "entity_id": "{{ player.entity_id }}"
  826.                               }
  827.                             }
  828.                           ]
  829.                         }
  830.                       ]
  831.                     }
  832.                   ]
  833.                 }
  834.               ]
  835.             },
  836.             {
  837.               "alias": "Check if resume_action_false group exists",
  838.               "if": "{{ integration_entities('group') | select('search', 'resume_action_false_ghresume_' ~ context.id | lower) | list | count > 0 }}\n",
  839.               "then": [
  840.                 {
  841.                   "alias": "Remove entity from group",
  842.                   "service": "group.set",
  843.                   "data": {
  844.                     "object_id": "resume_action_false_ghresume_{{ context.id | lower }}",
  845.                     "name": "Entities with actions which should not be resumed",
  846.                     "icon": "mdi:alert-octagon",
  847.                     "entities": "{%- set current = state_attr('group.resume_action_false_ghresume' ~ context.id | lower, 'entity_id') %} {{ iif(current == none, [], current) | reject('eq', player.entity_id) | list }}\n"
  848.                   }
  849.                 }
  850.               ]
  851.             },
  852.             {
  853.               "alias": "Remove entity from group",
  854.               "service": "group.set",
  855.               "data": {
  856.                 "object_id": "resume_active_ghresume_{{ context.id | lower }}",
  857.                 "name": "Entities which will be resumed by the Google Home Resume script",
  858.                 "icon": "mdi:autorenew",
  859.                 "entities": "{%- set g = 'group.resume_active_ghresume_' ~ context.id | lower %} {%- set current = state_attr(g, 'entity_id') %} {{ iif(current == none, [], current) | reject('eq', player.entity_id) | list }}\n"
  860.               }
  861.             },
  862.             {
  863.               "alias": "Remove entity from group",
  864.               "service": "group.set",
  865.               "data": {
  866.                 "object_id": "resume_script_active_ghresume_{{ context.id | lower }}",
  867.                 "name": "Entities currently active with Google Home Resume script",
  868.                 "icon": "mdi:play-box",
  869.                 "entities": "{%- set g = 'group.resume_script_active_ghresume_' ~ context.id | lower %} {%- set current = state_attr(g, 'entity_id') %} {{ iif(current == none, [], current) | reject('eq', player.entity_id) | list }}\n"
  870.               }
  871.             }
  872.           ],
  873.           "else": [
  874.             {
  875.               "wait_for_trigger": [
  876.                 {
  877.                   "platform": "event",
  878.                   "event_type": "call_service",
  879.                   "event_data": {
  880.                     "domain": "media_player",
  881.                     "service": "play_media",
  882.                     "service_data": {
  883.                       "media_content_type": "music",
  884.                       "entity_id": "{{ [ dummy_player ] }}"
  885.                     }
  886.                   }
  887.                 }
  888.               ]
  889.             },
  890.             {
  891.               "alias": "Send TTS message with picture",
  892.               "service": "media_player.play_media",
  893.               "target": "{{ target }}",
  894.               "data": {
  895.                 "media_content_id": "{{ wait.trigger.event.data.service_data.media_content_id }}",
  896.                 "media_content_type": "music",
  897.                 "announce": true,
  898.                 "extra": {
  899.                   "metadata": {
  900.                     "metadataType": 3,
  901.                     "title": "{{ large_text }}",
  902.                     "artist": "{{ small_text }}",
  903.                     "images": [
  904.                       {
  905.                         "url": "{{ picture_url }}"
  906.                       }
  907.                     ]
  908.                   }
  909.                 }
  910.               }
  911.             }
  912.           ]
  913.         }
  914.       ]
  915.     },
  916.     "blueprint_inputs": null,
  917.     "context": {
  918.       "id": "01GJQH284421RHYVGRM3VGKPSY",
  919.       "parent_id": null,
  920.       "user_id": "2a298aebc80446749be35680bdc494b1"
  921.     }
  922.   },
  923.   "logbookEntries": [
  924.     {
  925.       "when": 1669384448.779887,
  926.       "state": "on",
  927.       "entity_id": "script.google_home_resume_helper",
  928.       "icon": "mdi:cast-audio",
  929.       "context_user_id": "2a298aebc80446749be35680bdc494b1"
  930.     },
  931.     {
  932.       "when": 1669384458.553114,
  933.       "state": "paused",
  934.       "entity_id": "media_player.ufficio_milena",
  935.       "context_user_id": "2a298aebc80446749be35680bdc494b1",
  936.       "context_state": "on",
  937.       "context_entity_id": "script.google_home_resume_helper"
  938.     }
  939.   ]
  940. }
Add Comment
Please, Sign In to add comment