{"_id":"55f28173f9f3991900f38a1f","githubsync":"","__v":10,"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"},"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,"project":"54ebb40d6423300d003672c0","user":"5580f88e8625220d00429b74","editedParams2":true,"parentDoc":null,"updates":["56bf854cd0e91b0d007239c5","5b6c5278b02563000334ee07"],"next":{"pages":[],"description":""},"createdAt":"2015-09-07T00:57:22.407Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[{"language":"curl","name":"cURL","code":"curl -X PUT \"https://api.lifx.com/v1/lights/all/state\" \\\n     -H \"Authorization: Bearer [[app:Token]]\" \\\n     -d \"power=on\""},{"code":"<?php\n\n$link = \"https://api.lifx.com/v1/lights/all/state\";\n$authToken = \"[[app:Token]]\";\n\n$headers = array('Authorization: Bearer ' . $authToken);\n\n$data = 'power=on';\n\n$ch = curl_init($link);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $data);\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"PUT\");\n$response = curl_exec($ch);\n\n?>","language":"php"},{"code":"import requests\n\ntoken = \"[[app:Token]]\"\n\nheaders = {\n    \"Authorization\": \"Bearer %s\" % token,\n}\n\npayload = {\n    \"power\": \"on\",\n}\n\nresponse = requests.put('https://api.lifx.com/v1/lights/all/state', data=payload, headers=headers)","language":"python"},{"code":"package main\n\nimport (\n\t\"net/http\"\n\t\"strings\"\n)\n\nfunc main() {\n\n\tbody := strings.NewReader(`power=on`)\n\treq, err := http.NewRequest(\"PUT\", \"https://api.lifx.com/v1/lights/all/state\", body)\n\tif err != nil {\n\t\t// handle err\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer [[app:Token]]\")\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\tresp, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\t// handle err\n\t}\n\tdefer resp.Body.Close()\n\n}\n","language":"go"}]},"method":"put","results":{"codes":[{"status":"2XX","language":"json","code":"{\n  \"results\": [\n    {\n      \"id\": \"d3b2f2d97452\",\n      \"label\": \"Left Lamp\",\n      \"status\": \"ok\"\n    }\n  ]\n}","name":""},{"code":"","language":"text","status":202}]},"settings":"","auth":"required","params":[{"_id":"55810ef004ae5b0d00262877","ref":"","in":"path","required":true,"desc":"The [selector](doc:selectors) to limit which lights are controlled.","default":"","type":"string","name":"selector"},{"_id":"55810f5504ae5b0d0026287b","ref":"","in":"body","required":false,"desc":"The power state you want to set on the selector. `on` or `off`","default":"","type":"string","name":"power"},{"_id":"55ece0f254a67b1700edcf46","ref":"","in":"body","required":false,"desc":"The [color](doc:colors) to set the light to.","default":"","type":"string","name":"color"},{"_id":"55ece0f254a67b1700edcf45","ref":"","in":"body","required":false,"desc":"The brightness level from `0.0` to `1.0`. Overrides any brightness set in `color` (if any).","default":"","type":"double","name":"brightness"},{"_id":"55810f5504ae5b0d0026287a","ref":"","in":"body","required":false,"desc":"How long in seconds you want the power action to take. Range: `0.0` – `3155760000.0` (100 years)","default":"1.0","type":"double","name":"duration"},{"_id":"5823fc3a0c90d02d00fe65cf","ref":"","in":"body","required":false,"desc":"The maximum brightness of the infrared channel from `0.0` to `1.0`.","default":"","type":"double","name":"infrared"},{"_id":"5ad697075c9bed0003388c2b","ref":"","in":"body","required":false,"desc":"Execute the query [fast](#fast-mode), without initial state checks and wait for no results.","default":"false","type":"boolean","name":"fast"}],"url":"/lights/:selector/state"},"isReference":false,"order":2,"body":"Sets the state of the lights within the selector. All parameters (except for the selector) are optional. If you don't supply a parameter, the API will leave that value untouched.\n\nFor example, if you want to turn the light on to a pale blue at 50% brightness over 5 seconds, you'd send:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// PUT /v1/lights/all/state\\n{\\n  \\\"power\\\": \\\"on\\\",\\n  \\\"color\\\": \\\"blue saturation:0.5\\\",\\n  \\\"brightness\\\": 0.5,\\n  \\\"duration\\\": 5,\\n\\n  \\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Fast mode\"\n}\n[/block]\nThe API is designed to ensure consistent transitions for devices from one state to another.  For many operations, this involves having an accurate view of the current state of the device before taking any action, so we need to ask it for its state first.  Other transitions, in order to be smooth, require intermediate state changes; for example, to switch on and set to blue a light that is off and set to red, we first switch it to blue, wait for that to succeed, then switch it on, to avoid jarring transitions.\n\nAs this involves various network hops to the device, this process is slower than many traditional web APIs.  There are use-cases where this is unnecessary, for example those in which the client has a pretty good idea of the current state and just wants to send one state change message to the device.\n\nTo speed things up for such use-cases, when setting `fast=true`, we do none of checks described above, and just send the targets the end-state messages.  Because we don't wait around for a reply from the device in fast mode, you'll just get `202 Accepted` with no body if your request was valid.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Infrared\"\n}\n[/block]\nIf you want to set Infrared to maximum brightness and shutdown the visible bands, you would send:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// PUT /v1/lights/all/state\\n{\\n  \\\"power\\\": \\\"off\\\",\\n  \\\"infrared\\\": 1.0, \\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"set-state","type":"endpoint","title":"Set State"}

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Path Params

