MQTT data retrieve

How the workflow has to be wired to retrieve data that has been sent on a topic at
for example topic losant/deviceid/state

Publishing to losant/your-device-id/state will trigger the Device Trigger node. If you publish to any other non-losant topics, those will trigger the MQTT trigger node.

The losant/your-device-id/state is a special topic used when reporting device state. When that topic is used, the attributes reported will be saved to the database and then be available when building dashboards.

for example - Publishing to losant/my-device-id/xyztopic, I am having difficulty in subscribing to this topic. Can you please give a dashboard wiring of the nodes to be hooked properly.


There are only two topics available that start with “losant”. They are:

  1. losant/my-device-id/state
  2. losant/my-device-id/command

The first one allows the publishing of Device State. The second one is typically used to subscribe to Device Commands.

Any topic that starts with “losant” is a special topic that is used for one of the above purposes. If you attempt to subscribe to any other topic that starts with “losant”, your device will be disconnected.

If you want to use custom “xyztopic”, you can do so, but it can’t start with “losant”. You can publish and subscribe to any other topics. For example, you could use “my/custom/xyztopic” and that would work just fine.

coming back to this very late … sorry
If I need to send to a specific custom topic, do you have an example to do so say in python code.
The python code sample I have from the website, as below, can only send to a state topic
Please help with a code snippet going to a specific topic


import time
from losantmqtt import Device

# Construct device
device = Device("<credentials>")

def on_command(device, command):
    print("Command received.")

# Listen for commands.
device.add_event_observer("command", on_command)

# Connect to Losant.

# Send temperature once every second.
temp = 10
i = 1
while True:
    if device.is_connected():
        temp = temp + i
        device.send_state({"temperature": temp})