Get data from external server using websoket

My security system connected web to server and I can communicate to it by websokets. I can manually open websoket connection and send command from webpage. Could you please advise if can integrate it into Home Assistant? I probably should use rest_command, but I can’t get how I should perform several request to server (open connection, actual command, close connection). May be some one can share example with me? I was looking all over forum and HA documentation, but without success.

The restful command integration takes care of opening and closing the connection for you. Nice eh?

Do you have an example command?

Also you have cake. Happy two year anniversary of using the forum.

1 Like

To open connection I have to send url like:
ws://192.192.192.192:1122/?user=UserID&pass=password
and parameter d3

in Javascript it’s look like:

var socket = new WebSocket(“ws://185.27.192.163:1122/?user=UserID&pass=password”,“d3”);

Ones connection was established I can send command in josn format, like:

{“ID”:14,“Q”:“EVENTS”,“D”:{“affect”:1}}

The result will be josn which I can process to state of binary sensor (infrared detector) .

Or ( and it is actually better) to keep WebSocket always open and wait until server send josn with sensors state (if it change).
I have infrared detectors each room plus doors sensors and some fire sensors capable get current temperature. Hope fully I can use them for automatisation.

Maybe this?

rest_command:
  my_request:
    url: 'ws://185.27.192.163:1122'
    username: 'UserID'
    password: 'password'
    payload: '{"ID":14,"Q":"EVENTS","D":{"affect":1}}'

Look like is should something like:

rest_command:
 my_request:
   url: 'ws://185.27.192.163:1122/?user=UserID&pass=password'
   headers:
     WebSocket-Protocol: 'd3'
   payload: '{"ID":14,"Q":"EVENTS","D":{"affect":1}}'

Al least, when I call this command ws connection of another client get broken same time. But with rest_command I can’t see any response from server, so it is useless. I tried to use rest sensor, but it’s not accepting ws as resource, only http.