Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Two lights automation – IF/ELSE problem

$
0
0

@Fialad wrote:

Hi,
I have a hallway with two lights, one for day and other for night.
I have two automations that watch for either of the lights to turn ON.
Conditions determine what time of day it is, maybe look at the outside illumination levels and decide which light of the two to turn on.

My problem is determining in the action part if the correct light is already ON.
If so, I would turn both OFF, else I would turn ON just the right one.

I could split this into four automations and use conditions to determine this, but why if it can and should be determined in a simple IF ELSE statement in the action part.

This is the scheme:

Hallway Lights – Night

Trigger: Hallway OFF=>ON
Conditions: TIME 22:00–6:00 OR (TIME 15:00–22:00 AND Ilumination<500)
Action: IF (Hallway_Night==ON) THEN (Hallway=>OFF AND Hallway_Night=>OFF)
        ELSE (Hallway=>OFF AND Hallway_Night=>ON)


Hallway Lights – Day

Trigger: Hallway_Night OFF=>ON
Conditions: TIME 6:00–15:00 OR (TIME 15:00–6:00 AND Ilumination>500)
Action: IF (Hallway==ON) THEN (Hallway=>OFF AND Hallway_Night=>OFF)
        ELSE (Hallway=>ON AND Hallway_Night=>OFF)

And this is one of the automations working except I cannot figure out the action part with IF ELSE.
Note the action part of the code is just my intention – not an actual code I am trying.

- id: '1581701805691'
  alias: Hallway lights – night
  description: Use the night hallway light at night automatically
  trigger:
  - entity_id: light.hallway
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: or
    conditions:
    - after: '22:00'
      before: '6:00'
      condition: time
    - condition: and
      conditions:
      - after: '15:00'
        before: '22:00'
        condition: time
      - below: '500'
        condition: numeric_state
        entity_id: sensor.outside_ambient_light
  action:

IF ( light.hallway_night == ON ) { light.hallway => OFF, light.hallway_night => OFF  }
ELSE { light.hallway => OFF, light.hallway_night => ON  }

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles