Skip to content

custom message with response #380

Open
@paulius-dev

Description

@paulius-dev

I am trying to integrate home-assistant-js-websocket with jquery.
I use: https://cdn.jsdelivr.net/npm/[email protected]/dist/haws.umd.js compiled script.

authorization is successful, I receive all entities, I also send commands successfully.

Question. How can I send a custom message to HA and print a response?

I tried:

var service_data = {
entity_ids: ["sensor.temperature"],
minimal_response:true,
no_attributes: true,
significant_changes_only:true,
start_time:"2023-05-09T23:28:21.482Z",
type:"history/stream",
};
wsconn.sendMessagePromise(service_data).then(response => {
// Handle the response from Home Assistant
console.log("Received response:", response);
})
.catch(error => {
// Handle any errors that occurred
console.error("An error occurred:", error);
});

in Developer tools->Network tab (websocket) messages I see my request (type:"history/stream"....) and I get a response with historical data from HA successfully.

but in console i get
Received response: null

.then works good with:
HAWS.getUser(wsconn).then(response => {
// Handle the response from Home Assistant
console.log("Received response:", response);
})
.catch(error => {
// Handle any errors that occurred
console.error("An error occurred:", error);
});

Thanks for advice!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions