IKEA Motion sensor duration

Hi there, I am encountering unexpected behaviour when using IKEA E1745 motion sensor with Deconz

I have all the sensors in the same room for testing below in screenshot
Motion sensor 1, Drax Room Motion sensor 1, Kitchen Sensor 2 are connected to HA via Deconz
Motion Sensor Test occupancy is connected to HA via zigbee2mttt

Because there is a 60 sec for duration defined and cooldown period for sensor to 90sec, sensors goes to OFF state. Resulting sensor going ON-OFF-ON-OFF where it should actually be constant ON. That creates issues when building automation in HA.

zigbee2mqtt has already 90sec for the duration to match the delay, so there is a constant ON state whilst there is a motion

What I have tried is to set the duration to more than 60 sec or to 0.
As suggested setting config.duration to 0 would match the duration to delay which should solve the issue but I get an error “invalid value, 0, for parameter duration” when setting via rest or HA

Hello, what is the model id of this device ?

I can see something in code but perhaps not used for this one


                    else if (sensor->modelId() == QLatin1String("TRADFRI motion sensor"))
                    {
                        if (data.uinteger < 1 || data.uinteger > 60)
                        {
                            rsp.list.append(errorToMap(ERR_INVALID_VALUE, QString("/sensors/%1/config/%2").arg(id).arg(pi.key()),
                                                       QString("invalid value, %1, for parameter %2").arg(map[pi.key()].toString()).arg(pi.key())));
                            continue;
                        }
                    }

and value need to be < 60 ?

Its IKEA E1745 motion sensor. Yes that is the code for this sensor. There was a guy who commented this bit out and recompiled, it worked for him… I unfortunately do not know how to recompile etc…and would rather have it changed and updated from Deconz guys side. Before I suppose you could set it to 0 and sort this out but not it will throw an error as evident in the code

But your model is “TRADFRI motion sensor” ?

Set config.duration to 0 to prevent deCONZ from clearing state.presence based on that setting, using config.delay as reported by the sensor instead.

There was a guy who commented this bit out and recompiled, it worked for him

It’s this issue ? IKEA TRADFRI motion E1745 sensor duration · Issue #6336 · dresden-elektronik/deconz-rest-plugin · GitHub
So this device don’t use config/duration but config/delay instead ?

Can I just mention here you cannot set the duration to 0

Yes … But there is perhaps a comment usefull here TRADFRI motion sensor wrong timing in Deconz · Issue #1970 · dresden-elektronik/deconz-rest-plugin · GitHub

Hi Samanar,
yes, my model is a TRADFRI motion sensor. Yes, that is the issue that I created on GitHub.

That comment is not helpful. Whilst it might be for him setting config.duration to 1 makes things worse and sets the sensor from ON to OFF state after 1 sec and then you have the delay.

Sorry, I m going on holiday in some hours, be back in 1 week.
I will give this issue to others devs, I hope one of them have the device too.

Thanks Smanar, I can test for sure… For some reason, I suppose setting config.duration to 0 was taken out at some point, if we can set to match the duration to the delay that would solve this issue…

Hi Smanar, hope you had a lovely holiday. Do you have any updates on this?

Much appreciated

Oups, sorry, long time I m back, and no, I have totaly forget you, need to ask other dev to know if someone have take a look on it.

But I have an idea, the code use that


                        ResourceItem *item2 = sensor->item(RConfigDuration);
                        if (item2 && item2->toNumber() > 0)
                        {
                            sensor->durationDue = QDateTime::currentDateTime().addSecs(item2->toNumber());
                        }

And if I m understand we need to disable config/duration to use config/delay instead, no ?
So if it’s that, the correctif is easy, we just need to remove config/duration in the device json.

Do you know how to use DDF ? DDF cheat sheet · dresden-elektronik/deconz-rest-plugin Wiki · GitHub
Will be nice If you can share me the “actual automatic DDF”, less work for me to edit it.
In deconz, select the node, then take “edit DDF” and share to me the last tab “preview”.

Else you can to just remove it yourself from the DDF (with selecting it and press delete) then save the DDF, and make “hot reload”.

Hi Smanar, here is the Preview tab from DDF Editor. As I see it, the duration time should match the delay time. Otherwise, the sensor will go to off state before the delay in the sensor runs out.

