Even easier - use the HTTP Binding and JINJA transformation - no rules required.
All the prerequisites/caveats of the previous post still hold true, but everything can be configured via the UI if you desire. Simply, a String Item is linked to a String Channel in the HTTP Thing, and that String Channel uses a JINJA transformation to put the message into JSON required by the Matrix server.
Things file
//Matrix server
Thing http:url:matrix "Matrix" [
baseURL = "https://YOURMATRIXDOMAIN/",
refresh = "300",
timeout ="3000",
ignoreSSLErrors = "true",
commandMethod = "POST"
]
{
Channels:
Type string: home "Home Room" [
mode = "WRITEONLY",
commandExtension = "_matrix/client/r0/rooms/YOURROOMID/send/m.room.message?access_token=YOURACCESSTOKEN",
commandTransformation = "JINJA:{\"msgtype\":\"m.text\", \"body\":\"{{value}}\"}"
]
}
OH3 UI YAML
UID: http:url:matrix
label: Matrix
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: "true"
baseURL: https://YOURMATRIXDOMAIN/
delay: 0
stateMethod: GET
refresh: "300"
commandMethod: POST
timeout: "3000"
bufferSize: 2048
channels:
- id: home
channelTypeUID: http:string
label: Home Room
description: null
configuration:
mode: WRITEONLY
commandExtension: _matrix/client/r0/rooms/YOURROOMID/send/m.room.message?access_token=YOURACCESSTOKEN
commandTransformation: JINJA:{"msgtype":"m.text", "body":"{{value}}"}
Items file
String strMatrixMessageHomeRoom "Matrix message home room" {channel="http:url:matrix:home"}