home-assistant-libs / pytradfri

IKEA Trådfri/Tradfri API. Control and observe your lights from Python. Examples available. On pypi. Sans-io.
MIT License
946 stars 129 forks source link

Ikea smart blinds #242

Closed tjorim closed 5 years ago

tjorim commented 5 years ago

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Home Assistant

Version of pytradfri

6.0.1

Expected behaviour

The integration supports all Ikea Smart things, like controlling the new Ikea Fyrtur and Kadrilj blinds.

Actual behaviour

It looks like this library doesn't support those yet (and as a result HA neither).

ggravlingen commented 5 years ago

That’s correct and I don’t reckon any of us devs have one. Fingers crossed someone submits a PR here!

ggravlingen commented 5 years ago

To maybe move things forward a little bit, can anyone who owns a blind please submit the JSON-string from the blind. To do that, run the this script (choice 3 and 4): https://github.com/ggravlingen/pytradfri/blob/master/examples/debug_info.py

Please please paste the output in this issue.

fribse commented 5 years ago

I'm trying to run the script, but I get an error, first it complained that the debian didn't have libcoap, so I installed that, and now I get:

python3 debug_info.php x.x.x.x

Please provide the 'Security Code' on the back of your Tradfri gateway: KEY
Traceback (most recent call last):
  File "debug_info.php", line 61, in <module>
    psk = api_factory.generate_psk(args.key)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 164, in generate_psk
    self._psk = self.request(Gateway().generate_psk(existing_psk_id))
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 96, in request
    return self._execute(api_commands, timeout=timeout)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 88, in _execute
    'Error executing request: {}'.format(err)) from None
pytradfri.error.RequestError: Error executing request: Command '['coap-client', '-u', 'Client_identity', '-k', 'KEY', '-v', '0', '-m', 'post', '-f', '-', 'coaps://x.x.x.x:5684/15011/9063']' returned non-zero exit status 1
??
ggravlingen commented 5 years ago

Were you prompted for a key and typed in the text on the back of your gateway? Also, your logs references a PHP-file. Are you running a PHP-file?

fribse commented 5 years ago

I tried entering the key with the -K and also by being prompted, it's a py file, just a typo, I changed it, but got the same result.

ggravlingen commented 5 years ago

In that case, I’d recommend using the docket script, it’s normally easier.

fribse commented 5 years ago

Ok, I'm more or less a virgin with docker, so what's the container name?

ggravlingen commented 5 years ago

Run this script: https://github.com/ggravlingen/pytradfri/blob/master/script/dev_docker

fribse commented 5 years ago

I think I'm going to set up an RPI3 for this, the debian vm I have here, also fails on finding the Dockerfile in the script :-(

fribse commented 5 years ago

Ok, made a brandnew RPi3 with buster, and installed docker. That gives me this: unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/DockerfileRPI: no such file or directory I then created the DockerRPI file, and ran the docker command manually, and that got me this problem: Step 5/8 : COPY ./script/install-coap-client.sh install-coap-client.sh COPY failed: stat /var/lib/docker/tmp/docker-builder011634599/script/install-coap-client.sh: no such file or directory

ggravlingen commented 5 years ago

Did you do this?

git clone https://github.com/ggravlingen/pytradfri.git
cd pytradfri/script
./dev_docker
fribse commented 5 years ago

No, but that gave a success.

And when I run the debug_info.py I get this root@raspberrypi:/usr/src/app/examples# python3 debug_info.py x.x.x.x Please provide the 'Security Code' on the back of your Tradfri gateway: SecretKey Generated PSK: PSKKEY Traceback (most recent call last): File "/usr/lib/python3.4/subprocess.py", line 609, in check_output output, unused_err = process.communicate(inputdata, timeout=timeout) File "/usr/lib/python3.4/subprocess.py", line 960, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "/usr/lib/python3.4/subprocess.py", line 1659, in _communicate self.stdout.encoding) File "/usr/lib/python3.4/subprocess.py", line 888, in _translate_newlines data = data.decode(encoding) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "debug_info.py", line 78, in devices = api(devices_commands) File "/usr/src/app/pytradfri/api/libcoap_api.py", line 101, in request result = self._execute(api_command, timeout=timeout) File "/usr/src/app/pytradfri/api/libcoap_api.py", line 83, in _execute return_value = subprocess.check_output(command, **kwargs) File "/usr/lib/python3.4/subprocess.py", line 615, in check_output process.kill() File "/usr/lib/python3.4/subprocess.py", line 1691, in kill self.send_signal(signal.SIGKILL) File "/usr/lib/python3.4/subprocess.py", line 1681, in send_signal os.kill(self.pid, sig) ProcessLookupError: [Errno 3] No such process

ggravlingen commented 5 years ago

