UNPKG

matterbridge-tado-hw

Version:

A Matterbridge plugin that connects Tado° V2/V3/V3+ hot water control to the Matter smart home ecosystem

82 lines 3.36 kB
// Matterbridge plugin for Tado hot water control // Copyright © 2025 Alexander Thoukydides import { bridgedNode, MatterbridgeEndpoint, onOffSwitch, powerSource } from 'matterbridge'; import { OnOff } from 'matterbridge/matter/clusters'; import { PLUGIN_VERSION, VENDOR_ID, VENDOR_NAME } from './settings.js'; import { logError, MS } from './utils.js'; // A Matterbridge hot water control endpoint export class TadoHWDevice { config; tadoHWZone; log; switch; pollInterval; // Construct a new endpoint constructor(config, tadoHWZone) { this.config = config; this.tadoHWZone = tadoHWZone; // Create a switch device, using the serial number as its identifier // HERE - Consider replacing this by waterHeater const id = `Tado-${tadoHWZone.serialNumber}`; this.switch = new MatterbridgeEndpoint([onOffSwitch, bridgedNode, powerSource], { id }, this.config.debug); // Use the endpoint's logger this.tadoHWZone.log = this.log = this.switch.log; // Create the clusters for the switch device this.switch .createDefaultIdentifyClusterServer() .createDefaultGroupsClusterServer() .createDefaultBridgedDeviceBasicInformationClusterServer(tadoHWZone.deviceName, tadoHWZone.serialNumber, VENDOR_ID, VENDOR_NAME, tadoHWZone.productName, parseInt(this.tadoHWZone.softwareVersion, 10), tadoHWZone.softwareVersion, parseInt(PLUGIN_VERSION, 10), PLUGIN_VERSION) .createDefaultPowerSourceWiredClusterServer() .createDefaultOnOffClusterServer(); // Add command handlers for the switch device this.switch.addCommandHandler('identify', () => void this.identify()); this.switch.addCommandHandler('on', () => void this.setPower(true)); this.switch.addCommandHandler('off', () => void this.setPower(false)); } // Get the endpoint (so that the device can be registered) get endpoint() { return this.switch; } // Start polling the device and set the initial state start() { void this.pollPower(); this.pollInterval = setInterval(() => void this.pollPower(), this.config.pollInterval * MS); } // Stop polling the device stop() { clearInterval(this.pollInterval); this.pollInterval = undefined; } // Identify the hot water zone async identify() { try { this.log.info('Identifying'); await this.tadoHWZone.identify(); } catch (err) { logError(this.log, 'Identify', err); } } // Set the state of the hot water zone when changed from Matter async setPower(on) { try { this.log.info(`Setting power ${on ? 'ON' : 'OFF'}`); await this.tadoHWZone.setPower(on); await this.switch.updateAttribute(OnOff, 'onOff', on, this.log); } catch (err) { logError(this.log, 'Set power', err); } } // Poll the hot water zone for its current state async pollPower() { try { const on = await this.tadoHWZone.getPower(); await this.switch.updateAttribute(OnOff, 'onOff', on, this.log); } catch (err) { logError(this.log, 'Poll power', err); } } } //# sourceMappingURL=device-hw.js.map