Help turn on/off light with automation

i want to turn on the lights automatically when the sun is down and i’m at home. That also works so far.

alias: "[WZ] Stehlampen einschalten"
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition:
  - condition: or
    conditions:
      - condition: device
        device_id: 3d7b00cc230e891e8b886e0f8b59d3e3
        domain: device_tracker
        entity_id: device_tracker.handy_sven
        type: is_home
      - condition: device
        device_id: 8e4e11dac3bfaa26095fa53b07cdfcee
        domain: device_tracker
        entity_id: device_tracker.handy_stephie_2
        type: is_home
action:
  - type: turn_on
    device_id: a1b761ec5f62b99d8b3afa0175c5ac6c
    entity_id: switch.ikea_tradfri_steckdose_9de589fe_on_off
    domain: switch
  - type: turn_on
    device_id: 8552569d6978b212b8cb7087b41c66b3
    entity_id: light.ikea_tradfri_birne_e27_level_light_color_on_off
    domain: light
    brightness_pct: 65
mode: single

I turn them off when I go to bed with a button.

 - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: toggle
    entity: light.ikea_tradfri_birne_e27_level_light_color_on_off
    show_state: true
    brightness_pct: 100
    name: Stehleuchte WZ 1
    icon: mdi:lamp

if the lamps are switched off at night, the lamps should be switched on with a motion detector and off again after a few minutes. I have 2 automations for this

ON:

alias: "[WZ] Stehlampe 1 Motion an"
description: ""
trigger:
  - type: motion
    platform: device
    device_id: f579f2d9fb54d42f22899fe12af18f95
    entity_id: binary_sensor.ikea_bewegungsmelder_wz_on_off
    domain: binary_sensor
condition:
  - condition: device
    type: is_off
    device_id: 8552569d6978b212b8cb7087b41c66b3
    entity_id: light.ikea_tradfri_birne_e27_level_light_color_on_off
    domain: light
  - condition: sun
    before: sunset
action:
  - type: turn_on
    device_id: 8552569d6978b212b8cb7087b41c66b3
    entity_id: light.ikea_tradfri_birne_e27_level_light_color_on_off
    domain: light
    brightness_pct: 15
mode: single

OFF:

alias: "[WZ] Stehlampe 1 Motion aus"
description: ""
trigger:
  - type: no_motion
    platform: device
    device_id: f579f2d9fb54d42f22899fe12af18f95
    entity_id: binary_sensor.ikea_bewegungsmelder_wz_on_off
    domain: binary_sensor
condition: []
action:
  - type: turn_off
    device_id: 8552569d6978b212b8cb7087b41c66b3
    entity_id: light.ikea_tradfri_birne_e27_level_light_color_on_off
    domain: light
mode: single

The problem is that the lamp is always switched off and then switched on again by the motion detector. But I want that to only happen when I’ve turned off the lamp myself.

Here is an Eample

automation:
- id: one
  alias: "Turn on light when motion is detected"
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_1
      to: "on"
  action:
    - service: light.turn_on
      target:
        entity_id: light.living_room

Add a condition for motion activated automation that prevents trigger if the other automation turned it on

This Blueprint will probably be a solution for what you are looking for:

2 Likes

thanks, that was the solution.

1 Like