Select Page

HOW DO THE PAYLOAD AND THE TOPICS WORK?

TOPICS

The topics are: read, event, write and response.
Each topic has a different type of message that the MQTT broker uses to filter messages for each connected client, the topics are composed in levels divided by slash.

Example: home/livingroom/light

These are the four topics which we will subscribe to at the end of the configuration:

Topic read: Is used to retreve the status of the devices.

Topic response: Is the device’s reply to the automation server read request.

Topic write: This topic is used to set the value of  a device parameter.

Topic event: This topic display the status of the device in case it changes.

Topic Response

The “Topic Response” is needed to reply the read mesasge coming from the device.
i.e: First connection to retrieve the current status of the devices.

in this case the script is catching the json coming from the device and getting the status, in our case “ison“.





By clicking this link you will able to see how the script is set up.

Topic Write

The “Topic Write” sends the command to the device when the component in the EVE system changes.
i.e: When the user change a state of a switch from the App EVE Remote Plus.

Each device may requires a different type of message.

You can create the payload of the MQTT message  using a piece of javascript that starts from the value of EVE system component and prepare the message that your device need in the right format, pure text, JSON or any other.

Topic Write data sending

The  Switch and the other binary components comes with a value of 0 and 1 in the payload variable.

You can use this script to create your message based on its value:



By clicking this link you will able to see how the script is set up.

Inside the EVE System the percentage is processed as a value from 0 to 1, the components that uses the percentage such as the Slider or Changeable Value will have this configuration set up as its write topic.

You can use this script to create your message based on its value:




By clicking this link you will able to see how the script is set up.

To send RGB information the configuration is the following, we will use the component RGB light to set up the correct MQTT rgb configuration.




By clicking this link you will able to see how the script is set up.

Topic Event

The “Topic Event”, this topic will report a change status coming from the device.
i.e: A power meter reports the power consumed each time the value changes.

In case of a temperature, power, energy etc, the components choosen to display this values is the Info component. as you can see from the image below the script will just get the value coming from the device.

You can use this script to create your message based on its value:




By clicking this link you will able to see how the script is set up.

To report a switch status, it will be needed build the script as it follow.

In this case the scrpt will gather the payload coming from the device and so reporting the current status of the device.




By clicking this link you will able to see how the script is set up.

PAYLOAD

A payload is a piece of code that contains a javascript function.
For each topic, a javascript function is executed to process the topic payload.

json string example:

var data = JSON.parse(payload);var color = {“mode”:”color”,”red”:data.r,”green”:data.g,”blue”:data.b}; return JSON.stringify(color);

payload example

Discover more about our Shelly dedicated solution.

Still Need Help? Our Customer Service Is Here For You.