Commit af98fe64 authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

logger + timer rework

parent 1aa073d0
Loading
Loading
Loading
Loading
+30 −6
Original line number Diff line number Diff line
@@ -10,17 +10,20 @@ blueprint:
        entity:
          domain: binary_sensor
          device_class: motion
          multiple: false
    entity_illuminance:
      name: Illuminance Sensor
      selector:
        entity:
          domain: sensor
          device_class: illuminance
          multiple: false
    entity_illuminance_value:
      name: Illuminance Value
      selector:
        entity:
          domain: input_number
          multiple: false
    entity_condition:
      name: Condition
      selector:
@@ -28,17 +31,20 @@ blueprint:
          domain:
            - binary_sensor
            - input_boolean
          multiple: false
    entity_target:
      name: Light
      selector:
        entity:
          domain: light
          multiple: false
    timer_no_motion:
      name: Wait timer
      description: Time to leave the light on after last motion is detected.
      selector:
        entity:
          domain: timer
          multiple: false

# If motion is detected within the delay,
# we restart the script.
@@ -74,12 +80,19 @@ action:
          - service: light.turn_off
            target:
              entity_id: !input entity_target
          - service: logbook.log
            data_template:
              name: "Blueprint #"
              message: "Condition: trigger - timer finished; Action: light turned off"
      - conditions:
          - condition: trigger
            id: motion
          - condition: state
            entity_id: !input entity_trigger
            state: "on"
          - condition: state
            entity_id: !input entity_target
            state: "off"
          - condition: numeric_state
            entity_id: !input entity_illuminance
            below: !input entity_illuminance_value
@@ -87,15 +100,16 @@ action:
          - service: light.turn_on
            target:
              entity_id: !input entity_target
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion
          - service: logbook.log
            data_template:
              name: "Blueprint #"
              message: "Condition: trigger - motion started at dark; Action: light turned on."
      - conditions:
          - condition: trigger
            id: motion
          - condition: state
            entity_id: !input entity_trigger
            state: "off"
            state: "on"
          - condition: state
            entity_id: !input entity_target
            state: "on"
@@ -103,18 +117,24 @@ action:
          - service: timer.start
            target:
              entity_id: !input timer_no_motion
          - service: logbook.log
            data_template:
              name: "Blueprint #"
              message: "Condition: trigger - motion started at light; Action: timer (re)started."
      - 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
          - service: logbook.log
            data_template:
              name: "Blueprint #"
              message: "Condition: trigger - light started; Action: timer started"
      - conditions:
          - condition: trigger
            id: light
@@ -125,3 +145,7 @@ action:
          - service: timer.cancel
            target:
              entity_id: !input timer_no_motion
          - service: logbook.log
            data_template:
              name: "Blueprint #"
              message: "Condition: trigger - light stopped; Action: timer cancelled"