Hi,
I love XMPP And I wanted to discuss with my habot through Chat. I reimplement quickly card in a rule , inspired by Rhasspy to HABot
rule "XMPP Cmd to HABot"
when
Channel "xmppclient:xmppBridge:xmpp:xmpp_command" triggered
then
var openhab_url_prefix = "http://..."
var actionName = receivedEvent.split("#")
var url = openhab_url_prefix + "/rest/habot/chat"
var contenttype = "text/plain"
var output = sendHttpPostRequest(url, contenttype, actionName.get(1))
val actions = getActions("xmppclient","xmppclient:xmppBridge:xmpp")
var String intent = transform("JSONPATH", "$.intent.name", output)
var answer = transform("JSONPATH", "$.answer", output)
actions.publishXMPP(actionName.get(0), answer)
if (output.contains("matchedItemNames")) {
if (intent.contains("get-status")) {
var i = 0
var String item_name = transform("JSONPATH", "$.matchedItemNames[" + i + "]", output)
while (!item_name.startsWith("{\"")) {
var item_url = openhab_url_prefix + "/rest/items/" + item_name
var item_output = sendHttpGetRequest(item_url)
var item_label = transform("JSONPATH", "$.label", item_output)
var item_value = transform("JSONPATH", "$.state", item_output)
actions.publishXMPP(actionName.get(0), item_name + " (" + item_label + ") = " + item_value)
i++
item_name = transform("JSONPATH", "$.matchedItemNames[" + i + "]", output)
}
}
if (intent.contains("activate-object")) {
var i = 0
var String item_name = transform("JSONPATH", "$.matchedItemNames[" + i + "]", output)
while (!item_name.startsWith("{\"")) {
var item_url = openhab_url_prefix + "/rest/items/" + item_name
var item_output = sendHttpGetRequest(item_url)
var item_label = transform("JSONPATH", "$.label", item_output)
actions.publishXMPP(actionName.get(0), item_label + " (" + item_name + ")")
i++
item_name = transform("JSONPATH", "$.matchedItemNames[" + i + "]", output)
}
}
if (intent.contains("get-history")) {
var chart_url = openhab_url_prefix + "/chart?period="
var period = transform("JSONPATH", "$.card.slots.media[0].config.period", output)
chart_url += period
chart_url += "&theme=bright&t=1635285901890&items="
var i = 0
var String item_name = transform("JSONPATH", "$.matchedItemNames[" + i + "]", output)
while (!item_name.startsWith("{\"")) {
chart_url += item_name + ","
i++
item_name = transform("JSONPATH", "$.matchedItemNames[" + i + "]", output)
}
executeCommandLine(Duration.ofSeconds(1), "/bin/rm", "/tmp/chart.jpg")
executeCommandLine(Duration.ofSeconds(5), "/usr/bin/curl", chart_url, "-o", "/tmp/chart.jpg")
actions.publishXMPPImageByHTTP(actionName.get(0),"/tmp/chart.jpg")
}
} else {
var hint = transform("JSONPATH", "$.hint", output)
actions.publishXMPP(actionName.get(0), hint)
}
end
If your jabber client support voice input, you can send voice commands
We can even share Chart images through publishXMPPImageByHTTPThis text will be hidden