#-------------------------------------------
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# Read more about the house at https://vCloudInfo.com
# https://github.com/CCOSTAN/Home-AssistantConfig/issues/813
#-------------------------------------------

#-------------------------------------------
# sensor:
#   - platform: travisci
#     api_key: !secret travisci_api
#     scan_interval: 2400
#     monitored_conditions:
#       - state
#-------------------------------------------

#-------------------------------------------
rest_command:
  new_version_github_issue:
    url: https://api.github.com/repos/ccostan/Home-AssistantConfig/issues
    method: POST
    headers:
      Authorization: !secret github_token
    payload: '{"title":"Home-Assistant {{ version }} available","body":"Home-Assistant {{ version }} is now available /n https://www.home-assistant.io/latest-release-notes/ "}'
#-------------------------------------------

automation:

  - alias: "Update Available Notification"
    mode: restart
    id: 2f89ba6d-0db5-4a4a-a4df-56b8e15bb74f

    trigger:
      - platform: state
        entity_id: binary_sensor.updater
        to: 'on'

    action:
      - service: script.notify_engine
        data:
          title: 'Home Assistant {{ states.binary_sensor.updater.attributes.newest_version }} '
          value1: "Home Assistant {{ states.binary_sensor.updater.attributes.newest_version }} is now available."
          who: 'carlo'
          group: 'information'

      - service: rest_command.new_version_github_issue
        data_template:
          version: "{{ states.binary_sensor.updater.attributes.newest_version }} "