Guest User

helper

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