Autoclose service #
Service namespace: autoclose
Service for managing automatic opening hours for the container. If outside opening hours, the container will be fully closed, rejecting both access cards and the keep-unlocked setting.
Configuration #
Config json schema available on api/v1/device/<dev_id>/service/autoclose/config/schema:
curl -H "X-API-Key: <api key>" \
https://api.nr.iotready.no/api/v1/device/<dev_id>/service/autoclose/config/schema
| Field | Type | Description |
|---|---|---|
| timezone | string | IANA Timezone string, e.g. Europe/Oslo, for where the device is lSet to true to allow any identityocated |
| close_rules | array | Up to 8 rules for when the device should lock. Set to an empty array to disable the autoclose system. Each enry is an object with four fields. |
| close_rules.close_time | integer | Unix timestamp in seconds for first closure if timezone had been UTC |
| close_rules.end_time | integer | Unix timestamp for when this rule should no longer be checked. Set to 0 for no expiry |
| close_rules.close_duration | integer | How many seconds to close for when the rule takes effect |
| close_rules.repeat_time | integer | How often, in seconds, the rule should repeat |
Notes #
closed_rulesare overwritten when submitted. To append a new rule to existing rules, include a copy of the existing ones when submitting.- If
repeat_timeis set to 0, the rule will only be applied once. - There is a special implementation for
repeat_time=60*60*24*365, which will cause the rule to apply once a year, with automatic adjustment for leap years. - Overlaps in rules are fine, and follows “the lock should be open only if no rules apply”
close_timeandend_timeare given in UTC, and will be adjusted to the correct timezone when the rules are checked on-device. This ensures that rules work across daylight saving time.- UTC timestamps can be easily calculated in JavaScript with the
Date.UTCmethod. Note that this gives timestamps in milliseconds, so they should be divided by 1000 before using them.
Examples #
Read config: #
curl -H "X-IOTREADY-CONFIG-NEXT-GEN: true" -H "X-API-Key: <api key>" \
https://api.nr.iotready.no/api/v1/device/<dev_id>/service/autoclose/config
Close every day from 20:00 to 08:00 in Stavanger. Rule is: #
{
"close_time": 1761076800, // Date.UTC(2025, 9, 21, 20, 0)/1000
"end_time": 0,
"close_duration": 43200, // 20:00 -> 08:00 is 12 hours = 12 * 60 * 60 seconds
"repeat_time": 86400 // Every day -> every 24 hours = 24 * 60 * 60 seconds
}
Resulting in the following request:
curl -H "X-API-Key: <api key>" -X PUT \
-d '{"timezone":"Europe/Oslo","close_rules":[{"close_time": 1761076800,"end_time": 0,"close_duration": 43200,"repeat_time": 86400}]}' \
https://api.nr.iotready.no/api/v1/device/<dev_id>/service/access/config/value
Close every Sunday in Amsterdam #
{
"close_time": 1760832000, // Midnight of arbitrary Sunday: Date.UTC(2025, 9, 19, 0, 0)/1000
"end_time": 0,
"close_duration": 86400, // Close for 24 hours
"repeat_time": 604800 // Every week -> every 7 days = 7 * 24 * 60 * 60 seconds
}
Resulting in the following request:
curl -H "X-API-Key: <api key>" -X PUT \
-d '{"timezone":"Europe/Amsterdam","close_rules":[{"close_time": 1760832000,"end_time": 0,"close_duration": 86400,"repeat_time": 604800}]}' \
https://api.nr.iotready.no/api/v1/device/<dev_id>/service/access/config/value