Complexity of Rules

I’m a bit concerned with the increased complexity of rules when combining multiple events. Let’s say for example:

At 10:00 turn on light living room
At 11:00 turn on light bedroom

Now combine this with presence detection:

At 10:00, if somebody home, turn on light living room
At 11:00, if somebody home, turn on light bedroom

That’s all nice and easy. Now if one comes home late, everything is dark, so one would have to add the following rules

When somebody comes home, if it's after 10:00, turn on light living room
When somebody comes home, if it's after 11:00, turn on light bedroom

And that explodes exponentially if there are more conditions and trigger combinations. Think adding sunset to the mix, then I’d have to do 8 rules to cover all possibilities. And temperature, that makes 16 rules… things get out of hand really fast here…

Is there any sane solution that doesn’t mean duplicating all rules with switched conditions/trigger events?

I had the nearly exact same questions a few weeks ago :wink:

https://community.home-assistant.io/t/best-practice-for-automations-that-have-two-conditions/4889

The breakthrough for me was the realisation that you can have multiple triggers within the same automation.

Furthermore - if your automations get too complex, you might want to have a look at AppDaemon:
https://github.com/home-assistant/appdaemon

Sebastian

I knew it has a simple solution! Thank you so much!

This actually works! So that means one has to list the conditions twice under both the trigger and condition, but that is a lot better than having to exponentially duplicate whole rules.

For whoever asks that question the next time, here is how that rule now looks:

  - alias: Turn on light when sun sets and somebody home
    hide_entity: True
    trigger:
      - platform: sun
        event: sunset
        offset: '-00:30:00'
      - platform: state
        entity_id: group.all_devices
        to: 'home'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: 'group.all_devices'
          state: 'home'
        - condition: sun
          after: sunset
          after_offset: '-0:30:00'
        - condition: time
          after: '12:00:00'
          before: '23:59:00'
    action:
      service: homeassistant.turn_on
      entity_id: group.living

It would be cool to have that documented somewhere, eh? :wink:

mjl

So, to clarify, are those multiple triggers acting in an “or” configuration? Such that either of the two events (sunset - 0:30 OR group.all_devices to ‘home’) can “trigger” the automation, but the “action” is only performed if every “condition” is true?

Also, do you need the additional time condition? I can’t imagine sunset occurring before 12:00:00 (unless you live in a polar region), and would home-automation consider 1:00 AM as “after sunset”, if it’s a different day than when the sun went down?

Yes, that’s exactly it, triggers are cumulative (ie. the rule will fire if any trigger triggers).

The additional time condition… Well, I wasn’t sure what HA considers “after sunset” and wanted to avoid all the lights turning on if somebody comes home at 3am. I have a separate rule that turns on only the lights near the front door.