cancel
Showing results for 
Search instead for 
Did you mean: 

Can automation script editor call and shuffle a YouTube music playlist

Geoff18
Community Member

Is there any way in the new automation script editor to call a YouTube music playlist, shuffle it and then play it on the speaker that the automation was started from? I would like to create a bedtime routine that is triggered when I turn off my bedroom light switch. It would dim lights and play a playlist but Unfortunately with the basic google home routine I can't use the light switch as a starter

 

Cheers, Geoff 

1 Recommended Answer

DWB1973
Community Member

You're welcome, glad I was able to help.

I found an error and fixed it; the only valid key for device.state.OnOff is 'on'. Here's an updated rough draft for you to finish. 

metadata:
  name: Untitled # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
  description: Scripted automation # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”

automations:
  # “starters” and “actions” are required; “conditions” are optional.
  # Use Ctrl + Space to see autocomplete suggestions.

  # ---- STARTERS ---- #
  # Starters describe events that will start the automation.
  # To add more than one starter, duplicate the "- type" section under "starters".
  # If you add multiple starter events, any one of them happening will start the automation
  starters:
    - type: device.state.OnOff
      state: on
      # [available operators: is, isNot]
      is: false
      device: Device Name - Room Name

  condition:
    type: time.between
    # Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
    before: 
    # Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
    after: 
    # Optional. Days of the week to apply condition on.
    weekdays:
      - MON
      - TUE
      - WED
      - THU
      - FRI
      - SAT
      - SUN
  # ---- ACTIONS ---- #
  # Actions will start when a starter event takes place and all conditions are met.
  # Actions will start in the order they appear in the script and with any delay specified.
  # To add more than one action, duplicate the "- type" section under "actions".
  actions:
    - type: device.command.SetVolume # Set the volume of a given device.
      volumeLevel: Set volume level (1-100)
      device: Speaker Name - Room Name
    - type: assistant.command.OkGoogle
      okGoogle: Play playlist name on YouTube Music
      device: Speaker Name - Room Name
    - type: device.command.MediaShuffle # Shuffle the current playlist.
      device: Speaker Name - Room Name
    - type: device.command.BrightnessAbsolute # Adjust device absolute brightness.
      brightness: 50
      device: Device Name - Room Name
    - type: device.command.LightEffectSleep
      duration: 5min
      device: Device Name - Room Name

 

TimeBetweenState guidance:

https://developers.home.google.com/automations/schema/reference/standard/time_between_state

View Recommended Answer in original post

12 REPLIES 12

DWB1973
Community Member

Hello.

I am trying to script an automation for you, but I can't guarantee that it will work perfectly on the first attempt.  Would you be more specific with the light dimming action? Over what duration do you want the lights to fade from current brightness level to off? The range options are between 5 minutes and 1 hour.  Taking advice from this post at the Google Assistant Help Community, the automation will first play the playlist and then shuffle it.

https://support.google.com/assistant/thread/163145398/google-assistant-refuses-to-shuffle-named-play...

This is what I have done so far:

 

# ------------------------------------------------------------------------------------------ #
# Lines starting with “#” are comments and will be ignored by the automation.
# Indentation determines hierarchy within the script.
# Visit g.co/home/script-editor-docs for full documentation.
# ------------------------------------------------------------------------------------------ #

metadata:
  name: Untitled # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
  description: Scripted automation # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”

automations:
  # “starters” and “actions” are required; “conditions” are optional.
  # Use Ctrl + Space to see autocomplete suggestions.

  # ---- STARTERS ---- #
  # Starters describe events that will start the automation.
  # To add more than one starter, duplicate the "- type" section under "starters".
  # If you add multiple starter events, any one of them happening will start the automation
  starters:
    - type: device.state.OnOff
      state: off
      # [available operators: is, isNot]
      is: true
      device: Light (Bedroom) - Bedroom

  # ---- ACTIONS ---- #
  # Actions will start when a starter event takes place and all conditions are met.
  # Actions will start in the order they appear in the script and with any delay specified.
  # To add more than one action, duplicate the "- type" section under "actions".
  actions:
    - type: assistant.command.OkGoogle
      okGoogle: Play <playlist name> on YouTube Music
      devices: <select speaker name - location>
    - type: device.command.MediaShuffle # Shuffle the current playlist.
      devices: <select speaker name - location>
    - type: device.command.LightEffectSleep
      duration: <set duration>
      devices: <select speaker name - location>  

 

 

