###############################################################################
#   @author         :   Jeffrey Stone 
#   @date           :   10/29/2019
#   @package        :   Haunted Mansion Show
#   @description    :   Config used to put on the Pre-show from Disney's Haunted Mansion in the living room 
###############################################################################

input_boolean:
  haunted_mansion:
    name: Haunted Mansion

automation:
  # Turn on Haunted Mansion Show when input_boolean is flipped on
  - id: haunted_mansion_on
    alias: Haunted Mansion On
    mode: single
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.haunted_mansion
      to: 'on'
    action:
    - service: script.turn_on
      entity_id: script.haunted_mansion_start
    - delay: 00:20:00
    
  # Turn off Haunted Mansion Show when input_boolean is flipped off
  - id: haunted_mansion_off
    alias: Haunted Mansion Off
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.haunted_mansion
      to: 'off'
    action:
    - service: script.kill_this_ride
    - service: media_player.media_stop
      entity_id: media_player.ha_blue
    - service: script.turn_off
      entity_id: script.haunted_mansion_lights
  
  - id: haunted_mansion_show_trigger
    alias: Haunted Mansion show Trigger 
    initial_state: true
    trigger:
    - platform: state
      entity_id: media_player.ha_blue
      to: 'playing'
    condition:
    - condition: state 
      entity_id: input_boolean.haunted_mansion
      state: 'on'
    action:
    - service: script.turn_on 
      entity_id: script.haunted_mansion_lights
    

script:
  haunted_mansion_start:
    sequence:
    - condition: state
      entity_id: input_boolean.audible_notifications
      state: 'on'
    - condition: state
      entity_id: sensor.family_status
      state: Home
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.ha_blue
        volume_level: .6
    - service: media_player.play_media
      entity_id: media_player.ha_blue
      data:
        #media_content_id: http://192.168.7.40/audio/haunted_mansion_preshow_full.mp3
        media_content_id: /media/disney/DL_Haunted_Mansion.mp3
        media_content_type: "music"
  
  haunted_mansion_lights:
    sequence:
    - service: light.turn_on
      entity_id: group.rgb_lr
      data:
        rgb_color: [255,255,255]
    #- delay: 00:01:06
    - delay: 00:01:20
    - service: light.turn_on
      entity_id: group.rgb_lr
      data:
        rgb_color: [73,119,255]
    #- delay: 00:00:15
    - delay: 00:00:25
    - service: light.turn_on
      entity_id: group.rgb_lr
      data:
        brightness_pct: 25
    #- delay: 00:00:37
    - delay: 00:00:29
    - service: switch.turn_on
      entity_id: switch.rail_lights
    - service: switch.turn_off
      entity_id: switch.rail_lights
    - delay: 00:00:02
    - service: scene.turn_on
      data:
        entity_id: scene.haunted_lights_out
    - service: switch.turn_on
      entity_id: switch.rail_lights
    - service: switch.turn_off
      entity_id: switch.rail_lights
    #- delay: 00:00:10
    - delay: 00:00:14
    - service: light.turn_on
      entity_id: group.rgb_lr
      data:
        rgb_color: [255,255,255]
        brightness_pct: 25
    - delay:
        seconds: 160

