Multiple conditions to check after trigger

Going a bit further in automation I am running into a question.
I have a button, which acts as a trigger in an automation. That automation should activate a scene depending on time and sun state (‘above’ or ‘below’ horizon).
I guess I am now really missing an “else” inside a condition testing. If I would have to put the code in python:

if '7:00:00' < time < '8:00:00':
    scene.turn_on['7247']
elif time < '9:00:00':
    if sun.sun.state == 'above_horizon':
        scene.turn_on['64040']
    else:
        scene.turn_on['7247']

Putting that in a yaml script I guess I have to create three separate scripts which are all activated in the action part of the automation. Or am I missing something ?

blind_scene_at_time:
    alias: Activate a blind scene depending on time.
    sequence:
      - condition: time
        after: '7:00:00'
        before: '8:00:00'
      - service: scene.turn_on
        entity_id: scene.7247  #blinds semi close
blind_scene_at_time_and_sunrise:
  alias: Activate a blind scene depending on time and sunrise
  sequence:
    - condition: 
      condition: and
      conditions:
        - condition: state
          entity_id: sun.sun
          state: 'above_horizon'
        - condition: time
          after: '8:00:00'
          before: '9:00:00'
    - service: scene.turn_on
      entity_id: scene.64040 #blinds in daylight mode
blind_scene_at_time_and_sun_below_horizon:
  alias: Activate a blind scene in time slot and sun below horizon
  sequence:
    - condition:
      condition: and
      conditions:
        - condition: state
          entity_id: sun.sun
          state: 'below_horizon'
        - condition: time
          after: '8:00:00'
          before: '9:00:00'
    - service: scene.turn_on
      entity_id: scene.7247

If you want to write automations in Python, then use Appdaemon

Seconded (but I am biased!)

You can also do this in templates a lot easier than YAML as they support if then else constructs.

I didn’t get past the first page on templates, so I don’t really know if its easier. But if someone has even an inkling of Python, they shouldn’t be trying to learn either YAML or Templates.

I was trying to put the logic using the Appdaemon API, but I’m struggling with the second time comparison. Would this work?

if self.now_is_between('07:00:00', '08:00:00'):
  self.turn_on(scene.7247)
elif self.time() < '09:00:00':
  if self.sun_up():
    self.turn_on(scene.64040)
  else:
    self.turn_on(scene.7247)

Maybe it should be

elif self.time() < self.parsetime('09:00:00')

Yes, that looks pretty close :slight_smile:

@aimc
That’s what I thought of… .app daemon…
But I read there is also the possibilty to create custom components. Like so.

Would one be preferred over the other? Or is it just preference ?

You can use either - AppDaemon is intended to be more friendly for automations, custom components are generally used to add new components s and platforms to HA.