How do I setup in configuration.yaml to make the automation of motion sensor stop in a specific time of the day

I have been using this configuration for 2 pir sensor with sonoff bridge to control the lights in bhaus sala. this is working fine but this is working 24/7. I would like to control this configuration to deactivate in a specific time of the day or when it is sunset until 11pm or 23:00. Any help on how I may go about the scheduling?

  - alias: Turn on Bhaus Sala if there is movement
    trigger:
    - platform: state
      entity_id: binary_sensor.bhaus_sala_motion, binary_sensor.bhaus_kitchen_motion
      to: 'on'
    action:
    - service: homeassistant.turn_on
      data:
        entity_id:
        - switch.bhaus_sala
    - service: timer.start
      data:
        entity_id: timer.bhaussala

  - alias: Turn Off Bhaus Sala 5 minutes after trigger
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.bhaussala
    action:
    - service: homeassistant.turn_off
      data:
        entity_id:
        - switch.bhaus_sala
timer:
  bhaussala:
    duration: 00:05:00

Add a condition to your automation.

And please format your code properly.

Point 11

1 Like

Sorry for the newbie question @VDRainer I was actually scouring the forum for possible solutions but couldn’t find one. Thanks for guiding me to the right way. And here is my config now:

  - alias: Turn Off Bhaus Sala 5 minutes after trigger
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.bhaussala
    condition:
      condition: time
      after: 23:00:00
      before: 17:00:00
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
    action:
    - service: homeassistant.turn_off
      data:
        entity_id:
        - switch.bhaus_sala

But this is giving me an error in config check:
Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘after’]. Got None
extra keys not allowed @ data[‘condition’][0][‘before’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None
required key not provided @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 375). Please check the docs at https://home-assistant.io/components/automation/

It’s impossible to help if you don’t format your code.

Sorry I couldn’t quite figure how to paste the codes. Now i figured it out. Thanks @VDRainer Here is my code now

  - alias: Turn Off Bhaus Sala 5 minutes after trigger
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.bhaussala
    condition: 
      - condition: time
        before: 17:00:00
        after: 23:00:00
        weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
        - sat
        - sun
    action:
    - service: homeassistant.turn_off
      data:
        entity_id:
        - switch.bhaus_sala

put your time in quotes. '17:00:00', not just 17:00:00

1 Like

Hey! That did the trick @petro my config is valid now. I will test it out now. Restarting HASS. Thanks a lot!

1 Like

You should turn the condition into the ‘Turn on Bhaus Sala if there is movement’ automation, not in the ‘Turn off’ :slightly_smiling_face:

Hello @VDRainer, I couldn’t quite grasp what you meant with

I am trying to implement from 17:00 - 23:00 even if there is no motion detected the light stays on. My old config is this:

  - alias: Turn on Bhaus Sala if there is movement
    trigger:
    - platform: state
      entity_id: binary_sensor.bhaus_sala_motion, binary_sensor.bhaus_kitchen_motion
      to: 'on'
    action:
    - service: homeassistant.turn_on
      data:
        entity_id:
        - switch.bhaus_sala
    - service: timer.start
      data:
        entity_id: timer.bhaussala
    - service: timer.restart
      data:
        entity_id: timer.bhaussala

  - alias: Turn Off Bhaus Sala 5 minutes after trigger
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.bhaussala
    action:
    - service: homeassistant.turn_off
      data:
        entity_id:
        - switch.bhaus_sala

timer:
  bhaussala:
    duration: 00:05:00

This is without the condition. Now with the conditions set, I am monitoring the timer I noticed that the timer doesn’t reset to 5mins even though there is motion detected it just keeps going down until it stays in active although the light stays on but I am feeling there is something wrong here?

bandicam%202019-06-20%2008-56-03-586 bandicam%202019-06-20%2008-56-08-183