This commit is contained in:
sebseb7
2025-12-25 05:30:06 +01:00
parent 8f01f35470
commit ab89cbc97f
4 changed files with 195 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ const OUTPUT_BINDINGS = {
'BigDehumid': { device: 'tapo', channel: 'r0', type: 'switch' },
'CO2Valve': { device: 'tapo', channel: 'c', type: 'switch' },
'TentExhaust': { device: 'tapo', channel: 'fantent', type: 'switch' },
'CircFanLevel': { device: 'ac', channel: 'tent:fan', type: 'level' },
};
// =============================================
@@ -739,7 +740,6 @@ module.exports = {
function writeOutputValue(channel, value) {
const now = new Date().toISOString();
// Get last value for this channel
const lastStmt = db.prepare(`
SELECT id, value FROM output_events
WHERE channel = ?
@@ -747,6 +747,10 @@ module.exports = {
`);
const last = lastStmt.get(channel);
if (channel === 'CircFanLevel') {
console.log('[RuleRunner] Debug Bindings:', JSON.stringify(OUTPUT_BINDINGS['CircFanLevel']));
}
const valueChanged = !last || Math.abs(last.value - value) >= Number.EPSILON;
if (!valueChanged) {
@@ -765,10 +769,17 @@ module.exports = {
// Send command to bound physical device
const binding = OUTPUT_BINDINGS[channel];
if (binding) {
let commandValue = value;
if (binding.type === 'switch') {
commandValue = value > 0 ? 1 : 0;
}
console.log(`[RuleRunner] Binding for ${channel}: type=${binding.type}, val=${value}, cmdVal=${commandValue}`);
sendCommandToDevicePrefix(`${binding.device}:`, {
device: binding.channel,
action: 'set_state',
value: value > 0 ? 1 : 0
value: commandValue
});
}
}