Timed automation with presense detection not triggering

Hello community,
this is my first post here so please be kind to me :slightly_smiling_face:

I configured an automation which should turn on the kitchen light in the morning if at least one of two devices are at home and the sun is not yet up.
The device trackers are working and manually switching the light on and off is working as well but this automation is never triggering.
The sun-up change is happened are around 8:15 here right now so this should be okay, too.

Can you help me finding out what is wrong here?

- id: '1579591309996'
  alias: Turn light on in the morning if someone is at home
  description: ''
  trigger:
  - at: 06:45:00
    platform: time
  condition:
  - condition: device
    device_id: fd03bb[...]da
    domain: device_tracker
    entity_id: device_tracker.ane_lx1
    type: is_home
  - condition: or
    conditions:
    - condition: device
      device_id: caa8fa[...]b5
      domain: device_tracker
      entity_id: device_tracker.oneplus_a5000
      type: is_home
  - condition: and
    conditions:
    - before: sunrise
      condition: sun
  action:
  - device_id: 4bfb4[...]1e
    domain: light
    entity_id: light.kitchen
    type: turn_on

(i shortened the device_ids in this code, in real they are longer of course :slight_smile: )

Thank you in advance

I would write the conditions like this:

condition:
  condition: and
  conditions:
    - condition: sun
      before: sunrise
    - condition: or
      conditions:
        - condition: device
          device_id: caa8fa[...]b5
          domain: device_tracker
          entity_id: device_tracker.oneplus_a5000
          type: is_home
        - condition: device
          device_id: fd03bb[...]da
          domain: device_tracker
          entity_id: device_tracker.ane_lx1
          type: is_home

More info and examples here:

1 Like

@myxor, I think for your first automation (that you are asking a question about) this one is relatively complex but your attempt is pretty close to where it needs to be.

@browetd, your response is first rate, looks spot on to me, but you went further and included the link so that the OP could learn more. We are often lazy (including me) and don’t explain our answers properly

Well done to you both

@Mutt You are right…
@myxor as it is your first post, I will explain a little bit more…:

the AND/OR applies on the conditions with the same identation: so…

((before sunrise) AND (the result of the OR conditions))

So if I develop the OR as the identation is different (identation is very very important in Home Assistant):

((before sunrise) AND ((device 1 is home) OR (device 2 is home)))

I hope this is clearer, if not let me know… :wink:

Browtd, I was not being sarcastic, I thought your previous answer was very good (admittedly it’s now even better) myxor clearly has done some work on this issue rather than just posting a question without putting some effort in and then whining about it. Also his name implies an understanding of logic functions. He is not English but the question is sensibly asked with all relevant information (much better than I could do even with the assistance of Google’s mangling).
I am frustrated when I get an answer that works but I don’t understand and, as I say, I’m guilty of giving such answers myself.

I truly meant my approval. (not that it means much :rofl: )

@myxor, I know what you mean about entity names, but you can name them anything you want so shorter names (under a considered naming format (so you replace devices or expand in a logical manner)) can pay dividends. I’ve rebuilt my system twice to achieve this. First, when I was rebuilding my z wave network and the second when I moved to packages

1 Like

Thank you all for your kind help, after fixing the order of the conditions it is working as expected.