What im doing wrong?


alias: LIGHTS FRONT DOOR ON (Duplicate)
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.unifi_doorbell_detected_object
        state: person
      - condition: state
        entity_id: binary_sensor.front_sensor_motion
        state: detected motion
action:
  - type: turn_on
    device_id: 45e6aaaf4286ace2e84832326b105452
    entity_id: switch.sonoff_minir2
    domain: switch
  - service: notify.mobile_app_mi_iphony
    data:
      message: SOMEONE OUTSIDE
      title: LIGHTS ON
mode: single

i would like to turn the front door light when is sunset till sunrise and two motion sensors are triggered.

Are you able to reformat your yaml using the </> button so we can see it properly?

At first glance your trigger needs to be the motion sensors and your condition needs to be whether it is dark.

And look at this for how to use the sun sensor correctly Sun condition not working as expected - #6 by MisterIks

Something like this … and you don’t need to use “and” in your condition as “and” is default

alias: Turn on Front Door Light
description: ''
trigger:
  - type: motion
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxxxxxx
    entity_id: binary_sensor.motion_xxxxx
    domain: binary_sensor
condition:
  - condition: state
    entity_id: sensor.unifi_doorbell_detected_object
    state: person
  - alias: Sun down
    condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.d1
    domain: switch
mode: single

alias: FRONT DOOR LIGHTS ON
description: ''
trigger:
  - type: motion
    platform: device
    device_id: fdbf2edbeb5cfb2c8a422507299798b9
    entity_id: binary_sensor.front_sensor_motion
    domain: binary_sensor
condition:
  - condition: state
    entity_id: sensor.unifi_doorbell_detected_object
    state: person
  - alias: Sundown
    condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - type: turn_on
    device_id: 45e6aaaf4286ace2e84832326b105452
    entity_id: switch.sonoff_minir2
    domain: switch
  - service: notify.mobile_app_mi_iphony
    data:
      message: SOMEONE OUTSIDE
      title: LIGHTS ON
mode: single

Thanks for your help! If I press test on the first condition, I’m getting error, sun condition is fine (no error).

yes, i was thinking so, i don’t know how these sensors actually works and are “placed”, as the trigger is “motion” it then checks (state of “person detected”), but what if this sensor has not finished/changed yet ?, i guess it’s not “responds” as fast as motion, it has to “verify what it sees first” … and you rightly has it as first in your condition … so maybe this should be the first trigger

… or try with sun.sun as trigger, not sure it works, never tried

trigger:
  - platform: state
    entity_id: sun.sun
    state: below_horizon

… Nope i don’t think this works as trigger,
Add “person detection” as first trigger, actually i don’t know why you need 2, if “person detection” sees a person, there have to be some “motion” prior to this , right ?, so i think i would skip the motion-detection(i.e what if someone sneaks up to the “person-detection” then there will be no motion

I would normally have this as the trigger.

trigger:
  - platform: state
    entity_id: binary_sensor.front_sensor_motion
    to: 'on'
1 Like

yes, but he has 2, 1 motion-sensor, and 1 person-detection.sensor, … so if the motion triggers, and in split seconds checks state of “person-detection” this might not have changed yet, and automation stops

And you can save a few lines here as well:

action:
  - service: switch.turn_on
    entity_id: switch.sonoff_minir2

Not sure how this makes any difference. Looking at the docs Binary Sensor - Home Assistant the motion class is still either on or off?

because person-detection is a condition, and if this is still of, flow breaks, nothing happens, i don’t believe the “Trigger” waits for the conditions to change, either they are true or false

Yes you are right. I don’t think my suggested simplifcation of the trigger affects this. If there is a delay in the two detections then you might need to use a script and put a delay in the sequence then a choose to pick if the second motion detector is activated.

1 Like

yes something like that, but as i also don’t know where he have placed these sensors, and why he needs 2, its hard to tell what’s best

1 Like

just copy/saved your 2 "optimizations " :wink: , thx

1 Like

Hi,

Thanks for all your help, I became bit wiser😊, I will remove the first sensor and work on the person sensor.

I will let you know. If it’s fixed or still have some questions…

Once again thank you.

1 Like

Great i think i would have done the same, as i also have “specific” sensors for Near-entry-door vs driveway, garage front(so 1 sensor(front) turns on “lead-light” so people can see where they go, or some cat or Deer can trigger with out disturbing , and light up the house :), near-entry-sensor(close) can only be triggered by person walking by, so this i get notified about by, thou i have never tested car/person detection, as it seems like an “subscription” service for garage frontcam, maybe i find some “external” software for that eventually, also got a few tips from Oz to test. And on some cams i disabled Motion or “narrowed” down the “detection field” to avoid “false” detections

alias: FRONT DOOR LIGHTS ON
description: ''
trigger:
  - platform: state
    entity_id: sensor.unifi_doorbell_detected_object
    from: clear
    to: person
condition:
  - alias: Sun down
    condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - type: turn_on
    device_id: 45e6aaaf4286ace2e84832326b105452
    entity_id: switch.sonoff_minir2
    domain: switch
  - service: notify.mobile_app_mi_iphony
    data:
      message: SOMEONE OUTSIDE
      title: LIGHTS ON
mode: single

should be something like that? correct? btw the sun codition comes with error test! weird.

Yes looks good. If that sensor only has the states of clear and person then you wouldn’t need the from line but either way that should work. Although you might need quotes around the clear and person. See here Automation Trigger - Home Assistant

yes, the sun.sun shows error yes, because it’s not supported by the GUI, only in YALM, but it works fine, 2 of my motion-sensors using this( as you cant use sunset/sunrice in same 1 condition)

i appreciate your help, im very surprised how helpful you are, most of the time i get answers such search the forum. it seems its working fine but sometimes the automation has some delay to turns the lights on.

what does the quotes do in this situation?

thanks