Creating a Condition, based on "triggered by..."

Hope someone can give me some ideas…

So, I have an input_boolean (Visitors Mode - toggle) that allows me to cancel two automations, based on Motion, after 11.30PM, that turn on/off a lamp that I have in the living room, in case there’s someone over.

Then I created another two new automations, because my kid keeps forgetting there’s the “Visitors Mode” sigh , that toggles on the input_boolean, after 11.30PM, in case that the TV is on at that time. The same with toggling off the input_boolean when the TV is off, after that time.

The problem is that the last “auto toggling off”, will also turn off the input_boolean when I have someone over, if the TV is turned off.

Is there a way to condition it to “Not”, if the boolean was “triggered by service input_boolean.turn_off” / or Person; making a difference from “triggered by automation”?

Can you post all of the automations you have described?

Motion On - Lamp in Living Room:

alias: Motion ON
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion_sensor
    to: "on"
    enabled: false
  - platform: state
    entity_id:
      - binary_sensor.presence_46
    to: "on"
condition:
  - condition: time
    after: "00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
    enabled: true
  - condition: sun
    before: sunrise
    enabled: true
  - condition: state
    entity_id: input_boolean.cinema_mode
    state: "off"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.lamp
mode: single

Motion Off - Lamp in Living Room:

alias: Motion OFF
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion_sensor
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - type: no_motion
    platform: device
    device_id: 142c2d705647e00bf431e585ea5ceb63
    entity_id: binary_sensor.presence_46
    domain: binary_sensor
condition:
  - condition: time
    after: "00:00"
    before: "08:00"
    enabled: true
  - condition: state
    entity_id: input_boolean.visits
    state: "off"
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.lamp
mode: single

Auto On - Visitor Mode (toggle boolean):

alias: Auto on - Visitor Mode
description: ""
trigger:
  - platform: device
    device_id: 60cfe62a1c7f213593f15e9a72eb1197
    domain: media_player
    entity_id: media_player.lguj630v
    type: turned_on
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: time
    after: "23:50:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
    before: "06:00:00"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.visits
mode: single

Auto Off - Visitor Off (toggle boolean):

alias: Auto off - Visitor Mode
description: ""
trigger:
  - platform: device
    device_id: 60cfe62a1c7f213593f15e9a72eb1197
    domain: media_player
    entity_id: media_player.lguj630v
    type: turned_off
    for:
      hours: 0
      minutes: 3
      seconds: 0
condition:
  - condition: state
    entity_id: input_boolean.visits
    state: "on"
  - condition: time
    after: "00:00:00"
    before: "07:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.visits
mode: single
  • In ‘Motion ON’, the first State Trigger, that monitors binary_sensor.motion_sensor for an on state, is disabled (enabled: false).

  • In ‘Motion OFF’, the first State Trigger, that monitors binary_sensor.motion_sensor for an off state, is enabled.

So the first automation can’t detect when the motion sensor turns on but the second automation can detect when it turns off . Why? Is this the actual working version or were you experimenting with enabling/disabling individual triggers?


  • In ‘Motion ON’ the time range in the condition is from 00:00 to sunrise.

  • In ‘Motion OFf’ the time range in the condition is from 00:00 to 08:00.

Most motion-controlled lighting automations I have seen are symmetrical. In this case, the time periods for turning the light on and off aren’t identical and their respective State Condition doesn’t reference the same input_boolean. Why?

Yes, I’ve been experimenting with some problems related to one of the motion sensors. The binary_sensor_presence_46 is the newly added. Having the binary_sensor.motion_sensor, as trigger, disabled, on Motion On, was when I was testing both sensors.

The fact that both automations aren’t “symmetrical”, is related with the sunrise (06.58am) not always going accurate now-a-days with the light outside as the living room windows are located in South and West positions; it’s also going through some tests.


About the lack of reference of the input_boolean (Visitor Mode), there was no need for it to be within the Motion On; it’s (lamp) usually on, at the time, already. Only the input_boolean (Cinema Mode), so that it won’t turn that light on when that boolean is on.


Even though they do need some “cleaning”; everything is working.