Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Tutorials
    • All tutorials
      • Working with Yandex IoT Core from an Android device in Java
      • Working with Yandex IoT Core in C#
      • Working with Yandex IoT Core in Java
      • Status monitoring of geographically distributed devices
      • Sensor reading monitoring and event notifications
      • Testing message delivery
      • Emulating multiple IoT devices
      • Writing data from a device into a database

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create service accounts
  • Create the required Yandex IoT Core resources
  • Create a registry and set up username and password authentication
  • Create a device and set up username and password authentication
  • Create a device emulator in Cloud Functions
  • Create a function to emulate sending data from the device
  • Test the emulation function
  • Create a trigger to invoke the function once per minute
  • Create a function to process incoming data
  • Test the data processing function
  • Create a trigger to invoke the data processing function on a signal
  • Set up sensor reading monitoring
  • Create a dashboard
  • Create charts
  • Test the charts on the dashboard
  • Create a notification channel
  • Create an alert
  • How to delete the resources you created
  1. Application solutions
  2. Internet of Things (IoT)
  3. Sensor reading monitoring and event notifications

Sensor reading monitoring and event notifications

Written by
Yandex Cloud
Updated at May 13, 2025
  • Get your cloud ready
    • Required paid resources
    • Create service accounts
  • Create the required Yandex IoT Core resources
    • Create a registry and set up username and password authentication
    • Create a device and set up username and password authentication
  • Create a device emulator in Cloud Functions
    • Create a function to emulate sending data from the device
    • Test the emulation function
    • Create a trigger to invoke the function once per minute
    • Create a function to process incoming data
    • Test the data processing function
    • Create a trigger to invoke the data processing function on a signal
  • Set up sensor reading monitoring
    • Create a dashboard
    • Create charts
    • Test the charts on the dashboard
    • Create a notification channel
    • Create an alert
  • How to delete the resources you created

In this tutorial, you will set up monitoring and notifications for changes in readings of the sensors connected to Yandex IoT Core. To emulate sensors, we will use Yandex Cloud Functions. If you have any connected sensors, use them.

You do not need to create or configure VMs, as all steps in this tutorial are entirely based on serverless computing in Cloud Functions. The source code used in this tutorial is available on GitHub.

To configure monitoring of sensor readings in the server room:

  1. Get your cloud ready.
  2. Create the required Yandex IoT Core resources.
  3. Create a device emulator in Cloud Functions.
  4. Set up sensor reading monitoring.

If you no longer need the resources you created, delete them.

Get your cloud ready

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resources

The support cost includes:

  • Fee for the number of Yandex IoT Core messages (see Yandex IoT Core pricing).
  • Fee for the number of function invocations in Cloud Functions (see Yandex Cloud Functions pricing).
  • Fee for logging user metrics via the Monitoring API (see Yandex Monitoring pricing).

Create service accounts

  1. Create a service account named my-emulator-function-service-account for data sending. Assign the functions.functionInvoker and iot.devices.writer roles to it.
  2. Create a service account named my-metrics-function-service-account for data processing. Assign the functions.functionInvoker and editor roles to it.

Create the required Yandex IoT Core resources

Registry and device are the main Yandex IoT Core components for exchanging data and commands. Devices can only exchange data if created in the same registry.

Create a registry and set up username and password authentication

Management console
  1. In the management console, select the folder you are using to complete this tutorial.

  2. From the list of services, select IoT Core.

  3. Click Create registry.

  4. In the Name field, enter a name for the registry, e.g., my-registry.

  5. In the Password field, set a password for registry access. To create a password, you can use this password generator.

    Note

    Save the password as you will need it for authentication.

  6. Click Create.

Create a device and set up username and password authentication

