{"id":20463912,"url":"https://github.com/hemtjanst/tradfri-mqtt","last_synced_at":"2025-05-08T23:32:24.566Z","repository":{"id":24424507,"uuid":"101487542","full_name":"hemtjanst/tradfri-mqtt","owner":"hemtjanst","description":"Mirrors Trådfri gateways endpoints into MQTT and send commands to the gateway from MQTT","archived":false,"fork":false,"pushed_at":"2023-03-04T03:41:16.000Z","size":123,"stargazers_count":38,"open_issues_count":1,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-13T08:42:28.095Z","etag":null,"topics":["domotic","home-automation","mqtt","nodejs","smarthome","tradfri"],"latest_commit_sha":null,"homepage":"https://hemtjan.st/tradfri-mqtt","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hemtjanst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2017-08-26T13:30:06.000Z","updated_at":"2024-05-21T04:37:38.000Z","dependencies_parsed_at":"2025-04-07T17:01:44.226Z","dependency_job_id":"e842215a-a159-4883-a4eb-96eb717b2cad","html_url":"https://github.com/hemtjanst/tradfri-mqtt","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hemtjanst%2Ftradfri-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hemtjanst%2Ftradfri-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hemtjanst%2Ftradfri-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hemtjanst%2Ftradfri-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hemtjanst","download_url":"https://codeload.github.com/hemtjanst/tradfri-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253164338,"owners_count":21864238,"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":["domotic","home-automation","mqtt","nodejs","smarthome","tradfri"],"created_at":"2024-11-15T13:13:33.792Z","updated_at":"2025-05-08T23:32:24.247Z","avatar_url":"https://github.com/hemtjanst.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trådfri-MQTT\nThis project mirrors most of the Trådfri gateways endpoints into MQTT and can be\nused to send commands to the Trådfri gateway over MQTT\n\nSee [hemtjan.st/tradfri-mqtt](https://hemtjan.st/tradfri-mqtt) for more information\n\n## Using NPM\nInstalling via NPM:\n\n```bash\nnpm install -g tradfri-mqtt\n```\n\nTo start the service:\n```bash\n# 192.168.0.99 = Your trådfri gateway\n# abcdefgh = The pre-shared key printed under the gateway\n# tcp://127.0.0.1:1883 = Address to MQTT\n\ntradfri-mqtt -g 192.168.0.99 -p abcdefgh -a tcp://127.0.0.1:1883\n```\n\n## Using docker\n\n```bash\ndocker volume create tradfri-mqtt-data\ndocker run -d \\\n  --name tradfri-mqtt \\\n  --volume tradfri-mqtt-data:/data \\\n  --env TRADFRI_GATEWAY=192.168.0.99 \\\n  --env TRADFRI_PSK=abcdefgh \\\n  --env MQTT_ADDRESS=tcp://127.0.0.1:1883 \\\n  hemtjanst/tradfri-mqtt\n```\n\nFor armv7 (i.e. raspberry pi 3+), use hemtjanst/tradfri-mqtt:arm7\n\n## Arguments\n\n|Argument                       |Alias|Environment Var  |Description                                |Default      |\n|-------------------------------|-----|-----------------|-------------------------------------------|-------------|\n|`--gateway \u003cip\u003e`               |`-g` |TRADFRI_GATEWAY  |IP Address of Trådfri Gateway              |**Required** |\n|`--psk \u003ckey\u003e`                  |`-p` |TRADFRI_PSK      |Pre-shared key of gateway                  |             |\n|`--mqtt tcp://mqtt-broker:1883`|`-a` |MQTT_ADDRESS     |Address of MQTT broker                     |**Required** |\n|`--mqttUsername foo`           |`-n` |MQTT_USERNAME    |Username of MQTT broker                    |             |\n|`--mqttPassword bar`           |`-w` |MQTT_PASSWORD    |Password of MQTT broker                    |             |\n|`--topicPrefix \u003ctopic\u003e`        |`-x` |MQTT_TOPIC_PREFIX|Topic prefix                               |`tradfri-raw`|\n|`--topicCommand \u003ctopic\u003e`       |`-c` |MQTT_TOPIC_CMD   |Topic for commands                         |`tradfri-cmd`|\n|`--username \u003cusername\u003e`        |`-u` |TRADFRI_USERNAME |Username for authentication token          |             |\n|`--token \u003ctoken\u003e`              |`-t` |TRADFRI_TOKEN    |Authentication token (not the same as PSK!)|             |\n|`--storage \u003cpath\u003e`             |`-s` |TRADFRI_STORAGE  |Path to store data in                      |             |\n\n\n## Getting updates\n\ntradfri-mqtt will try to observe everything that's being published from the gateway, and mirror the messages into\nMQTT with the prefix `tradfri-raw/`.\n\nFor example, if the trådfri pushes and update for the lightbulb `65554`, the raw json message will be published\nto the MQTT topic `tradfri-raw/15001/65554`.\n\nSubscribing to `tradfri-raw/#` will give you all messages, `tradfri-raw/15001/#` all accessory\nupdates and `tradfri-raw/15004/#` all group updates.\n\n## Sending commands\n\nCommands to the trådfri gateway can be sent by publishing them to the MQTT topic `tradfri-cmd`.\nThe payload should be a json-encoded string matching the definition:\n\n```typescript\nexport declare type TfCommand = {\n    // CoAP Method\n    method: \"get\" | \"post\" | \"put\" | \"delete\" | \"reset\",\n    // URL without any prefixes, i.e. \"15001/65540\"\n    url: string,\n    // Optional id of the request, will be included in the reply\n    id?: string,\n    // Replies will be sent to this MQTT topic\n    replyTopic?: string,\n    // Payload of the request (for POST or PUT)\n    payload?: object|string,\n}\n```\n\nIf `replyTopic` is set, a reply will be sent to that topic. The definition of the reply:\n```typescript\nexport declare type TfReply = {\n    // ID of the request as set in TfCommand\n    id?: string,\n    // Response code, for example \"2.04\"\n    code: string,\n    // Format of the response, 50 = json\n    format: number,\n    // Payload, if format is json the payload is decoded into an object,\n    // otherwise it will be a raw string\n    payload: string|object,\n}\n```\n\n### Sample requests\n\n#### Put request\nSent to the `tradfri-cmd` topic:\n```json\n{\n  \"method\": \"put\",\n  \"url\": \"15004/162515\",\n  \"id\": \"group-set-on\",\n  \"replyTopic\": \"tradfri-reply/xyz\",\n  \"payload\": {\n    \"5850\": 1\n  }\n}\n```\n\nReceived from the `tradfri-reply/xyz` topic:\n```json\n{\n  \"id\": \"group-set-on\",\n  \"code\": \"2.04\",\n  \"format\": null,\n  \"payload\": \"\"\n}\n```\n\n#### Get request\n\nSent to the `tradfri-cmd` topic:\n```json\n{\n  \"method\": \"get\",\n  \"url\": \"15004/162515\",\n  \"id\": \"group-get\",\n  \"replyTopic\": \"tradfri-reply/xyz\"\n}\n```\n\nReceived from the `tradfri-reply/xyz` topic:\n```json\n{\n  \"id\": \"group-get\",\n  \"code\": \"2.05\",\n  \"format\": 50,\n  \"payload\": {\n    \"5850\": 1,\n    \"5851\": 0,\n    \"9001\": \"Name of group\",\n    \"9002\": 1498068278,\n    \"9003\": 162515,\n    \"9018\": {\n      \"15002\": {\n        \"9003\": [65546,65547,65548]\n      }\n    },\n    \"9039\": 220248\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhemtjanst%2Ftradfri-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhemtjanst%2Ftradfri-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhemtjanst%2Ftradfri-mqtt/lists"}