Wb-rules правила обрабатываются с задержкой

Добрый день! Столкнулся с ситуацией, в которой долго пытался разобраться самостоятельно.
Имеется датчик движения zigbee aqara, модуль mr6c (скорость 115200), модуль WBIO-DI-WD-14. С помощью этого оборудования реализовано включение света на модуле mr6c с помощью кнопки на модуле WBIO-DI-WD-14, и по датчику движения. По кнопке свет включается мгновенно, по датчику движения задержка до 5 сек. В виртуальном устройстве факт движения фиксируется примерно через полсекунды, дальше пауза, и только потом реакция оборудования. Правило обрабатывается с задержкой, запись в логе появляется вместе с включением света. Что я делаю не так и как с этим бороться?
Простые примеры:

defineRule({
whenChanged: “Sensor motion 3/occupancy”,
then: function (newValue, devName, cellName) {
if(newValue==“true”){
log ("{}: зафиксировано движение", devName);
dev[“mr6c-97/K4”] = true;
}
else{
dev[“mr6c-97/K4”] = false;
}
},
});

defineRule({
asSoonAs: function () {
return (dev[“wb-gpio/EXT2_IN9”]);
},
then: function () {
log (“зафиксировано нажатие кнопки”);
dev[“mr6c-97/K4”] = !dev[“mr6c-97/K4”];
}
});

Добрый день.
Какой релиз ПО установлен?
предлагаю для диагностики подписаться на топики:

mosquitto_sub -v -t "/devices/Sensor motion 3/occupancy" -t "/devices/mr6c-97/K4"

и проверить - какое время проходит между изменением

Добрый день! Почему-то не увидел ответ, думал, что остался без помощи и заменил контроллер с 6 версии на 7. Стало немного лучше, задержка около 1,5-2 сек, но все равно смысл теряется от применения.
На топики подписался, увидел, что датчик спамит брокер, не знаю, в этом ли дело. Но запись о включении канала проходит все равно с задержкой, относительно первой публикации обнаружения движения.
Как здесь время увидеть, не знаю.
mosquitto_sub -v -t “/devices/Sensor motion 2/controls/occupancy” -t “/devices/wb-mr6c_183/controls/K2”
/devices/Sensor motion 2/controls/occupancy false
/devices/wb-mr6c_183/controls/K2 0
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/wb-mr6c_183/controls/K2 1
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true

Запустите параллельно вывод лога, строчка
log ("{}: зафиксировано движение", devName);
выполняется один раз вместе с переключением реле?

да, выполняется одновременно один раз с включением реле, это я сразу проверял

Довольно интересно, попробую воспроизвести.

А почему “true” Именно в кавычках?
Покажите контрол, как он есть в MQTT?

Sensor motion 2 occupancy text /devices/Sensor motion 2/controls/occupancy false

Текстовый формат

Советую поменять так:

defineRule({
whenChanged: "Sensor motion/occupancy",
then: function (newValue, devName, cellName) {
 if(newValue=="true"){
   log ("{}: зафиксировано движение", devName);
   dev[devName][cellName] = "";
   dev["mr6c-97/K4"] = true;
 }
 else if(newValue=="false"){
   dev[devName][cellName] = "";
   dev["mr6c-97/K4"] = false;
 }
},
});

Не помогло. В одной строчке лога пустое сообщение публикуется, а после опять несколько строк с сообщением “true”. При том zigbee2mqtt публикует единожды, а на деле в виртуальное устройство записывается серия одинаковых сообщений. Это проблема с конвертером wb-zigbee2mqtt?

Zigbee2MQTT:info 2022-10-25 19:48:06: MQTT publish: topic ‘zigbee2mqtt/Sensor motion 2’, payload ‘{“battery”:100,“device_temperature”:32,“illuminance”:12,“illuminance_lux”:12,“linkquality”:114,“occupancy”:true,“voltage”:3015}’
zigbee2mqtt/Sensor motion 2 {“battery”:100,“device_temperature”:32,“illuminance”:12,“illuminance_lux”:12,“linkquality”:114,“occupancy”:true,“voltage”:3015}
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true
/devices/Sensor motion 2/controls/occupancy true

Опытным путем обнаружил, что если подписаться напрямую на топик z2m, то свет включается без задержек, не считая небольшого лага самого протокола zigbee.

trackMqtt(“zigbee2mqtt/Sensor motion 2/#”, function(message){
mes = JSON.parse(message.value);
if (mes[“occupancy”] == true){
dev[“wb-mr6c_196/K4”] = true;
}
else if(mes[“occupancy”] == false){
dev[“wb-mr6c_196/K4”] = false;
}
log ("{} # {}", message.topic, mes[“occupancy”]);
});

Но все правила переделывать на такой лад, это такое себе… Все равно не могу понять, почему конвертер wb-z2m многократно пишет в топик виртуального устройства, может из-за этого правила выполняются не сразу. При том я посмотрел, такое происходит со всеми топиками, вот например изменение температуры:

/devices/0x00124b00226a0a6d/controls/temperature 26.14
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 27.99
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.83
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33
/devices/0x00124b00226a0a6d/controls/temperature 26.33

Нашел ответ Wb-zigbee2mqtt дублирование после update devices
Видимо, при настройке zigbee устройств не единожды нажал на кнопку update devices, что привело к многократному подписанию на топики. Интересная реакция

А после перезапуска wb-rules по 1 публикации на каждое событие?

Да, после перезапуска wb-rules по одной публикации