#-------------------------------------------
# Visit The Main Blog for More Home Assistant Goodness - https://www.vCloudInfo.com
# Follow me on the socials - @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# YouTube Related Packages from @Pinkywafer
# https://github.com/pinkywafer/Home-Assistant_Config/blob/master/packages/youtube/vcloudinfo.yaml
# More information found here in these issues
# https://github.com/CCOSTAN/Home-AssistantConfig/issues/720
#-------------------------------------------

sensor:
  - platform: youtube
    channel_id: UC301G8JJFzY0BZ_0lshpKpQ

  - platform: socialblade
    name: vCloudinfo_info
    channel_id: UC301G8JJFzY0BZ_0lshpKpQ

automation:
  - alias: YouTube Notification - vCloudInfo
    id: 4840f2ae-a0eb-497b-bf78-5e99ff28a9f0
    trigger:
      - platform: state
        entity_id: sensor.vcloudinfo

    condition:
      - condition: template
        value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"

    action:
      - repeat:
          count: 1
          sequence:
            - delay: '00:03:00'
            - service: script.tweet_engine_no_image
              data:
                tweet: >
                  {{ [
                  "New Video! {{ states('sensor.vcloudinfo') }} - {{ state_attr('sensor.vcloudinfo','url') }} "
                  ] | random }}
                who: 'ccostan'

            - delay: '00:10:00'

            - service: script.tweet_engine_no_image
              data:
                tweet: >
                  {{ [
                  "New Video! {{ states('sensor.vcloudinfo') }} - {{ state_attr('sensor.vcloudinfo','url') }} "
                  ] | random }}
                who: 'BearStoneHA'

            - delay: '12:30:00'