Commit 61cb6c73 authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

with main light

parent 2637c63e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -20,4 +20,10 @@ My blueprints

---

## Motion-activated Light with Timer, Condition, Illuminance and MAin Light
[![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_illuminance_main.yaml)

---


WIP =)
+155 −0
Original line number Diff line number Diff line
blueprint:
  name: Motion-activated Light with Timer, Condition, Illuminance and Main Light
  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_illuminance_main.yaml
  input:
    entity_trigger:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    entity_illuminance:
      name: Illuminance Sensor
      selector:
        entity:
          domain: sensor
          device_class: illuminance
    entity_illuminance_value:
      name: Illuminance Value
      selector:
        entity:
          domain: input_number
    entity_condition:
      name: Condition
      selector:
        entity:
          domain:
            - binary_sensor
            - input_boolean
    entity_target:
      name: Motion 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
    entity_light_main:
      name: Main Light
      selector:
        entity:
          domain: light

# 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
  - platform: state
    entity_id:
      - !input entity_light_main
    id: light_main

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"
          - condition: numeric_state
            entity_id: !input entity_illuminance
            below: !input entity_illuminance_value
          - condition: state
            entity_id: !input entity_light_main
            state: "off"
        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"
          - condition: state
            entity_id: !input entity_light_main
            state: "off"
        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
      - conditions:
          - condition: trigger
            id: light_main
          - condition: state
            entity_id: !input entity_light_main
            state: "on"
        sequence:
          - service: light.turn_off
            target:
              entity_id: !input entity_target
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion