Files
Openhab-AI-Bridge/openhab/ai_bridge.rules.js
T

41 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// openHAB JS Scripting – Dialog an die Bridge senden
// JavaScript Scripting Add-on muss installiert/aktiviert sein.
//
// Token und URL anpassen!
const { rules, triggers, actions } = require('openhab');
const BRIDGE_URL = 'http://192.168.178.60:8090/api/v1/dialog';
const BRIDGE_TOKEN = 'REPLACE_WITH_BRIDGE_TOKEN';
rules.JSRule({
name: 'AI Bridge - Dialog senden',
description: 'Sendet Text aus AI_Bridge_DialogCommand an die Bridge und startet den Claude-Flow',
tags: ['AI', 'MCP'],
triggers: [triggers.ItemCommandTrigger('AI_Bridge_DialogCommand')],
execute: (event) => {
const text = String(event.receivedCommand || '').trim();
if (!text) return;
try {
actions.HTTP.sendHttpPostRequest(
BRIDGE_URL,
'application/json',
JSON.stringify({
text: text,
title: 'openHAB Dialog',
notify_text: 'KI_DIALOG'
}),
{
'Authorization': 'Bearer ' + BRIDGE_TOKEN,
'Content-Type': 'application/json'
},
8000
);
console.info('AI Bridge dialog sent: ' + text.substring(0, 80));
} catch (e) {
console.error('AI Bridge dialog failed: ' + e);
}
}
});