#-------------------------------------------
#  Fire Tablet Alarm Panel -
#  http://www.vmwareinfo.com/2017/07/visualizing-smart-home-using-home.html
#-------------------------------------------
#
homeassistant:
  customize_glob:
    "input_boolean.clock_snooze":

      

media_player:
  - platform: floorplan_speaker
    name: Alarm Clock

#---Sensors for Fire Tablet-----------------------------

binary_sensor:
  - platform: mqtt
    state_topic: floorplan/clock_motion
    name: Clock Motion
    device_class: motion
    retain: true

    

  - platform: mqtt
    state_topic: floorplan/clock_plugged
    name: Clock Plugged
    retain: true

    

light:
  - platform: mqtt
    name: Clock Screensaver
    state_topic: floorplan/clock_screensaver
    command_topic: floorplan/clock_screensaver/set
    brightness: true

sensor:
  - platform: mqtt
    state_topic: "clock/stacey_alarm_time"
    name: clock_stacey_alarm_time
    retain: true

    

input_boolean:
  clock_snooze:
    name: Clock Snooze
    initial: off

automation:
  - alias: 'Snooze Button off in 10 minutes'
    id: 7cfd94e2-0b99-4de1-af98-2085d51ef88b
    trigger:
      - platform: state
        entity_id:
          - input_boolean.clock_snooze
        to: 'on'
        from: 'off'
    action:
      - delay:
          minutes: 10
      - service: input_boolean.turn_off
        entity_id: input_boolean.clock_snooze

#Turn on the clock - turn off the screensaver so we can see it.
  # - alias: Turn off Screensaver so we can see the time
  #  id: 26016b2a-4760-4438-a665-95d5b18f0797
  #   trigger:
  #     - platform: state
  #       entity_id:
  #         - binary_sensor.sleepnumber_carlo_carlo_is_in_bed
  #         - binary_sensor.sleepnumber_carlo_stacey_is_in_bed
  #         - light.bedroom_screensaver
  #       to: 'off'
  #
  #   action:
  #     - service: light.turn_off
  #       entity_id: light.clock_screensaver

#-----Turn on the Music--------------------------------------
  - alias: 'Play Radio when Snooze button is turned off.'
    id: f0982a8b-6d30-4f2e-803f-0f341d188287

    trigger:
      - platform: state
        entity_id:
          - input_boolean.clock_snooze
        to: 'off'
        from: 'on'
      - platform: template
        value_template: '{{states.sensor.time.state == states.sensor.clock_stacey_alarm_time.state}}'
    condition:
      - condition: state
        entity_id: input_boolean.school_mode
        state: 'on'
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
      - condition: state
        entity_id: group.family
        state: 'home'
    action:
      - service: media_player.volume_set
        data:
          entity_id:
            - media_player.alarm_clock
          volume_level: 0.3
      - service: media_player.play_media
        data:
          entity_id:
            - media_player.alarm_clock
          #media_content_id: "http://listen.181fm.com/181-kickincountry_128k.mp3"
          media_content_id: "http://listen.djcmedia.com:80/americascountryhigh"
          media_content_type: audio/mp4
      - service: light.turn_off
        entity_id: light.clock_screensaver

#-----Turn off the Music--------------------------------------
  - alias: 'Turn off the Radio when the snooze is turned on.'
    id: c21173ef-0418-49da-a1b8-b961c79dc6d7

    trigger:
      - platform: state
        entity_id:
          - input_boolean.clock_snooze
        to: 'on'
        from: 'off'

    action:
      - service: media_player.media_stop
        entity_id: media_player.alarm_clock