Announcement

Collapse
No announcement yet.

Ikea Tradfri - trying to control

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Ikea Tradfri - trying to control

    Playing again and need some guidance.
    I have MQTT set up and working well with my house alarm via a python script and a Sonoff module having flashed it with Tasmota.
    I now want to interact with some Ikea Tradfri devices I have.
    My link between the Ikea bridge and MQTT is hemtjanst/tradfri-mqtt: Mirrors Trådfri gateways endpoints into MQTT and send commands to the gateway from MQTT (github.com)
    I can see all the Ikea devices in MQTT both via this plugin as well as an MQTT Explorer that is handy to view the traffic through the broker.

    I am using a plugin outlet to test. There are 18 'Sub's set up for the device and I only see a change in one; Sub: tradfri-raw/15001/65541:3312:5850

    If I turn on the outlet using the Ikea app I can see the change in the plugin on the associations page, I can also see the change in the MQTT Explorer. Both show values of 1 and 0.

    I am struggling to send a command to turn the outlet On or Off via an HS event. I can turn the Sonoff On and Off via an event, I can also trigger things in my alarm.

    Any help on the format of the command needed - or which of the 18 'Sub's I need to send the command to would be appreciated.

    #2
    tradfri-raw/15001/65541:3312:5850 implies to me that the MQTT Topic is 'tradfri-raw/15001/65541' and the Payload is JSON containing '{"3312":{:"5850":1}}'

    Code:
    { "method": "put", "url": "15004/162515", "id": "group-set-on", "replyTopic": "tradfri-reply/xyz", "payload": { "5850": 1 } }
    From the above example the following would be the mcsMQTT setup if mapping the topic to a HS device.

    Code:
    Pub Topic ... tradfri-cmd
    Payload Template ... { "method": "put", "url": "15001/65541", "id": "group-set-on", "replyTopic": "tradfri-reply/15001/65541", "payload": { "5850": $$VALUE: } }
    Control/Status UI ... Button
    VSP ... 0=0;off
    ....... 1=1;on
    I am not familiar with the Tradfri gateway so don't know what something like "group-set-on" has a special meaning. It may be the case that either "group-set-on" and "group-set-off" need to set depending upon the desired command state. If this is the case then the Payload template would contain group-set-$$LABEL:

    Note also that the tradfri-raw topic is a dump of whatever the gateway is sending. This is useful to get the data you will need to communicate with the device. It is likely you do not want to map any of these into HS. What you will be associating (if you want HS devices) is the tradfri-reply topic that will be sent after the tradfri-cmd topic is published by HS/mcsMQTT.

    In your case you asked for this to be a MQTT Event Action. In this case to turn the end point On the following would be sent.
    Code:
    tradfri-cmd={ "method": "put", "url": "15001/65541", "id": "group-set-on", "replyTopic": "tradfri-reply/15001/65541", "payload": { "5850": 1} }
    Note that group-set-on and "5850":1 are fixed for the On intent. If you wanted Off it likely would be group-set-off and "5850":0" . The example shows an end point of 5851 too. It could be that Off is "5851":1

    What Trådfri-MQTT has done is a very simple MQTT wrapper around the REST protocol used by the gateway. It provides the communication interface, but does not follow the normal way MQTT clients exchange information. It is still very usable, but just different.




    Comment


      #3
      Thank you for the reply. Time for more experimentation.

      Comment


        #4
        So far I've not made progress :-(

        Looking at the MQTT Explorer when I switch the device on and off 5850 shows either 1 or 0.
        In the Ikea app devices are grouped, so I assume the example given is to turn a group of devices on or off.

        When experimenting with using an event in HS I see the following in the MQTT Explorer;

        Click image for larger version

Name:	Tradfri-reply.PNG
Views:	153
Size:	247.9 KB
ID:	1440385
        Which indicates to me the message is getting there. But I don't get a result of the device turning on.

        I now wonder if the original setup went OK. I did get error messages but they left me feeling there wasn't a problem - but if there is I can work on it;

        Click image for larger version

Name:	Install.PNG
Views:	137
Size:	213.7 KB
ID:	1440386

        I not only posted your event code directly into the event, I also tried variations but nothing worked.

        Comment


          #5
          The topic used to show status was requested to be tradfr-reply/15001/65541 which is what MQTT Explorer is showing. The status is reported as 1/On. Do you mean the light does not turn on or do you mean you do not know where to look for the status in mcsMQTT/HS? I suspect your install is OK. The developer probably never tested node versions beyond 10.

          Comment


            #6
            The device does not come on.

            Comment


              #7
              I read the documentation in the link again.

              I see that the "id" parameter in the command is optional so no need to worry about "group-set-on" value.
              The replyTopic was also documented. The unit gave a response code of 5.0. This should mean something to someone who knows the range or responses it can provide. It also returned null for the response format. This should have been a number and most likely 50 to indicate a JSON response. The payload of "r":"08" should also mean something to one that knows the range of responses that the gateway will provide. Best guess is that the response it trying to indicate some issue with the command.

              Suggest the next step is to better understand the COAP/REST protocol used by Tradfri. I only scanned, but what looks like a good tutorial is https://learn.pimoroni.com/tutorial/...s-from-your-pi. Another approach is if there is some means to interact with the tradfri-mqtt author.

              In that tutorial it identifies a single bulb endpoint to be 65537. Rather than trying to control 65541 I suggest you try to control the individual light 65537

              Comment


                #8
                More experimentation - thanks for the direction.

                Comment


                  #9
                  I'm beginning to think this may be beyond me!

                  65537 is a bulb, 65541 is a plugin mains adapter. I have both in my system. I tried with 65537 but still no result. I also tried without the group set on value.
                  It's a shame as the Ikea devices are not expensive!

                  Comment

                  Working...
                  X