Get steps and walking distance from your ios device

Tags: #<Tag:0x00007fc40b9d5d10> #<Tag:0x00007fc40b9d5c20>

owntracks can send the steps and walking distance that your iphone measures to home assistant. you have to poll owntracks for that

automation:
  alias: "get steps"
  trigger:
    - platform: time
      # Matches every hour at 10 minutes past whole
      minutes: 10
      seconds: 00
  action:
    - service: mqtt.publish
      data:
        topic: "owntracks/eins/ix/cmd"
        payload_template: '{"_type" : "cmd", "action": "reportSteps"}'
        qos: 2

for owntracks remote commands to work, you might have to configure owntracks to accept commands. i think this is not set by default. it might require to set "cmd":true via remote configuration. if owntracks is set up and reportSteps is requested via mqtt regularly, these sensors should populate:

sensor:
  - platform: mqtt
    state_topic: "owntracks/eins/ix/step"
    name: "Steps Felix"
    value_template: '{{ value_json.steps }}'
  - platform: mqtt
    state_topic: "owntracks/eins/ix/step"
    name: "Distance Felix"
    unit_of_measurement: "m"
    value_template: '{{ value_json.distance | round(1) }}'

Having trouble getting this to work, cmd:true is set, I checked by exporting the .otrc file and taking a a look at it.

my automation.yaml contains:

- alias: "get steps"
  trigger:
    platform: time
    # Matches every hour at 10 minutes past whole
    minutes: 10
    seconds: 00
  action:
    service: mqtt.publish
    data:
      topic: "owntracks/Iain/iphone/cmd"
      payload_template: '{"_type" : "cmd", "action": "reportSteps"}'
      qos: 2

Iain in the topic is my UserID in owntracks, iphone is my DeviceID.

The sensor appears but never updates, my location tracking using owntracks works fine.

Sensor is in configuration.yaml as follows:

sensor:
  - platform: mqtt
    state_topic: "owntracks/Iain/iphone/step"
    name: "Steps Iain"
    value_template: '{{ value_json.steps }}'
  - platform: mqtt
    state_topic: "owntracks/Iain/iphone/step"
    name: "Distance Iain"
    unit_of_measurement: "m"
    value_template: '{{ value_json.distance | round(1) }}'

Any thoughts?

have you checked wheter it works if you use an mqtt debugging tool like mqtt.fx?
publish the cmd payload to owntracks/Iain/iphone/cmdwith mqtt.fx while being subscribed to /owntracks/# and see wheter owntracks answers with the arcoring payload?

@diplix I just tried your solution. It seems to work well when my iphone is unlocked and Owntracks is open and on the foreground. Is there any trick to get this with Owntracks force closed (or at least put to the background) and the iphone locked?
Just tried a little further, I only get it to work in the background and with the iphone locked as long as I have move mode enabled.

it works in the background, too, but only if the phone gives owntracks computing time. usually this happens (in the background, with a locked phone) when significant location changes happen — and for that it should be sufficient to have significant changes mode enabled.

what i did (see above) was set up a recurring automation that sends queries to the phone, which then, if send with qos 2, get answered when the phone changes location or crosses a geofence. so when i get home, i usually have acurate steps displayed, that got transmited to HA when i entered the home zone.

Thanks for the fast response. I’ll play a bit with it and see what works best for me :slight_smile:

The script is also good for finding my flights climbed :slight_smile:

image

1 Like