{"id":16775094,"url":"https://github.com/juangesino/lux","last_synced_at":"2025-03-16T17:44:26.084Z","repository":{"id":79339629,"uuid":"134681122","full_name":"juangesino/lux","owner":"juangesino","description":"Internet-connected Photon-enabled relay module for lights.","archived":false,"fork":false,"pushed_at":"2018-05-24T09:50:58.000Z","size":33,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T14:07:05.096Z","etag":null,"topics":["electronics","iot","iot-device","particle","particle-io","particle-photon","photon","relay","relay-switch","smart-lights","smart-switch"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juangesino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-24T07:54:24.000Z","updated_at":"2020-01-16T10:12:10.000Z","dependencies_parsed_at":"2023-02-24T19:00:31.789Z","dependency_job_id":null,"html_url":"https://github.com/juangesino/lux","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juangesino%2Flux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juangesino%2Flux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juangesino%2Flux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juangesino%2Flux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juangesino","download_url":"https://codeload.github.com/juangesino/lux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910690,"owners_count":20367538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electronics","iot","iot-device","particle","particle-io","particle-photon","photon","relay","relay-switch","smart-lights","smart-switch"],"created_at":"2024-10-13T06:51:00.740Z","updated_at":"2025-03-16T17:44:26.044Z","avatar_url":"https://github.com/juangesino.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"text-align:center\"\u003e\u003cimg src=\"resources/banner-logo.png\" alt=\"Photon Particle Logo\" width=\"500\" align=\"center\" /\u003e\u003c/div\u003e\n\n# Lux\n\nInternet-connected \u003ca href=\"https://store.particle.io/collections/photon\" target=\"_blank\"\u003ePhoton\u003c/a\u003e-enabled relay module for controlling lights.\n\n## About\n\nThis is an IoT open source and open hardware project for controlling a relay over the internet. The project is intended to be used for controlling lights, but it can really be used for controlling anything (coffee machine, fan, heater, water pump, etc.).\n\nThis project uses the amazing internet-connected \u003ca href=\"https://store.particle.io/collections/photon\" target=\"_blank\"\u003ePhoton\u003c/a\u003e and a relay module. The photon exposes a function called `relay` to manipulate the relay over the internet and a cloud variable `lightState` to get the current state (on/off).\n\nRead more about Particle variables \u003ca href=\"https://docs.particle.io/reference/firmware/photon/#particle-variable-\" target=\"_blank\"\u003ehere\u003c/a\u003e.\n\nRead more about Particle functions \u003ca href=\"https://docs.particle.io/reference/firmware/photon/#particle-function-\" target=\"_blank\"\u003ehere\u003c/a\u003e.\n\n### The `relay` function\n\nThe relay function takes an optional param to determine the kind of action to perform on the relay. If the parameter is not present, the function will toggle the relay (on if it's currently off and vice versa).\n\nAdditionally, the parameter can be a string either `on` or `off` to force that state on the relay.\n\nThe resulting state is returned as an integer inside the `data` of the response in a variable called `return_value`. If the value is `1` the current state is on.\n\n### The `lightState` variable\n\nSimple. Returns `true` if the relay is on and `false` if it's off.\n\n## Setup\n\n### Materials\n\n- \u003ca href=\"https://store.particle.io/collections/photon\" target=\"_blank\"\u003ePhoton\u003c/a\u003e\n- Relay module (like \u003ca href=\"https://www.amazon.com/SunFounder-Channel-Optocoupler-Expansion-Raspberry/dp/B00E0NTPP4/\" target=\"_blank\"\u003ethis\u003c/a\u003e one)\n- Breadboard\n- Some breadboard jumper wires\n- Button (*optional*)\n- LED (*optional*)\n\n### Connections\n\nAs seen in the code, the relay must be connected to the Photon's `D0` pin, the button to `D2` and the status LED to pin `D7`. Depending on the relay module you might have to connect it to ground and the `5V` pin as well (more info on relays \u003ca href=\"http://www.instructables.com/id/Controlling-AC-light-using-Arduino-with-relay-modu/\" target=\"_blank\"\u003ehere\u003c/a\u003e).\n\nThe relay's terminals must be connected as a switch cutting the AC power to whatever you are trying to control. To achieve this I disassemble a power strip (like \u003ca href=\"https://www.amazon.com/AmazonBasics-6-Outlet-Surge-Protector-Power/dp/B00TP1C1UC\" target=\"_blank\"\u003ethis one\u003c/a\u003e) and replaced the switch with my relay.\n\n⚠️ **WARNING**: Be extremely careful when manipulating AC. It's dangerous. If you don't know what you're doing, just don't do it. I am not responsible for you not being careful enough.\n\n## Deploy\n\nTo deploy this on your Photon, you have two options: the we IDE provided by Particle or connecting your device via USB to your computer.\n\nI suggest using the IDE because it's the easiest and fastest way.\n\nFor the web IDE read \u003ca href=\"https://docs.particle.io/guide/getting-started/build/photon/\" target=\"_blank\"\u003ehere\u003c/a\u003e.\n\nFor USB connection read \u003ca href=\"https://docs.particle.io/guide/getting-started/connect/photon/\" target=\"_blank\"\u003ehere\u003c/a\u003e.\n\n### Particle credentials\n\nOnce your device is all set, you will need your credentials to operate it.\n\nYou will need a device ID and an access token. The device ID can be found [here](https://console.particle.io/devices) and the access token [here](https://build.particle.io) inside the settings.\n\n## Usage\n\nBecause we exposed the cloud function and variable, in order to use it we just need to make HTTP calls!\n\n### Webhooks\n\n#### Let there be light\n\nMake an HTTP POST request as follows:\n\n```\nPOST /v1/devices/\u003cDEVICE-ID\u003e/relay?access_token=\u003cACCESS-TOKEN\u003e HTTP/1.1\nHost: api.particle.io\nCache-Control: no-cache\nContent-Type: application/x-www-form-urlencoded\n\nparam=on\n```\n\nWhere `\u003cDEVICE-ID\u003e` is your device's ID and `\u003cACCESS-TOKEN\u003e` is a valid access token.\n\nExample (cURL):\n\n```sh\n$\u003e curl --request POST \\\n  --url 'https://api.particle.io/v1/devices/9999999999/relay?access_token=AAAA9999ZZZZ' \\\n  --header 'Cache-Control: no-cache' \\\n  --header 'Content-Type: application/x-www-form-urlencoded' \\\n  --data param=on\n```\n\n#### Let there be darkness\n\nMake an HTTP POST request as follows:\n\n```\nPOST /v1/devices/\u003cDEVICE-ID\u003e/relay?access_token=\u003cACCESS-TOKEN\u003e HTTP/1.1\nHost: api.particle.io\nCache-Control: no-cache\nContent-Type: application/x-www-form-urlencoded\n\nparam=off\n```\n\nWhere `\u003cDEVICE-ID\u003e` is your device's ID and `\u003cACCESS-TOKEN\u003e` is a valid access token.\n\nExample (cURL):\n\n```sh\n$\u003e curl --request POST \\\n  --url 'https://api.particle.io/v1/devices/9999999999/relay?access_token=AAAA9999ZZZZ' \\\n  --header 'Cache-Control: no-cache' \\\n  --header 'Content-Type: application/x-www-form-urlencoded' \\\n  --data param=off\n```\n\n#### Let there be toggle\n\nMake an HTTP POST request as follows:\n\n```\nPOST /v1/devices/\u003cDEVICE-ID\u003e/relay?access_token=\u003cACCESS-TOKEN\u003e HTTP/1.1\nHost: api.particle.io\nCache-Control: no-cache\nContent-Type: multipart/form-data;\n```\n\nWhere `\u003cDEVICE-ID\u003e` is your device's ID and `\u003cACCESS-TOKEN\u003e` is a valid access token.\n\nExample (cURL):\n\n```sh\n$\u003e curl --request POST \\\n  --url 'https://api.particle.io/v1/devices/9999999999/relay?access_token=AAAA9999ZZZZ' \\\n  --header 'Cache-Control: no-cache'\n```\n\n#### Get the current state\n\nMake an HTTP GET request as follows:\n\n```\nGET /v1/devices/\u003cDEVICE-ID\u003e/lightState?access_token=\u003cACCESS-TOKEN\u003e HTTP/1.1\nHost: api.particle.io\nCache-Control: no-cache\n```\n\nWhere `\u003cDEVICE-ID\u003e` is your device's ID and `\u003cACCESS-TOKEN\u003e` is a valid access token.\n\nExample (cURL):\n\n```sh\n$\u003e curl --request GET \\\n  --url 'https://api.particle.io/v1/devices/9999999999/lightState?access_token=AAAA9999ZZZZ' \\\n  --header 'Cache-Control: no-cache'\n```\n\nYou will get a response like this:\n\n```json\n{\n  \"cmd\": \"VarReturn\",\n  \"name\": \"lightState\",\n  \"result\": false,\n  \"coreInfo\": {\n    \"last_app\": \"\",\n    \"last_heard\": \"2018-05-24T09:36:46.971Z\",\n    \"connected\": true,\n    \"last_handshake_at\": \"2018-05-11T11:29:18.741Z\",\n    \"deviceID\": \"9999999999\",\n    \"product_id\": 1\n  }\n}\n```\n\nThe `result` attribute is what you're interested in.\n\n### Android App\n\nI also built an Android app using Meteor to control this switch. Go check it out: [github.com/juangesino/photon](https://github.com/juangesino/photon).\n\n## Contributing\n\n1. Fork it ( https://github.com/juangesino/lux/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\nSee [MIT-LICENSE](https://github.com/juangesino/lux/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuangesino%2Flux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuangesino%2Flux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuangesino%2Flux/lists"}