Controlling IKEA Tradfri Devices without an IKEA Hub

IKEA sell some very affordable wireless controlled lights and power outlets, such as the TRÅDFRI Control outlet kit – a 3kW socket outlet with on/off remote for £19.

These can be bought individually:
Wireless Dimmer (on/off remote) for £6
Wireless Control Outlet (3kW socket outlet) for £10

But whilst you can control (from a computer) IKEA devices via a £25 TRÅDFRI Gateway using coap, it is also possible to do so via a Zigbee CC2531 USB dongle, such as https://uk.banggood.com/Wireless-Zigbee-CC2531-Sniffer-Bare-Board-Packet-Protocol-Analyzer-Module-USB-Interface-Dongle-p-1227206.html.

The following are good sources of reference:

You need a CC2531  configured as a coordinator (which requires a programmer to do so).

Programming a CC2531

https://www.zigbee2mqtt.io/getting_started/flashing_the_cc2531.html
apt install dh-autoreconf libusb-1.0 libboost-all-dev
git clone https://github.com/dashesy/cc-tool.git
cd cc-tool
./bootstrap
./configure
make
Connect CC debugger –> Downloader cable –> CC2531 USB sniffer
Connect BOTH the CC2531 USB sniffer and the CC debugger to your PC using USB
Debugger Light should be green (if red press reset button)
download https://github.com/Koenkk/Z-Stack-firmware/raw/master/coordinator/Z-Stack_Home_1.2/bin/default/CC2531_DEFAULT_20190608.zip
sudo ./cc-tool -e -w CC2531ZNP-Prod.hex
Programmer: CC Debugger
Target: CC2531
Erasing flash…
Completed
Writing flash (241 KB)…
Completed (17.96 s.)

Configuring MQTT broker and zigbee gateway

https://www.zigbee2mqtt.io/getting_started/running_zigbee2mqtt.html
https://www.rs-online.com/designspark/rounding-up-unruly-zigbees-with-zigbee2mqtt
ls -l /dev/ttyACM0
sudo curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs git make g++ gcc mosquitto mosquitto-clients
sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
sudo chown -R me:users /opt/zigbee2mqtt
cd /opt/zigbee2mqtt
npm install
vi /opt/zigbee2mqtt/data/configuration.yaml
sudo vi /etc/group add me to dialout
npm start

Pair devices

E1743 IKEA TRADFRI ON/OFF switch (on, off, brightness up/down/stop)
https://www.zigbee2mqtt.io/devices/E1743.html
4 quick presses of link button by battery

E1702 IKEA TRADFRI control outlet
https://www.zigbee2mqtt.io/devices/E1603_E1702.html
Insert paperclip in reset hole

Look for messages

cd /opt/zigbee2mqtt; npm start  # run MQTT broker and zigbee-MQTT gateway

Note the device ids.

zigbee2mqtt:info 2019-12-13T11:31:38: 0x000d6ffffe9cabcd (0x000d6ffffe9cabcd): E1743 - IKEA TRADFRI ON/OFF switch (EndDevice)
zigbee2mqtt:info 2019-12-13T11:31:38: 0x000d6ffffe7aefab (0x000d6ffffe7aefab): E1603/E1702 - IKEA TRADFRI control outlet (Router)

Press button on remote, and note the topic (zigbee2mqtt/0x000d6ffffe9cabcd) and message ("click":"on").

zigbee2mqtt:info 2019-12-13T15:50:41: MQTT publish: topic 'zigbee2mqtt/0x000d6ffffe9cabcd', payload '{"linkquality":128,"battery":21,"click":"on"}'

https://community.openhab.org/t/zigbee2mqtt-and-zigbee-bulbs-small-tutorial/72129
https://joonas.fi/2018/12/17/ikea-tradfri-bulbs-without-tradfri-gateway-getting-started/

Send a message to device

The outlet responds to two types of message syntax, simple and JSON:
mosquitto_pub -h localhost -t 'zigbee2mqtt/0x000d6ffffe7aefab/set' -m 'OFF'
mosquitto_pub -h localhost -t 'zigbee2mqtt/0x000d6ffffe7aefab/set' -m '{"state": "ON"}'

Now create a listener loop

https://github.com/raphaelcohn/bish-bosh gives a way of interacting with MQTT, but we can do it more directly:
https://unix.stackexchange.com/questions/188525/how-to-subscribe-a-bash-script-as-a-mqtt-client gives a good starting example. We used this to create listener.sh

 

cd /opt/zigbee2mqtt; npm start  # run MQTT broker and zigbee-MQTT gateway
listener.sh

So our listener.sh responds to clicks from the remote by issuing on/off instructions to the power outlet.

Other Methods

It is possible to  bind the switch directly to the outlet – https://www.zigbee2mqtt.io/information/binding.html 

Of course you could choose to use a full smart software home hub, such as Home Assistant or OpenHAB.