Help with automation night lights

Dear All,

My name is Oriol, I’m starting with Home Assistant, up to now using the foro, manuals, tutorials I could solve all problems I got.

But now I’m try to do an automation that:

Trigger
When we arrive at home ( 1 user of more… using life360)

Conditions
-Entrance lights are switched off.
AND
-Sun state: below_horizon

action
-Switch on entrance light
-Star timer to switch off the light in 5 minuts

This is the code I’ve:

- id: '1595094439711'
  alias: night 
  description: ''
  trigger:
  - entity_id: device_tracker.life360_User1
    event: enter
    platform: zone
    zone: zone.home
  - entity_id: device_tracker.life360_User2
    event: enter
    platform: zone
    zone: zone.home
  - entity_id: device_tracker.life360_User3
    event: enter
    platform: zone
    zone: zone.home
  - entity_id: device_tracker.life360_User4
    event: enter
    platform: zone
    zone: zone.home
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: switch.entrance_light
      state: 'off'
    - condition: state
      entity_id: sun.sun
      state: below_horizon
  action:
  - data: {}
    entity_id: switch.entrance_light
    service: switch.turn_on
  - data:
      entity_id: timer.tempsretardfarolesnit
    service: timer.start

I’m sure that the problem I’ve is with sun condition. as If I take out this condition, it runs perfect, So my point of view is that I have a problem on AND. Could someone help me to understand why?

Thanks a lot! Keep Save of Covid!

Oriol
Home Assistant Core 0.112.4
Operating System 4.10
On Raspberry 4

Welcome.
Please read this, especially point 11

Thanks a lot! I Hope is more clear now.

Are you sure that is the actual code. I’m surprised it even passes the configuration check. The indentation is way off.

Dear Francisp, Thanks a lot for your help an patient, is my 1st post so I’m trying to understand all rules and way-to-do!
Thanks another time!
PD. also I broke my left had 3 weeks ago, and is really difficult to write with just one hand overall: ` :sweat_smile:

There is nothing wrong with that part of your automation, I have the exact same thing in some of my automations (minus the name of the switch :slight_smile: ) .

That part probably comes from the automation editor ? I would have written it as

  action:
  - data: 
      entity_id: switch.entrance_light
    service: switch.turn_on

But else, I don’t see a problem. You did reload automations after changing something ?

Hi,
Yes it comes ( part) from automation editor, and yes I reload it.
I made the change that you suggest, and chane the sun to above_horizon ( just to do the trials right now)
I’ll come back!
Thanks a lot!

Hi, At the end I rewrite the automation… now is perfect! I could not understand what was wrong! Thanks a lot!