How to create your own smart home scenario with Rightech IoT Cloud

In this article, we will explain how to create a scenario in which the platform controls the LED depending on temperature. Commands to the device will be sent without your participation in accordance with the specified logic.

Let’s create the following automation option:

  • if the temperature value obtained from the device is less than 20 °, turn on the blue color of the LED,
  • if more than 30 ° – red,
  • if the value is in the range of 20 ° to 30 °, then turn on the green color.

Of course, it is possible to implement similar logic directly on the device. However, implementing such a scenario using the platform gives an obvious advantage: if you need to change the logic of the work, it is enough to edit the state or condition of the transition in the machine. This does not require programming skills and does not have to re-patch the device.

To solve this problem, we will need an esp8266 card and the LED itself, the color of which will be controlled from the platform. We talked about connecting a similar device here.

You can import an object model by reference:

GitHub link

Arduino sketch:

GitHub link

YouTube link with this use case.

1. Automation creation

Go to the “Logic” section and create a new automation. When creating, we define the name of the automation and select the model of the connected device.

In this automation we will need at least 5 states:

  • “Start” – the state in which the automation gets after starting;
  • “Turn off” – the temperature on the device is still unknown; the LED is off;
  • “Coldly” – the temperature less than 20 °; the LED is lit in blue;
  • “Fine” – the temperature in the range from 20 ° to 30 °; the LED is green;
  • “Hot” – temperature more than 30 °; the LED is red.

Create these states in the automaton.

In the “Start” state, we add the “message to operator” action to send the information that the machine is running to the platform interface. From this state, we create a transition to the “Turn off” state, then add the “Instant transition” event. This transition will work immediately after the automation starts.

We add the corresponding LED control commands to other states:

  • “Turn off” – command to turn off the LED;
  • “Coldly” – “turn on blue” command;
  • “Fine” – “turn on green” command;
  • “Hot” – command “turn on red color”.

We also add the “message to operator” action to notify you that the state of the started machine has changed.

Now we add transitions between states and set conditions. In these transitions, we will use the “Data received” event. It will occur every time the device sends data. In order to implement our scenario, we add additional transition conditions. For example, to enter the “Coldy” state from the “Turn off” state, you must add a temperature check in the transition condition (Add conditions button). The same condition must be checked in transitions from “Fine” to “Coldy”, from “Hot” to “Coldy”.

Similarly, set the transition logic for other states. After filling all transition conditions, the automation takes the following form:

You can import the final automaton:

GitHub link

2. Scenario launch

We go to the “Objects” section, select our device and add the created automation in the “Services”/”Logic” tab. Press the “Start” button to start.

When the temperature data is received in different ranges, the corresponding messages are published and the required color of the LED is illuminated.

Try creating your IoT project with Rightech IoT Cloud now 🙂

And if you have any questions, welcome to our chat of like-minded fellas: