Struggling with a variety of topics

Your code looks good and easy to do but Im still struggling to add a delay or something to make my bathroom light stop on longer than a 1min when motion is detected. I seem to get errors in the code or the light stops on but it never does it to what I tell it too.

this is my code. I hope you can help me with something that should be easy to do but not :slight_smile:

I’m using a Desk Lamp to make things easier to test:

  alias: Turn on Desk Lamp
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: 5310bf32ba8e3d560bed459e660d617d
    entity_id: da850b72e7c5e88222dc33802e3edbe1
    domain: binary_sensor
  condition:
  - condition: time
    after: 09:00:00
    before: '18:00:00'
  action:
  - type: turn_on
    device_id: 50c44d6919b421581237941a26338ab8
    entity_id: fd67cc742b22d5bed9346692778998aa
    domain: light
  mode: single
- id: '1693220799421'
  alias: Turn off Desk Lamp
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: 5310bf32ba8e3d560bed459e660d617d
    entity_id: da850b72e7c5e88222dc33802e3edbe1
    domain: binary_sensor
  condition:
  - condition: time
    after: 09:00:00
    before: 06:00:00
  action:
  - type: turn_off
    device_id: 50c44d6919b421581237941a26338ab8
    entity_id: fd67cc742b22d5bed9346692778998aa
    domain: light
  mode: single

Can you try to re-write your automation using state enities & call service, so the automation becomes more clear?
(see Why and how to avoid device_ids in automations and scripts)

I would write it something like this:

alias: Turn on/off Desk Lamp on motion between 09:00 and 18:00 and off after 10min without motion
description: ""
mode: restart
trigger:
  - platform: state
    id: "on"
    entity_id:
      - binary_sensor.motionmasterbedroom_occupancy
    to: "on"
  - platform: state
    id: "off"
    entity_id:
      - binary_sensor.motionmasterbedroom_occupancy
    to: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "on"
          - condition: time
            after: "09:00:00"
            before: "18:00:00"
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.light_hallway_upstairs
    default:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.light_hallway_upstairs

This will trigger when motion is detected/cleared.
When it is detected, and time is between 09:00 and 18:00, lamp will turn on and automation is restarted.
When it is cleared for 10 minutes, lamp will turn off and automation is restarted. Note that lamp will always turn off, also outside the window 09:00-18:00 :wink:

Thank you for this help I’m very new to this and I will have a look now at changing it! Can I easily add Sun instead of time as I did time just for now during the day to test to see if I could get it to work? so normally I have it to do this tast when the sun set and the sun raise but id also at some point later do it to light on the sensors!

I’m also not at all sure how to add things into a state!

can you help me learn this please?

You want to trigger when motion is detected, so:
attribute: This depends a bit of the sensor; It looks like your sensor is a combined sensor for luminance and motion, so if the state is motion, leave empty. If the motion is only available as an attribute of a combined sensor, select motion.
from: irrellevant, just leave empty
to: detected

I dont seem to be getting these options you say, I have nothing to pick the state as Motion. I do know the sensor does luminance on it why I was trying to find ways to know which sensor I was using by using ID to find them but now Im picking the :slightly_smiling_face: entity of it but get no options to pick if motion is detected :man_shrugging:

I’m not getting any light coming on at all now. So not sure what Ive done wrong. I found a different way to find the Desk light using Services also now with you saying to do it this way.

- id: '1693220576809'
  alias: Turn on Desk Lamp
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.lumi_lumi_motion_ac02_motion
    from: 'on'
    for:
      hours: 0
      minutes: 3
      seconds: 0
    to: 'on'
  condition:
  - condition: time
    after: 09:00:00
    before: '18:00:00'
  action:
  - service: light.turn_on
    data: {}
    target:
      device_id: 50c44d6919b421581237941a26338ab8
  mode: single
- id: '1693220799421'
  alias: Turn off Desk Lamp
  description: ''
  trigger: []
  condition: []
  action: []
  mode: single

from: 'on'
to: 'on'

??
Which is translated in the GUI to
from: ‘detected’
to: ‘detected’

I thought I mentioned:

I did but looking on the code it does not go to the same as yours so I messed around with it until it did! now I took them all out and left them empty The light still does not come on and the code it nothing like yours is! Like I said I have no clue what to put in these options I have never done that or looked at them before so I’m trying to go off what you say but I also have Dyslexia which is also another issue I have to try to deal with :slight_smile: Yes, I know it does not get it to work but I tend to have to keep changing things and guessing to try to get it to work. I have so far spent 2 months trying to get this to work and still cannot do it. It was easier in Smartlife as it stopped on easier than this!