Looks like you maybe have non-English names in your devices but other than that, I’m out of clues. The docker works on my computer.

fribse commented 5 years ago

Yes, I do have quite a few danish device names. Oh well, I hope somebody else can help out with this then, I'm not going to rename all my devices, that will mess up my HA automations.

fribse commented 5 years ago

I tried doing a raspbian stretch install, just to make sure that it wasn't a factor that buster doens't have it's own docker image. But I still get the same message about the danish character set.

fribse commented 5 years ago

Ok, so I renamed all the devices to items without danish letters. Image in 2019 programmers doesn't know about international charactersets, geez, embarrasing. This is the output of 3 and 4, look for Rullegardin. I hope it doesn't disclose 'dangerous' information.

What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 3
    Printing information about all devices paired to the Gateway
    [  
    {  
      "15015":[  
         {  
            "5536":0.0,
            "9003":0
         }
      ],
      "3":{  
         "0":"IKEA of Sweden",
         "1":"FYRTUR block-out roller blind",
         "2":"",
         "3":"2.2.007",
         "6":3,
         "9":77
      },
      "5750":7,
      "9001":"Rullegardin i sovevaerelse",
      "9002":1566141494,
      "9003":65601,
      "9019":1,
      "9020":1566402653,
      "9054":0,
      "9084":" 9d 58 b0 2 4 6a df be 77 e5 c1 e0 a2 26 2e 57"
    }
    ]
ggravlingen commented 5 years ago

Please don't be rude, this is an open source project where we spend some of our free time building the code that makes up pytradfri. The person who contributed that script probably don't live in a country where special characters are a problem.

Anyways, thanks for submitting the output. I stripped out the unnecessary bits.

ggravlingen commented 5 years ago

Having looked at this a bit, I believe I need the output from 2. Gateway endpoints.

fribse commented 5 years ago

Rude??? I beg your pardon, how is it rude that I point out that a programmer of today makes the same mistakes as we did in the 80's (yes I'm that old, and worked with assembler back then) ? I had hoped that people had learned something in the last 30 years, so Yes, I feel it is embarrasing, I'm not namecalling, it's just a statement. Ok, I will rename all the enities again 🙄

fribse commented 5 years ago

Output of '2':

What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 2

Printing information about endpoints in the Gateway

[
    "/15006",
    "/15001",
    "/15004",
    "/15004/add",
    "/15004/remove",
    "/15010",
    "/15005",
    "/15005/add",
    "/15005/remove",
    "/15011/15012",
    "/15011/9034",
    "/15011/9030",
    "/15011/9031",
    "/15011/9102",
    "/15011/9094",
    "/15011/9095",
    "/15011/9104",
    "/15010/265938",
    "/15010/320958",
    "/15004/131080",
    "/15005/131080",
    "/15005/131091/196666",
    "/15005/131091/196667",
    "/15005/131091/196668",
    "/15004/131094",
    "/15005/131094",
    "/15005/131097/196686",
    "/15004/131097",
    "/15005/131097",
    "/15001/65578",
    "/15001/65543",
    "/15001/65561",
    "/15001/65538",
    "/15001/65568",
    "/15001/65554",
    "/15001/65558",
    "/15001/65588",
    "/15001/65544",
    "/15001/65549",
    "/15001/65560",
    "/15001/65559",
    "/15001/65557",
    "/15001/65550",
    "/15001/65582",
    "/15001/65562",
    "/15001/65540",
    "/15001/65592",
    "/15001/65542",
    "/15001/65546",
    "/15001/65576",
    "/15001/65551",
    "/15001/65545",
    "/15001/65541",
    "/15001/65537",
    "/15001/65571",
    "/15005/131100/196693",
    "/15005/131100/196694",
    "/15005/131100/196695",
    "/15001/65599",
    "/15004/131100",
    "/15005/131100",
    "/15005/131074/196611",
    "/15005/131074/196612",
    "/15005/131074/196613",
    "/15005/131074/196614",
    "/15005/131075/196615",
    "/15005/131075/196616",
    "/15005/131075/196617",
    "/15005/131074/196620",
    "/15004/131075",
    "/15005/131075",
    "/15005/131080/196633",
    "/15005/131080/196634",
    "/15005/131080/196635",
    "/15005/131085/196648",
    "/15005/131085/196649",
    "/15005/131085/196650",
    "/15005/131094/196675",
    "/15005/131094/196676",
    "/15005/131094/196677",
    "/15005/131095/196678",
    "/15005/131095/196679",
    "/15005/131095/196680",
    "/15004/131073",
    "/15005/131073",
    "/15001/65555",
    "/15001/65570",
    "/15001/65585",
    "/15001/65579",
    "/15001/65536",
    "/15001/65591",
    "/15001/65587",
    "/15004/131095",
    "/15005/131095",
    "/15005/131097/196684",
    "/15005/131097/196685",
    "/15001/65567",
    "/15001/65539",
    "/15005/131078/196627",
    "/15005/131078/196628",
    "/15005/131078/196629",
    "/15004/131085",
    "/15005/131085",
    "/15004/131091",
    "/15005/131091",
    "/15005/131083/196642",
    "/15005/131083/196643",
    "/15005/131083/196644",
    "/15004/131083",
    "/15005/131083",
    "/15004/131078",
    "/15005/131078",
    "/15004/131074",
    "/15005/131074",
    "/15005/131090/196663",
    "/15005/131090/196664",
    "/15005/131090/196665",
    "/15004/131090",
    "/15005/131090",
    "/15005/131073/196608",
    "/15005/131073/196609",
    "/15005/131073/196610",
    "/15011/9063",
    "/15001/65600",
    "/15001/65601"
]

