Motion: turn off light but not when iMac is active not working

Hi, I have this automation, where light turn on when there is motion, turn off when there have been no motion for 3 minutes. But if iMac is active, the light must not be turned off.

But the light does not turn off, after the iMac is inactive? What i’m doing wrong?

alias: Tanjas Kontor Motion
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 1da4a376d6a402f5ee85a4d729404159
    entity_id: binary_sensor.tanjas_kontor_motion
    domain: binary_sensor
    id: motion-detected
  - type: no_motion
    platform: device
    device_id: 1da4a376d6a402f5ee85a4d729404159
    entity_id: binary_sensor.tanjas_kontor_motion
    domain: binary_sensor
    id: motion-notdetected
    for:
      hours: 0
      minutes: 3
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: motion-detected
          - type: is_illuminance
            condition: device
            device_id: 1da4a376d6a402f5ee85a4d729404159
            entity_id: sensor.tanjas_kontor_motion_illuminance
            domain: sensor
            below: 50
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 80
            target:
              area_id: tanjas_kontor
      - conditions:
          - condition: trigger
            id: motion-notdetected
        sequence:
          - if:
              - type: is_off
                condition: device
                device_id: ea1d7286edb2de376c615a4536284254
                entity_id: binary_sensor.tanjas_imac_active
                domain: binary_sensor
            then:
              - service: light.turn_off
                data: {}
                target:
                  area_id: tanjas_kontor
mode: single

You need to add a trigger that detects when the iMac is inactive and then turn off the light.

The following automation employs three State Triggers for detecting when there is/isn’t motion and when the iMac is turned off.

alias: Tanjas Kontor Motion
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.tanjas_kontor_motion
    from: 'off'
    to: 'on'
    variables:
      is_true: "{{ states('sensor.tanjas_kontor_motion_illuminance') | int(100) < 50 }}"
      percent: 80
  - platform: state
    entity_id: binary_sensor.tanjas_kontor_motion
    from: 'on'
    to: 'off'
    for:
      minutes: 3
    variables:
      is_true: "{{ is_state('binary_sensor.tanjas_imac_active', 'off') }}"
      percent: 0
  - platform: state
    entity_id: binary_sensor.tanjas_imac_active
    from: 'on'
    to: 'off'
    for:
      seconds: 30
    variables:
      is_true: "{{ true }}"
      percent: 0
condition:
  - condition: template
    value_template: "{{ is_true }}"
action:
  - service: light.turn_on
    data:
      brightness_pct: "{{ percent }}"
    target:
      area_id: tanjas_kontor
mode: single
1 Like

Thanks, but there is nothing turning off the light?

Turning on with brightness zero is the same as turning off. Just try it in the developer tools, the light has the state off after turning it on with zero brightness.

1 Like