Advertisement
Guest User

Untitled

a guest
Feb 1st, 2022
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.47 KB | None | 0 0
  1. blueprint:
  2.   name: Motion Light ON
  3.   description: Turn light(s) ON when motion is detected and OFF when there is no motion.
  4.   domain: automation
  5.   input:
  6.     motion_entity:
  7.       name: Motion Sensor
  8.       selector:
  9.         entity:
  10.           domain: binary_sensor
  11.           device_class: motion
  12.     switch_target:
  13.       name: Switch
  14.       default: {}
  15.       selector:
  16.         target:
  17.           entity:
  18.             domain: switch
  19.     light_target:
  20.       name: Light
  21.       default: {}
  22.       selector:
  23.         target:
  24.           entity:
  25.             domain: light
  26.     no_motion_wait:
  27.       name: Wait time
  28.       description: "Time to leave the light on after motion sensor changes to 'clear' (off)."
  29.       default: 30
  30.       selector:
  31.         number:
  32.           min: 0
  33.           max: 3600
  34.           unit_of_measurement: seconds
  35.  
  36. # If motion is detected while automation is running, script will restart.
  37. mode: restart
  38.  
  39. trigger:
  40.   platform: state
  41.   entity_id: !input motion_entity
  42.   to: "on"
  43.  
  44. variables:
  45.   light_target: !input light_target
  46.   switch_target: !input switch_target
  47.  
  48. action:
  49.   - choose:
  50.       - conditions: "{{ light_target and switch_target }}"
  51.         sequence:
  52.           - service: switch.turn_on
  53.             target: !input switch_target
  54.           - service: light.turn_on
  55.             target: !input light_target
  56.           - wait_for_trigger:
  57.               - platform: state
  58.                 entity_id: !input motion_entity
  59.                 to: 'off'
  60.           - delay: !input no_motion_wait
  61.           - service: switch.turn_off
  62.             target: !input switch_target
  63.           - service: light.turn_off
  64.             target: !input light_target
  65.       - conditions: "{{ switch_target }}"
  66.         sequence:
  67.           - service: switch.turn_on
  68.             target: !input switch_target
  69.           - wait_for_trigger:
  70.               - platform: state
  71.                 entity_id: !input motion_entity
  72.                 to: 'off'
  73.           - delay: !input no_motion_wait
  74.           - service: switch.turn_off
  75.             target: !input switch_target
  76.       - conditions: "{{ light_target }}"
  77.         sequence:
  78.           - service: light.turn_on
  79.             target: !input light_target
  80.           - wait_for_trigger:
  81.               - platform: state
  82.                 entity_id: !input motion_entity
  83.                 to: 'off'
  84.           - delay: !input no_motion_wait
  85.           - service: light.turn_off
  86.             target: !input light_target
  87.     default: []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement