From my reading of the Matrix integration docs, this should cause a “matrix_command” event to be fired in Home Assistant when I send a message like “!ha testing” to the #homeassistant room on my Matrix server, but I’ve monitored for that event in the Developer Tools page event monitoring and no “matrix_command” events are firing when I send messages to that room.
I’m able to use the notify service to send messages to the configured Matrix server/room successfully, just not able to receive commands via the “matrix_command” event.
Nope, still not sure what’s going on. It seems to work for just a short time after I restart Home Assistant, and then stops working. Looking at the Home Assistant user I’ve added on my Matrix server, it shows as “offline”. So it seems like HA just stops listening after a bit or doesn’t reconnect or something.
I don’t see that red exclamation mark on the messages from my HA user, though maybe it’s because I haven’t done the verification on my own session either. Couldn’t get it to work right for my own account.
I think the issue in both cases is that the matrix bot running in HA doesn’t support e2e encryption. make a channel that’s unencrypted and see if that helps.
Ah, I see and apologies: I missed your message about it working briefly. If it were an encrypted channel, it would never work.
I’ll see if I can reproduce it. I’d like to be able to rely on this instead of using slack or telegram and I currently have a terrible network connection so I suspect that I’ll be able to At least if it has anything to do with disconnection issues.
So, I did a little testing and am able to get the sample chat client from that library to fail with enough bad network connectivity. I suspect this is what’s happening. Unfortunately, I don’t really know enough about HA to do anything about it right now but I’ve been enjoying the ecosystem and plan to get more familiar with it so I can make some stuff. Once I’m to that point, I’ll circle back here and see if I can lend a hand.
If my suspicions about network connectivity are correct, you could probably fix your issues by setting up a matrix server locally and federating it. Then connect HA to your local server and let your local server deal with the intricacies of disconnection and resync.
Hopefully someone who has a more informed clue will stumble upon this though and get you some answers sooner.
I am also able to communicate with HA using the websocket API in the same stand-alone program (though I haven’t yet connected these two ends, but this shouldn’t be too complicated).
Both APIs are based on asyncio.
So I’m sure that I can implement what the HA core matrix component(?) does with a stand-alone program.
But what we actually need is a rewrite of the HA core matrix component itself (I mean integrated into HA).
However, I’m stuck at this point for several reasons and really need help from an experienced HA developer.
While I’m an experienced Python developer I have never before worked with async/await.
I have absolutely no experience with HA development - indeed I’m still struggling with the basics (nomenclature etc).
The async matrix client needs a native library (libolm) for encryption/decryption.
My HA works on a 4 GB Raspi 4 (based on the hassos_rpi-4.14.img.gz). I don’t know how I could develop there.
I have the same problem. I have an not encrypted room. After start of HA the matrix user shows “online” and receives commands as expected. After a nightly or another reconnect of my connection the matrix user showing offline and don’t accept any command. But the matrix user is able to send notifications. But after sending the messages to the room the user is still offline and don’t receive anything until restarting my HA.
##################################
notify:
- name: matrix_notify
platform: matrix
default_room: "!ngOVAHjEysFUqyMfake:matrix.w00t.nl"
##################################
matrix:
homeserver: https://matrix.w00t.nl
username: "@HASS:matrix.w00t.nl"
password: ***
rooms:
- "!ngOVAHjEysFUqyMfake:matrix.w00t.nl"
commands:
- word: help
name: help
rooms:
- "!ngOVAHjEysFUqyMfake:matrix.w00t.nl"
- word: pauze
name: pauze
rooms:
- "!ngOVAHjEysFUqyMfake:matrix.w00t.nl"
- word: song
name: song
rooms:
- "!ngOVAHjEysFUqyMfake:matrix.w00t.nl"
- word: "home"
name: home
- expression: "(?P<name>.*) stinkt"
name: stink
- expression: "My name is (?P<name>.*)"
name: introduction
- expression: "(?P<name>.*) is lief"
name: lief
the automations:
alias: React to !song
description: ''
trigger:
- platform: event
event_type: matrix_command
event_data:
command: song
condition: []
action:
- service: notify.matrix_notify
data:
message: >
Het nummer wat op staat is: {{
state_attr('media_player.mpd','media_content_id') }}
mode: single
alias: React to an stinkie
description: ''
trigger:
- platform: event
event_type: matrix_command
event_data:
command: stink
condition: []
action:
- service: notify.matrix_notify
data:
message: Tijd om jezelf ff te wassen {{trigger.event.data.args['name']}}
mode: single
i’ve set this up a long time ago… maybe i forgot something to post but it still works
I gave up receiving commands and sending replies last year.
Now, learning that in HA 2023.10, the old matrix integration was replaced by one based on matrix-nio (see https://github.com/home-assistant/core/pull/72797), I picked it up again.
For me the results changed: Sending and receiving works, also for long time.
But, it only works when the command is issued in the first default room:
Ah, wait. My seconds room has encryption activated. Thus the client won’t accept commands from there though it can post there.
I now created another unencrypted test room and yes, it takes commands from there.
For me it’s not possible to send encrypted messages from home assistant to other users on my matrix server. But as you said, the problem could be caused by the unverified session.
But it doesn’t offer the possibility to verify the session I think. I will take a look at it again tomorrow and try to figure out if I could expand this integration or how to verify the session.
I could fork that repo and try to integrate this feature, perhaps I can switch it