Please let me know within an hour if you need others, otherwise I will rename the items back to their proper names.

ggravlingen commented 5 years ago

Can the blinds be controlled from IKEA's own app? Looking at the data returned from the gateway, it doesn't quite follow the usual pattern for the devices that are controllable.

fribse commented 5 years ago

Yes they can. The app shows it like this (the top slider is the controller, the bottom is the blind. Screenshot_20190823-070308

fribse commented 5 years ago

Btw. The blinds require a 'repeater' to be installed close to them, that could be the reason for it looking different?

ggravlingen commented 5 years ago

Thanks for the confirmation that it works in the app! Then it should somehow be possible to reverse engineer.

Putting a longer version of your extract back here:

[  
   {  
      "15009":[  
         {  
            "9003":0
         }
      ],
      "3":{  
         "0":"IKEA of Sweden",
         "1":"TRADFRI remote control",
         "2":"",
         "3":"1.2.223",
         "6":3,
         "9":74
      },
      "5750":0,
      "9001":"Adrians fjernbetjening",
      "9002":1556813419,
      "9003":65578,
      "9019":1,
      "9020":1566438361,
      "9054":0
   },
   {  
      "15009":[  
         {  
            "9003":0
         }
      ],
      "3":{  
         "0":"IKEA of Sweden",
         "1":"TRADFRI remote control",
         "2":"",
         "3":"1.2.223",
         "6":3,
         "9":74
      },
      "5750":0,
      "9001":"Nathaliedaemper",
      "9002":1547834301,
      "9003":65543,
      "9019":1,
      "9020":1566438523,
      "9054":0
   },
   {  
      "15009":[  
         {  
            "9003":0
         }
      ],
      "3":{  
         "0":"IKEA of Sweden",
         "1":"TRADFRI wireless dimmer",
         "2":"",
         "3":"1.2.248",
         "6":3,
         "9":60
      },
      "5750":0,
      "9001":"Lysdaemper spejl",
      "9002":1549475041,
      "9003":65561,
      "9019":1,
      "9020":1566449363,
      "9054":0
   },
   {  
      "3":{  
         "0":"IKEA of Sweden",
         "1":"TRADFRI bulb E27 CWS opal 600lm",
         "2":"",
         "3":"1.3.009",
         "6":1
      },
      "3311":[  
         {  
            "5706":"f1e0b5",
            "5707":5427,
            "5708":42596,
            "5709":30015,
            "5710":26870,
            "5850":0,
            "5851":178,
            "9003":0
         }
      ],
      "5750":2,
      "9001":"Spisebord 1",
      "9002":1547811894,
      "9003":65537,
      "9019":1,
      "9020":1566455569,
      "9054":0
   },
   {  
      "3":{  
         "0":"IKEA of Sweden",
         "1":"TRADFRI transformer 10W",
         "2":"",
         "3":"1.2.245",
         "6":1
      },
      "3311":[  
         {  
            "5850":0,
            "5851":1,
            "9003":0
         }
      ],
      "5750":2,
      "9001":"Kontor",
      "9002":1553287081,
      "9003":65571,
      "9019":1,
      "9020":1566459464,
      "9054":0
   },
   {  
      "15014":[  
         {  
            "9003":0
         }
      ],
      "3":{  
         "0":"IKEA of Sweden",
         "1":"TRADFRI signal repeater",
         "2":"",
         "3":"2.0.019",
         "6":1
      },
      "5750":6,
      "9001":"Signalforstaerker",
      "9002":1566141249,
      "9003":65600,
      "9019":1,
      "9020":1566401800,
      "9054":0,
      "9084":" 83 6f b7 c 7a f4 8a 14 4a 94 4a 94 41 e0 a2 4f"
   },
   {  
      "15015":[  
         {  
            "5536":0.0,
            "9003":0
         }
      ],
      "3":{  
         "0":"IKEA of Sweden",
         "1":"FYRTUR block-out roller blind",
         "2":"",
         "3":"2.2.007",
         "6":3,
         "9":77
      },
      "5750":7,
      "9001":"Rullegardin i sovevaerelse",
      "9002":1566141494,
      "9003":65601,
      "9019":1,
      "9020":1566402653,
      "9054":0,
      "9084":" 9d 58 b0 2 4 6a df be 77 e5 c1 e0 a2 26 2e 57"
   }
]
ggravlingen commented 5 years ago

OK, this will be a bumpy ride as I controlling the blind doesn't work exactly as the lights. I've created a new branch with some changes in it that I'd like you to checkout. Please.run this command: git checkout 201908222012

Then please run the debug-command again, as you did above. I've updated the code so that it (hopefully) works with non-English letters so you don't have to rename. Let's get that decoding working before we do anything else here.

Following that code working, I'd like you to extract the part that references your bedroom blind (as in the abbreviated version of your post above) with the blinds fully up, fully down and then set at half way. I need to understand what values the command takes.

Thank you

ggravlingen commented 5 years ago

To clarify part two in my post above, I'm really only interested in the value in 5536 for the different scenarios, as it appears to be the value representing the state of the blind.

      "15015":[  
         {  
            "5536":0.0,
            "9003":0
         }
      ],
vdaele commented 5 years ago

The value 5536 ranges from 0 (open) to 100 (closed). I have no clue yet what the 9003 is

ggravlingen commented 5 years ago

@vdaele thank you! Can you please try running the example_blinds script in the branch mentioned above? It should set them half way, if working properly.

vdaele commented 5 years ago

Sorry, I don't have your branch but I can confirm that this payload works {"15015": [{"5536": 50}]} It triggers coap notifications like (note the occasional back jump from 41 to 24!) {"15015":[{"5536":0,"9003":0}],... {"15015":[{"5536":8,"9003":0}],... {"15015":[{"5536":13,"9003":0}],... {"15015":[{"5536":19,"9003":0}],... {"15015":[{"5536":24,"9003":0}],... {"15015":[{"5536":30,"9003":0}],... {"15015":[{"5536":36,"9003":0}],... {"15015":[{"5536":19,"9003":0}],... {"15015":[{"5536":41,"9003":0}],... {"15015":[{"5536":24,"9003":0}],... {"15015":[{"5536":47,"9003":0}],... {"15015":[{"5536":50,"9003":0}],...

ggravlingen commented 5 years ago

Thank you! I believe that's how I setup the command to be run yesterday. Let's see if anyone can clone the branch and confirm this.

vdaele commented 5 years ago

Any idea what the 15015/9003 key could be?

Note also that the Blinds have also two accompanying devices (not controllable afaics). A signal repeater (also having this 9003 key) { "15014": [ { "9003": 0 } ], "3": { "0": "IKEA of Sweden", "1": "TRADFRI signal repeater", "2": "", "3": "2.0.019", "6": 1 }, "5750": 6, "9001": "TRADFRI signal repeater", "9002": 1566565798, "9003": 65555, "9019": 1, "9020": 1566565804, "9054": 0, "9084": " 42 e6 cc f1 80 62 c4 88 79 90 2b 56 a7 2c 53 a6" } and a open/close remote { "3": { "0": "\u0002KE", "1": "TRADFRI open/close remote", "2": "", "3": "2.2.008", "6": 3, "9": 100 }, "5750": 1, "9001": "TRADFRI open/close remote", "9002": 1566565741, "9003": 65554, "9019": 1, "9020": 1566566097, "9054": 0 }

ggravlingen commented 5 years ago

9003 is an ID-number. Doesn't do anything in this context.

Ref: https://github.com/ggravlingen/pytradfri/blob/b1164295c50ec76bc0389b84f0a9adb0325c1aaf/pytradfri/const.py#L33

trizz commented 5 years ago

I've tested your branch, but nothing happens...

root@linuxkit-025000000001:/usr/src/app# python examples/example_blinds.py  192.168.2.26
Please provide the 'Security Code' on the back of your Tradfri gateway: XXXXXXXX
Generated PSK:  XXXXXXXX
[<65559 - Gordijn Keuken (FYRTUR block-out roller blind)>]
root@linuxkit-025000000001:/usr/src/app# python examples/example_blinds.py  192.168.2.26
[<65559 - Gordijn Keuken (FYRTUR block-out roller blind)>]

Gordijn Keuken is the name of the device. Also worth to mention that this library does not work on MacOS :)

