Help Getting Automation to work

good morning guys;
i’m trying to set this automation up but for some reason i can’t seem to get it to work, would you guys be able to help me with it please.

- id: '1703677342247'
  alias: Turn On/Off Master Bath Light Day and Night
  description: Turn On/Off Master Bath Light Day and Night
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.mbath_all_motion_sensors
    from: 'off'
    to: 'on'
  condition:
  - condition: time
    after: 07:00:00
    before: '21:59:00'
  - condition: or
    conditions:
    - condition: time
      after: '22:00:00'
      before: 06:58:00
  action:
  - service: light.turn_on
    target:
      entity_id: light.mbath_vanity_lights
    data:
      transition: 1
      brightness_pct: 100
  - wait_for_trigger:
    - platform: state
      entity_id:
      - binary_sensor.mbath_all_motion_sensors
      for:
        hours: 0
        minutes: 0
        seconds: 30
  - service: light.turn_off
    target:
      entity_id: light.mbath_vanity_lights
    data:
      transition: 20
  - service: light.turn_on
    target:
      entity_id: light.mbath_vanity_lights
    data:
      transition: 2
      brightness_pct: 49
  - wait_for_trigger:
    - platform: state
      entity_id:
      - binary_sensor.mbath_all_motion_sensors
      for:
        hours: 0
        minutes: 0
        seconds: 30
  - service: light.turn_off
    target:
      entity_id: light.mbath_vanity_lights
    data:
      transition: 30
  mode: single

Which light.turn_on vs light.turn_off, do you expect the action to execute, you have double of both
I suggest you start with a simple automation, and “add” conditions/actions until it “fails to work”

I would do it something like this:

alias: Turn On/Off Master Bath Light Day and Night
description: Turn On/Off Master Bath Light Day and Night
trigger:
  - platform: state
    entity_id:
      - binary_sensor.mbath_all_motion_sensors
    from: "off"
    to: "on"
    id: "on"
  - platform: state
    entity_id:
      - binary_sensor.mbath_all_motion_sensors
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30
action:
  - choose:
      - conditions:
          - condition: time
            after: "22:00:00"
            before: "06:58:00"
          - condition: trigger
            id:
              - "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.mbath_vanity_lights
            data:
              transition: 2
              brightness_pct: 40
     - conditions:
          - condition: time
            after: "07:00:00"
            before: "21:59:00"
          - condition: trigger
            id:
              - "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.mbath_vanity_lights
            data:
              transition: 1
              brightness_pct: 100
    default:
      - service: light.turn_off
        target:
          entity_id: light.mbath_vanity_lights
        data:
          transition: 30
1 Like

thank you very much for the hint and i will give that a try

thank you for your reply,
i would like the light to be at 100% brightness from 7am to 8pm for example and at 30-40% brightness from 1030pm to 6am.

Yes that was also what i thought, but it wasn’t specified in the “action” , however AceIndys “solution” seems much more “elegant” than what i could have come up with :slight_smile:
I tend to end up with 2 automations, but eventually i might go through them, when i see better/more simple solutions, i save them in a text-file … for boring days :slight_smile:

If you’re interested, this is what I use for my hallway downstairs (as the MQTT motion sensor does not have a timeout):

alias: Hallway Downstairs Light on Motion
description: Off when no motion for 9 mins
trigger:
  - alias: When motion detected hallway downstairs Pir [D41D0E] was trigged by MQTT
    platform: mqtt
    topic: TasmotaBRG1/tele/RESULT
    payload: D41D0E
    value_template: "{{ value_json.RfReceived.Data}}"
    id: Motion
condition: []
action:
  - alias: "Between 21:00 and 6:30, turn on 10% , otherwise 100% "
    choose:
      - conditions:
          - condition: time
            after: "21:00:00"
            before: "06:30:00"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 10
            target:
              entity_id: light.light_hallway_downstairs
    default:
      - service: light.turn_on
        data:
          brightness_pct: 100
        target:
          entity_id: light.light_hallway_downstairs
  - delay:
      hours: 0
      minutes: 9
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.light_hallway_downstairs
mode: restart
1 Like

It’s actually first time i “noticed” the " default: " feature , which is often my reasons for 2 “solution” :slight_smile:

Most of my motion-sensors (the aqara) has a default timeout, about 1 min , enough for most places i use them(lead-lights etc), the others (Tapo) i use them where i need lights-on for specified time

Is it possible to use - delay, under " Default: " ?

Yeah, sure, why not…it is just ‘another’ action :thinking:

Yes, but i only want the delay for the “default” action
… or the choose/conditions … never mind, ill check my self :blush:
… just have to "merged (2) of my simple automations, so i can try out “default:”