Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom message with response #380

Open
paulius-dev opened this issue May 11, 2023 · 0 comments
Open

custom message with response #380

paulius-dev opened this issue May 11, 2023 · 0 comments

Comments

@paulius-dev
Copy link

paulius-dev commented May 11, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant