You can try this:
- id: luce_test
alias: Luce test
trigger:
- platform: state
entity_id: device_tracker.mi_9t_pro, device_tracker.mi_9_pro
- platform: state
entity_id: sun.sun
action:
- choose:
- conditions:
- "{{ is_state('sun.sun', 'below_horizon') }}"
- "{{ is_state('device_tracker.mi_9t_pro', 'not_home') }}"
- "{{ is_state('device_tracker.mi_9_pro', 'not_home') }}"
sequence:
- service: light.turn_on
target:
entity_id: light.comodino
- conditions:
- "{{ is_state('sun.sun', 'above_horizon') }}"
- "{{ is_state('device_tracker.mi_9t_pro', 'home') }}"
- "{{ is_state('device_tracker.mi_9_pro', 'home') }}"
sequence:
- service: light.turn_off
target:
entity_id: light.comodino
If the sun is below_horizon and no one is home, the light is turned on.
If the sun is above_horizon and everyone is home, the light is turned off.