Management console
  1. In the management console, select the folder you are using to complete this tutorial.

  2. From the list of services, select IoT Core.

  3. Select the registry you created in the previous step.

  4. Select Devices in the left-hand menu.

  5. Click Add device.

  6. In the Name field, enter a device name, e.g., my-device.

  7. In the Password field, set a password for device access. To create a password, you can use this password generator.

    Note

    Save the password as you will need it for authentication.

  8. Optionally, add an alias:

    1. Click Add alias.

    2. Fill in the fields: enter an alias, e.g., events, and the topic type after $devices/{id}, e.g., events.

      You can now use the events alias instead of the $devices/{id}/events topic.

    3. Repeat these steps for each alias you add.

  9. Click Create.

  10. Repeat these steps for each device you create.

Create a device emulator in Cloud Functions

The emulator sends data from device sensors and processes data for monitoring and alerts.

Create a function to emulate sending data from the device

Management console
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Cloud Functions.
  3. Create a function:
    1. Click Create function.
    2. In the Name field, enter a name for the function, e.g., my-device-emulator-function.
    3. Click Create.
  4. Create a function version:
    1. In the Editor window that opens, select Node.js 18.

    2. Disable Add files with code examples.

    3. Click Continue.

    4. In the Method field, select Code editor.

    5. Click Create file:

      • File name: device-emulator.js.
      • File contents: Function code from GitHub.
    6. Similarly, create a file named package.json with the following content:

      {
        "name": "my-app",
        "version": "1.0.0",
        "dependencies": {
          "yandex-cloud": "*"
        }
      }
      
    7. In the Entry point field, specify device-emulator.handler.

    8. Under Parameters, specify:

      • Timeout: 10
      • Memory: 128 MB
      • Service account: my-emulator-function-service-account
      • Environment variables:
        Key Description Value
        HUMIDITY_SENSOR_VALUE Baseline humidity sensor reading 80.15
        TEMPERATURE_SENSOR_VALUE Baseline temperature sensor reading 25.25
        RACK_DOOR_SENSOR_VALUE Rack door sensor reading False
        ROOM_DOOR_SENSOR_VALUE Server room door sensor reading False
        SMOKE_SENSOR_VALUE Smoke sensor reading False
        WATER_SENSOR_VALUE Water sensor reading False
        IOT_CORE_DEVICE_ID ID of the device you created. See the management console,
        Yandex IoT Core
        DEVICE_ID Custom devicename It is specified by the user.
    9. Click Save changes.

Test the emulation function

Optionally, to get detailed information from the sensors, subscribe the registry to the Yandex IoT Core device topic.

CLI

If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.

Run this command:

yc iot mqtt subscribe \
  --username <registry_ID> \
  --password <registry_password> \
  --topic '$devices/<device_ID>/events' \
  --qos 1

Where:

  • --username and --password: Credentials for authentication with a username and password.
  • --topic: Device topic for sending data or topic alias.
  • --qos: Quality of service (QoS).

The command should keep running until the test is complete.

Management console
  1. In the management console, select the folder you are using to complete this tutorial.

  2. In the list of services, select Cloud Functions.

  3. Select the function named my-device-emulator-function.

  4. In the left-hand menu, select Testing.

  5. In the Version tag list, select $latest, which is the most recently created function.

  6. Click Run test.

    If the function runs successfully, the Done field will show Function status and the Function output field, the following result:

    {
      "statusCode" : 200
    }
    

    If you subscribed to the Yandex IoT Core device topic, you will get the following JSON strings in your terminal:

    {
      "DeviceId":"my-device-id",
      "TimeStamp":"2024-06-14T15:29:59Z",
      "Values":[
          {"Type":"Float","Name":"Humidity","Value":"80.84"},
          {"Type":"Float","Name":"Temperature","Value":"25.46"},
          {"Type":"Bool","Name":"Water sensor","Value":"False"},
          {"Type":"Bool","Name":"Smoke sensor","Value":"False"},
          {"Type":"Bool","Name":"Room door sensor","Value":"False"},
          {"Type":"Bool","Name":"Rack door sensor","Value":"False"}
          ]
      }
    

