diff --git a/node-red/flows/smoke_detector.json b/node-red/flows/smoke_detector.json index 62d4c25..e780024 100644 --- a/node-red/flows/smoke_detector.json +++ b/node-red/flows/smoke_detector.json @@ -253,7 +253,7 @@ "type": "function", "z": "smoke_flow_tab", "name": "📢 Gruppen-Sirene EIN", - "func": "const group = msg.group;\nconst detector = msg.detector;\n\nconst siren = detector.siren;\n\nif (!siren) {\n node.status({fill:'yellow', shape:'dot', text:'Keine Sirene für ' + detector.sensor});\n return [null, msg];\n}\n\nconst alarmMsg = {\n payload: {\n data: {\n entity_id: siren\n }\n }\n};\n\nnode.status({fill:'red', shape:'dot', text:'Sirene: ' + siren});\n\nreturn [[alarmMsg], msg];", + "func": "// =====================================================\n// ALLE SIRENEN DER GRUPPE EINSCHALTEN\n// =====================================================\n\nconst group = msg.group;\n\n// Sammle ALLE Sirenen der Gruppe (nicht nur die des auslösenden Detectors)\nconst sirens = (group.detectors || [])\n .filter(d => d.siren)\n .map(d => d.siren);\n\nif (sirens.length === 0) {\n node.status({fill:'yellow', shape:'dot', text:'Keine Sirenen in Gruppe ' + group.name});\n return [null, msg];\n}\n\n// Duplikate entfernen (falls mehrere Detectors die gleiche Sirene haben)\nconst uniqueSirens = [...new Set(sirens)];\n\nconst alarmMsgs = uniqueSirens.map(siren => ({\n payload: {\n data: {\n entity_id: siren\n }\n }\n}));\n\nnode.status({fill:'red', shape:'dot', text: group.name + ': ' + uniqueSirens.length + ' Sirene(n) EIN'});\nnode.log('Gruppe ' + group.name + ': Schalte ' + uniqueSirens.length + ' Sirene(n) ein: ' + uniqueSirens.join(', '));\n\nreturn [alarmMsgs, msg];", "outputs": 2, "timeout": "", "noerr": 0, @@ -263,7 +263,7 @@ "x": 940, "y": 320, "wires": [["ha_switch_on"], ["func_notify_group_devices"]], - "outputLabels": ["Sirene", "Weiter"] + "outputLabels": ["Sirenen", "Weiter"] }, { "id": "ha_switch_on", @@ -664,8 +664,8 @@ "type": "function", "z": "smoke_flow_tab", "name": "⏹️ Gruppen-TTS stoppen", - "func": "const groupId = msg.stop_group_id;\nconst deviceId = msg.stop_device_id;\nconst config = global.get('smoke_config');\n\nif (!config || !config.groups) {\n node.warn('Keine Config vorhanden!');\n return null;\n}\n\nconst group = config.groups.find(g => g.id === groupId);\nif (!group) {\n node.warn('Gruppe nicht gefunden: ' + groupId);\n node.warn('Verfügbare Gruppen: ' + config.groups.map(g => g.id + ':' + g.name).join(', '));\n return null;\n}\n\nconst device = group.devices.find(d => d.device_id === deviceId);\nif (!device) {\n node.warn('Gerät nicht in Gruppe gefunden: ' + deviceId);\n node.warn('Verfügbare Geräte: ' + group.devices.map(d => d.device_id).join(', '));\n return null;\n}\n\n// TTS-Key mit Group ID\nconst ttsKey = `tts_active_${groupId}_${deviceId}`;\nflow.set(ttsKey, false);\n\nnode.status({fill:'green', shape:'dot', text: group.name + ': TTS gestoppt ' + device.device_name});\nnode.log('TTS gestoppt für ' + device.device_name + ' in Gruppe ' + group.name + ' (Key: ' + ttsKey + ')');\n\nmsg.device = device;\nmsg.group = group;\n\nreturn msg;", - "outputs": 1, + "func": "const groupId = msg.stop_group_id;\nconst deviceId = msg.stop_device_id;\nconst config = global.get('smoke_config');\n\nif (!config || !config.groups) {\n node.warn('Keine Config vorhanden!');\n return null;\n}\n\nconst group = config.groups.find(g => g.id === groupId);\nif (!group) {\n node.warn('Gruppe nicht gefunden: ' + groupId);\n node.warn('Verfügbare Gruppen: ' + config.groups.map(g => g.id + ':' + g.name).join(', '));\n return null;\n}\n\nconst device = group.devices.find(d => d.device_id === deviceId);\nif (!device) {\n node.warn('Gerät nicht in Gruppe gefunden: ' + deviceId);\n node.warn('Verfügbare Geräte: ' + group.devices.map(d => d.device_id).join(', '));\n return null;\n}\n\n// TTS-Key mit Group ID\nconst ttsKey = `tts_active_${groupId}_${deviceId}`;\nflow.set(ttsKey, false);\n\nnode.status({fill:'green', shape:'dot', text: group.name + ': TTS gestoppt ' + device.device_name});\nnode.log('TTS gestoppt für ' + device.device_name + ' in Gruppe ' + group.name + ' (Key: ' + ttsKey + ')');\n\nmsg.device = device;\nmsg.group = group;\n\n// Reset-Message für Delay-Node senden (löscht wartende Messages)\nconst resetMsg = { reset: true };\n\nreturn [msg, resetMsg];", + "outputs": 2, "timeout": "", "noerr": 0, "initialize": "", @@ -673,7 +673,7 @@ "libs": [], "x": 750, "y": 920, - "wires": [["func_clear_group_notifications"]] + "wires": [["func_clear_group_notifications"], ["delay_tts"]] }, { "id": "func_clear_group_notifications", @@ -812,8 +812,8 @@ "type": "function", "z": "smoke_flow_tab", "name": "⏹️ Alle TTS in Gruppe stoppen", - "func": "// =====================================================\n// STOPPE ALLE TTS-LOOPS IN EINER BESTIMMTEN GRUPPE\n// =====================================================\n\nconst eventData = msg.payload;\nconst groupId = eventData.group_id || (eventData.event && eventData.event.group_id);\nconst groupName = eventData.group_name || (eventData.event && eventData.event.group_name) || 'Unbekannt';\n\nif (!groupId) {\n node.warn('Keine group_id im Event!');\n return null;\n}\n\nconst config = global.get('smoke_config');\n\nif (!config || !config.groups) {\n node.warn('Keine Config vorhanden!');\n return null;\n}\n\nconst group = config.groups.find(g => g.id === groupId);\nif (!group) {\n node.warn('Gruppe nicht gefunden: ' + groupId);\n return null;\n}\n\nlet stoppedCount = 0;\nfor (let device of group.devices) {\n const ttsKey = `tts_active_${groupId}_${device.device_id}`;\n if (flow.get(ttsKey)) {\n flow.set(ttsKey, false);\n stoppedCount++;\n }\n}\n\nnode.status({fill:'green', shape:'dot', text: `✅ ${group.name}: ${stoppedCount} TTS gestoppt`});\nnode.log('Gruppe ' + group.name + ': ' + stoppedCount + ' TTS-Loops gestoppt');\n\nreturn msg;", - "outputs": 1, + "func": "// =====================================================\n// STOPPE ALLE TTS-LOOPS IN EINER BESTIMMTEN GRUPPE\n// =====================================================\n\nconst eventData = msg.payload;\nconst groupId = eventData.group_id || (eventData.event && eventData.event.group_id);\nconst groupName = eventData.group_name || (eventData.event && eventData.event.group_name) || 'Unbekannt';\n\nif (!groupId) {\n node.warn('Keine group_id im Event!');\n return null;\n}\n\nconst config = global.get('smoke_config');\n\nif (!config || !config.groups) {\n node.warn('Keine Config vorhanden!');\n return null;\n}\n\nconst group = config.groups.find(g => g.id === groupId);\nif (!group) {\n node.warn('Gruppe nicht gefunden: ' + groupId);\n return null;\n}\n\nlet stoppedCount = 0;\nfor (let device of group.devices) {\n const ttsKey = `tts_active_${groupId}_${device.device_id}`;\n if (flow.get(ttsKey)) {\n flow.set(ttsKey, false);\n stoppedCount++;\n }\n}\n\nnode.status({fill:'green', shape:'dot', text: `✅ ${group.name}: ${stoppedCount} TTS gestoppt`});\nnode.log('Gruppe ' + group.name + ': ' + stoppedCount + ' TTS-Loops gestoppt');\n\n// Reset-Message für Delay-Node senden (löscht wartende Messages)\nconst resetMsg = { reset: true };\n\nreturn [null, resetMsg];", + "outputs": 2, "timeout": "", "noerr": 0, "initialize": "", @@ -821,7 +821,7 @@ "libs": [], "x": 490, "y": 1220, - "wires": [[]] + "wires": [[], ["delay_tts"]] }, { "id": "event_stop_all", @@ -846,8 +846,8 @@ "type": "function", "z": "smoke_flow_tab", "name": "⏹️ ALLE TTS stoppen (alle Gruppen)", - "func": "// =====================================================\n// STOPPE ALLE TTS-LOOPS IN ALLEN GRUPPEN\n// =====================================================\n\nconst config = global.get('smoke_config');\n\nif (!config || !config.groups) {\n node.warn('Keine Config vorhanden!');\n return null;\n}\n\nlet stoppedCount = 0;\nfor (let group of config.groups) {\n for (let device of group.devices) {\n const ttsKey = `tts_active_${group.id}_${device.device_id}`;\n if (flow.get(ttsKey)) {\n flow.set(ttsKey, false);\n stoppedCount++;\n }\n }\n}\n\nnode.status({fill:'green', shape:'dot', text: `✅ ${stoppedCount} TTS gestoppt (alle Gruppen)`});\nnode.log('NOTFALL: ' + stoppedCount + ' TTS-Loops in allen Gruppen gestoppt');\n\nreturn msg;", - "outputs": 1, + "func": "// =====================================================\n// STOPPE ALLE TTS-LOOPS IN ALLEN GRUPPEN\n// =====================================================\n\nconst config = global.get('smoke_config');\n\nif (!config || !config.groups) {\n node.warn('Keine Config vorhanden!');\n return null;\n}\n\nlet stoppedCount = 0;\nfor (let group of config.groups) {\n for (let device of group.devices) {\n const ttsKey = `tts_active_${group.id}_${device.device_id}`;\n if (flow.get(ttsKey)) {\n flow.set(ttsKey, false);\n stoppedCount++;\n }\n }\n}\n\nnode.status({fill:'green', shape:'dot', text: `✅ ${stoppedCount} TTS gestoppt (alle Gruppen)`});\nnode.log('NOTFALL: ' + stoppedCount + ' TTS-Loops in allen Gruppen gestoppt');\n\n// Reset-Message für Delay-Node senden (löscht wartende Messages)\nconst resetMsg = { reset: true };\n\nreturn [null, resetMsg];", + "outputs": 2, "timeout": "", "noerr": 0, "initialize": "", @@ -855,6 +855,6 @@ "libs": [], "x": 520, "y": 1280, - "wires": [[]] + "wires": [[], ["delay_tts"]] } ]