sthorsen commented 5 years ago

Hi, I don't know if you need more info.

I just bought a blind and GW, and I would like to help in any way I can I hope this can help, else let me know if you need anything :)

Printing information about the Gateway b'{\n "9023": "2.tradfri.pool.ntp.org",\n "9029": "1.8.26",\n "9054": 0,\n "9055": 0,\n "9059": 1567142394,\n "9060": "2019-08-30T05:19:54.017712Z",\n "9061": 0,\n "9062": 0,\n "9066": 5,\n "9069": 1567104280,\n "9071": 2,\n "9072": 3,\n "9073": 31,\n "9074": 0,\n "9075": 59,\n "9076": 10,\n "9077": 27,\n "9078": 1,\n "9079": 0,\n "9080": 60,\n "9081": "7e2b6d52044000c1",\n "9082": false,\n "9083": "N/A",\n "9092": 1,\n "9093": 0,\n "9103": "a1nvlh0fc0asuq.iot.eu-central-1.amazonaws.com",\n "9105": 1,\n "9106": 1,\n "9107": 1,\n "9200": "a2719cc9-7ba6-4da6-aba6-b947d4d98554"\n}' root@development:/usr/src/app# python examples/debug_info.py 192.168.2.180 What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 2

Printing information about endpoints in the Gateway b'[\n "/15006",\n "/15001",\n "/15004",\n "/15004/add",\n "/15004/remove",\n "/15010",\n "/15005",\n "/15005/add",\n "/15005/remove",\n "/15011/15012",\n "/15011/9034",\n "/15011/9030",\n "/15011/9031",\n "/15011/9102",\n "/15011/9094",\n "/15011/9095",\n "/15011/9104",\n "/15005/131073/196608",\n "/15005/131073/196609",\n "/15005/131073/196610",\n "/15001/65537",\n "/15001/65536",\n "/15004/131073",\n "/15005/131073",\n "/15001/65538",\n "/15011/9063"\n]' root@development:/usr/src/app# python examples/debug_info.py 192.168.2.180 What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 3

