Thingsquare Lighting supports scheduled operation by relying on the network-wide time synchronization. A schedule consists of a set of timed actions, such as turn up lights to 70% at 7 am on weekdays and then turn them off again at 6 pm. The timed actions are relative to the days of a week, making it easy to configure a weekly lighting schedule in a particular time zone.

Schedules are compiled and pushed to light devices using the device variable lsched. The schedule contains one or multiple timed actions back-to-back without any separator. Each timed action is 7 bytes long, and each schedule may contain up to 8 timed actions:

  • single 'w' character, identifying the schedule type
  • single byte bit-pattern with active weekdays, where 0b1 is Monday
  • single byte containing the number of full hours since midnight (xx:--)
  • single byte containing the number of minutes since last hour (--:xx)
  • three bytes containing the dim-levels of r, g, and b respectively

Schedule example

The following schedule instructs a light device to keep lights on during evenings and nights, and turn them off again during the day. Consider the following lsched value, in decimal representation:
[119, 31, 7, 0, 0, 0, 0, 119, 31, 18, 0, 70, 70, 70]

There are two events in the above schedule, hence totalling 14 bytes.

  • 119 is the ASCII code for 'w', identifying the timed action type.
  • 31 == 0b0011111, so the events are active Monday-Friday.
  • 7 = 7 hours from midnight, at 7 am.
  • 0 = 0 minutes from hour. The activation time for this event is hence 07:00 or 7:00 am.
  • The other event is similarly activated at 18:00 or 6:00 pm.
  • The remaining three bytes in each schedule controls the rgb values: 0% and 70%.

Default schedule

A default schedule can be configured programmatically using the thsq_schedule_set_default function.

thsq_schedule_set_default(uint8_t *sched, int len)