Create a trigger to invoke the function once per minute

Management console
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Cloud Functions.
  3. In the left-hand panel, select Triggers.
  4. Click Create trigger.
  5. In the Name field, enter a name for the trigger, e.g., my-emulator-function-trigger.
  6. In the Type field, select Timer.
  7. In the Cron expression field, enter * * * * ? * (invoke once per minute).
  8. Under Function settings, enter the parameters previously set for the function:
    • Function: my-device-emulator-function
    • Function version tag: $latest
    • Service account: my-emulator-function-service-account
  9. Optionally, configure the Repeat request settings and Dead Letter Queue settings sections to protect data against loss.
    • Repeat request settings enable automatic retries if the current function invocation fails.

    • Dead Letter Queue settings enable redirecting messages that consumers failed to process in regular queues.

      You can configure a standard message queue as a DLQ. If you do not have a message queue yet, create one in Yandex Message Queue.

  10. Click Create trigger.

Create a function to process incoming data

Management console
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Cloud Functions.
  3. In the left-hand panel, select Functions.
  4. Create a function:
    1. Click Create function.
    2. In the Name field, enter a name for the function, e.g., my-monitoring-func.
    3. Click Create.
  5. Create a function version:
    1. In the Editor window that opens, select Python 3.12.

    2. Disable Add files with code examples.

    3. Click Continue.

    4. In the Method field, select Code editor.

    5. Click Create file:

      • File name: monitoring.py.

      • File contents: Function code from GitHub.

        Within this function, the makeAllMetrics method handles the processing of data to send to the monitoring service. If you want to add or remove parameters, make changes to this method.

    6. In the Entry point field, specify monitoring.msgHandler.

    7. Under Parameters, specify:

      • Timeout: 10

      • Memory: 128 MB

      • Service account: my-metrics-function-service-account

      • Environment variables:

        Key Description Value
        VERBOSE_LOG Enabling or disabling data logging True
        METRICS_FOLDER_ID ID of the folder where you deployed the services and for which you will create a dashboard in Monitoring. See the management console.
    8. Click Save changes.

Test the data processing function

Management console
  1. In the management console, select the folder you are using to complete this tutorial.

  2. In the list of services, select Cloud Functions.

  3. Select the my-monitoring-func function.

  4. In the left-hand menu, select Testing.

  5. In the Version tag list, select $latest, which is the most recently created function.

  6. In the Payload field, paste the following data:

    {
      "messages": [
      {
        "event_metadata": {
          "event_id": "160d239876d9714800",
          "event_type": "yandex.cloud.events.iot.IoTMessage",
          "created_at": "2020-05-08T19:16:21.267616072Z",
          "folder_id": "b112345678910"
        },
        "details": {
          "registry_id": "are1234567890",
          "device_id": "are0987654321",
          "mqtt_topic": "$devices/are0987654321/events",
          "payload": "eyJWYWx1ZXMiOiBbeyJUeXBlIjogIkZsb2F0IiwgIlZhbHVlIjogIjI1Ljc0IiwgIk5hbWUiOiAiSHVtaWRpdHkifSwgeyJUeXBlIjogIkZsb2F0IiwgIlZhbHVlIjogIjgwLjY1IiwgIk5hbWUiOiAiVGVtcGVyYXR1cmUifSwgeyJUeXBlIjogIkJvb2wiLCAiVmFsdWUiOiAiRmFsc2UiLCAiTmFtZSI6ICJXYXRlciBzZW5zb3IifSwgeyJUeXBlIjogIkJvb2wiLCAiVmFsdWUiOiAiRmFsc2UiLCAiTmFtZSI6ICJTbW9rZSBzZW5zb3IifSwgeyJUeXBlIjogIkJvb2wiLCAiVmFsdWUiOiAiRmFsc2UiLCAiTmFtZSI6ICJSb29tIGRvb3Igc2Vuc29yIn0sIHsiVHlwZSI6ICJCb29sIiwgIlZhbHVlIjogIkZhbHNlIiwgIk5hbWUiOiAiUmFjayBkb29yIHNlbnNvciJ9XSwgIlRpbWVTdGFtcCI6ICIyMDIwLTA1LTIxVDIzOjEwOjE2WiIsICJEZXZpY2VJZCI6ICIwZTNjZTFkMC0xNTA0LTQzMjUtOTcyZi01NWM5NjEzMTk4MTQifQ=="
        }
      }]
    }
    
  7. Click Run test.

    If the function runs successfully, the Done field will show Function status and the Function output field, the following result:

    {
      "statusCode" : 200 ,
      "headers" : {
        "Content-Type" : "text/plain"
      },
    "isBase64Encoded" : false
    }
    

