Commit 5ed67a63 authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

motion lights

parent 82eae99d
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
# home-assistant_blueprints
Home Assistant Blueprints
# Home Assistant Blueprints

My blueprints

---

## Motion-activated Light with Timer

[![Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.](https://my.home-assistant.io/badges/blueprint_import.svg)](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2FDmitriySafronov%2Fhome-assistant_blueprints%2Fblob%2Fmaster%2Fautomation%2Fmotion_light_timer.yaml)

---

## Motion-activated Light with Timer and Condition
[![Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.](https://my.home-assistant.io/badges/blueprint_import.svg)](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2FDmitriySafronov%2Fhome-assistant_blueprints%2Fblob%2Fmaster%2Fautomation%2Fmotion_light_timer_condition.yaml)

---

WIP =)
+101 −0
Original line number Diff line number Diff line
blueprint:
  name: Motion-activated Light with Timer
  description: Turn on a light when motion is detected and turn it off when "no-motion" timer finishes.
  domain: automation
  source_url: https://github.com/DmitriySafronov/home-assistant_blueprints/blob/master/automation/motion_light_timer.yaml
  input:
    entity_trigger:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    entity_target:
      name: Light
      selector:
        entity:
          domain: light
    timer_no_motion:
      name: Wait timer
      description: Time to leave the light on after last motion is detected.
      selector:
        entity:
          domain: timer

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: !input timer_no_motion
    id: timer
  - platform: state
    entity_id:
      - !input entity_trigger
    id: motion
  - platform: state
    entity_id:
      - !input entity_target
    id: light

action:
  - choose:
      - conditions:
          - condition: trigger
            id: timer
        sequence:
          - service: light.turn_off
            target:
              entity_id: !input entity_target
      - conditions:
          - condition: trigger
            id: motion
          - condition: state
            entity_id: !input entity_trigger
            state: "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input entity_target
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion
      - conditions:
          - condition: trigger
            id: motion
          - condition: state
            entity_id: !input entity_trigger
            state: "off"
          - condition: state
            entity_id: !input entity_target
            state: "on"
        sequence:
          - service: timer.start
            target:
              entity_id: !input timer_no_motion
      - conditions:
          - condition: trigger
            id: light
          - condition: state
            entity_id: !input entity_target
            state: "on"
          - condition: template
            value_template: "{{ trigger.to_state.context.parent_id == none }}"
        sequence:
          - service: timer.start
            target:
              entity_id: !input timer_no_motion
      - conditions:
          - condition: trigger
            id: light
          - condition: state
            entity_id: !input entity_target
            state: "off"
        sequence:
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion
+113 −0
Original line number Diff line number Diff line
blueprint:
  name: Motion-activated Light with Timer and Condition
  description: Turn on a light when motion is detected and turn it off when "no-motion" timer finishes on specific condifion
  domain: automation
  source_url: https://github.com/DmitriySafronov/home-assistant_blueprints/blob/master/automation/motion_light_timer_condition.yaml
  input:
    entity_trigger:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    entity_condition:
      name: Condition
      selector:
        entity:
          domain:
            - binary_sensor
            - input_boolean
    entity_target:
      name: Light
      selector:
        entity:
          domain: light
    timer_no_motion:
      name: Wait timer
      description: Time to leave the light on after last motion is detected.
      selector:
        entity:
          domain: timer

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: !input timer_no_motion
    id: timer
  - platform: state
    entity_id:
      - !input entity_trigger
    id: motion
  - platform: state
    entity_id:
      - !input entity_target
    id: light

condition:
  - condition: state
    entity_id: !input entity_condition
    state: "on"

action:
  - choose:
      - conditions:
          - condition: trigger
            id: timer
        sequence:
          - service: light.turn_off
            target:
              entity_id: !input entity_target
      - conditions:
          - condition: trigger
            id: motion
          - condition: state
            entity_id: !input entity_trigger
            state: "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input entity_target
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion
      - conditions:
          - condition: trigger
            id: motion
          - condition: state
            entity_id: !input entity_trigger
            state: "off"
          - condition: state
            entity_id: !input entity_target
            state: "on"
        sequence:
          - service: timer.start
            target:
              entity_id: !input timer_no_motion
      - conditions:
          - condition: trigger
            id: light
          - condition: state
            entity_id: !input entity_target
            state: "on"
          - condition: template
            value_template: "{{ trigger.to_state.context.parent_id == none }}"
        sequence:
          - service: timer.start
            target:
              entity_id: !input timer_no_motion
      - conditions:
          - condition: trigger
            id: light
          - condition: state
            entity_id: !input entity_target
            state: "off"
        sequence:
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion