Automation sunset nano switch

Hi!

I’m new to home assistant and have been trying to learn how to do automations recently.

I want my outside lights on my patio to turn on at sunset and if I am or my wife is home. For now I only have the condition for my phone to be home but i will add my wifes phone also. I have been following smart home junkies youtube video for this and some other forum posts but it doesn’t work. I have been using the visual editor and not so much the YAML editor.
Appreciate if someone can help me.
Pasting the code under here so maybe someone can see what im doing wrong:

id: '1735225111225'
alias: Utebelysning baksida solnedång
description: Tänder utebelysningen på baksidan om solen är nere och Jesper är hemma
triggers:
  - trigger: sun
    event: sunset
    id: Solnedgång
conditions:
  - condition: device
    device_id: 34b16bd2b8ccc5aea16285d7409c****
    domain: device_tracker
    entity_id: 64bb92051fddd6a6641ab2b72e8d****
    type: is_home
    enabled: true
  - condition: time
    after: '16:00:00'
    weekday:
      - sat
      - sun
      - fri
      - thu
      - tue
      - wed
      - mon
    before: '23:00:00'
actions:
  - if:
      - condition: trigger
        id:
          - Solnedgång
    then:
      - action: switch.turn_on
        target:
          entity_id: switch.nano_switch_gen5_without_meter
        data: {}
mode: single

First, change out the device ids for entity ids.

Second, remove the condition on “time”

You also don’t need the “if” in the action as you only have one trigger.

This will help simplify the automation. Once done, wait for sunset to occur when your phone is home and look at the automation trace to see what happens. I’d also test the turn on action in developer tools / actions to make sure that actually turns on the light.