Automation with two triggers (time based) to turn on and off switch

Hi all.
Want to setup an automation “Auto motion detect” to activate/deactivate motion detect based on time, but not get rid how write the config.
I’d like to have the turn on and turn off action in same alias because don’t want to switch off more than one “frontend switch” to enable/disable the automation

Here what I’ve tried without success

automation:
  - alias: "anoter automation"
    trigger:
      platform: state
      entity_id: an_id
      state: turn_on
    action:
       - service: shell_command.clear_captures
       - service: notify.telegram
         data: [...]

  - alias: "Auto motion detect"
    trigger:
      - platform: time
        after: '01:30:00'
        action:
          - service: switch.turn_on
            entity_id: switch.camera_garage_motion
          - service: notify.telegram
            data:
                message: Attivato motion detect in garage
      - platform: time
        after: '06:30:00'
          action:
            - service: switch.turn_off
              entity_id: switch.camera_garage_motion
            - service: notify.telegram
              data:
                message: Disattivato motion detect in garage

Here’s the error

homeassistant.bootstrap: Invalid config for [automation]: [action] is an invalid option for [automation]. Check: automation->trigger->0->action.

1 Like

Your “action” block should come after the trigger definitions, not inside them. So you have something like:

automation
    - alias: "name"
      trigger: 
       - trigger one...
       - trigger two...
      action:
        .....

Actions happen in response to any of the triggers. You can use conditions to filter that if necessary…

So there is no way, to make weekly schedule for a lamp, or switch? I have a weekly timer on lights, with different on/off times for mon-fri and sat-sun. Is such automation possible?

That’s totally possible. Your trigger would look at the time of day. You’d have a condition that’d check whether it’s a weekday or weekend. Then your action would control your lights.

Just make sure that your actions aren’t “inside” your triggers. They’re at the same level. The automation has: trigger, condition, action. The trigger and condition use the various platforms to check time/date/motion/etc.

Here’s a complicated example that creates an alarm clock. You can see in his condition where he’s testing for days of the week.

If I’m not mistaken (I’m new to this, too), you’d have a separate automation for weekends vs weekdays.

So I need to make ON action for weekday:[mon, tue, wed, thu, fri] and time[8:00:00], or weekday:[sat, sun] andt time[10:00:00] and similar to OFF action?

Right. But your trigger will be the time of day and you’ll use the weekday/weekend information as a condition. So, HA will say: OK, it’s 8am and I’m supposed to run this automation… and it’s a weekday, so I’ll continue to execute these actions.

1 Like

Thanks, I dig an example, it seems great, realy great.

@ih8gates Thanks for this explanation, very easy to understand how the automation works :slight_smile:

I need to do something similar. If the time is after 2000 before 0300 i want to dim the hallway light to 50%, and after 06:30 before 2000 i want to dim the hallway light to 100%
The trigger is a motion sensor, do any here have a example for me, or do i need to make multiple automation ?