mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-24 11:39:53 +00:00
Add cache_state option to configuration.yaml. #70
This commit is contained in:
+22
-7
@@ -13,6 +13,19 @@ const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/\\w+
|
||||
const pollInterval = 60 * 1000; // seconds * 1000.
|
||||
const softResetTimeout = 3600 * 1000; // seconds * 1000.
|
||||
|
||||
/**
|
||||
* Home Assistant requires ALL attributes to be present in ALL MQTT messages send by the device.
|
||||
* https://community.home-assistant.io/t/missing-value-with-mqtt-only-last-data-set-is-shown/47070/9
|
||||
*
|
||||
* Therefore zigbee2mqtt BY DEFAULT caches all values and resend it with every message.
|
||||
* advanced.cache_state in configuration.yaml allows to configure this.
|
||||
* https://github.com/Koenkk/zigbee2mqtt/wiki/Configuration
|
||||
*/
|
||||
const cacheState = settings.get().advanced && settings.get().advanced.cache_state === false ? false : true;
|
||||
if (settings.get().homeassistant && !cacheState) {
|
||||
logger.warn('In order for Home Assistant integration to work properly set `cache_state: true');
|
||||
}
|
||||
|
||||
class Controller {
|
||||
constructor() {
|
||||
this.zigbee = new Zigbee();
|
||||
@@ -320,14 +333,16 @@ class Controller {
|
||||
}
|
||||
|
||||
mqttPublishDeviceState(deviceID, payload, cache) {
|
||||
// Add cached state to payload
|
||||
if (this.stateCache[deviceID]) {
|
||||
payload = {...this.stateCache[deviceID], ...payload};
|
||||
}
|
||||
if (cacheState) {
|
||||
// Add cached state to payload
|
||||
if (this.stateCache[deviceID]) {
|
||||
payload = {...this.stateCache[deviceID], ...payload};
|
||||
}
|
||||
|
||||
// Update state cache with new state.
|
||||
if (cache) {
|
||||
this.stateCache[deviceID] = payload;
|
||||
// Update state cache with new state.
|
||||
if (cache) {
|
||||
this.stateCache[deviceID] = payload;
|
||||
}
|
||||
}
|
||||
|
||||
const deviceSettings = settings.getDevice(deviceID);
|
||||
|
||||
Reference in New Issue
Block a user