Not_home to home with mqtt and owntracks not working for me

I have a typical setup with Owntracks send mqtt message to my Cloudmqtt account. I setup a trigger with the transition from not_home to home state but it does not work. My state does change to home when I get within the assigned radius form home, but the state just before is not “not_home” but a mqtt message showing the location. Just before that mqtt message, the state is “not_home”. But since the transition is not from not_home to home the trigger never occurs. So why the state while I am still not home shows as the actual mqtt message? It should show as not_home.

Here is part of my configuration:

device_tracker:
  - platform: owntracks
  - platform: mqtt
    devices:
        qjvvyniw_phonebm: owntracks/qjvvyniw/PhoneBM

mqtt:
  broker: HIDDEN.cloudmqtt.com
  port: HIDDEN
  client_id: qjvvyniw_phonebm
  keepalive: 60
  username: HIDDEN
  password: HIDDEN

zone:
  name: Home
  latitude: HIDDEN
  longitude: HIDDEN
  radius: 450
  icon: mdi:home

automation 3:
alias: Open garage when I arrive home
trigger:
platform: state
entity_id: device_tracker.qjvvyniw_phonebm
from: ‘not_home’
to: ‘home’
condition:
- condition: time
after: ‘17:00:00’
before: ‘19:00:00’
weekday:
- mon
- tue
- wed
- thu
- fri
action:
service: shell_command.garage

This is how it looks like just before my state changed to home:

Any idea what is going on.

I’m no expert but instead of state change from “not_home” to “home” I use something like this

  trigger:
    - platform: zone
      entity_id: device_tracker.owntracks_MYPHONE
      zone: zone.home
      event: enter

So the platform zone instead of the platform state and this works for me

I am trying to set up the zone.home enter/leave. My owntracks setup uses iBeacons as a “-home” waypoint. I get the messages coming onto HA but the automations are not triggering using the enter/leave message. I can get them to trigger if I send a message via the cloudmqtt console with a modified GPS location ( to simulate a different location ) but thought that this should be overridden by the zone.home trigger.

Can you help guide me on how to debug this.

My automation.yaml

- alias: Leave
  trigger:
    platform: zone
    entity_id: device_tracker.phone_samsiphone
    zone: zone.home
    event: leave  
#    platform: state
#    entity_id: device_tracker.phone_samsiphone
#    from: 'home'
#    to: 'not_home'
#    for:
#      minutes: 4
  action:
    - service: switch.turn_off
      entity_id:
        - group.living_room
        - group.bedroom
        - switch.study_airconditioner

        
- alias: Return
  trigger:
#    platform: state
#    entity_id: device_tracker.phone_samsiphone
#    from: 'not_home'
#    for:
#      minutes: 4
#    to: 'home'
    platform: zone
    entity_id: device_tracker.phone_samsiphone
    zone: zone.home
    event: enter
  action:
    - service: switch.turn_on
      entity_id:
        - switch.living_room_fan
        - switch.living_room_lamp
    - service: script.turn_on
      entity_id:    
        - script.turn_on_bredroom_fan
        - script.turn_on_sound_bar

My zones.yaml

- name: home
  latitude: !secret homeassistant_latitude
  longitude: !secret homeassistant_longitude
  radius: 200
  icon: mdi:home