The new IKEA Dirigera hub

This is quick and dirty Linux bash script to show how easy it is to control devices when you obtain your JWT token. Works for me as I have only 3 blinds and a lamp: (requires httpie v 3.2.1)

To use this script obtain JWT token and discover hub IP, device IDs (and what they can receive) using Dirigera dump script by @Tamagotchi and modify below bash script to your liking:

#!/bin/bash
###
## Proof of concept script to control IKEA devices via the Dirigera home hub using obtained JWT token and httpie (version >= 3.2.1 as it supports bearer token authentication)
## Created by Landi (landi@athae.net) 2023
###

TOKEN="eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1MjNiOTliZTg0MjQ3NjZhYjJmZWFkYjg2MTAyYzlmNjFlMzIwM2ViMWRjZjMzMTg1NTVkYWFlY2I0MmM2OGEifQ.eyJpc3MiOiJkZTExYzEwZS03ZWFmLTRmNGQtYjRiNy05NTE1ZGY2Y2Y0YzkiLCJ0eXBlIjoiYWNjZXNzIiwiYXVkIjoiaG9tZXNtYXJ0LmxvY2FsIiwic3ViIjoiNGNmZDY4ZTQtMWRlNS00YzdhLTlkMzItYTZlYzc2NzA0NDRhIiwiaWF0IjoxNjcyODU5NTAxLCJleHAiOjE5ODg0MzU1MDF9.QbLJwoVpmBeWJdiVmoro3jvEpGrjuw3TmI7Gsc0RjY_A5bdeW4QbjtzjiJP9t0iCmEY4Wd6KIepRAMJihKgeXg";
DEBUG=0; # set up to 1 to view request/response
DIRIGERA_IP = "172.21.12.97"

case $1 in
   "blind-antek"):
   	DEVICE="ce7f737f-2d91-4c52-ba11-859b1a63898b_1" && DTYPE="BLINDS";
   	;;
   "blind-bedroom"):
   	DEVICE="5071a875-d8f5-4f24-93dd-a85f74351314_1" && DTYPE="BLINDS";
   	;;
   "blind-balcony"):
   	DEVICE="73a87432-4afa-4ba1-93ec-d32c4f1dec69_1" && DTYPE="BLINDS";
   	;;
   "sink-lamp"):
   	DEVICE="dcb18886-6468-4959-ae6f-477ef094d193_1" && DTYPE="LAMP";
   	;;
   *): 	ERROR=1;
   	;;
esac

case $2 in
   "on"|"ON"|"down"|"DOWN"):
   	if [ $DTYPE == "LAMP" ]; then COMMAND='[{"attributes":{"isOn":true}}]'; elif [ $DTYPE == "BLINDS" ]; then COMMAND='[{"attributes":{"blindsState":"down"}}]'; else ERROR=1; fi
   	;;
   "off"|"OFF"|"up"|"UP"):
   	if [ $DTYPE == "LAMP" ]; then COMMAND='[{"attributes":{"isOn":false}}]'; elif [ $DTYPE == "BLINDS" ]; then COMMAND='[{"attributes":{"blindsState":"up"}}]'; else ERROR=1; fi
   	;;
   "dim"|"DIM"|"level"):
   	if [ $DTYPE == "LAMP" ]; then if [ $3 -gt 0 ] && [ $3 -le 100 ]; then COMMAND='[{"attributes":{"lightLevel":'$3'}}]'; else ERROR=1; fi; elif [ $DTYPE == "BLINDS" ]; then COMMAND='[{"attributes":{"blindsTargetLevel":'$3'}}]'; else ERROR=1; fi
   	;;
   "colortemp"):
   	if [ $DTYPE == "LAMP" ]; then if [ $3 -ge 2700 ] && [ $3 -le 5000 ]; then COMMAND='[{"attributes":{"colorTemperature":'$3'}}]'; else ERROR=1; fi; else ERROR=1; fi
   	;;
   *): ERROR=1;
   	;;
esac

if [ $ERROR -eq 1 ]; then echo "usage $0 devicename <on>|<off>|<up>|<down>|<level> 1-100|<colortemp> 2700-5000"; exit 1; fi
if [ $DEBUG -eq 1 ]; then ARGUMENTS='--verbose --all'; else ARGUMENTS='-qq'; fi
echo "$COMMAND" | https $ARGUMENTS --verify=no -A bearer -a $TOKEN PATCH $DIRIGERA_IP:8443/v1/devices/$DEVICE 
3 Likes