Geoff18
Community Member

Hey mate, thank you so much for this. I was really stuck on the part of getting a playlist to play and then shuffle it. I didn't realise that you could put basically any ok google command in there so this should solve the music side of things.

 

I was hoping to dim my bedside lamp from say 50% to 0% over 5 minutes. Do I just need to put a command saying turn the light to 50% and then a pause of 30 seconds, then a command to tun it to 45% and then another pause and so on until it is 0%?

DWB1973
Community Member

Do I just need to put a command saying turn the light to 50% and then a pause of 30 seconds, then a command to tun it to 45% and then another pause and so on until it is 0%?

No, the LightEffectSleep command is already programmed to decrementally dim the lights over a designated period of time. I have added the command to adjust light brightness before it begins the dimming segment of the automation. Try this one:

 

 

  # ---- STARTERS ---- #
  # Starters describe events that will start the automation.
  # To add more than one starter, duplicate the "- type" section under "starters".
  # If you add multiple starter events, any one of them happening will start the automation
  starters:
    - type: device.state.OnOff
      state: off
      # [available operators: is, isNot]
      is: true
      device: <select device name - location>

  # ---- ACTIONS ---- #
  # Actions will start when a starter event takes place and all conditions are met.
  # Actions will start in the order they appear in the script and with any delay specified.
  # To add more than one action, duplicate the "- type" section under "actions".
  actions:
    - type: assistant.command.OkGoogle
      okGoogle: Play <playlist name> on YouTube Music
      devices: <select speaker name - location>
    - type: device.command.MediaShuffle # Shuffle the current playlist.
      devices: <select device name - location>
    - type: device.command.BrightnessAbsolute # Adjust device absolute brightness.
      brightness: 50
      devices: <select device name - location>
    - type: device.command.LightEffectSleep
      duration: 5min
      devices: <select device name - location>  

 

 

You may want to add a schedule condition, so the automation will only run during certain times of the day (bedtime) instead of every time the bedside lamp is turned off. Also, its probably a good idea to choose a volume level that you want the playlist to be played.

Geoff18
Community Member

Omg thank you so much for showing me how this works. As you can probably tell I'm just learning all this stuff and tbh the only programming I've ever done in the past was making a triangle draw shapes on a commodore 64 back in primary school. 

 

I'll test this out when I get a day to myself. 

 

Thanks again for all your help, it's been amazing and very educational 

DWB1973
Community Member

You're welcome, glad I was able to help.

I found an error and fixed it; the only valid key for device.state.OnOff is 'on'. Here's an updated rough draft for you to finish. 

metadata:
  name: Untitled # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
  description: Scripted automation # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”

automations:
  # “starters” and “actions” are required; “conditions” are optional.
  # Use Ctrl + Space to see autocomplete suggestions.

  # ---- STARTERS ---- #
  # Starters describe events that will start the automation.
  # To add more than one starter, duplicate the "- type" section under "starters".
  # If you add multiple starter events, any one of them happening will start the automation
  starters:
    - type: device.state.OnOff
      state: on
      # [available operators: is, isNot]
      is: false
      device: Device Name - Room Name

  condition:
    type: time.between
    # Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
    before: 
    # Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
    after: 
    # Optional. Days of the week to apply condition on.
    weekdays:
      - MON
      - TUE
      - WED
      - THU
      - FRI
      - SAT
      - SUN
  # ---- ACTIONS ---- #
  # Actions will start when a starter event takes place and all conditions are met.
  # Actions will start in the order they appear in the script and with any delay specified.
  # To add more than one action, duplicate the "- type" section under "actions".
  actions:
    - type: device.command.SetVolume # Set the volume of a given device.
      volumeLevel: Set volume level (1-100)
      device: Speaker Name - Room Name
    - type: assistant.command.OkGoogle
      okGoogle: Play playlist name on YouTube Music
      device: Speaker Name - Room Name
    - type: device.command.MediaShuffle # Shuffle the current playlist.
      device: Speaker Name - Room Name
    - type: device.command.BrightnessAbsolute # Adjust device absolute brightness.
      brightness: 50
      device: Device Name - Room Name
    - type: device.command.LightEffectSleep
      duration: 5min
      device: Device Name - Room Name

 

