blueprint: name: IKEA MYGGSPRAY E2494 Motion Sensor (Matter) v2.1 description: 'Full-featured automation for the IKEA MYGGSPRAY E2494 Matter motion sensor. Supports independent actions for motion, illuminance (high/low), and battery alerts. ' domain: automation source_url: https://github.com/aledziko/HA-blueprints/blob/main/IKEA/Matter/ikea-myggspray-e2494/ikea-myggspray-e2494-matter-motion-sensor.yaml author: aledziko input: motion_entity: name: MYGGSPRAY Motion Sensor description: Select the MYGGSPRAY motion sensor (binary_sensor). selector: entity: filter: - device_class: - occupancy domain: - binary_sensor - device_class: - motion domain: - binary_sensor reorder: false multiple: false use_time_window: name: Enable Active Hours? description: Restrict automation to a specific time window. default: false selector: boolean: {} active_start_time: name: Active Start Time description: Automation starts working at this time (if enabled). default: 08:00:00 selector: time: {} active_end_time: name: Active End Time description: Automation stops working at this time (if enabled). default: '22:00:00' selector: time: {} no_motion_wait: name: Wait time (Motion) description: Time to wait after last motion is detected before running the "off" action. default: 120 selector: number: min: 0.0 max: 3600.0 unit_of_measurement: seconds step: 1.0 mode: slider motion_on_action: name: 'Action: Motion Detected' description: Run when motion is detected (and dark enough). default: [] selector: action: {} motion_off_action: name: 'Action: Motion Stopped' description: Run after the sensor stops detecting motion and wait time elapsed. default: [] selector: action: {} illuminance_entity: name: (Optional) Illuminance Sensor description: Select the light sensor (sensor.illuminance). default: [] selector: entity: filter: - domain: - sensor device_class: - illuminance reorder: false multiple: false motion_cutoff: name: (Optional) Motion Light Cutoff description: Only trigger "Motion Detected" action if LUX is BELOW this value (0 to disable). default: 0 selector: number: min: 0.0 max: 3000.0 unit_of_measurement: lux step: 1.0 mode: slider illuminance_high_threshold: name: (Optional) Light High Threshold description: Trigger "High Action" when LUX goes ABOVE this value (e.g. 500 lx). default: 500 selector: number: min: 0.0 max: 3000.0 unit_of_measurement: lux step: 1.0 mode: slider high_action: name: 'Action: Light High' description: Run when light exceeds threshold (e.g. close curtains). default: [] selector: action: {} illuminance_low_threshold: name: (Optional) Light Low Threshold description: Trigger "Low Action" when LUX goes BELOW this value (e.g. 5 lx). default: 5 selector: number: min: 0.0 max: 3000.0 unit_of_measurement: lux step: 1.0 mode: slider low_action: name: 'Action: Light Low' description: Run when light drops below threshold (e.g. open curtains). default: [] selector: action: {} battery_entity: name: (Optional) Battery Sensor description: Select the battery level sensor (sensor.battery). default: [] selector: entity: filter: - domain: - sensor device_class: - battery reorder: false multiple: false battery_low_threshold: name: (Optional) Battery Low Level description: Threshold for battery alert (%). default: 30 selector: number: min: 0.0 max: 100.0 unit_of_measurement: '%' step: 1.0 mode: slider battery_low_action: name: 'Action: Battery Low' description: Run when battery drops below threshold. default: [] selector: action: {} mode: parallel max_exceeded: silent trigger_variables: motion_entity_input: !input motion_entity illuminance_entity_input: !input illuminance_entity motion_cutoff_input: !input motion_cutoff high_threshold_input: !input illuminance_high_threshold low_threshold_input: !input illuminance_low_threshold battery_entity_input: !input battery_entity battery_threshold_input: !input battery_low_threshold use_time_window_input: !input use_time_window triggers: - trigger: state entity_id: !input motion_entity from: 'off' to: 'on' id: motion_on - trigger: state entity_id: !input motion_entity from: 'on' to: 'off' for: seconds: !input no_motion_wait id: motion_off - trigger: template value_template: "{{ illuminance_entity_input != none and \n states(illuminance_entity_input) | is_number and \n states(illuminance_entity_input) | float(0) > high_threshold_input | float(100000) }}\n" id: light_high - trigger: template value_template: "{{ illuminance_entity_input != none and \n states(illuminance_entity_input) | is_number and \n states(illuminance_entity_input) | float(100000) < low_threshold_input | float(-1) }}\n" id: light_low - trigger: template value_template: "{{ battery_entity_input != none and \n states(battery_entity_input) | is_number and \n states(battery_entity_input) | float(100) < battery_threshold_input | float(-1) }}\n" id: battery_low condition: - condition: or conditions: - condition: template value_template: '{{ not use_time_window_input }}' - condition: time after: !input active_start_time before: !input active_end_time actions: - choose: - conditions: - condition: trigger id: motion_on sequence: - delay: 1.5 - condition: template value_template: "{% set cutoff = motion_cutoff_input | float(0) %} {% if cutoff == 0 %}\n true\n{% else %}\n {% set lux = states(illuminance_entity_input) | float(-1) %}\n {{ lux == -1 or lux <= cutoff }}\n{% endif %}\n" - sequence: !input motion_on_action - conditions: - condition: trigger id: motion_off sequence: !input motion_off_action - conditions: - condition: trigger id: light_high sequence: !input high_action - conditions: - condition: trigger id: light_low sequence: !input low_action - conditions: - condition: trigger id: battery_low sequence: !input battery_low_action