- alias: Bathroom - Automatic Lights
  id: "1745394462114"
  description: ""
  triggers:
    - entity_id:
        - binary_sensor.bathroom_motion_sensor
      from: "off"
      to: "on"
      trigger: state
      id: motion_detected
    - entity_id:
        - binary_sensor.bathroom_motion_sensor
      from: "on"
      to: "off"
      trigger: state
      for:
        hours: 0
        minutes: 5
        seconds: 0
      id: motion_cleared
    - trigger: event
      event_type: timer.finished
      event_data:
        entity_id: timer.bathroom_lights_timer
      id: timer_finished
  conditions: []
  actions:
    - choose:
        - conditions:
            - condition: trigger
              id:
                - timer_finished
          sequence:
            - choose:
                - conditions:
                    - condition: template
                      value_template: "{{ not is_state('binary_sensor.bathroom_motion_sensor','on')  }}     "
                  sequence:
                    - action: light.turn_off
                      metadata: {}
                      data: {}
                      enabled: true
                      target:
                        entity_id: light.group_bathroom
              enabled: true
              default:
                - action: timer.start
                  metadata: {}
                  data:
                    duration: 00:15:00
                  target:
                    entity_id: timer.bathroom_lights_timer
        - conditions:
            - condition: trigger
              id:
                - motion_detected
          sequence:
            - variables:
                brightness:
                  "{% set h=now().hour|int %}\n{% set m=now().minute|int %}\n{%
                  set t=h*60+m %}\n{% set min_brightness = 20 %}\n{% set max_brightness
                  = 100 %}\n{%if t>720 %}\n  {{((1440-t)/720*80+min_brightness)|int}}\n{%elif
                  t<=720 %}\n  {{((t)/720*80+min_brightness)|int}}      \n{%endif%}\n"
                color_temp_kelvin:
                  "{% set min_temp = 3500 %}\n{% set max_temp = 5100 %}\n{%
                  set h=now().hour|int %}\n{% set m=now().minute|int %}\n{% set t=h*60+m
                  %}\n{%if t>720 %}\n  {{((1440-t)/720*1600+min_temp)|round(-2)|int}}\n{%elif
                  t<=720 %}\n  {{((t)/720*1600+min_temp)|round(-2)|int}}      \n{%endif%}\n"
                color_temp: "{{(1000000/color_temp_kelvin)|round(0)|int}}"
              enabled: true
            - if:
                - condition: state
                  entity_id: timer.bathroom_lights_timer
                  state: active
              then:
                - action: timer.cancel
                  metadata: {}
                  data: {}
                  target:
                    entity_id: timer.bathroom_lights_timer
            - action: light.turn_on
              metadata: {}
              data:
                brightness_pct: "{{brightness}}"
              target:
                entity_id: light.group_bathroom
              enabled: true
            - delay:
                hours: 0
                minutes: 0
                seconds: 1
                milliseconds: 0
              enabled: true
            - action: light.turn_on
              metadata: {}
              data:
                kelvin: "{{color_temp_kelvin}}"
              target:
                entity_id: light.group_bathroom
              enabled: true
        - conditions:
            - condition: trigger
              id:
                - motion_cleared
          sequence:
            - if:
                - condition: template
                  value_template: "{{ not is_state('binary_sensor.bathroom_motion_sensor','on')  }}      "
              then:
                - action: timer.start
                  metadata: {}
                  data:
                    duration: 00:10:00
                  target:
                    entity_id: timer.bathroom_lights_timer
  mode: parallel
  max_exceeded: silent
  max: 10