selector:
required
string
The [selector](doc:selectors) to limit which lights are controlled.

Body Params

power:
string
The power state you want to set on the selector. `on` or `off`
color:
string
The [color](doc:colors) to set the light to.
brightness:
double
The brightness level from `0.0` to `1.0`. Overrides any brightness set in `color` (if any).
duration:
double1.0
How long in seconds you want the power action to take. Range: `0.0` – `3155760000.0` (100 years)
infrared:
double
The maximum brightness of the infrared channel from `0.0` to `1.0`.
fast:
booleanfalse
Execute the query [fast](#fast-mode), without initial state checks and wait for no results.

Examples


Result Format


Documentation

Sets the state of the lights within the selector. All parameters (except for the selector) are optional. If you don't supply a parameter, the API will leave that value untouched. For example, if you want to turn the light on to a pale blue at 50% brightness over 5 seconds, you'd send: [block:code] { "codes": [ { "code": "// PUT /v1/lights/all/state\n{\n \"power\": \"on\",\n \"color\": \"blue saturation:0.5\",\n \"brightness\": 0.5,\n \"duration\": 5,\n\n \n}", "language": "json" } ] } [/block] [block:api-header] { "title": "Fast mode" } [/block] The API is designed to ensure consistent transitions for devices from one state to another. For many operations, this involves having an accurate view of the current state of the device before taking any action, so we need to ask it for its state first. Other transitions, in order to be smooth, require intermediate state changes; for example, to switch on and set to blue a light that is off and set to red, we first switch it to blue, wait for that to succeed, then switch it on, to avoid jarring transitions. As this involves various network hops to the device, this process is slower than many traditional web APIs. There are use-cases where this is unnecessary, for example those in which the client has a pretty good idea of the current state and just wants to send one state change message to the device. To speed things up for such use-cases, when setting `fast=true`, we do none of checks described above, and just send the targets the end-state messages. Because we don't wait around for a reply from the device in fast mode, you'll just get `202 Accepted` with no body if your request was valid. [block:api-header] { "type": "basic", "title": "Infrared" } [/block] If you want to set Infrared to maximum brightness and shutdown the visible bands, you would send: [block:code] { "codes": [ { "code": "// PUT /v1/lights/all/state\n{\n \"power\": \"off\",\n \"infrared\": 1.0, \n}", "language": "json" } ] } [/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 }}