Can someone help me and check if I did it correct?

I am trying to make my light turn on automatically if it gets dark enough with the condition that I am at home.
This is my first automation and there are a lot of options in witch I’m not sure what to put.
This si my YML

alias: Lights
description: Turn un lights. when it's dark
trigger:
  - type: value
    platform: device
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: sensor.light
    domain: sensor
    below: 1000
condition:
  - condition: state
    entity_id: device_tracker.iphone
    state: home
    attribute: gps_accuracy
condition: and
    conditions:
      - condition: device
        type: is_off
        device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        entity_id: switch.xxxxxxxxxxxxxxxxxxxx_x
        domain: switch
action:
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.xxxxxxxxxxxxxxxxxxxx_x
    domain: switch
mode: restart

Can someone tell me if this is going to work?

I am using a Smart Life light and a BH1750 sensor with ESPHome

Thanks in advance

I am no expert, but I think it should be like this:

condition:
  condition: and
  conditions:
      - condition: device
        type: is_off
        device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        entity_id: switch.xxxxxxxxxxxxxxxxxxxx_x
        domain: switch
     - condition: state
        entity_id: device_tracker.iphone
        state: home
        attribute: gps_accuracy

Otherwise it looks fine. Let us know if it works!

I think it should be

condition:
  - condition: and
    conditions:
      - condition: device
        type: is_off
        device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        entity_id: switch.xxxxxxxxxxxxxxxxxxxx_x
        domain: switch
     - condition: state
        entity_id: device_tracker.iphone
        state: home
        attribute: gps_accuracy

Edit: I think this is actually the same

1 Like

Great minds think alike!

(counting down until someone comes in and correct the both of us) :slight_smile:

1 Like

BTW, what is the default with multiple conditions? Should be “and” right? So don’t think that is needed actually.

1 Like

Yeah, that also makes sense :sweat_smile:

The gps_accuracy attribute is more likely to be a number (like 65) than home. I think you want to delete the whole attribute: gps_accuracy line unless you had some other use for it, such as in a separate numeric_state condition. The state of the device_tracker entity is the current zone (or not_home), and that appears to be what you’re interested in.