Printing information about all devices paired to the Gateway b'[\n {\n "15014": [\n {\n "9003": 0\n }\n ],\n "3": {\n "0": "IKEA of Sweden",\n "1": "TRADFRI signal repeater",\n "2": "",\n "3": "2.0.019",\n "6": 1\n },\n "5750": 6,\n "9001": "TRADFRI signal repeater",\n "9002": 1567104721,\n "9003": 65537,\n "9019": 1,\n "9020": 1567106701,\n "9054": 0,\n "9084": " 88 10 2b 34 a 14 41 89 70 82 f 1e 55 c8 90 49"\n },\n {\n "15009": [\n {\n "9003": 0\n }\n ],\n "3": {\n "0": "\u0002KE",\n "1": "TRADFRI open/close remote",\n "2": "",\n "3": "2.2.008",\n "6": 3,\n "9": 87\n },\n "5750": 0,\n "9001": "TRADFRI open/close remote",\n "9002": 1567104607,\n "9003": 65536,\n "9019": 1,\n "9020": 1567104838,\n "9054": 0\n },\n {\n "15015": [\n {\n "5536": 8.0,\n "9003": 0\n }\n ],\n "3": {\n "0": "IKEA of Sweden",\n "1": "FYRTUR block-out roller blind",\n "2": "",\n "3": "2.2.007",\n "6": 3,\n "9": 55\n },\n "5750": 7,\n "9001": "TRADFRI blind",\n "9002": 1567104827,\n "9003": 65538,\n "9019": 1,\n "9020": 1567106738,\n "9054": 0,\n "9084": " ea b6 6c ba 1d 3a 1d 58 bb 1f 57 c7 85 68 b2 6f"\n }\n]' root@development:/usr/src/app# python examples/debug_info.py 192.168.2.180 What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 4

Printing information about all lamps paired to the Gateway No lamps paired root@development:/usr/src/app# python examples/debug_info.py 192.168.2.180 What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 5

Printing information about smart tasks No smart tasks defined root@development:/usr/src/app# python examples/debug_info.py 192.168.2.180 What information about your Tradfri network do you need?

  1. Gateway
  2. Gateway endpoints
  3. All paired devices
  4. All paired lamps
  5. All smart tasks
  6. All groups Make a choice: 6

Printing information about all groups defined in the Gateway b'[\n {\n "5850": 0,\n "5851": 0,\n "9001": "TRADFRI group",\n "9002": 1567104607,\n "9003": 131073,\n "9018": {\n "15002": {\n "9003": [\n 65536,\n 65538\n ]\n }\n },\n "9039": 196608,\n "9108": 0\n }\n]' root@development:/usr/src/app#


- python3 -i -m pytradfri 192.168.2.180
I made modified the code a bit so I can list blinds in the API and 

root@development:~/thorsen/pytradfri# git diff pytradfri/main.py diff --git a/pytradfri/main.py b/pytradfri/main.py index 1162cb9..1cde35b 100644 --- a/pytradfri/main.py +++ b/pytradfri/main.py @@ -61,6 +61,12 @@ if name == 'main': gateway = Gateway() devices_commands = api(gateway.get_devices()) devices = api(devices_commands)

