Pocster
December 14, 2023, 5:31pm
1
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.
Pocster
December 14, 2023, 5:58pm
2
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!
Pocster
December 14, 2023, 6:36pm
3
Ok - it doesn’t work. Because the count down timer hasn’t changed to idle i.e. it was idle before!. Hmmmmmm…
aceindy
(Aceindy)
December 14, 2023, 6:40pm
4
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
motion —> turn on light
no-motion for 2 minutes —> turn off light
Pocster
December 14, 2023, 7:16pm
5
Thanks
I get what you are saying - but where’s that in the UI??? ( forgive noob ness! )
Pocster
December 14, 2023, 7:17pm
6
Found it! - will try!
Not sure what you mean by set "id motion " though…
aceindy
(Aceindy)
December 14, 2023, 7:23pm
7
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
Edwin_D
(Edwin D.)
December 14, 2023, 7:25pm
8
Or the shorter version using templates:
This gets asked a lot so here is an example for automating a light to come on with movement and go off after there is no movement for a short time.
trigger:
- platform: state
entity_id: binary_sensor.your_motion_sensor_here # change this
to: 'on'
- platform: state
entity_id: binary_sensor.your_motion_sensor_here # change this
to: 'off'
for:
minutes: 2 # adjust as necessary
action:
- service: "light.turn_{{ trigger.to_state.state }}"
target:
entity_id: …
1 Like
Pocster
December 14, 2023, 9:19pm
9
Erm . You want me to fly before I can walk
Assuming I can do what I need through the UI - baby steps please .
Pocster
December 14, 2023, 9:20pm
10
So not possible in the UI ??
aceindy
(Aceindy)
December 15, 2023, 5:34am
11
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
Pocster
December 15, 2023, 7:52am
12
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
Pocster
December 15, 2023, 8:52am
14
Lots for me to learn ! Can’t understand why such a relatively simple automation can’t be setup in the UI though ….
aceindy
(Aceindy)
December 15, 2023, 9:49am
15
Unfortunately the UI doesn’t understand template sensors (yet ).
Meaning, you will have this warning:
But you can do with UI, except the template must be done in yaml
Edwin_D
(Edwin D.)
December 15, 2023, 10:01am
16
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
Pocster
December 15, 2023, 3:24pm
18
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 ???
123
(Taras)
December 15, 2023, 3:33pm
19
Pocster:
Lots for me to learn !
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
Pocster
December 15, 2023, 6:36pm
20
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 !