Owntracks + CloudMQTT - what am I doing wrong?

Hi folks, first time poster, be gentle with me! :slight_smile:

I’ve been fiddling with HA for a couple of months now, and I have it doing a few things that I’m happy with - but I’m having little luck with device tracking, and I hope someone can point out where I’m going wrong.

I am trying to use Owntracks, connected to a free CloudMQTT instance, then trigger automations based on devices changing zone.

My device shows as “HOME” on HA->Overview, and shows in the correct place on the map when I’m out. The configured Zones show as yellow circles on the map. So (I believe) the Owntracks -> CloudMQTT -> HA path must all be working, and the problem lie with my automations(?)

I’ve setup a bunch of similar test automations, cribbing from examples on the HA site. These appear under “Automation” on HA->Overview, and work if activated manually (i.e. send a notification via mailgun). But they don’t ever trigger on my device moving/changing zones.

I DO see entries in the logbook such as " is at "

I suspect (part of) the problem is that I’m not referring to devices correctly. Can someone explain the distinction between the Owntracks settings “Device ID”, “Tracker ID” and “username”, and which should be used in HA with entity_id: device_tracker.?

Or I guess equivalently, which part of the device entry in known_devices.yaml goes in entity_id: device_tracker.?

I also have the Unifi device tracker component installed, which might complicate things? But I think that, so far, HA is simply seeing everything on unifi, including the phones that are also running Owntracks, as entirely separate devices (“Android-xxxxxxx”)

Any suggestions?

Here’s my automations.yaml:

  - alias: 'Leave Home Test'
    trigger:
      platform: zone
      event: leave
      zone: zone.home
      entity_id: device_tracker.apgS3New
    action:
      service: notify.mailgun
      data:
        message: 'Test left the house'

  - alias: 'Leave Home notification apgS3'
    trigger:
      platform: zone
      event: leave
      zone: zone.home
      entity_id: device_tracker.apgS3
#    condition:
#      condition: time
      #after: '20:00'
    action:
      service: notify.mailgun
      data:
        message: 'A (apgS3) left the house'

  - alias: 'Leave Home Vanadium'
    trigger:
      platform: zone
      event: leave
      zone: zone.home
      entity_id: device_tracker.Vanadium
    action:
      service: notify.mailgun
      data:
        title: 'Vanadium left the house'
        message: 'Vanadium left the building'
        
  - alias: 'Leave Home notification S3'
    trigger:
      platform: zone
      event: leave
      zone: zone.home
      entity_id: device_tracker.S3
#    condition:
#      condition: time
      #after: '20:00'
    action:
      service: notify.mailgun
      data:
        title: 'A (S3) left the house'
        message: '...yes he did!'

  - alias: 'Arrive Home notification apgS3'
    trigger:
      platform: zone
      event: enter
      zone: zone.home
      entity_id: device_tracker.apgS3
    action:
      service: notify.mailgun
      data:
        message: 'A (apgS3) got home'
        
  - alias: 'Arrive GT notification apgS3'
    trigger:
      platform: zone
      event: enter
      zone: zone.gt
      entity_id: device_tracker.apgS3
    action:
      service: notify.mailgun
      data:
        message: 'A (apgS3) got to GT'      

username is the mqtt username, deviceid is the name of the device which translates to device_tracker.‘deviceid’, and tracker id is a 2 letter id (that shows up on the map) to differentiate it from others.

As for tracking leaving/arriving home, you can just use state change from home to not_home or not_home to home instead of entering exit zones. This way you can write 1 automation for all devices.

Thanks for the info :slight_smile:

I don’t merely want it for leaving/arriving home though - these are just tests to figure out the syntax. I want to do things, say, when I leave work, or if my partner gets home and I’m still at work, or well, all sorts of possibilities really.

Maybe I could do this with state changes (?) - but it seems like the zone events are specifically designed for my purposes, so it seems silly not to use them?

Do you have any idea why the automations posted aren’t triggering?

I only use home/not_home/ or the name of my zone so I’m not really sure. You can still do stuff like leaving work with state changes as well. ie

when someone comes home ,

i have

- alias: Someone came home
  trigger:
    - platform: state
      entity_id: entity
      from: 'not_home'
      to: home
  action:
    - service: notify.html5
      data_template:
        title: "Home Assitant"
        message: "{{ trigger.to_state.attributes.friendly_name }} arrived home at {{ states('sensor.time') }}"
        target: ['cyclops', 'gambit']
    - service: mqtt.publish
      data_template:
        topic: "ha/{{ trigger.to_state.attributes.friendly_name | lower }}_home_status"
        payload: home
        retain: false

i have multiple entities listed so whichever one triggers the automation it’s added to the mqtt topic and the html5 notification. hence 1 automation for multiple entites. I do the same with different zones but using the state change.

OK, well, it’s something to try, anyway! :slight_smile: Will give it a shot.

Ooh, though actually, I notice your code has a “-” at the third level of nesting, i.e. “- platform: state”, “- service: notify.html5”, where mine does not “platform: zone”. Could it be as simple as that?

I thought I’d literally cut and pasted from an example though :confused: YAML is new to me.

it shouldn’t. I have the - because in mine automatons I have multiple entities.