root@development:/usr/src/app# python3 -i -m pytradfri 192.168.2.180
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001']
DEBUG:pytradfri.api.libcoap_api:Received: [65537,65536,65538]
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001', 65537]
DEBUG:pytradfri.api.libcoap_api:Received: {"9054":0,"9001":"TRADFRI signal repeater","9002":1567104721,"9020":1567106701,"9003":65537,"5750":6,"9019":1,"9084":" 88 10 2b 34 a 14 41 89 70 82 f 1e 55 c8 90 49","3":{"3":"2.0.019","0":"IKEA of Sweden","1":"TRADFRI signal repeater","2":"","6":1},"15014":[{"9003":0}]}
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001', 65536]
DEBUG:pytradfri.api.libcoap_api:Received: {"9054":0,"9001":"TRADFRI open/close remote","9002":1567104607,"9020":1567104838,"9003":65536,"5750":0,"9019":1,"3":{"3":"2.2.008","0":"\u0002KE","1":"TRADFRI open/close remote","2":"","6":3,"9":87},"15009":[{"9003":0}]}
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001', 65538]
DEBUG:pytradfri.api.libcoap_api:Received: {"9054":0,"9001":"TRADFRI blind","9002":1567104827,"9020":1567106738,"9003":65538,"5750":7,"9019":1,"9084":" ea b6 6c ba 1d 3a 1d 58 bb 1f 57 c7 85 68 b2 6f","3":{"3":"2.2.007","0":"IKEA of Sweden","1":"FYRTUR block-out roller blind","2":"","6":3,"9":55},"15015":[{"5536":8.0,"9003":0}]}
No lights found!
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15004']
DEBUG:pytradfri.api.libcoap_api:Received: [131073]
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15005', <pytradfri.command.Command object at 0x7f057d6b5d50>]
DEBUG:pytradfri.api.libcoap_api:Received: [131073]
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15010']
DEBUG:pytradfri.api.libcoap_api:Received: []
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '15012']
DEBUG:pytradfri.api.libcoap_api:Received: {"9023":"2.tradfri.pool.ntp.org","9059":1567142675,"9200":"a2719cc9-7ba6-4da6-aba6-b947d4d98554","9079":0,"9071":2,"9060":"2019-08-30T05:24:35.026104Z","9107":1,"9082":false,"9062":0,"9103":"a1nvlh0fc0asuq.iot.eu-central-1.amazonaws.com","9061":0,"9029":"1.8.26","9081":"7e2b6d52044000c1","9080":60,"9078":1,"9054":0,"9083":"N/A","9073":31,"9066":5,"9055":0,"9069":1567104280,"9072":3,"9074":0,"9075":59,"9076":10,"9092":1,"9077":27,"9105":1,"9093":0,"9106":1}