{
  "schema": "devcap1.schema.json",
  "manufacturername": "$MF_IKEA",
  "modelid": "TRADFRI motion sensor",
  "product": "TRADFRI motion sensor",
  "sleeper": false,
  "status": "Draft",
  "subdevices": [
    {
      "type": "$TYPE_PRESENCE_SENSOR",
      "restapi": "/sensors",
      "uuid": [
        "$address.ext",
        "0x01",
        "0x0006"
      ],
      "fingerprint": {
        "profile": "0x0104",
        "device": "0x0850",
        "endpoint": "0x01",
        "in": [
          "0x0000",
          "0x0001",
          "0x1000"
        ],
        "out": [
          "0x0006",
          "0x0008"
        ]
      },
      "items": [
        {
          "name": "attr/id"
        },
        {
          "name": "attr/lastannounced"
        },
        {
          "name": "attr/lastseen"
        },
        {
          "name": "attr/manufacturername"
        },
        {
          "name": "attr/modelid"
        },
        {
          "name": "attr/name"
        },
        {
          "name": "attr/swversion"
        },
        {
          "name": "attr/type"
        },
        {
          "name": "attr/uniqueid"
        },
        {
          "name": "config/alert",
          "description": "The currently active alert."
        },
        {
          "name": "config/battery",
          "description": "The current device battery level in 0&ndash;100&thinsp;%.",
          "parse": {
            "at": "0x0021",
            "cl": "0x0001",
            "cppsrc": "power_configuration.cpp:194",
            "ep": 1,
            "eval": "Item.val = Attr.val"
          },
          "default": 0
        },
        {
          "name": "config/duration",
          "description": "The duration until presence is automatically turned back to false."
        },
        {
          "name": "config/on"
        },
        {
          "name": "config/reachable"
        },
        {
          "name": "state/lastupdated"
        },
        {
          "name": "state/presence",
          "description": "True when presence is detected.",
          "default": false
        }
      ]
    }
  ],
  "bindings": [
    {
      "bind": "unicast",
      "src.ep": 1,
      "dst.ep": 1,
      "cl": "0x0000"
    },
    {
      "bind": "unicast",
      "src.ep": 1,
      "dst.ep": 1,
      "cl": "0x0001",
      "report": [
        {
          "at": "0x0021",
          "dt": "0x20",
          "min": 300,
          "max": 2700,
          "change": "0x00000001"
        }
      ]
    },
    {
      "bind": "groupcast",
      "config.group": 0,
      "src.ep": 1,
      "cl": "0x0006"
    },
    {
      "bind": "groupcast",
      "config.group": 0,
      "src.ep": 1,
      "cl": "0x0008"
    },
    {
      "bind": "groupcast",
      "config.group": 252,
      "src.ep": 1,
      "cl": "0x0006"
    },
    {
      "bind": "groupcast",
      "config.group": 252,
      "src.ep": 1,
      "cl": "0x0008"
    }
  ]
}

You are sure from the comment on the other post, it seem we need to disable config/duration for the code use config/delay instead.

Set config.duration to 0 to prevent deCONZ from clearing state.presence based on that setting, using config.delay as reported by the sensor instead.

I will ask more information to Ebaauwn, because I have trying to make a new DDF without config/duration, but you have nothing for config delay.

Ok I have found the code part, and you need to state/dark. And from the code, you need to have them added in the device json by the code, idk why you don’t have them …

Can you try this DDF to test

{
   "schema":"devcap1.schema.json",
   "manufacturername":"$MF_IKEA",
   "modelid":"TRADFRI motion sensor",
   "product":"TRADFRI motion sensor",
   "sleeper":false,
   "status":"Gold",
   "subdevices":[
      {
         "type":"$TYPE_PRESENCE_SENSOR",
         "restapi":"/sensors",
         "uuid":[
            "$address.ext",
            "0x01",
            "0x0006"
         ],
         "items":[
            {
               "name":"attr/id"
            },
            {
               "name":"attr/lastannounced"
            },
            {
               "name":"attr/lastseen"
            },
            {
               "name":"attr/manufacturername"
            },
            {
               "name":"attr/modelid"
            },
            {
               "name":"attr/name"
            },
            {
               "name":"attr/swversion"
            },
            {
               "name":"attr/type"
            },
            {
               "name":"attr/uniqueid"
            },
            {
               "name":"config/battery",
               "parse":{
                  "at":"0x0021",
                  "cl":"0x0001",
                  "cppsrc":"power_configuration.cpp:194",
                  "ep":1,
                  "eval":"Item.val = Attr.val"
               },
               "default":0
            },
            {
               "name":"config/delay"
            },
            {
               "name":"config/on"
            },
            {
               "name":"config/reachable"
            },
            {
               "name":"state/lastupdated"
            },
            {
               "name":"state/dark"
            },
            {
               "name":"state/presence",
               "default":false
            }
         ]
      }
   ],
   "bindings":[
      {
         "bind":"unicast",
         "src.ep":1,
         "dst.ep":1,
         "cl":"0x0001",
         "report":[
            {
               "at":"0x0021",
               "dt":"0x20",
               "min":300,
               "max":2700,
               "change":"0x00000001"
            }
         ]
      },
      {
         "bind":"unicast",
         "src.ep":1,
         "dst.ep":1,
         "cl":"0x0006"
      }
   ]
}

Note for later

{
  "name": "state/presence",
  "default": false,
  "parse": {
    "cl": "0x0006",
    "cmd": "0x42",
    "eval": "Item.val = ZclFrame.at(0)"
  }
}

I discovered that after upgrading to 2.19.1 deCONZ failed to recognize the IKEA Motion sensor delay entity:
image
[OBS Bad in Norwegian means bathroom]

This occurred for all my IKEA motion sensors. It is a very important setting as it can be used to overcome the 3min default delay in these sensors, which is way too short.

However, after activating the sensors (moving around in front of them), until they triggered, and then reload the deCONZ integration, everything came back to normal again.

