{"_id":"55f65cc16be5ea0d00bbbf4c","category":{"_id":"55f28172f9f3991900f38a16","__v":3,"pages":["55f28173f9f3991900f38a1d","55f28173f9f3991900f38a1e","55f28173f9f3991900f38a1f","55f28173f9f3991900f38a20","55f28173f9f3991900f38a21","55f28173f9f3991900f38a22","55f28173f9f3991900f38a23","55f28173f9f3991900f38a24","55f28173f9f3991900f38a25","55f28173f9f3991900f38a26","55f28173f9f3991900f38a27","55f63d46fe4cce21005c785e","55f65cc16be5ea0d00bbbf4c"],"project":"54ebb40d6423300d003672c0","version":"55f28172f9f3991900f38a13","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-06-17T05:23:31.147Z","from_sync":false,"order":2,"slug":"api-endpoints","title":"API Endpoints"},"editedParams":true,"editedParams2":true,"user":"5580f88e8625220d00429b74","version":{"_id":"55f28172f9f3991900f38a13","project":"54ebb40d6423300d003672c0","__v":2,"createdAt":"2015-09-11T07:23:30.065Z","releaseDate":"2015-09-11T07:23:30.065Z","categories":["55f28172f9f3991900f38a14","55f28172f9f3991900f38a15","55f28172f9f3991900f38a16","55f66acb297b37170058accb"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"__v":1,"project":"54ebb40d6423300d003672c0","parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-14T05:36:01.809Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[{"language":"json","code":"// POST https://api.lifx.com/v1beta1/lights/:selector/cycle with the following JSON body\n{\n  \"states\": [\n    {\n      \"brightness\": 1.0\n    },\n    {\n      \"brightness\": 0.5\n    },\n    {\n      \"brightness\": 0.1\n    },\n    {\n      \"power\": \"off\"\n    }\n  ],\n  \"defaults\": {\n    \"power\": \"on\", // all states default to on\n    \"saturation\": 0, // every state is white\n    \"duration\": 2.0 // all transitions will be applied over 2 seconds\n  }\n}\n// If the light is currently off, sending this request will turn it on to maximum brightness over 2 seconds.\n// If the request is sent again, the light will transition to 50% brightness over 2s, and so on\n      ","name":"example.json"}]},"method":"post","results":{"codes":[{"name":"","code":"{\n  \"results\": [\n    {\n      \"id\": \"dxxxxxxxxxx\",\n      \"label\": \"Light 1\",\n      \"status\": \"ok\"\n    },\n    {\n      \"id\": \"dxxxxxxxxxx\",\n      \"label\": \"Light 2\",\n      \"status\": \"ok\"\n    }\n  ]\n}","language":"json","status":"2XX"}]},"settings":"","auth":"required","params":[{"_id":"55810ef004ae5b0d00262877","ref":"","in":"body","required":true,"desc":"Array of `state` hashes as per [Set State](doc:set-state). Must have 2 to 5 entries.","default":"","type":"array_mixed","name":"states"},{"_id":"55ece66058faec2b00365e3c","ref":"","in":"body","required":false,"desc":"Default values to use when not specified in each `states[]` object.","default":"","type":"object","name":"defaults"},{"_id":"55fba302af72eb0d0007df49","ref":"","in":"body","required":false,"desc":"Direction in which to cycle through the list. Can be `forward` or `backward`","default":"forward","type":"string","name":"direction"}],"url":"/lights/:selector/cycle"},"isReference":false,"order":8,"body":"This endpoint lets you easily have a set of lights transition to the next state in a list of states you supply without having to implement client side logic to calculate the next state in the sequence.\n\nFor example, you can have a hardware button that will cycle through a few different brightness settings and off by simply binding a button press to send an identical Cycle request, and the API figures out the rest.\n\nThe API scores each `state` hash against the current states of all the lights in the selector, and if the score is high enough to be considered a match, it will apply the next `state` in the list, looping back to the first one if necessary. If there's no close match, it will apply the closest `state` to the selector.\n\nThe maximum of 5 states was selected so a user would not have to press a button more than 6 times to achieve their desired state.\n\nThe optional `direction` parameter determines the direction the API uses to determine the next `state`.\n\nIf you have a scenario where the Cycle API does not work as expected, please let us know on the forums.\n[block:html]\n{\n  \"html\": \"<div>\\n</div>\\n<style>\\ndiv.try-it-out {\\n  display: none\\n}\\n</style>\"\n}\n[/block]","excerpt":"Make the light(s) cycle to the next or previous state in a list of states.","slug":"cycle","type":"endpoint","title":"Cycle"}

postCycle

Make the light(s) cycle to the next or previous state in a list of states.

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Body Params

states:
required
array of mixed
Array of `state` hashes as per [Set State](doc:set-state). Must have 2 to 5 entries.
defaults:
object
Default values to use when not specified in each `states[]` object.
direction:
stringforward
Direction in which to cycle through the list. Can be `forward` or `backward`

Examples


Result Format


Documentation

This endpoint lets you easily have a set of lights transition to the next state in a list of states you supply without having to implement client side logic to calculate the next state in the sequence. For example, you can have a hardware button that will cycle through a few different brightness settings and off by simply binding a button press to send an identical Cycle request, and the API figures out the rest. The API scores each `state` hash against the current states of all the lights in the selector, and if the score is high enough to be considered a match, it will apply the next `state` in the list, looping back to the first one if necessary. If there's no close match, it will apply the closest `state` to the selector. The maximum of 5 states was selected so a user would not have to press a button more than 6 times to achieve their desired state. The optional `direction` parameter determines the direction the API uses to determine the next `state`. If you have a scenario where the Cycle API does not work as expected, please let us know on the forums. [block:html] { "html": "<div>\n</div>\n<style>\ndiv.try-it-out {\n display: none\n}\n</style>" } [/block]

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}