Example commands:
> devices
> homekit_id
> blind.blind_control.blinds
> api(gateway.reboot())
> groups
> moods
> tasks
> dump_devices()
> dump_all()
>>> devices
[<65537 - TRADFRI signal repeater (TRADFRI signal repeater)>, <65536 - TRADFRI open/close remote (TRADFRI open/close remote)>, <65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
>>> blinds
[<65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
>>> dump_devices()
[{'15014': [{'9003': 0}],
  '3': {'0': 'IKEA of Sweden',
        '1': 'TRADFRI signal repeater',
        '2': '',
        '3': '2.0.019',
        '6': 1},
  '5750': 6,
  '9001': 'TRADFRI signal repeater',
  '9002': 1567104721,
  '9003': 65537,
  '9019': 1,
  '9020': 1567106701,
  '9054': 0,
  '9084': ' 88 10 2b 34 a 14 41 89 70 82 f 1e 55 c8 90 49'},
 {'15009': [{'9003': 0}],
  '3': {'0': '\x02KE',
        '1': 'TRADFRI open/close remote',
        '2': '',
        '3': '2.2.008',
        '6': 3,
        '9': 87},
  '5750': 0,
  '9001': 'TRADFRI open/close remote',
  '9002': 1567104607,
  '9003': 65536,
  '9019': 1,
  '9020': 1567104838,
  '9054': 0},
 {'15015': [{'5536': 8.0, '9003': 0}],
  '3': {'0': 'IKEA of Sweden',
        '1': 'FYRTUR block-out roller blind',
        '2': '',
        '3': '2.2.007',
        '6': 3,
        '9': 55},
  '5750': 7,
  '9001': 'TRADFRI blind',
  '9002': 1567104827,
  '9003': 65538,
  '9019': 1,
  '9020': 1567106738,
  '9054': 0,
  '9084': ' ea b6 6c ba 1d 3a 1d 58 bb 1f 57 c7 85 68 b2 6f'}]
>>> dump_all()
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['.well-known', 'core']
DEBUG:pytradfri.api.libcoap_api:Received: <//15006>;ct=0;obs,<//15001>;ct=0;obs,<//15004>;ct=0;obs,<//15004/add>;ct=0,<//15004/remove>;ct=0,<//15010>;ct=0;obs,<//15005>;ct=0;obs,<//15005/add>;ct=0,<//15005/remove>;ct=0,<//15011/15012>;ct=0;obs,<//15011/9034>;ct=0,<//15011/9030>;ct=0,<//15011/9031>;ct=0,<//15011/9102>;ct=0,<//15011/9094>;ct=0;obs,<//15011/9095>;ct=0;obs,<//15011/9104>;ct=0;obs,<//15005/131073/196608>;ct=0;obs,<//15005/131073/196609>;ct=0;obs,<//15005/131073/196610>;ct=0;obs,<//15001/65537>;ct=0;obs,<//15001/65536>;ct=0;obs,<//15004/131073>;ct=0;obs,<//15005/131073>;ct=0;obs,<//15001/65538>;ct=0;obs,<//15011/9063>;ct=0
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15006']
DEBUG:pytradfri.api.libcoap_api:Received: [{"9002":1567106685,"9014":0,"9015":5001}]
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001']
DEBUG:pytradfri.api.libcoap_api:Received: [65537,65536,65538]
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15004']
DEBUG:pytradfri.api.libcoap_api:Received: [131073]
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15010']
DEBUG:pytradfri.api.libcoap_api:Received: []
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15005']
DEBUG:pytradfri.api.libcoap_api:Received: [131073]
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '15012']
DEBUG:pytradfri.api.libcoap_api:Received: {"9023":"2.tradfri.pool.ntp.org","9059":1567142869,"9200":"a2719cc9-7ba6-4da6-aba6-b947d4d98554","9079":0,"9071":2,"9060":"2019-08-30T05:27:49.019496Z","9107":1,"9082":false,"9062":0,"9103":"a1nvlh0fc0asuq.iot.eu-central-1.amazonaws.com","9061":0,"9029":"1.8.26","9081":"7e2b6d52044000c1","9080":60,"9078":1,"9054":0,"9083":"N/A","9073":31,"9066":5,"9055":0,"9069":1567104280,"9072":3,"9074":0,"9075":59,"9076":10,"9092":1,"9077":27,"9105":1,"9093":0,"9106":1}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9034']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9030']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9031']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9102']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9094']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9095']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9104']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15005', '131073', '196608']
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"EVERYDAY","9068":1,"9002":1567104607,"9003":196608,"9057":0,"15016":[{"9003":65538}]}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15005', '131073', '196609']
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"RELAX","9068":1,"9002":1567104607,"9003":196609,"9057":1,"15016":[{"9003":65538}]}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15005', '131073', '196610']
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"FOCUS","9068":1,"9002":1567104607,"9003":196610,"9057":2,"15016":[{"9003":65538}]}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001', '65537']
DEBUG:pytradfri.api.libcoap_api:Received: {"9054":0,"9001":"TRADFRI signal repeater","9002":1567104721,"9020":1567106701,"9003":65537,"5750":6,"9019":1,"9084":" 88 10 2b 34 a 14 41 89 70 82 f 1e 55 c8 90 49","3":{"3":"2.0.019","0":"IKEA of Sweden","1":"TRADFRI signal repeater","2":"","6":1},"15014":[{"9003":0}]}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001', '65536']
DEBUG:pytradfri.api.libcoap_api:Received: {"9054":0,"9001":"TRADFRI open/close remote","9002":1567104607,"9020":1567104838,"9003":65536,"5750":0,"9019":1,"3":{"3":"2.2.008","0":"\u0002KE","1":"TRADFRI open/close remote","2":"","6":3,"9":87},"15009":[{"9003":0}]}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15004', '131073']
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"TRADFRI group","9002":1567104607,"9003":131073,"5850":0,"5851":0,"9039":196608,"9108":0,"9018":{"15002":{"9003":[65536,65538]}}}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15005', '131073']
DEBUG:pytradfri.api.libcoap_api:Received: [196608,196609,196610]
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15001', '65538']
DEBUG:pytradfri.api.libcoap_api:Received: {"9054":0,"9001":"TRADFRI blind","9002":1567104827,"9020":1567106738,"9003":65538,"5750":7,"9019":1,"9084":" ea b6 6c ba 1d 3a 1d 58 bb 1f 57 c7 85 68 b2 6f","3":{"3":"2.2.007","0":"IKEA of Sweden","1":"FYRTUR block-out roller blind","2":"","6":3,"9":55},"15015":[{"5536":8.0,"9003":0}]}
None

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.2.180 get ['15011', '9063']
DEBUG:pytradfri.api.libcoap_api:Received: 
None

