EN

MQTT

Model

🚩

Problem: Suppose you have a kettle that transmits water temperature in degrees Fahrenheit. You want to turn it on and off on command based on the temperature. According to the firmware in the kettle's controller, it runs the MQTT protocol and

  • sends temperature data in packets with a `kettle/temperature' topiary.
  • turns on when a packet arrives with kettle/actions and {"on" : true} data.
  • is turned off when a packet with the kettle/actions topic and {"on" : false} data arrives.

To connect the kettle to the platform, create an MQTT model for it.

There are several parameters in the template model. Remove the unnecessary parameters and leave only the temperature. In the Temperature parameter, set the desired topical under Source and change the unit of measure.

For more information on forming MQTT arguments

There are also two commands in the template model, edit them:

  1. change the identifier to a more appropriate one;

  2. change the name with which the command is displayed in the interface;

  3. specify the top and data according to what the device expects to receive.

For more information on forming MQTT actions

View a preview of the object with the model you created by clicking the Show preview button. preview**.

If you wish, select an icon to display the object on the map, or upload your own image.

Model to import (opens in a new tab)

Object

Create an object for your kettle. Select the model you just created. Then enter the ID that is used as the ClientID of the device when connecting via MQTT. Provide a name for the object. To further secure access To further secure access to the object, under MQTT Authentication, specify a login and password.

Also under Coordinates you can specify the specific geo position of the kettle, by specifying latitude and longitude, or select a point on the map. Then it will be stationary on the map even if there are no coordinates in the data package.

Once saved, the instructions for configuring the device to the platform will open, and the the icon will immediately appear on the map at the selected location.

Object to import (opens in a new tab)

You can add another object - for example, your neighbor's kettle. Then you should the same steps, but with a different unique identifier and name. The model can remain the same if the devices are identical.

Connection

To connect devices to the platform, specify in the firmware settings

  • host dev.rightech.io
  • port 1883 (8883 when connecting via TLS)

If you specified a login and password, don't forget to specify them as well.

Make sure that after saving the settings, the data is sent and displayed in the interface.

Send commands and check that connected devices respond to them.

Handlers

🚩

Task: In this example, the temperature of the water in the kettle is sent in degrees Fahrenheit. However, in order to evaluate the received values and generate the However, in order to evaluate the received values and generate the correct setpoint values in an automation scenario, it is much more convenient to operate in degrees Fahrenheit. to operate with values in degrees Celsius. In this case, you can make a a handler that converts the values from one unit of measurement to another according to the formula.

Create a new handler.

The function takes as input argument a temperature in degrees Fahrenheit, and as output it takes temperature in degrees Celsius. For the conversion is the corresponding formula. Check the correct operation of the handler in test mode.

Add a handler on all the necessary objects - in this example it will be two teapots.

Since they have the same model, set the match for the arguments of the model and handler parameters once. If the models were different, it would be need to match the parameters for each model.

There is no parameter for the output parameter in degrees Celsius in the model yet. Go to to the model to add it. Note that the source in this case does not need to be filled in, because this parameter does not come in the data packet from the device, but is calculated in the handler. device, but is calculated in the handler.

Add a new argument as an output parameter to the handler.

Processing of data packets from the device starts automatically when all parameters are filled in. all parameters. Go to objects and check that the calculated values appear in the interface.

Hide the parameter display with degrees Fahrenheit for convenience.

That way, when you get new values, you'll only see the values you want to see values.

Logic

Maintaining hot water temperature in the kettle

🚩

Problem: Suppose you have the task of maintaining a constant temperature of the water in the kettle above 80 degrees. If the temperature drops below that, the kettle must be turned on. As soon as the temperature rises above 99 deg, the kettle should be turned off.

Such a task can be easily realized automatically from two states: kettle on and the kettle is off. Transitions between these states will take place at receiving the corresponding values of water temperature.

Create a new automaton.

Since the logic of the automation scenario calls for cyclic temperature control, the automaton will be infinite, final state can be moved out of sight and not used. Create two states of the automaton.

Transitions between states will occur when certain data is received, so the transition events will be the same - Data received, but the conditions are different.

Now define what actions should be performed on the states. First, turning the kettle on and off.

Second, for additional indication in the object interface, you can change the the status of the object.

The automaton is ready. Select the objects and run it.

Now when the appropriate temperature is received, a command is sent to to turn the kettle on/off.

Also the status of the object is changed to current.

Automaton to import (opens in a new tab)

Switching on the kettle on command, only if the water has cooled down

🚩

Task: Suppose you have a task to remotely turn on the kettle on command. kettle on command, but you want it to turn on only if the water in the kettle is below 85 degrees Celsius. the water in the kettle is below 85 degrees.

Such a task is also easy to implement with an automaton. It will contain three states: temperature check, low temperature and high temperature. Transitions between these states will occur when the corresponding values of water temperature.

Create a new automaton.

In this case, the automaton will be a finite automaton. In addition to the final state create three states.

The transition from the temperature check state will happen when certain data, so the transition events will be the same - Received data, but the conditions are different.

💡

Tip: Use the Instantaneous Transition event, not Data Received, if you want the conditions to be checked for the current values without waiting for a new data packet to be received.

After performing certain actions in one of the two states, you need to go to the final state. The Momentary transition event is suitable for this purpose. In this case event Instantaneous transition.

Now define what actions should be performed in the states. In the state temperature check no action is required, the automaton is in it, until a packet with the current temperature value arrives. In the low temperature state it is necessary to send a command to turn on the kettle. In the high temperature state temperature it is possible to send a notification to the platform that the temperature is is high enough and the switch-on is not performed.

The automaton is ready. Go to the device model to create the command by which it will run. Under Run, select the automaton that you just you just made.

Navigate to the kettle object you want to execute this command on. The command you sent will only be considered executed when the automaton completes its work.

In this case, the automaton will complete its work only after receiving the data packet and performing the specified actions - for example, sending notifications. perform the specified actions - for example, sending a notification when the temperature is high. temperature.

Labels

If the kettles you are monitoring are of different brands, you can add labels to the objects to quickly jump to the description on the website of the of the manufacturer.

Create two labels.

After adding a tag to an object, click on it - in a new browser tab the link you specified will open in a new browser tab.