d_sellers1

Auto Light Automation

Nov 4th, 2023
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.75 KB | None | 0 0
  1. alias: Auto Office Lights
  2. description: ""
  3. trigger:
  4.   - platform: state
  5.     id: light_off_to_on
  6.     entity_id:
  7.      - light.office_lights
  8.     from: "off"
  9.     to: "on"
  10.   - platform: state
  11.     id: light_on_to_off
  12.     entity_id:
  13.      - light.office_lights
  14.     from: "on"
  15.     to: "off"
  16.   - platform: state
  17.     entity_id:
  18.      - binary_sensor.office_motion_detector_motion
  19.     from: "off"
  20.     to: "on"
  21.     id: motion_detected
  22.   - platform: state
  23.     entity_id:
  24.      - binary_sensor.office_motion_detector_motion
  25.     from: "on"
  26.     to: "off"
  27.     id: motion_cleared
  28.   - platform: event
  29.     event_type: timer.finished
  30.     event_data:
  31.       entity_id: timer.automation_auto_office_lights
  32.     id: timer_finished
  33.   - platform: state
  34.     entity_id:
  35.      - input_boolean.automation_auto_office_lights
  36.     id: toggle_automation_off_to_on
  37.     from: "off"
  38.     to: "on"
  39.   - platform: state
  40.     entity_id:
  41.      - input_boolean.automation_auto_office_lights
  42.     from: "on"
  43.     to: "off"
  44.     id: toggle_automation_on_to_off
  45. condition:
  46.   - alias: Automation enabled or just recently turned off
  47.     condition: or
  48.     conditions:
  49.       - condition: state
  50.         entity_id: input_boolean.automation_auto_office_lights
  51.         state: "on"
  52.       - condition: template
  53.         value_template: |-
  54.           {{ is_state('input_boolean.automation_auto_office_lights', 'off') and
  55.                  (now() - states.input_boolean.automation_auto_office_lights.last_changed).total_seconds() < 10 }}
  56. action:
  57.   - alias: Choose between the 6 triggers
  58.     choose:
  59.       - conditions:
  60.           - condition: trigger
  61.             id:
  62.              - light_off_to_on
  63.         sequence:
  64.           - service: timer.start
  65.             data:
  66.               duration: >-
  67.                 {{
  68.                 states.input_number.automation_auto_office_lights_duration.state
  69.                 | int(0)*60 }}
  70.             target:
  71.               entity_id: timer.automation_auto_office_lights
  72.       - conditions:
  73.           - condition: trigger
  74.             id:
  75.              - light_on_to_off
  76.         sequence:
  77.           - service: timer.cancel
  78.             data: {}
  79.             target:
  80.               entity_id: timer.automation_auto_office_lights
  81.       - conditions:
  82.           - condition: trigger
  83.             id:
  84.              - motion_detected
  85.         sequence:
  86.           - if:
  87.               - condition: state
  88.                 entity_id: light.office_lights
  89.                 state: "off"
  90.             then:
  91.               - service: light.turn_on
  92.                 data: {}
  93.                 target:
  94.                   entity_id: light.office_lights
  95.             alias: Are the lights on or off?
  96.           - if:
  97.               - condition: state
  98.                 entity_id: timer.automation_auto_office_lights
  99.                 state: active
  100.             then:
  101.               - service: timer.cancel
  102.                 data: {}
  103.                 target:
  104.                   entity_id: timer.automation_auto_office_lights
  105.             alias: Is the timer already running?
  106.       - conditions:
  107.           - condition: trigger
  108.             id:
  109.              - motion_cleared
  110.         sequence:
  111.           - if:
  112.               - condition: state
  113.                 entity_id: light.office_lights
  114.                 state: "on"
  115.             then:
  116.               - service: timer.start
  117.                 data:
  118.                   duration: >
  119.                    {{
  120.                     states.input_number.automation_auto_office_lights_duration.state
  121.                     | int(0)*60 }}
  122.                 target:
  123.                   entity_id: timer.automation_auto_office_lights
  124.       - conditions:
  125.           - condition: trigger
  126.             id:
  127.              - timer_finished
  128.         sequence:
  129.           - service: light.turn_off
  130.             data: {}
  131.             target:
  132.               entity_id: light.office_lights
  133.       - conditions:
  134.           - condition: trigger
  135.             id:
  136.              - toggle_automation_off_to_on
  137.           - condition: state
  138.             entity_id: light.office_lights
  139.             state: "on"
  140.         sequence:
  141.           - if:
  142.               - condition: state
  143.                 entity_id: light.office_lights
  144.                 state: "on"
  145.             then:
  146.               - service: timer.start
  147.                 data: {}
  148.                 target:
  149.                   entity_id: timer.automation_auto_office_lights
  150.       - conditions:
  151.           - condition: trigger
  152.             id:
  153.              - toggle_automation_on_to_off
  154.           - condition: state
  155.             entity_id: light.office_lights
  156.             state: "on"
  157.         sequence:
  158.           - service: timer.cancel
  159.             data: {}
  160.             target:
  161.               entity_id: timer.automation_auto_office_lights
  162. mode: single
Advertisement
Add Comment
Please, Sign In to add comment