Might be easy once I get my head around it but it’s not working for me yet :slight_smile:

  alias: Turn on Desk Lamp
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.lumi_lumi_motion_ac02_motion
    for:
      hours: 0
      minutes: 3
      seconds: 0
    to: 'on'
  condition:
  - condition: time
    after: 09:00:00
    before: '20:00:00'
  action:
  - service: light.turn_on
    data:
      brightness_pct: 60
    target:
      device_id: 50c44d6919b421581237941a26338ab8
  mode: single
- id: '1693220799421'
  alias: Turn off Desk Lamp
  description: ''
  trigger: []
  condition: []
  action: []
  mode: single

This is as it is now and no light is coming on at all. could there be something else causing it to not work? Apart from the user :slight_smile:

That State Trigger is designed to trigger when it detects continuous motion for a minimum of 3 minutes.

In other words, in order to turn on the light, it has to detect 3 uninterrupted minutes of motion.

I doubt that’s the behavior you want. Can you explain how you want the motion detector to control the light?

Do you mean it should come on right away then continuous motion for a minimum of 3 minutes? as this is what I want the light to turn on the light it used too using Smartlife, Id walk in and the light would then stop on as long as Im moving in the room for the length of the time Im in that room? But I also want it to not turn off after in 1 min when I go out of them room like all of them do as standard! I want it to turn off after 3 mins or maybe 2 mins just depending but 1 min is so annoying no time to do anything and causes things to also blink on and off which is also very annoying.

The trouble is nothing seems to work no matter what I do . took me 2 weeks to just get a light on in HA with the way you have to set it up with Automation and still learning Now! But now no light comes on at all on this Motion Sensor.

If I am looking at the data provided so far, this ‘should’ work:

alias: Turn on/off Desk Lamp on motion between 09:00 and 18:00 and off after 10min without motion
description: ""
mode: restart
trigger:
  - platform: state
    id: "on"
    entity_id:
      - binary_sensor.lumi_lumi_motion_ac02_motion
    to: "on"
  - platform: state
    id: "off"
    entity_id:
      - binary_sensor.lumi_lumi_motion_ac02_motion
    to: "off"
    for:
      hours: 0
      minutes: 3
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "on"
          - condition: time
            after: "09:00:00"
            before: "18:00:00"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 60
            target:
              entity_id: light.kithcen_led_2
    default:
      - service: light.turn_off
        data: {}
        target:
          entity_id: llight.kithcen_led_2

What @123 and I tried to say it, there should be NO motion for 3 minutes ,:

    to: "off"
    for:
      hours: 0
      minutes: 3
      seconds: 0

No.

The State Trigger (that you created) will trigger only after detecting the binary_sensor turning on and staying on for at least 3 minutes.

Unless you’re waving your arms in front of the motion detector for a solid 3 minutes, it won’t trigger.

If you want the State Trigger to trigger when no motion has been detected for 3 minutes then you should use aceindy’s latest example.

no but yes it should come on right away or id miss the board :rofl:and stay on until I leave, then turn off after 2 mins :slight_smile:

If that’s what you want then the example you posted above definitely doesn’t achieve it.

Use what aceindy posted.

https://community.home-assistant.io/t/delaying-a-motion-sensor-trigger/481095/26?u=aceindy

Has data is now and no light coming on to go to even if its stops on 3 mins!

  alias: Turn on Desk Lamp
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.lumi_lumi_motion_ac02_motion
    for:
      hours: 0
      minutes: 3
      seconds: 0
    to: 'on'
  condition:
  - condition: time
    after: 09:00:00
    before: '20:00:00'
  action:
  - service: light.turn_on
    data:
      brightness_pct: 60
    target:
      entity_id: light.desk_lamp_bulb
  mode: single
- id: '1693220799421'
  alias: Turn off Desk Lamp
  description: ''
  trigger: []
  condition: []
  action: []
  mode: single

:man_shrugging:

You are missing one trigger…
(just for your info, an automation can have more than one trigger, my example has 2…

Why don’t you just copy/paste my code, see what happens and continue from there? :thinking:

it gives me loads of error if i copy your code! Do you not think something else is at play here as I have tried all entities for the sensor to make sure is not missing anything!

I will try to copy the little bit you have just posted see what it does to me!

It’s the automation aceindy posted here