- alias: Floor - Motion Detected
  id: "1729322217129"
  description: ""
  triggers:
    - entity_id:
        - binary_sensor.pir_unit_1_pir_sensor
        - binary_sensor.pir_unit_2_pir_sensor
      from: "off"
      to: "on"
      trigger: state
      id: motion_detected
    - entity_id:
        - binary_sensor.pir_unit_1_pir_sensor
        - binary_sensor.pir_unit_2_pir_sensor
      from: "on"
      to: "off"
      trigger: state
      for:
        hours: 0
        minutes: 1
        seconds: 30
      id: motion_cleared
    - trigger: event
      event_type: timer.finished
      event_data:
        entity_id: timer.floor_lights_turnoff_delay
      id: timer_finished
  conditions:
    - condition: or
      conditions:
        - condition: state
          entity_id: person.lucy_foxx
          state: home
        - condition: state
          entity_id: person.faelis_skribblekitty
          state: home
  actions:
    - choose:
        - conditions:
            - condition: trigger
              id:
                - timer_finished
          sequence:
            - choose:
                - conditions:
                    - condition: template
                      value_template:
                        "{{ not is_state('binary_sensor.pir_unit_1_pir_sensor','on')
                        and not is_state('binary_sensor.pir_unit_2_pir_sensor','on') and
                        is_state('input_select.floor_light_mode','Auto') }}     "
                  sequence:
                    - action: light.turn_off
                      metadata: {}
                      target:
                        entity_id: light.group_floor
                      data: {}
                      enabled: false
                    - action: script.ashley_s_light_fader
                      metadata: {}
                      data:
                        lampBrightnessScale: zeroToOneHundred
                        easingTypeInput: auto
                        endBrightnessPercent: "0"
                        endBrightnessEntityScale: zeroToOneHundred
                        shouldStopIfTheLampIsTurnedOffDuringTheFade: false
                        shouldResetTheStopEntityToOffAtStart: false
                        shouldInvertTheValueOfTheStopEntity: false
                        minimumStepDelayInMilliseconds: 100
                        shouldTryToUseNativeLampTransitionsToo: false
                        isDebugMode: false
                        transitionTime:
                          hours: 0
                          minutes: 0
                          seconds: 1
                        light: light.group_floor
              enabled: true
              default:
                - action: timer.start
                  metadata: {}
                  data:
                    duration: 00:01:30
                  target:
                    entity_id: timer.floor_lights_turnoff_delay
        - conditions:
            - condition: trigger
              id:
                - motion_detected
            - condition: not
              conditions:
                - condition: state
                  entity_id: input_select.floor_light_mode
                  state: "Off"
          sequence:
            - variables:
                brightness:
                  "{% set h=now().hour|int %}\n{% set m=now().minute|int %}\n{%
                  set t=h*60+m %}\n{% set min_brightness = 5 %}\n{% set max_brightness =
                  85 %}\n{%if t>720 %}\n  {{((1440-t)/720*80+min_brightness)|int}}\n{%elif
                  t<=720 %}\n  {{((t)/720*80+min_brightness)|int}}      \n{%endif%}\n"
                color_temp_kelvin:
                  "{% set min_temp = 3200 %}\n{% set max_temp = 5400 %}\n{%
                  set h=now().hour|int %}\n{% set m=now().minute|int %}\n{% set t=h*60+m
                  %}\n{%if t>720 %}\n  {{((1440-t)/720*2200+min_temp)|round(-2)|int}}\n{%elif
                  t<=720 %}\n  {{((t)/720*2200+min_temp)|round(-2)|int}}      \n{%endif%}\n"
                color_temp: "{{(1000000/color_temp_kelvin)|round(0)|int}}"
            - if:
                - condition: state
                  entity_id: timer.floor_lights_turnoff_delay
                  state: active
              then:
                - action: timer.cancel
                  metadata: {}
                  data: {}
                  target:
                    entity_id: timer.floor_lights_turnoff_delay
            - if:
                - condition: template
                  value_template: "{{brightness==5}}"
              then:
                - action: light.turn_on
                  metadata: {}
                  enabled: true
                  data:
                    brightness_pct: "{{brightness}}"
                  target:
                    entity_id:
                      - light.floor_ceiling_entrance_3
                      - light.floor_ceiling_faelis_3
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
                  enabled: true
                - action: light.turn_on
                  metadata: {}
                  data:
                    kelvin: "{{color_temp_kelvin}}"
                  target:
                    entity_id:
                      - light.floor_ceiling_entrance_3
                      - light.floor_ceiling_faelis_3
                  enabled: true
              else:
                - action: light.turn_on
                  metadata: {}
                  data:
                    brightness_pct: "{{brightness}}"
                  target:
                    entity_id: light.group_floor
                  enabled: true
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 1
                    milliseconds: 0
                  enabled: true
                - action: light.turn_on
                  metadata: {}
                  data:
                    kelvin: "{{color_temp_kelvin}}"
                  target:
                    entity_id: light.group_floor
                  enabled: true
        - conditions:
            - condition: trigger
              id:
                - motion_cleared
          sequence:
            - if:
                - condition: template
                  value_template:
                    "{{ not is_state('binary_sensor.pir_unit_1_pir_sensor','on')
                    and not is_state('binary_sensor.pir_unit_2_pir_sensor','on') }}      "
              then:
                - action: timer.start
                  metadata: {}
                  data:
                    duration: 00:01:00
                  target:
                    entity_id: timer.floor_lights_turnoff_delay
  mode: parallel
  max_exceeded: silent
  max: 10
