LED Motion sensor automation

In my Master Bedroom closet I have a Wyze motion sensor that triggers a KULED switch to turn the closet light on/off. (CODE BELOW)

I want to add an automation that the light is triggered from 6AM to 9PM, then I want my LED strip (WLED Controlled Wemos d1 mini) to come on from 9PM tp 6AM if motion is triggered.

Where I am having trouble is with the time condition. If some one can point me in the right direction I would appreciate it.

Current code for motion sensor.

####################################################
#         MASTER CLOSET LIGHTS ON 16MAR2021        #
####################################################
- id: "1589495884826"
  alias: "Lights - Closet Lights ON"
  description: Master Bedroom Closet Lights ON
  trigger:
    - entity_id: binary_sensor.wyze_closet
      platform: state
      to: "on"
      from: "off"
  condition: []
  action:
    - entity_id: switch.master_bedroom_closet_light
      service: switch.turn_on
####################################################
#         MASTER CLOSET LIGHTS OFF 16MAR2021       #
####################################################
- id: "1589596007289"
  alias: "Lights - Closet Lights OFF"
  description: Master Bedroom Closet Lights OFF
  trigger:
    - entity_id: binary_sensor.wyze_closet
      for: 00:01:00
      platform: state
      to: "off"
      from: "on"
  condition: []
  action:
    - entity_id: switch.master_bedroom_closet_light
      service: switch.turn_off
  mode: single
####################################################
#            END OF CONFIGURATION FILE             #
####################################################

Would I just add the following to the above automation in the Lights On section and reverse it for the LED automation.

  condition:
    condition: time
    after: "06:00:00"
    before: "21:00:00"

The assumption I am making is that you have two lights:

  1. switch.master_bedroom_closet_light
  2. switch.master_bedroom_led_light
  • If the current hour is between 6 and 21 you want to turn on the 1st light, not the 2nd light.
  • If the time is outside those hours you want to turn on the 2nd light, not the 1st light.

The following single automation should handle turning the appropriate light on/off based on the motion sensor’s activities.

- id: "example_abc_123"
  alias: "Automatic Closet Lights"
  description: Master Bedroom Closet Lights
  mode: queued
  trigger:
    - entity_id: binary_sensor.wyze_closet
      platform: state
      to: "on"
      from: "off"
    - entity_id: binary_sensor.wyze_closet
      for: 00:01:00
      platform: state
      to: "off"
      from: "on"
  condition: []
  action:
    - service: "switch.turn_{{ trigger.to_state.state }}"
      target:
        entity_id: "switch.master_bedroom_{{ 'closet' 6 <= if now().hour < 21 else 'led' }}_light"

If the led light’s name is different, I can help you modify the template accordingly.

Thank you, worked great.

1 Like

Glad to hear it meets your requirements.

Please consider marking my post with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been solved. It makes it easier for users to find answers to similar questions. For more information, refer to guideline 21 in the FAQ.