#Multiple triggers not working

22 messages · Page 1 of 1 (latest)

gloomy orbit
#

I have an Everything Presence Lite, my smart TV and some ceiling lights & lamps in my living room.

I'm trying to create an automation that will do the following:

Triggers:

  • Occupancy detected
  • TV turned on

Conditions:

  • Illumination below 50 lux (measured by EPL)

Actions:

  • Conditional action
    • 1: If the TV is off, turn on the main lights and turn off the lamps
    • 2: If the TV is on, turn on the lamps and turn off the main lights
  • Wait on occupancy clearing for 1 minute
  • Turn off all lights

The occupancy detection part of this all works fine. If the TV is on when the sensor is triggered it turns the lamps on, otherwise the main lights.

However, the intention is that when you first walk into the room while the TV is off, the main light will come on. Then when you turn on the TV it will re-trigger the automation swapping to the lamps. This doesn't seem to work.

Can anyone help me?

vague finch
#

Hello @gloomy orbit,
I'm sorry, but if you don't format your code so we can read it, we won't be of much help.

dim jayBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

gloomy orbit
#

Sorry, I'm very new to Home Assistant - is there a place to get the automation yaml that I've missed?

nimble spindle
vague finch
#

Show what you did by clicking on edit as yaml in the ui editor and copy/paste that using the display method from the prior post.

nimble spindle
#

Oh yeah.. always forget it's in the UI

gloomy orbit
#

I think I found it:

alias: Living Room Lights Automation
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.living_room_everything_presence_lite_occupancy
    to: "on"
  - trigger: state
    entity_id:
      - media_player.living_room_tv
    to: "on"
conditions:
  - type: is_illuminance
    condition: device
    device_id: c7f197d34ef034d6679ad1bc5f19fa5c
    entity_id: 461aece7fb9b6297a1e675a75db8bb5b
    domain: sensor
    below: 50
actions:
  - choose:
      - conditions:
          - condition: not
            conditions:
              - condition: state
                entity_id: media_player.living_room_tv
                state: "on"
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              brightness_pct: 75
            target:
              entity_id: light.living_room_lights
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.living_room_lamps
      - conditions:
          - condition: state
            entity_id: media_player.living_room_tv
            state: "on"
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              brightness_pct: 75
            target:
              entity_id: light.living_room_lamps
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.living_room_lights
  - wait_for_trigger:
      - type: not_occupied
        device_id: c7f197d34ef034d6679ad1bc5f19fa5c
        entity_id: 339aa3f3c2e5c6613ef147a61a0380e2
        domain: binary_sensor
        trigger: device
        for:
          hours: 0
          minutes: 1
          seconds: 0
    continue_on_timeout: false
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id:
        - light.living_room_lamps
        - light.living_room_lights
mode: single
nimble spindle
#

it looks like it'll get stuck on the "wait for occupancy" trigger which in single mode will prevent it from re-triggering when you turn the TV on

gloomy orbit
#

I hadn't even seen "mode" in the UI. Just found it. Would "restart" have the effect I'm looking for?

nimble spindle
#

if you want to keep it all in one automation I'd recommend something like:
wait_for_trigger goes to triggers instead - give it an id of "empty"
conditions - illuminance OR trigger ID == "empty"
actions: IF trigger ID == "empty" THEN turn off the lights ELSE [everthing else in you current choose block]

#

"restart" would probably work fine ^^ - i try to avoid messing with the modes unless i have to, because i never look at it much and it can change the behaviour in ways i'm not expecting when I don't pay attention

gloomy orbit
# nimble spindle if you want to keep it all in one automation I'd recommend something like: wait_...

I'm not sure I fully understand this. Let me repeat it back and see if I have it correct.

Instead of the "Wait for trigger" I should instead create a new trigger in the top triggers section for when the room becomes "not occupied". Editing this trigger's ID to "empty" (or some other known value)

I then amend the condition to allow it to pass if either the illuminance is less than 50 OR the trigger ID was our known value.

I then add a branch to the "choose" section (moving it to the first element) which has a condition to check the trigger ID and turns off the lights if it's our known value?

nimble spindle
#

yup, exactly

gloomy orbit
#

Ok, I'll give it a try, thanks.

#

Are the conditions "AND" by default?

vague finch
#

yes

gloomy orbit
#

last question for now - in a "choose" action, are the "default actions" executed on every run, or only if no other branch is chosen?

#

The trace graph makes it look like every run but that feels odd to me coming from a programming background with switch statements

vague finch
#

If it's under default, it happens if nothing else happens. If it's after the choose scope ends, it will happen every time.

gloomy orbit
#

Ok, that makes sense. Thanks