Sunrise/Sunset-Based Schedule

Last Updated on : 2024-01-18 08:36:03download

Schedule a task based on the sunrise and sunset times at the device’s location. This type of schedule is suitable for outdoor lighting.

Features

  • One sunrise-based schedule.
  • One sunset-based schedule.
  • One-time or weekly recurring schedule.
  • Every time the device requests schedules from the cloud, it will download the sunrise/sunset-based schedule for 28 days. The scheduled task can still be executed even if the device goes offline.

How it works

Sequence diagram

DeviceCloudAppSync the sunrise/sunset-based schedule after power on.Enable or modify a scheduled task.The scheduled task is updated.Request the latest scheduled task.Return information.Check if a scheduled task is due.The framework notifies the application oftask processing.alt[The scheduled task is due.]loopDeviceCloudApp

Schedule update mechanism

  • After the device is powered on and connected to the internet, it requests the scheduled task from the cloud.
  • When the cloud notifies the device of a schedule update, the device requests the scheduled task from the cloud.
  • The device requests the scheduled task from the cloud every week.
  • If there is only one week of sunrise/sunset data saved in the device, the request cycle will be changed to every 12 hours.

Exception handling mechanism

Assuming the schedule stored on the device is as follows:

Weekly recurring: from Monday to Friday.

Date Day of week Sunrise time Sunset time Schedule on/off
January 1, 2024 Monday 07:28 17:06 On
January 2, 2024 Tuesday 07:28 17:07 On
January 3, 2024 Wednesday 07:29 17:08 On
January 4, 2024 Thursday 07:29 17:09 On
January 5, 2024 Friday 07:30 17:10 On
January 6, 2024 Saturday 07:29 17:11 Off
January 7, 2024 Sunday 07:28 17:12 Off
January 26, 2024 Friday 07:22 17:31 On
January 27, 2024 Saturday 07:22 17:32 Off
January 28, 2024 Sunday 07:21 17:33 Off
  • After the schedule is on, the device has been disconnected from the internet.

    Assuming the current date is February 2, 2024.

    The device will execute the weekly recurring schedule based on the last specified time until it goes online and updates the task. That is, the schedule will be executed based on the sunrise/sunset data on January 26, 2024.

  • After the device goes offline and loses power, it stays offline when powered on.

    Assuming the power loss occurred on January 4, 2024, and the device was powered on again on January 5, 2024.

    • The device has a built-in RTC. After power on, the device’s clock is restored to January 5, 2024. The schedule will be executed based on the sunrise/sunset data on January 5, 2024.
    • The device does not have a built-in RTC. After power on, the device’s clock is reset to January 1, 1970. Therefore, The sunrise/sunset-based schedule will not be executed until the device’s clock reaches January 4, 2024.

Development guide

Open tuya_iot_config.h and check if the following macro is defined.

#define ENABLE_ASTRO_TIMER 1

Reference the header

  • tuya_cloud_com_defs.h

How to use

  1. Create a product on the Tuya IoT Development Platform and then enter the product development process. Click the Device Interaction tab and select a panel that supports sunrise/sunset schedules.

    If the panel you have selected does not support this feature or if you are unsure which panel supports it, contact your account manager or submit a service ticket.

  2. During device initialization, the application registers the callbacks for processing object-type and raw-type DP commands.

  3. The TuyaOS framework initializes, adds, deletes, or modifies the scheduled task, without involving the application.

  4. When a scheduled task is due, the framework will notify the application using the DP command callback. The command source cmd_tp in the DP data receiving struct is DP_CMD_TIMER.

FAQs

Why are the sunrise and sunset times displayed on the panel exactly reversed, or is there a deviation in their accuracy?

This is because the location of the device differs from the one set for the app account. For example, if the device is in the China Data Center while the app account belongs to the Europe Data Center. In this case, the cloud retrieves and presents the sunrise and sunset times on the panel using the latitude and longitude of the device’s location (China Data Center).