Create a trigger to invoke the data processing function on a signal

The trigger will invoke the function when a message appears in the device topic.

Management console
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Cloud Functions.
  3. In the left-hand panel, select Triggers.
  4. Click Create trigger.
  5. In the Name field, enter a name for the trigger, e.g., my-monitoring-func-trigger.
  6. In the Type field, select IoT Core (device).
  7. Under IoT Core message settings, enter the parameters previously set for the registry and device:
    • Registry: my-registry.
    • Device: my-device.
    • MQTT topic: $devices/<device_ID>/events, where <device_ID> is the device ID in Yandex IoT Core.
  8. Under Function settings, enter the parameters previously set for the function:
    • Function: my-monitoring-func
    • Function version tag: $latest
    • Service account: my-metrics-function-service-account
  9. Optionally, configure the Repeat request settings and Dead Letter Queue settings sections to protect data against loss.
    • Repeat request settings enable automatic retries if the current function invocation fails.

    • Dead Letter Queue settings enable redirecting messages that consumers failed to process in regular queues.

      You can configure a standard message queue as a DLQ. If you do not have a message queue yet, create one in Yandex Message Queue.

  10. Click Create trigger.

All data from the device will be automatically sent to Monitoring.

Set up sensor reading monitoring

Yandex Monitoring dashboards are used to monitor sensor readings. The controller sends readings to the server every 60 seconds using MQTT. When they reach the specified limits, Monitoring sends notifications to users.

Data transmission format
{
  "DeviceId":"e7a68b2d-464e-4222-88bd-c9e8********",
  "TimeStamp":"2020-05-21T10:16:43Z",
  "Values":[{
    "Type":"Float",
    "Name":"Humidity",
    "Value":"12.456"
  },
  {
    "Type":"Float",
    "Name":"Temperature",
    "Value":"-23.456"
  },
  {
    "Type":"Bool",
    "Name":"Water sensor",
    "Value":"false"
  },
  {
    "Type":"Bool",
    "Name":"Smoke sensor",
    "Value":"false"
  },
  {
    "Type":"Bool",
    "Name":"Room door sensor",
    "Value":"true"
  },
  {
    "Type":"Bool",
    "Name":"Rack door sensor",
    "Value":"false"}
    ]
 }

Set up sensor reading monitoring: create charts on the dashboard, notification channel, and alert.

Create a dashboard

Monitoring UI
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Monitoring.
  3. Navigate to the Dashboards tab.
  4. Click Create.
  5. At the top right, click Save.
  6. In the window that opens, enter a name for the dashboard and click Save.

Create charts

Create a temperature variation chart:

Monitoring UI
  1. In the management console, select the folder you are using to complete this tutorial.

  2. In the list of services, select Monitoring.

  3. Navigate to the Dashboards tab.

  4. Next to the dashboard name, click → Edit.

  5. In the bottom section, click Graph.

  6. Create a query for the chart:

    1. In the query editor, click .
    2. In the list of services (service=), select Custom Metrics.
    3. In the list of chart types (name=), select Temperature, which is room temperature.
    4. In the device_id= list, select the ID of the device for which you want to create a chart.
  7. At the top right, click Save.

