Location based automation not quite working

Hi there,

I am trying to get wifi location working. I’ve had some success, but things seem to have stopped working.

Could any of you code ninja’s take a look at the below code to see if there is something wrong (or indeed something that I could be doing better).

One thing that I am not certain on is whether there should be quote marks around the ‘home’ and ‘not_home’ bits.

- action:
  - data:
      event: wifi_away
    service: ifttt.trigger
  - data:
      entity_id: light.all_lights
    service: light.turn_off
  alias: Wifi Away Mart
  condition:
  - after: sunrise
    before: sunset
    before_offset: 00:40:00
    condition: sun
  - condition: state
    entity_id: device_tracker.claregrsiphone6
    state: 'not_home'
  - after: 08:30
    before: '10:30'
    condition: time
    weekday:
    - mon
    - tue
    - wed
    - fri
    - sat
    - sun
  id: '1515596681496'
  trigger:
  - entity_id: device_tracker.pixel2
    from: 'home'
    platform: state
    to: 'not_home'

Cheers people!

Man, this is precisely why I hate the automation editor - it formats everything all over the place, and then when it breaks and someone comesand asks for help it’s a royal PITA to scrub through it and find the problem.

/rant over :stuck_out_tongue_closed_eyes:

Anywho, assuming I’ve understood your problem correctly, try this…

- id: '1515596681496'
  alias: Wifi Away Mart
  trigger:
    platform: state
    entity_id: device_tracker.pixel2
    to: 'not_home'
  condition:
    - condition: sun
      after: sunrise
    - condition: sun
      before: sunset
      before_offset: 00:40:00
    - condition: state
      entity_id: device_tracker.claregrsiphone6
      state: 'not_home'
    - condition: time
      after: 08:30
      before: '10:30'
    - condition: time
      weekday:
        - mon
        - tue
        - wed
        - fri
        - sat
        - sun
  action:
  - service: ifttt.trigger
    data:
      event: wifi_away
  - service: light.turn_off
    entity_id: light.all_lights

…that’s respecting all the conditions you already had, although I suspect they’re overkill and duplicating. I didn’t bother trying to work out the logic, just added a couple of lines here and there to prevent the sun conditions overlapping and cleaned it up a bit.

1 Like

Thanks for taking the time / effort to reformat this!

I’ll give it a go asap.

I’m just getting into Hassio, so I’m now converting my automations (built with the editor) into proper ones. The YAML formatting is giving me a few headaches though!

Thanks again :slight_smile:

1 Like

@anon43302295
Just a quick thing I don’t get -

- condition: time
      after: 08:30
      before: '10:30'

Why is 08:30 without quotes and 10:30 with? (or is this a typo)?

Yeah, they should all be in quotes, that was a typo from your OP that I accidentally carried over.

Should probably have the seconds on the end too.