Motion lighting

Hi All,

Very new to HA - but enjoying it!
I’m sure there’s a simple solution to my problem.

Motion sensor - detects motion fine and triggers lights (which are timed )etc.
But if you stay under the sensor moving it will never report ‘non movement’ ( obvious I know) . But that means I can’t reset a timer - because we never have zero movement.
Essentialy when ever there is movement I set a timer. On further movement I want to reset the timer again - but of course this never happens as the state never changes.

Hope that makes sense!.

What’s the best way to deal with this issue?

thanks in advance.

Think I’ve solved my own problem!

Lights off only when sensor changes state to no motion ( even if timer is idle ).

Seems to work!

Ok - it doesn’t work. Because the count down timer hasn’t changed to idle i.e. it was idle before!. Hmmmmmm…

There is no real need to use a timer, use ‘off for x time’:

  • Set the automation mode to ‘restart’.
  • Set one trigger on motion detected, set id ‘motion’
  • Set one trigger on motion cleared, set id ‘no-motion’
  • action choose options by trigger id
    1. motion —> turn on light
    2. no-motion for 2 minutes —> turn off light

Thanks
I get what you are saying - but where’s that in the UI??? ( forgive noob ness! )

Found it! - will try!

Not sure what you mean by set "id motion " though…

description: ""
mode: restart
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motionmasterbedroom_occupancy
    from: "on"
    id: Motion
  - platform: state
    entity_id:
      - binary_sensor.motionmasterbedroom_occupancy
    to: "off"
    for:
      hours: 0
      minutes: 3
      seconds: 0
    id: No_Motion
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Motion
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.light_hallway_upstairs
            data: {}
      - conditions:
          - condition: trigger
            id:
              - No_Motion
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.light_hallway_upstairs
            data: {}
1 Like

Or the shorter version using templates:

1 Like

Erm . You want me to fly before I can walk :blush:
Assuming I can do what I need through the UI - baby steps please .

So not possible in the UI ??

just open the automation in yaml mode, paste the code there, and change back to ui mode…

There is no other way to exchange automation then what i described here above :wink:

Hi

Ok - will try !
Ultimately I want 2 movement sensors to control 1 light .

This is how I do it. One automation does the lot.

YAML
  - id: f4e1bb68-319b-4183-a83b-07ae397420ae
    alias: 'Kitchen downlights auto'
    mode: restart
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_ms6_home_security_motion_detection
        from: 'off'
        to: 'on'
      - platform: state
        entity_id: binary_sensor.kitchen_presence_occupancy
        from: 'off'
        to: 'on'
    condition:
      condition: or
      conditions:
      - condition: template
        value_template: "{{ states('sensor.kitchen_ms6_illuminance') | int(0) < states('input_number.kitchen_min_lux') | int(1) }}"
      - condition: state
        entity_id: light.kitchen_light_level
        state: 'on'
    action:
      - service: light.turn_on
        data:
          entity_id: light.kitchen_light_level
          brightness_pct: "{{ state_attr('switch.adaptive_lighting_kitchen', 'brightness_pct') | int(100) }}"
      - wait_template: "{{ is_state('binary_sensor.kitchen_presence', 'off') }}"
        timeout: '01:00:00'
      - delay: '00:00:30'
      - condition: and
        conditions:
          - condition: state
            entity_id: light.kitchen_light_level
            state: 'on'
      - service: light.turn_on
        data:
          entity_id: light.kitchen_light_level
          brightness_pct: "{{ state_attr('switch.adaptive_lighting_kitchen', 'brightness_pct') /2 | int(100) }}"
      - delay: '00:0{{ states.input_number.kitchen_light_auto_off_time.state | int(1) }}:00'
      - service: light.turn_off
        entity_id: light.kitchen_light_level
1 Like

Lots for me to learn ! Can’t understand why such a relatively simple automation can’t be setup in the UI though ….

Unfortunately the UI doesn’t understand template sensors (yet :thinking:).

Meaning, you will have this warning:


But you can do with UI, except the template must be done in yaml :wink:

It can, the visual editor creates yaml and accepts yaml. But the compact example I posted uses a small template, and templates are by nature too powerfull to do visually, so the visual editor will keep that bit in a text editor.

Also, you can create the automation without templates, fully visually, it leads to a bigger automation. You choose. Any example above without {{ … }} above will most likely yield a fully visually editable automation.

What I posed can be done in the UI, I’m just old school and use packages for all my code

1 Like

Thinking out loud here - but wouldn’t a virtual switch be better ?

So a motion sensor sets a virtual switch on change of state .
A virtual switch per sensor ( so they’ll always reflect motion or not without a state change )

This not a more robust method ???

Or you can use a Blueprint specifically designed to perform the task. You just fill in the Blueprint’s fields and it generates the automation.

Here are two examples (for a light controlled by motion and other things) but there are others in the Blueprints Exchange section.

1 Like

I think the solution was simpler than I imagined ( inspired by my virtual switch thought )
Group both sensors together and they act as a binary switch . Easy to read for automation !