Create other charts in a similar way:

  • Humidity: Room air humidity.
  • Water sensor: Water on the floor (yes/no).
  • Smoke sensor: Smoke in the room (yes/no).
  • Room door sensor: Room door state (open/closed).
  • Rack door sensor: Server rack door state (open/closed).

The dashboard is available to all Yandex Cloud users with the viewer role via the link. You can customize it, zoom in or out, and enable or disable auto-refresh.

Test the charts on the dashboard

If you change the baselines in the environment variables of the emulation function, you will see these changes in the charts.

Management console
  1. In the management console, select the folder you are using to complete this tutorial.

  2. In the list of services, select Cloud Functions.

  3. Select the function named my-device-emulator-function.

  4. Click the Editor tab.

  5. Change some original variable values as you like under Environment variables in the Value field at the bottom of the window.

    Key Original value New value
    HUMIDITY_SENSOR_VALUE 80.15 40
    TEMPERATURE_SENSOR_VALUE 25.25 15
    RACK_DOOR_SENSOR_VALUE False True
    ROOM_DOOR_SENSOR_VALUE False True
    SMOKE_SENSOR_VALUE False True
    WATER_SENSOR_VALUE False True
  6. Click Save changes and wait for the operation to complete.

Monitoring UI
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Monitoring and check how the chart metrics have changed.

Create a notification channel

Customize a list of recipients and select a notification method.

Monitoring UI
  1. In the management console, select the folder you are using to complete this tutorial.

  2. In the list of services, select Monitoring.

  3. Navigate to the Notification channels tab.

  4. Click Create channel.

  5. In the Name field, enter a name for the channel, e.g., my-message-channel.

  6. In the Method list, select Email.

    You can also set up notifications through text messages, push, or Telegram.

  7. In the Recipients list, select an account.

    You can select multiple recipients for notifications. You can specify the accounts of users having access to your cloud as recipients. Learn more about how to add users to Yandex Cloud here.

  8. Click Create.

Create an alert

Create an alert based on the room temperature sensor readings and connect the created notification channel to it.

Monitoring will send this alert to the recipients if the temperature sensor in the server room shows a certain temperature within a certain period (5 minutes):

  • 50 degrees: Warning alert.
  • 70 degrees: Alarm alert (critical value).
Monitoring UI
  1. In the management console, select the folder you are using to complete this tutorial.
  2. In the list of services, select Monitoring.
  3. Click Create alert.
  4. In the Name field, enter a name for the alert.
  5. Under Alert configuration, click and fill out the fields:
    1. In the list of services (service=), select Custom Metrics.
    2. In the list of alert types (name=), select Temperature.
    3. In the device_id= list, select the ID of the device for which you want to create an alert.
  6. Under Alert conditions, set the alert trigger conditions:
    1. In the Aggregation function list, select Average.
    2. In the Comparison function list, select Greater than.
    3. In the Warning field, enter 50.
    4. In the Alarm field, enter 70.
    5. In the Evaluation window list, select 5 minutes.
  7. Under Notifications, click Edit, and then Add.
  8. In the window that opens, select my-message-channel in the Notification method field and click Add.
  9. At the bottom of the window, click Create.

You can create and configure alerts for any metric in Monitoring.

Once you complete this tutorial:

  • You will be able to monitor sensor readings on the charts.
  • If sensor readings reach the specified limits, you will receive notifications.

How to delete the resources you created

To stop paying for the resources you created:

  • Delete the registry in Yandex IoT Core.
  • Delete the device in Yandex IoT Core.
  • Delete the functions in Cloud Functions.
  • Delete the triggers invoking functions in Cloud Functions.
  • Delete the dashboard in Monitoring.
  • Delete the alert in Monitoring.
  • Delete the notification channel in Monitoring.

Was the article helpful?

Previous
Status monitoring of geographically distributed devices
Next
Testing message delivery
Yandex project
© 2025 Yandex.Cloud LLC