Ignore state

Still learning so bear with me but I’m trying to set up an automation for when a device leaves one location and arrives at another. I’m currently doing this based on state, but am concerned that it will not function as I intend.

Consider this state timeline: home, not_home, work

Current automation:
  trigger:
    platform: state
    from: "home"
    to: "work"
    entity_id: device_tracker.myphone
  action:
    service: notify.notify_push_android
    data:
      message: I made it to work!!!

I’m thinking this will never be triggered due to the state changing from home to not_home BEFORE being changed to work.

Is there a way to ignore the transitive state? Or is there a better way to do this?

Hi!

Only using “state: work” should trigger when the device changes to that state, no matter the previous state. Haven’t tested this myself though.

Current automation:
  trigger:
    platform: state
    state: "work"
    entity_id: device_tracker.myphone
  action:
    service: notify.notify_push_android
    data:
      message: I made it to work!!!

Thanks Martin, but I’m interested in taking it a step further. Perhaps I drive by work on my way to the grocery store, or what have you. I’d like to only alert when I leave home and arrive at work.

I might be able to set a boolean if I leave home, and check it when I arrive at work to see if I’d just left home…

Maybe using the condition’s for?

Current automation:
  trigger:
    platform: state
    state: "work"
    entity_id: device_tracker.myphone
  condition:
    platform: state
    state: 'not_home'
    for:
      minutes: 30 #or the time you spent to travel from home to work
  action:
    service: notify.notify_push_android
    data:
      message: I made it to work!!!
1 Like