At first I thought that the upgrade to 2.19.01 broke this entity. The error message from HA suggests that. I’ve never experienced anything like this before.

Hu ?
This message is from HA or the deconz plugin on HA ? (I have skipped this release note …)
And now all is working ?

Its in home assistant and it says this because the integration is loaded bit the entity is not created which means the data is not in the device data

HI Smanar, I have changed DDF and added config/delay and state/dark. Would that change anything by itself or do we need to do more to solve this delay issue? Sensor still behaves as it was before, see below. Kitchen sensor 2 is the same model but connected via Zigbee2Mqtt.

So it’s still same result ?
You have tried to delete and re-include the device with the new DDF ?

wich one value you have in config/delay ?

I have put 90 for the delay, I will try to re-add the sensor. Will it retain the DDF when i delete and re-add ?

Yes, and it will include it only with data on the DDF, so you will be sure the issue is not from the previous inclusion with legacy code.

To be sure you can take a look on the API (for exemple on phoscon/help/API Information/Sesnsors) you need to have in the JSON “state/dark” and no “state/duration”.

From ebaauw

The Trådfri motion sensors do not send anything when motion is no longer detected. When they detect motion, they send an On with Timed Off command to the associated group. The REST API plugin eavesdrops on this command, and sets state.presence on the sensor resource to true. It also sets config.delay to the time specified in the command: between 1 and 10 minutes for the old model (depending on the dial setting), and 3 minutes for the new model. The sensor will not register new motion, until shortly before this time has passed. The REST API plugin sets state.presence to false automatically, config.duration seconds after it set state.presence to true. I think config.duration is initialised to 60, leading to two minutes in the dark for the new model. Set config.duration to 0 and the REST API plugin will use config.delay instead, making sure state.presence is set to false at the same moment the lights in the associated group turn off automatically.

And for the solution part

All deCONZ does is reset state.presence to false automatically, config.duration seconds after the sensor has reported motion. This is because the sensor does not report when it no longer detects motion. You need to align config.duration to the sensor’s interval. This is done by a PUT to the sensor’s config with a body of {"duration": 0} (to use config.delay) or "{"duration": 180} (for three minutes).

Problem the API don’t permit value 0 or > 60.

Someone have perhaps a solution using DDF too, but making the reverse of me, I remove duration, and him add it with a fixed value

On my side I trying with this code part https://github.com/dresden-elektronik/deconz-rest-plugin/blob/master/de_web_plugin.cpp#L14011

                item = s.item(RConfigDuration);
                if (item && item->toNumber() > 0)
                {
                    s.durationDue = QDateTime::currentDateTime().addSecs(item->toNumber());
                }
                else if (delay > 0)
                {
                    s.durationDue = QDateTime::currentDateTime().addSecs(delay);
                }

If I have understand the code, if the device haven’t config/duration, it use delay value.

Edit:
Ok So I m wrong, on this part delay is a return from the zigbee request, not something you can set. And you can put the value you want, this code update the value you set with the value in the zigbee request.
I don’t understand, config/delay is totaly useless for this device ?

Edit 2:

So forget all I have said before, the only way I m seing to make this device working is using duration, and with a bigger value.

Perhaps with setting it using DDF


{
   "schema":"devcap1.schema.json",
   "manufacturername":"$MF_IKEA",
   "modelid":"TRADFRI motion sensor",
   "product":"TRADFRI motion sensor",
   "sleeper":false,
   "status":"Gold",
   "subdevices":[
      {
         "type":"$TYPE_PRESENCE_SENSOR",
         "restapi":"/sensors",
         "uuid":[
            "$address.ext",
            "0x01",
            "0x0006"
         ],
         "items":[
            {
               "name":"attr/id"
            },
            {
               "name":"attr/lastannounced"
            },
            {
               "name":"attr/lastseen"
            },
            {
               "name":"attr/manufacturername"
            },
            {
               "name":"attr/modelid"
            },
            {
               "name":"attr/name"
            },
            {
               "name":"attr/swversion"
            },
            {
               "name":"attr/type"
            },
            {
               "name":"attr/uniqueid"
            },
            {
               "name":"config/battery",
               "parse":{
                  "at":"0x0021",
                  "cl":"0x0001",
                  "cppsrc":"power_configuration.cpp:194",
                  "ep":1,
                  "eval":"Item.val = Attr.val"
               },
               "default":0
            },
            {
               "name":"config/delay"
            },
            {
               "name":"config/on"
            },
            {
               "name":"config/reachable"
            },
            {
               "name":"state/lastupdated"
            },
            {
               "name":"state/dark"
            },
            {
             "name": "config/duration",
             "default": 100
            },
            {
               "name":"state/presence",
               "default":false
            }
         ]
      }
   ],
   "bindings":[
      {
         "bind":"unicast",
         "src.ep":1,
         "dst.ep":1,
         "cl":"0x0001",
         "report":[
            {
               "at":"0x0021",
               "dt":"0x20",
               "min":300,
               "max":2700,
               "change":"0x00000001"
            }
         ]
      },
      {
         "bind":"unicast",
         "src.ep":1,
         "dst.ep":1,
         "cl":"0x0006"
      }
   ]
}