{"__v":0,"_id":"55f28173f9f3991900f38a25","category":{"__v":3,"_id":"55f28172f9f3991900f38a16","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,"project":"54ebb40d6423300d003672c0","user":"5580f88e8625220d00429b74","version":{"__v":2,"_id":"55f28172f9f3991900f38a13","project":"54ebb40d6423300d003672c0","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"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-07T01:20:32.230Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[{"name":"","code":"// PUT https://api.lifx.com/v1/lights/states with the following JSON body\n{\n  \"states\": [\n    {\n      \"selector\": \"[selector 1]\",\n      \"power\": \"on\"\n    },\n    {\n      \"selector\": \"[selector N]\",\n      \"brightness\": 0.5\n    }\n  ],\n  \"defaults\": {\n    \"duration\": 5.0 // all states will be applied over 5 seconds\n  }\n}\n    \n      ","language":"json"},{"code":"<?php\n\n$authToken = \"[[app:Token]]\";\n\n$data = array(\n    \"states\" => array(\n        array(\n            \"selector\" => \"id:d073d501b1e5\",\n            \"brightness\" => 0.1,\n            \"kelvin\" => 2700,\n        ),\n        array(\n            \"selector\" => \"id:d073d503a4c1\",\n            \"brightness\" => 0.75,\n            \"kelvin\" => 2700,\n        )\n    ),\n    \"defaults\" => array(\n        \"duration\" => 300,\n    )\n);\n\n$link = \"https://api.lifx.com/v1/lights/states\";\n$headers = array(\n    'Authorization: Bearer ' . $authToken,\n    'Content-Type: application/json'\n);\n$ch = curl_init($link);\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"PUT\");\n\n$response = curl_exec($ch);\n\n?>","language":"php"},{"code":"import requests\nimport json\n\ntoken = \"[[app:Token]]\"\n\nheaders = {\n    \"Authorization\": \"Bearer %s\" % token,\n}\n\npayload = {\n  \"states\": [\n    {\n        \"selector\" : \"id:d073d501b1e5\",\n        \"hue\": 200,\n        \"brightness\": 0.1\n    },\n    {\n         \"selector\" : \"group:Kitchen\",\n         \"brightness\": 0.5\n    }\n  ],\n  \"defaults\": {\n    \"power\": \"on\",\n    \"saturation\": 0,\n    \"duration\": 2.0\n\n}\n\n}\n\nresponse = requests.put('https://api.lifx.com/v1/lights/states', data=json.dumps(payload), headers=headers)\nprint(response.content)","language":"python"}]},"method":"put","results":{"codes":[{"status":"2XX","language":"json","code":"{\n  \"results\": [\n    {\n      \"operation\": {\n        \"selector\": \"[selector 1]\",\n        \"power\": \"on\",\n        \"duration\": 5.0\n      },\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    },\n    {\n      \"operation\": {\n        \"selector\": \"[selector 2]\",\n        \"brightness\": 0.5,\n        \"duration\": 5.0\n      },\n      \"results\": [\n        {\n          \"id\": \"dxxxxxxxxxx\",\n          \"label\": \"Light 3\",\n          \"status\": \"ok\"\n        },\n        {\n          \"id\": \"dxxxxxxxxxx\",\n          \"label\": \"Light 4\",\n          \"status\": \"ok\"\n        }\n      ]\n    }\n  ]\n}","name":""}]},"settings":"","auth":"required","params":[{"_id":"55810ef004ae5b0d00262877","ref":"","in":"body","required":true,"desc":"Array of `state` hashes as per [Set State](doc:set-state). No more than 50 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"}],"url":"/lights/states"},"isReference":false,"order":3,"body":"This endpoint allows you to set different states on multiple selectors in a single request.\n\nEach hash in `states` is comprised of a `state` hash as per [Set State](doc:set-state), except with the inclusion of `selector` which you would normally specify in the URL in a [Set State](doc:set-state) request.\n\nYou can optionally use the `defaults` hash to specify the base hash that each `state` hash is built from.\n\nThe API will attempt to execute each operation at the same time but does not make any guarantees.\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":"Set multiple states across multiple selectors.","slug":"set-states","type":"endpoint","title":"Set States"}

putSet States

Set multiple states across multiple selectors.

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). No more than 50 entries.
defaults:
object
Default values to use when not specified in each `states[]` object.

Examples


Result Format


Documentation

This endpoint allows you to set different states on multiple selectors in a single request. Each hash in `states` is comprised of a `state` hash as per [Set State](doc:set-state), except with the inclusion of `selector` which you would normally specify in the URL in a [Set State](doc:set-state) request. You can optionally use the `defaults` hash to specify the base hash that each `state` hash is built from. The API will attempt to execute each operation at the same time but does not make any guarantees. [block:html] { "html": "<div>\n</div>\n<style>\ndiv.try-it-out {\n display: none\n}\n</style>" } [/block]

User Information

Try It Out

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