video_lighting_on:
  alias: Video Lighting On
  sequence:
  - service: light.turn_on
    entity_id: light.desk_accent_level_light_color_on_off
  - service: light.turn_on
    entity_id: light.kitchen_sink_level_light_color_on_off
  - service: light.turn_on
    entity_id: light.tower_spotlight_level_on_off
  - service: switch.turn_on
    entity_id: switch.tplink_a2
  - service: light.turn_on
    entity_id: light.kat_lamp
  - service: light.turn_on
    entity_id: light.jeff_lamp_level_light_color_on_off
  mode: single
example_master_bedroom_lights_w_level:
  sequence:
  - service: light.turn_on
    entity_id: light.jeff_lamp_level_light_color_on_off, light.tower_spotlight_level_on_off,
      light.kat_lamp
    data:
      brightness: '{{ level | int }}'
      color_temp: 369
  mode: single
  alias: Example Master Bedroom Lights with Level
tts_notification:
  sequence:
  - choose:
    - conditions:
      - condition: state
        entity_id: input_text.room_presence
        state: kitchen
      sequence:
      - service: media_player.turn_on
        entity_id: media_player.kitchen_display
      - service: media_player.volume_set
        target:
          entity_id: media_player.kitchen_display
        data:
          volume_level: 0.8
      - service: tts.amazon_polly_say
        data:
          entity_id: media_player.kitchen_display
          message: <speak> Welcome Home! </speak>
    - conditions:
      - condition: state
        entity_id: input_text.room_presence
        state: skylar_bedroom
      sequence:
      - service: notify.alexa_media_skylar_s_bedroom
        data:
          message: Welcome home!
          data:
            type: tts
    - conditions:
      - condition: state
        entity_id: input_text.room_presence
        state: main
      sequence:
      - service: media_player.turn_on
        entity_id: media_player.ha_blue
      - service: media_player.volume_set
        target:
          entity_id: media_player.ha_blue
        data:
          volume_level: 0.8
      - service: tts.amazon_polly_say
        data:
          entity_id: media_player.ha_blue
          message: <speak> Welcome Home! </speak>
    default: []
  mode: single
  alias: TTS Notification - Welcome Home
randomize_vacation_lights:
  alias: randomize vacation lights
  sequence:
  - repeat:
      until:
      - condition: sun
        after: sunrise
      sequence:
      - service: notify.mobile_app_jeffrey_ha_app
        data:
          message: Running Vacation Lights
      - service: input_text.set_value
        target:
          entity_id: input_text.current_random_light
        data:
          value: '{{ state_attr(''group.vacation_lights'',''entity_id'') | random
            }}'
      - service: homeassistant.turn_on
        data:
          entity_id: '{{ states(''input_text.current_random_light'') }}'
      - delay:
          minutes: '{{ range(1,3) | random | int }}'
      - service: homeassistant.turn_off
        data:
          entity_id: '{{ states(''input_text.current_random_light'') }}'
      - service: input_text.set_value
        data:
          entity_id: input_text.current_random_light
          value: None
  mode: single

# I have modified this from the verison on the video. 
# Due to a logic issue I went with the homeassistant.toggle
# service so that it wontmatter if an entity is on or off, it will
# simply toggle it to the oppostite state. 
# I also added a service call that would execute after the repeat section that 
# turn off all the entities, for example when the sun is up, turn off all the lights
# in the vacation group  
improved_randomize_vacation_lights:
  alias: improved_randomize vacation lights
  sequence:
  - repeat:
      until:
      - condition: state
        entity_id: sun.sun
        state: 'above_horizon'
      sequence:
      - service: notify.mobile_app_jeffrey_ha_app
        data:
          message: Running Vacation Lights
      - service: homeassistant.toggle
        data:
          entity_id: >
            {{ expand('group.vacation_lights') | map(attribute='entity_id') | list | random }}
      - delay:
          minutes: '{{ range(1,3) | random | int }}'
  # - service: homeassistant.turn_off
  #   entity_id: group.vacation_lights
  mode: single

# Below is a demo script that can be used to test the effect. It uses a set count for repeat, 
# and seconds for delay. 
# It has also been updated to use the cleaner homeassistant.toggle service so we dont have to 
# worry about which entities are on or off.   
randomize_vacation_lights_demo:
  alias: randomize vacation lights - demo
  sequence:
  - repeat:
      count: '8'
      sequence:
      - service: homeassistant.toggle
        data:
          entity_id: >
            {{ expand('group.vacation_lights') | map(attribute='entity_id') | list | random }}
      - delay:
          seconds: '{{ range(2,5) | random | int }}'
  - service: homeassistant.turn_off 
    entity_id: group.vacation_lights
  mode: single
activate_arches_lamp:
  alias: Activate Arches Lamp
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: activate arches lamp
      media_content_type: routine
    entity_id: media_player.living_room_echo
  mode: single
deactivate_arches_lamp:
  alias: Deactivate Arches Lamp
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: deactivate arches
      media_content_type: routine
    entity_id: media_player.living_room_echo
  mode: single
dog_mode_lighting_on:
  alias: Dog Mode Lighting On
  sequence:
    - condition: state
      entity_id: sun.sun
      state: below_horizon
    - condition: state
      entity_id: input_boolean.sentry_mode
      state: 'on'
    - service: scene.turn_on
      entity_id: scene.diminished_kitchen_lighting
    - service: scene.turn_on
      entity_id: scene.security_kitchen_lighting
open_lr_curtains_lamp:
  alias: Open Living Room Curtains
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: open living room curtains
      media_content_type: custom
    entity_id: media_player.living_room_echo
  mode: single
close_lr_curtains_lamp:
  alias: Close Living Room Curtains
  sequence:
  - service: media_player.play_media
    data:
      media_content_id: close living room curtains
      media_content_type: custom
    entity_id: media_player.living_room_echo
  mode: single