diff options
Diffstat (limited to 'blueprints/automation/motion/motion_switch.yaml')
-rw-r--r-- | blueprints/automation/motion/motion_switch.yaml | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/blueprints/automation/motion/motion_switch.yaml b/blueprints/automation/motion/motion_switch.yaml new file mode 100644 index 0000000..c78e31f --- /dev/null +++ b/blueprints/automation/motion/motion_switch.yaml @@ -0,0 +1,163 @@ +blueprint: + name: Motion-activated Switch + description: Turn on a light when motion is detected and surroundings are dark + domain: automation + input: + motion_entity: + name: Motion Sensor + selector: + entity: + domain: binary_sensor + device_class: motion + + illumination_test: + name: Illumination Test + description: Select how to check if existing illumination is sufficient + default: sun + selector: + select: + options: + - label: Illuminance Sensor + value: sensor + - label: Sun Elevation + value: sun + - label: Always turn on lights + value: none + illuminance_entity: + name: Illuminance Sensor + description: Sensor providing information about illumination in the room (keep empty to rely on sun position) + selector: + entity: + domain: sensor + device_class: illuminance + lux_threshold: + name: LUX threshold + description: Threshold bellow which we consider that lighting is needed + default: 40 + selector: + number: + min: 10 + max: 1000 + unit_of_measurement: lux + sun_elevation: + name: Sun Elevation + description: Sun elevation (suggested between 0 and -6) when dusks settles and we need to turn on lights) + default: 0 + selector: + number: + min: -30 + max: 30 + unit_of_measurement: ° + + + light_target: + name: Light Target + default: [] + selector: + entity: + multiple: true + domain: [switch, light] + no_motion_wait: + name: Wait time + description: Time to leave the light on after last motion is detected. + default: 120 + selector: + number: + min: 0 + max: 3600 + unit_of_measurement: seconds + + on_click: + name: on_click + description: Additional actions to perform while turning on master light + default: [] + selector: + action: + off_click: + name: off_click + description: Additional actions to perform while turning off master light + default: [] + selector: + action: + + + +variables: + lux_threshold: !input lux_threshold + illuminance_entity: !input illuminance_entity + test: !input illumination_test + + current_lux: '{{ (states(illuminance_entity) | float) }}' + +# If motion is detected within the delay, +# we restart the script. +mode: restart +max_exceeded: silent + +trigger: + - platform: state + id: "turn_on" + entity_id: !input motion_entity + from: "off" + to: "on" + - platform: state + id: "turn_off" + entity_id: !input motion_entity + from: "on" + to: "off" + for: + seconds: !input no_motion_wait + +action: + - choose: + - conditions: + - condition: trigger + id: "turn_on" + sequence: + - choose: + - conditions: + - condition: template + value_template: '{{ test == "sensor" }}' + sequence: + - if: + - condition: template + value_template: '{{ (states(illuminance_entity) | float) < lux_threshold }}' + then: + - choose: [] + default: !input "on_click" + - service: switch.turn_on + target: + entity_id: !input light_target + + - conditions: + - condition: template + value_template: '{{ test == "sun" }}' + sequence: + - if: + - condition: numeric_state + entity_id: sun.sun + attribute: elevation + below: !input sun_elevation + then: + - choose: [] + default: !input "on_click" + - service: switch.turn_on + target: + entity_id: !input light_target + default: + - choose: [] + default: !input "on_click" + - service: switch.turn_on + target: + entity_id: !input light_target + + - conditions: + - condition: trigger + id: "turn_off" + sequence: + - choose: [] + default: !input "off_click" + - service: switch.turn_off + target: + entity_id: !input light_target + default: [] |