Automation - or and an atrigger

I would like to turn off the light based on automation and two device trackers. So the light should be turned off if both device trackers indicate that the devices are not at home anymore, but shouldn’t turn off if just one device leaves. Or a combination of device tracker and time. Is there any way to do or and on operations?

You could do something like:

- alias: 'Light Off When Away'
  
  trigger:
    platform: state
    entity_id: group.name #group with both device trackers
    to: 'not_home'
        
  action:
    - service: light.turn_off
      entity_id: light.name
1 Like

Was just about to write something similar as @gbboy.
The important thing is to put the device trackers in a group and use the group state as the trigger (or a condition); the group then is ‘home’ as long as one device is home and the group is only ‘not_home’ when both devices are away.

1 Like

Seems working, but how can I achieve to get a combination of device tracker and time or sunset or sunrise?

This question is not that easy to answer.
You need to decide which one you want to be the trigger (the home status is changing OR the sun sets/rises) and which one you want to make the condition (carry out the action only if anybody/nobody is at home or the if sun is up/down still/already) and then define the action.
This depends on what you want to achieve, e.g. the light comes on at sunset only if somebody is at home or the light turns on when I come home only if it’s after sunset.

I have the following ideas:
-Open the blinds and turn on the light during weekdays if it’s after 06:00 and someone is at home
-Open the blinds during the weekend if it’s after 10:00 and someone is at home.

The easiest will be to create two automations, one for weekdays and one for weekends.

Here is how I turn on my dumb coffee machine:

######################################################################
- alias: NespressoPlug - turn on weekdays
  trigger:
    platform: time
    at: '05:30:00'
  condition: 
    condition: and
    conditions:
      - condition: state
        entity_id: group.people
        state: 'home'
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
  action:
    - service: homeassistant.turn_on
      entity_id: switch.coffeeplug
######################################################################
- alias: NespressoPlug - turn on weekends
  trigger:
    platform: time
    at: '07:00:00'
  condition: 
    condition: and
    conditions:
      - condition: state
        entity_id: group.people
        state: 'home'
      - condition: time
        weekday:
          - sat
          - sun
  action:
    - service: homeassistant.turn_on
      entity_id: switch.coffeeplug

I’m not really sure how to drive the cover component, though.

Or, if you want it to be even fancier, you can distinguish days based on the Workday Binary Sensor and use it instead of the weekday condition I have in mine.
Take a look here: https://home-assistant.io/components/binary_sensor.workday/

1 Like