Combination of states as trigger?

I’m struggling to get following working and based on a few searches I did on both Hass and Node RED I fear it’s not possible in an easy way. There is no single main trigger, so I cannot use the other states just as conditions.

I have a set of states, e.g.

person 1
person 2
time of day
TV
lights
prevent auto away

And I have three home away states: home, sleep, away

for home to activate following should be the case:
person 1 or person 2 home
time of day: between 7:00 & 0:00
TV: can be anything
lights: can be anything
prevent auto away: can be anything

for sleep to activate following should be the case:
person 1 or person 2 home
time of day: between 0:00 & 7:00
TV: off
lights: off
prevent auto away: can be anything

for away to activate following should be the case:
person 1 and person 2 away
time of day: can be anything
TV: can be anything
lights: can be anything
prevent auto away:

Thanks!!

Sounds like a use case for a template sensor: https://www.home-assistant.io/integrations/template/

In short: Create a template sensor and for the value template, have if/ifelse/else check for each of the situations you’ve described.
For example (not actual code, just so you get the idea):

{% if person1 or person2 at home and time is between 7-0:00 %}
home
{% elseif ℅}

Then just use the state change of your template sensor as a trigger

First off, this is actually pretty standard. You can have multiple triggers and multiple conditions.

You can group the person entities to make it easy on those. Then the group is home if either is home and not_home if both are away.

Similarly you can use a light group to group the lights.

First

  1. Two triggers - group going to home and time of 07:00
  2. Two conditions - group is home, time after 06:59 and before 00:00

Second

  1. Two triggers - group going to home, time of 00:00
  2. Conditions - group is home, time after 23:59 and before 07:00, TV is off, lights are off

Third

  1. Trigger - group is away

For example, on the second one:

automation:
- alias: Sleep mode
  trigger:
  - platform: state
    entity_id: group.my_people
    to: 'home'
  - platform: time
    at: '00:00:00'
  conditions:
  - condition: state
    entity_id: group.my_people
    state: 'home'
  - condition: state
    entity_id: media_player.the_tv
    state: 'off'
  - condition: state
    entity_id: lights.the_lights
    state: 'off'
  action:
  - service: some_service.call_goes_here
    ....
1 Like

Thanks a lot guys! Gonna try your input.