>>>

@@ -85,8 +86,8 @@ def run(): print(blinds)

 # Example 4: Set the light level of the light
root@development:/usr/src/app# python examples/example_blinds.py 192.168.2.180
[<65537 - TRADFRI signal repeater (TRADFRI signal repeater)>, <65536 - TRADFRI open/close remote (TRADFRI open/close remote)>, <65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
[<65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
<pytradfri.command.Command object at 0x7f53c372c2d0>
root@development:/usr/src/app#
sthorsen commented 5 years ago

Hi, I found this project and it works really well with the blinds :) https://github.com/eriklupander/tradfri-go

ggravlingen commented 5 years ago

@sthorsen can you please pull the latest version of the branch and try the test script?

sthorsen commented 5 years ago

Hi @ggravlingen

Sure, just did but the blind does not react

root@development:/usr/src/app# python examples/example_blinds.py 192.168.2.180
[<65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
<pytradfri.command.Command object at 0x7fe62e435e90>
ggravlingen commented 5 years ago

Thank you! I've added a few debug printouts, can you please try again?

sthorsen commented 5 years ago

Sure, here you go

root@development:/usr/src/app# python examples/example_blinds.py 192.168.2.180
15001
15001/65537
15001/65538
15001/65536
[<65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
['15001', 65538]
[{'5523': 50}]
15001/65538
<pytradfri.command.Command object at 0x7f8b55b5dc50>
ggravlingen commented 5 years ago

@sthorsen! Thanks again! Looks like I was sending the command to 5523 instead of 5536. I've updated and would appreciate another run.

sthorsen commented 5 years ago

Hehe, no problem

root@development:/usr/src/app# python examples/example_blinds.py 192.168.2.180
[<65538 - TRADFRI blind (FYRTUR block-out roller blind)>]
['15001', 65538]
[{'5536': 50}]

I think the payload should be something like this:?

{"15015": [{"5536":50}]}
ggravlingen commented 5 years ago

You're absolutely right, I need to remember how to change the path to 15015.

ggravlingen commented 5 years ago

I've made some changes now that should send the payload to 15015. Also updated the dockerfile for Raspberry Pi to the latest version of Python.

sthorsen commented 5 years ago

Hi @ggravlingen, I just tried your update. The blind is not moving but here are the output :) I set the position to 10

root@development:/usr/src/app# python examples/example_blinds.py 192.168.2.180
coap-client -u -k  -v 0 -m get coaps://192.168.2.180:5684/15001
{'stderr': -3, 'timeout': 10, 'universal_newlines': True}
coap-client -u -k -v 0 -m get coaps://192.168.2.180:5684/15001/65537
{'stderr': -3, 'timeout': 10, 'universal_newlines': True}
coap-client -u -k -v 0 -m get coaps://192.168.2.180:5684/15001/65538
{'stderr': -3, 'timeout': 10, 'universal_newlines': True}
coap-client -u -k -v 0 -m get coaps://192.168.2.180:5684/15001/65536
{'stderr': -3, 'timeout': 10, 'universal_newlines': True}
coap-client -u -k -v 0 -m get coaps://192.168.2.180:5684/15001/65540
{'stderr': -3, 'timeout': 10, 'universal_newlines': True}
['15015', 65538]
[{'5536': 10}]
coap-client -u -k -v 0 -m put -f - coaps://192.168.2.180:5684/15015/65538
{'stderr': -3, 'timeout': 10, 'universal_newlines': True, 'input': '[{"5536": 10}]'}
ggravlingen commented 5 years ago

@sthorsen haha, this is difficult to do without having a blind on my own :) Thank you for your patience. Btw, I edited your post and removed the user/key data that was in there.

@vdaele what command exactly did you invoke to control the blinds?

sthorsen commented 5 years ago

@ggravlingen Oh, thank you. I missed that :) Yeah, it is hard to integrate devices you don't have on hand ;) But don't worry, we will get it to work :) I'm sorry I can't help more. But I'm not that into Python

But I'm here to test it :)

sthorsen commented 5 years ago

Oh, and as you can see. I have 2 blinds connected now :)

vdaele commented 5 years ago

I don't use pytradfri. But If I understand the comments above correctly, you are sending a weird payload like

['15015', 65538]
[{'5536': 10}]

while it should be (no need anymore to repeat the 65538)

{"15015": [{"5536": 50}]}
ggravlingen commented 5 years ago

65538 is the ID of the specific blind we want to change the state of so it has to be there somewhere in the command.

The command we're sending to the gateway at the moment is [{"5536": 10}] to the COAP endpoint coaps://192.168.2.180:5684/15015/65538.

vdaele commented 5 years ago

You have to send {"15015": [{"5536": 50}]}