TimeBetweenState guidance:

https://developers.home.google.com/automations/schema/reference/standard/time_between_state

Geoff18
Community Member

Thank you so much again, I got this working and its awesome. the script even helped me write another rule for syncing my virtual door lock switch in Smartthings and the actual door lock switch in home. I'm starting to get the hang of it all. now google just need to make an easy GUI like sharptools

DWB1973
Community Member

SharpTools, eh?  Now I know you're a connoisseur of home automations.  I like their GUI layout as well, and possibly someday we can hope that the GH script editor will be similar.  By the way, if your question was answered - please mark the accepted answer.

Geoff18
Community Member

Done. Thanks again for all the help 

shelleyoguera
Community Member

While the new automation script editor doesn't have native YouTube playlist integration, you can achieve your bedtime routine by using CapCut video editor for Chromebook. First, create a video with a dark screen or soothing visuals. Then, set it to play when the bedroom light switch is turned off, along with your desired music playlist on your speaker. This way, you can create a custom bedtime experience that suits your needs.

Jorden1122
Community Member

Although the latest script automation tool lacks built-in support for YouTube playlists, you can still craft a personalized bedtime ambiance using the idle office tycoon codes  . Start by producing a video featuring calming imagery or a simple dark screen. Next, configure the system to play this video in response to turning off the bedroom lights, simultaneously initiating a relaxing music playlist on your speaker. This method allows you to tailor a unique nighttime setting that aligns with your preferences.

GPatricia
Community Member

An automation script editor typically doesn't have direct control over YouTube playlists, which means it can't shuffle them without using third-party APIs or applications. To achieve playlist shuffling or calling from an automation script, you would need a combination of a YouTube API and an automation tool, which could require significant coding and setup.

Regarding the "TikTok downloader," be aware that downloading content from platforms like TikTok may violate their terms of service and copyright laws, so it's essential to ensure any download is legal and respects the rights of content creators. If you want to download TikTok content, there are specific tools available, but use them cautiously and ethically.

When using automation tools, ensure you're adhering to YouTube's and other platforms' policies and respecting copyright laws. If you need to shuffle a YouTube playlist, consider using YouTube's built-in features or third-party applications designed specifically for that purpose, but ensure these applications comply with YouTube's terms of service and copyright guidelines.

GPatricia
Community Member

Yes, automation script editors can interact with YouTube to some extent, but their ability to call and shuffle a YouTube music playlist is typically limited by YouTube's API restrictions and the capabilities of the automation tool. If you use a script editor to control YouTube, you would need to integrate with YouTube's API, which has specific requirements for handling playlists.

A straightforward way to shuffle a YouTube playlist is through the YouTube app or website, where you can enable the "shuffle" option for a playlist. For automation, tools like Selenium or Puppeteer can interact with web pages, but these approaches might not support all YouTube functionalities due to security and user-interaction constraints.

If you want to create an automated script to manage YouTube playlists, you need to use the YouTube Data API, which allows limited interaction with playlists. To use this API, you need to set up a developer account, obtain appropriate permissions, and use the correct API endpoints. Note that the API's capacity to manage playlists and shuffle tracks is more restricted than direct user interaction on YouTube.

Regarding "hair food oil," that's unrelated to the question of automation scripts and YouTube playlists. However, if you wanted information about hair food oil, I'd suggest looking into its benefits for hair health and common types of oils used in hair care.