Help in multiple condition in automation action

i have an automation when i’m home it will trigger few action, like:
disable alarm
send notification
turn on light
turn on fan

but the last two need to be triggered only if a specific condition is matched, for the light only if sun is down or light sensor lower than 30
and for the fan i need to turn it on only if the temperature is higher than 25,

but how can i write this? because from what i understand if one condition is not met the execution is stopped, but as i have 2 separate condition how can one not stop the other ??

thanks

You just described the or condition.

mmm i don’t understand i have 2 separate condition but they are independent and enable or not an action

if i have something like:
condition or:

  • sun down
  • illumantion < 30

service:

  • turn on light

condition:

  • temperature > 25

service:

  • turn on fan

but if none of the first condition is met (illumination is 60 and sun is up) also the second condition (temperature) would not be executed as it’s after the first condition … no ?

make the last 2 actions something like this:
(Changing the sensors etc to yours obviously!)

  - if:
      - condition: or
        conditions:
          - condition: state
            entity_id: sun.sun
            state: below_horizon
          - condition: numeric_state
            entity_id: sensor.garage_motion_sensor_lux_level
            below: '30'
    then:
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.garden
  - if:
      - condition: numeric_state
        entity_id: sensor.garage_temp
        above: '25'
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.office_fan_plug2

You should be more clear, which conditions have to be used in combination.

Make a list of the conditions you want to use, and how they should interact together.

  • condition1 = always true
  • condition2 = true, if condition1 is true, otherwise false allowed
  • condition3 = only, if both condition1 and condition2 are true

and so on. For now, we can’t see, what you really wanted to be combined.

What @rossk posted is one possibiltiy, but first one needs to know, what it is exactly, that you want. :slight_smile:

i didn’t know about if then in yaml … maybe it’s new ? i think this is what i was looking for
two separate if … that will trigger or not a service. thanks

If, then, else is available in .yaml and via the Ui.

You could similarly have use a choose action then listed the first condition and action. Followed by another choose action like this:

  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: sun.sun
                state: below_horizon
              - condition: numeric_state
                entity_id: sensor.garage_motion_sensor_lux_level
                below: '30'
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.garden
    default: []
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.garden_temp_average
            above: '25'
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.office_fan_plug2
    default: []

This would achieve exactly the same thing

Personally, and for simplicity, instead of trying to pack a bunch of different conditions into a single automation, typically I’ll write an automation that fires individual scripts - each of these scripts is what contains the conditions for the actions each script executes.

Automation
|
– Script 1 - Conditions 1 - Actions 1
– Script 2 - Conditions 2 - Actions 2
– Script 3 - Conditions 3 - Actions 3
– etc…

There seem to be two trains of thoughts in the HA community, with the preference to try to reduce the # of automations/scripts and combine using if/else/conditions/choose/other means vs. having a greater # of automations / scripts - each with a ‘simpler’ purpose.

Will leave it to you whether you define ‘simple’ as one automation with a bunch of (IMO) complicated conditions or multiple automations/scripts.

Here’s an example of an automation that I trigger at 8pm, which turns OFF our family room air freshener, and then fires scripts to turn on our master bedroom and children’s room’s humidifiers - each of these is based on A) whether the person(s) are home and B) weather / HVAC (kids use upstairs, parents use downstairs) conditions inside the scripts.

image

Always more than one way to skin a cat in HA.