MQTT Publish does not appear to send payload

I am trying to use Publish. to send the following payload to get my steps to my sensor
using my HiveMq broker

action: mqtt.publish
data:
  qos: "2"
  retain: false
  topic: owntracks/jason/iphone/
  payload: "'{\"_type\" : \"cmd\", \"action\": \"reportSteps\"}'"

Matt Explorer shows a different payload being received.

{
  "_type": "location",
  "acc": 5,
  "alt": 82,
  "batt": 100,
  "bs": 3,
  "bssid": "e6:bf:fa:94:cf:a7",
  "conn": "w",
  "inregions": [],
  "inrids": [],
  "lat": 45.407334,
  "lon": -122.664804,
  "m": 1,
  "p": 101.226,
  "ssid": "Yatesst",
  "tid": "jh",
  "tst": 1760678783,
  "vac": 14
}


Did I. misconfigure the Publish Command ?

I’m not sure what that is, but if you expect those to be variables, what is loading the variables, and 2 that is not a template so that would be sent up as literally what you type if it is accepted at all.

The topic appears to have been set-up by Owntracks. Pushing data to that topic would be confusing things. Is there something telling you to do this? I smell an LLM hallucination suggestion coming on here…

Once you figure out what is the right topic and you have your data, IO suggest looking here for format suggestions:

Example from the docs:

action: mqtt.publish
data:
  topic: homeassistant/sensor/Acurite-986-1R-51778/config
  payload: >-
    {"device_class": "temperature",
    "unit_of_measurement": "\u00b0C",
    "value_template": "{{ value|float }}",
    "state_topic": "rtl_433/rtl433/devices/Acurite-986/1R/51778/temperature_C",
    "unique_id": "Acurite-986-1R-51778-T",
    "device": {
    "identifiers": "Acurite-986-1R-51778",
    "name": "Bathroom",
    "model": "Acurite",
    "model_id": "986",
    "manufacturer": "rtl_433" }
    }

Examples from me in a blueprint, but the format is the same…

Not sure what a “LLM hallucination” is, I do know I am a hacker playing in water over his head and beyond his understanding. I am trying to utilize Owntracks. and trying obtain the steps recorded by mu iPhone. The gibberish I posted was supposed to be out put by a python program I was provided under GitHub

#!/usr/bin/env python3

import datetime
import time
import json
import sys

days = -1 # yesterday
days = 0  # only 0 or negative values make sense

def unix_epoch(t, delta):
    dt = t + delta

    return int(time.mktime(dt.timetuple()))

now = datetime.datetime.today()

f = now.replace(now.year, now.month, now.day, 0, 0, 1, 0)
t = now.replace(now.year, now.month, now.day, 23, 59, 59, 0)

delta = datetime.timedelta(days=days)

payload = {
        '_type' : 'cmd',
        'action' : 'reportSteps',
        'from'  : unix_epoch(f, delta),
        'to'    : unix_epoch(t, delta),
}
print(json.dumps(payload))

I can’t seem to get that program to run. (I guess I am supposed to to create an action) and can’t figure out how to access the steps that the iPhone pedometer is suppose to have recorded. Like I said I shouldn’t be playing with matches. Thank you for your time

Jason

Try something way simpler than trying to run a Python script to generate a JSON payload that you then paste into a Home Assistant script, especially since you recognize you’re in over your head. Break the problem up into pieces.

First, try to successfully run mqtt.publish without a JSON payload, on a clear topic that somebody else isn’t posting to. That way you know that you’ve got at least the basic building block you need before trying to build with it.

Go to Developer tools → Actions and run this while listening on the topic my_test/test:

action: mqtt.publish
data:
  topic: "my_test/test"
  payload: "FROM HA DEVELOPER TOOLS"

Does it come through?

1 Like

Thanks for your response. Yes your sample went through. I think I have a workable understanding of the mqtt.publish, I know where all the topics show on my broker are coming from. The core of my issue I think is how can I access the steps that the iPhone pedometer is suppose to have recorded. I think it is in a JSON file (database?). somewhere. The payload I showed with real content was was published by owntracks “send locatiion” which is suppopsedly built into home assistant.

looking at the Owmtracks documentation is built this action

action: mqtt.publish
data:
  qos: "2"
  retain: false
  topic: owntracks/jason/iphone/steps
  evaluate_payload: false
  payload: |-
    _type: "steps",
    elements

what is received is this



steps = _type "steps"

I don’t know anything about OwnTracks, but the front of its documentation (“What it does”) makes me think that you cannot publish commands yourself. Instead, OwnTracks probably simply pushes data from the phone as it receives it. This makes sense; to respond to commands that you push to OwnTracks, the service would need to run something much more sophisticated in the cloud than what is required if the OwnTracks app is just pushing MQTT payloads from the phone to the cloud.

I’m guessing you should be listening on the topic owntracks/jason/iphone/step for an MQTT message with _type set to steps.

If you’re listening to owntracks/jason/iphone/, which is where you’ve also been trying to publish messages (probably to no avail, as noted above), all you’re getting is type: location messages because you’re only listening to that specific topic, not to subtopics. Per the Topics section in the JSON API documentation from OwnTracks:

In MQTT mode the apps publish to:

  • owntracks/user/device with _type=location for location updates, and with _type=lwt
    . . .
  • owntracks/user/device/step to report step counter

If you listen to owntracks/jason/iphone/#, you will get messages published to subtopics, too, like owntracks/jason/iphone/steps. Or if what you want to be getting is just the steps messages, then listen on owntracks/jason/iphone/steps.

Hopefully this gets you started enough to where you can understand the rest of the OwnTracks documentation.

Thanks again. The issue appears to be with getting the actual data in the payload

My attempt at an action to publish my steps is

action: mqtt.publish
data:
  qos: "2"
  retain: false
  topic: owntracks/jason/iphone/steps
  payload: |
    "_type": "steps",
    elements

my broker shows.

owntracks
  jason
   iphone
    steps = "_type": "steps", elements

Might be an issue with the quotes but I just dont seem to be getting the content

we crossed each other in messages
(as you can see below). I understand what you are saying and the bottom line maybe is that what I am trying to do , record steps, can not be force by publishing I will subscribe at the device level and see what happens

it also appears not to be automatically published. Oh well.

The app on your phone has no idea that you’ve subscribed. You have to wait for it to push a message.

Make sure you have the right topic. I’d use the # version so you catch any message, which at least will give you a clue faster if it’s working.

Yes I understand that I am subscribed to owntracks/jason/iphone/# and this is what I get


owntracks

â–ĽJason

iphone = {“_type”:“location”,“acc”:42,“alt”:0,“batt”:0,“bs”:1,“conn”:“w”,“inregions”:,“inrids”:,“lat”:45.407425,“lon”:-122.665351,“m”:1,“tid”:“jh”,“tst”:1760759836}



owntracks
jason
iphone = {"_type":"location","acc":42,"alt":0,"batt":0,"bs":1,"conn":"w","inregions":[],"inrids":[],"lat":45.407425,"lon":-122.665351,"m":1,"tid":"jh","tst":1760759836}

Nothing seems to publish steps. That is publishsed when I send my location using owntracks. I think I have an issue with owntracks. and like you said you aren’t familiar heck neither am I obviousily. Looking at the owntracks booklet. and corresponding GitHub repository. I’m back to the mosquitto_pub -q 2 -t owntracks/jj/5s/cmd -m '{"_type" : "cmd", "action": "reportSteps"}'

OK as II can best figure it out…adtre waiting several days. the phone starting publishing steps. No use what I did or why.