본문 바로가기
스마트홈 IoT 월드/스마트홈 설정 문제해결 팁

zigbee mqtt topic 리포팅 주기 설정 방법

by 레드추파 2025. 8. 19.
728x90
반응형

리포팅 주기 설정 방법

 

 

IOT 센서의 리포팅 주기(MQTT publish topic)가 잦으면 다른 장치의 트래픽을 방해하거나 자동화가 불필요하게 많이 실행될 수 있습니다.

 

알리에서 구매한 이산화탄소 센서 (TS0601) 리포팅 주기 0.5초여서 리포팅 주기를 변경한 방법을 공유하고자 합니다.

 

 

 

 

외부 컨버터 사용

 

리포팅 주기를 변경할 수 있는 장치도 있지만 펌웨어에서 하드코딩된 부분이라 설정을 직접 변경할 수 없는 장치도 있습니다.

이런 경우에는 외부 컨버터를 사용합니다.

 

external_converters 폴더를 생성하여 TS0601_CO2.js 파일을 업로드 합니다.

(/homeassistant/zigbee2mqtt/external_converters/TS0601_CO2.js)

 


 

TS0601_CO2.js

const exposes = require('zigbee-herdsman-converters/lib/exposes');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const legacy = require('zigbee-herdsman-converters/lib/legacy');
const e = exposes.presets;

const STARTUP_DELAY = 1.0;  // Delay before first report in seconds
const PUBLISH_DELAY = 30.0; // Delay between each data publish in seconds

const legacy_tuya_with_delay = {
    cluster: 'manuSpecificTuya',
    type: ['commandDataReport', 'commandDataResponse'],
    convert: (model, msg, publish, options, meta) => {
        const now = Date.now();  
        
        if (!meta.device.private_cache) {
            meta.device.private_cache = {};
            meta.device.private_next_update = now + STARTUP_DELAY * 1000;
        }

        const changes = legacy.fromZigbee.tuya_air_quality.convert(model, msg, publish, options, meta);
        Object.assign(meta.device.private_cache, changes);

        if (now >= meta.device.private_next_update) {
            const result = { ...meta.device.private_cache };
            meta.device.private_next_update = now + PUBLISH_DELAY * 1000;  // Schedule next publish
            meta.device.private_cache = {};  // Clear cache after publishing
            return result;
        } else {
            return {};  // Do not publish if delay has not passed
        }
    }
};

const definition = {
    fingerprint: tuya.fingerprint('TS0601', ['_TZE204_ogkdpgy2']),
    model: 'TS0601_co2_sensor',
    vendor: 'Tuya',
    description: 'NDIR CO2 sensor with delayed reporting',
    fromZigbee: [legacy_tuya_with_delay],
    toZigbee: [],
    exposes: [e.co2()],
};

module.exports = definition;

 

TS0601_CO2.js
0.00MB

 

 

지그비 제조사에 적힌 내용을 위의 코드에 변경하면 됩니다.

 

리포팅 주기는 입맛대로 설정하시면 됩니다.

 

zigbee2mqtt 에드온을 재시작하면 리포팅 주기가 30초로 변경되어 과도하게 보고하는 것을 막을 수 있습니다. 

 



 

출처: https://community.home-assistant.io/t/carbon-monoxide-detector-is-very-chatty-tuya-ts0601/729267/5

 

Carbon Monoxide detector is very "chatty" - Tuya TS0601

I have 2 CO2 sensors doing the same. I’ve adapted a code that can be loaded in “external_convertors” in Zigbee2MQTT that fixes reporting issue in Z2M. Feel free to check it out. There are instructions and how to adapt the reporting interval based on

community.home-assistant.io

 

728x90
반응형