Away Automation - What am I doing wrong?

Hi All, hoping for some guidance with an automation I’ve created to open my curtains in the morning when I’m not at home. As of yet, it’s never actually ran. I end up logging into HA remotely and opening them manually, anyway, here’s the automation as it stands : -

  alias: Open SpareRoom Curtains when I'm Away
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states(''person.xxxxxxxxxx'') != ''home'' }}'
  condition:
  - condition: state
    entity_id: cover.spareroom_curtains
    state: closed
  - condition: and
    conditions:
    - condition: time
      before: '10:00:00'
      after: 08:30:00
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
  action:
  - service: cover.open_cover
    data: {}
    target:
      device_id: e0e356ecedb99258511d74455ae0c45e

N.B. I’ve replaced my person ID with xxxxxxxxxx above.
Can anyone tell what I’m doing wrong please?

Thank You in advance.

The one missing quote?

value_template: '{{ states(''person.xxxxxxxxxx') != ''home'' }}'
                                              ^                                                           

Ah sorry, that ’ does exist in the original, i must have gotten overzealous with my replacement x’s!
I’ll edit the code above.

I would swap the conditions and trigger and have the days and times you want the automation to run up top. With the condition of you not being home.

Or are you trying to run this automation as you leave?
If yes use a state trigger changing from home or to not_home for you person entity.

trigger:
  - platform: state
    entity_id: person.xxxx
    from: home

Try this:

alias: Open SpareRoom Curtains when I'm Away
description: ''
trigger:
  - platform: state
    entity_id: person.xxxx
    from: home
condition:
  - and:
      - condition: state
        entity_id: cover.spareroom_curtains
        state: closed
      - condition: time
        after: '08:30:00'
        before: '10:00:00'
action:
  - service: cover.open_cover
    target:
      entity_id: cover.spareroom_curtains

Just a few notes:

  • I wouldn’t use the device_id, use the entity_id instead (better readability)
  • always check your indentation
  • always use different quotation marks so you don’t get confused. Eg. outside you use double quotes (not double single quotes), so inside the template you can use single quotes:
    Dont do: '{{ states(''person.xxxxxxxxxx'') != ''home'' }}'
    Do: "{{ states('person.xxxxxxxxxx') != 'home' }}"
  • work with template triggers or conditions only, if you can’t use the “standards” like state or event. Does the job, but readability is better with “standards”. :slight_smile:
1 Like

Thanks Paddy, I’ll give that a go.
@SgtBatten, no it’s for when I’m away on holiday or whatever, not when leaving.

Then the condition and trigger need to swap as I said.

Otherwise your trigger only activates the moment you leave and not daily.

trigger:
  - platform: time
    at: '09:00:00'
condition:
  - and:
      - condition: state
        entity_id: cover.spareroom_curtains
        state: closed
      - condition: state
        entity_id: person.xxxxxx
        state: not_home
action:
  - service: cover.open_cover
    target:
      entity_id: cover.spareroom_curtains
1 Like

Thanks SgtBatten

The trigger/condition swap worked a treat.

If you don’t mind, could you please mark the last post from @SgtBatten as solution? Would be great, as others could directly see that there is a solution in this thread. :slight_smile:

Thanks and good you got it working! :slight_smile: Have a nice weekend! :slight_smile:

1 Like