npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tradfri-mqtt

v0.1.4

Published

This project mirrors most of the Trådfri gateways endpoints into MQTT and can be used to send commands to the Trådfri gateway over MQTT

Downloads

19

Readme

Trådfri-MQTT

This project mirrors most of the Trådfri gateways endpoints into MQTT and can be used to send commands to the Trådfri gateway over MQTT

See hemtjan.st/tradfri-mqtt for more information

Using NPM

Installing via NPM:

npm install -g tradfri-mqtt

To start the service:

# 192.168.0.99 = Your trådfri gateway
# abcdefgh = The pre-shared key printed under the gateway
# tcp://127.0.0.1:1883 = Address to MQTT

tradfri-mqtt -g 192.168.0.99 -p abcdefgh -a tcp://127.0.0.1:1883

Using docker

docker volume create tradfri-mqtt-data
docker run -d \
  --name tradfri-mqtt \
  --volume tradfri-mqtt-data:/data \
  --env TRADFRI_GATEWAY=192.168.0.99 \
  --env TRADFRI_PSK=abcdefgh \
  --env MQTT_ADDRESS=tcp://127.0.0.1:1883 \
  hemtjanst/tradfri-mqtt

For armv7 (i.e. raspberry pi 3+), use hemtjanst/tradfri-mqtt:arm7

Arguments

|Argument |Alias|Environment Var |Description |Default | |-------------------------------|-----|-----------------|-------------------------------------------|-------------| |--gateway <ip> |-g |TRADFRI_GATEWAY |IP Address of Trådfri Gateway |Required | |--psk <key> |-p |TRADFRI_PSK |Pre-shared key of gateway | | |--mqtt tcp://mqtt-broker:1883|-a |MQTT_ADDRESS |Address of MQTT broker |Required | |--mqttUsername foo |-n |MQTT_USERNAME |Username of MQTT broker | | |--mqttPassword bar |-w |MQTT_PASSWORD |Password of MQTT broker | | |--topicPrefix <topic> |-x |MQTT_TOPIC_PREFIX|Topic prefix |tradfri-raw| |--topicCommand <topic> |-c |MQTT_TOPIC_CMD |Topic for commands |tradfri-cmd| |--username <username> |-u |TRADFRI_USERNAME |Username for authentication token | | |--token <token> |-t |TRADFRI_TOKEN |Authentication token (not the same as PSK!)| | |--storage <path> |-s |TRADFRI_STORAGE |Path to store data in | |

Getting updates

tradfri-mqtt will try to observe everything that's being published from the gateway, and mirror the messages into MQTT with the prefix tradfri-raw/.

For example, if the trådfri pushes and update for the lightbulb 65554, the raw json message will be published to the MQTT topic tradfri-raw/15001/65554.

Subscribing to tradfri-raw/# will give you all messages, tradfri-raw/15001/# all accessory updates and tradfri-raw/15004/# all group updates.

Sending commands

Commands to the trådfri gateway can be sent by publishing them to the MQTT topic tradfri-cmd. The payload should be a json-encoded string matching the definition:

export declare type TfCommand = {
    // CoAP Method
    method: "get" | "post" | "put" | "delete" | "reset",
    // URL without any prefixes, i.e. "15001/65540"
    url: string,
    // Optional id of the request, will be included in the reply
    id?: string,
    // Replies will be sent to this MQTT topic
    replyTopic?: string,
    // Payload of the request (for POST or PUT)
    payload?: object|string,
}

If replyTopic is set, a reply will be sent to that topic. The definition of the reply:

export declare type TfReply = {
    // ID of the request as set in TfCommand
    id?: string,
    // Response code, for example "2.04"
    code: string,
    // Format of the response, 50 = json
    format: number,
    // Payload, if format is json the payload is decoded into an object,
    // otherwise it will be a raw string
    payload: string|object,
}

Sample requests

Put request

Sent to the tradfri-cmd topic:

{
  "method": "put",
  "url": "15004/162515",
  "id": "group-set-on",
  "replyTopic": "tradfri-reply/xyz",
  "payload": {
    "5850": 1
  }
}

Received from the tradfri-reply/xyz topic:

{
  "id": "group-set-on",
  "code": "2.04",
  "format": null,
  "payload": ""
}

Get request

Sent to the tradfri-cmd topic:

{
  "method": "get",
  "url": "15004/162515",
  "id": "group-get",
  "replyTopic": "tradfri-reply/xyz"
}

Received from the tradfri-reply/xyz topic:

{
  "id": "group-get",
  "code": "2.05",
  "format": 50,
  "payload": {
    "5850": 1,
    "5851": 0,
    "9001": "Name of group",
    "9002": 1498068278,
    "9003": 162515,
    "9018": {
      "15002": {
        "9003": [65546,65547,65548]
      }
    },
    "9039": 220248
  }
}