Description
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!