Basic time trigger automation help

Hi All,

If this is in the wrong place or is not formatted correctly, please let me know, it’s my first post.

I’m trying to automate my garage to open and close when I leave for work in the morning. I leave at about the same time every morning (~7:30am) but I’d like it to only do so during the week (mon-fri) and when I’m actually home. For some reason the automation below does not work and I’m not sure why.

- alias: 'Morning garage cycle'
  hide_entity: false
  trigger:
    platform: time
    hours: 7
    minutes: 20
    seconds: 0
  condition:
    condition: and
    conditions:
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
      - condition: state
        entity_id: danny.device_tracker
        state: home
  action:
    - service: homeassistant.turn_on
      entity_id: script.morning_garage

I use this configuration to open and close the garage routinely:

- alias: Open and close garage upon arrival
  initial_state: 'on'
  hide_entity: false
  trigger:
    - platform: state
      entity_id: device_tracker.danny
      from: 'not_home'
      to: 'home'
    - platform: state
      entity_id: device_tracker.christina
      from: 'not_home'
      to: 'home'
  condition:
    - condition: time
      before: '23:59:00'
  action:
    service: homeassistant.turn_on
    entity_id: script.garage_trip_cycle

Any help would be great. Thanks

There is a workday sensor, which will probably help simplify it (since it also takes into account national holidays). I think too you want to use an actual time, rather than separate hours, minutes and seconds:

- alias: 'Morning garage cycle'
  hide_entity: false
  trigger:
    platform: time
    after: '07:20:00'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'binary_sensor.workday_sensor'
        state: 'on'
      - condition: state
        entity_id: danny.device_tracker
        state: home
  action:
    - service: homeassistant.turn_on
      entity_id: script.morning_garage

If you then trigger the automation manually, does it open the garage?

shoudn’t

  - condition: state
    entity_id: danny.device_tracker
    state: home

be

  - condition: state
    entity_id: device_tracker.danny
    state: home
1 Like

Can’t believe I missed that :frowning: Good spot!

As @forsquirel already mentioned, the problem is probably with danny.device_tracker, but I would like to add that the part below seems a bit unnecessary, just remove the condition part if you want the trigger to work all the time.

condition:
    - condition: time
      before: '23:59:00'

you are right since the clock resets at midnight anyway, “00:00:01” would be before '07:30:00", and before ‘23:59:00’

Oh dear, no wonder it wasn’t working. Thanks for spotting that.

Thanks for showing me the workday sensor, that’s going to simplify a lot of my other automations too.