Add home assistant
This commit is contained in:
parent
8a65d22c12
commit
4a2c6aa761
@ -2,5 +2,7 @@ module.exports = {
|
|||||||
FORCE_DB_SYNC: process.env.FORCE_DB_SYNC,
|
FORCE_DB_SYNC: process.env.FORCE_DB_SYNC,
|
||||||
NODE_ENV: process.env.NODE_ENV,
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
PORT: process.env.PORT,
|
PORT: process.env.PORT,
|
||||||
DEVICE_ID: process.env.DEVICE_ID
|
DEVICE_ID: process.env.DEVICE_ID,
|
||||||
|
HA_URL: process.env.HA_URL,
|
||||||
|
HA_TOKEN: process.env.HA_TOKEN
|
||||||
};
|
};
|
||||||
|
|||||||
@ -26,6 +26,18 @@ const config = require("./config");
|
|||||||
const transConfig = require("./config/transcribe.config");
|
const transConfig = require("./config/transcribe.config");
|
||||||
const { handlePythonOutput } = require("./scripts/py/pythonOutput");
|
const { handlePythonOutput } = require("./scripts/py/pythonOutput");
|
||||||
|
|
||||||
|
// === HomeAssistant ===
|
||||||
|
const ha = {}
|
||||||
|
|
||||||
|
ha.client = axios.create({
|
||||||
|
baseURL: config.HA_URL,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${config.HA_TOKEN}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// === Speaker ===
|
||||||
let speaker = null;
|
let speaker = null;
|
||||||
let speakerChannels = null;
|
let speakerChannels = null;
|
||||||
|
|
||||||
@ -145,6 +157,26 @@ async function processor(group, consumer, streamKey) {
|
|||||||
await playAudio("Reminder, " + String(msg.message.value));
|
await playAudio("Reminder, " + String(msg.message.value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "light_on":
|
||||||
|
await playAudio("Turning on light.");
|
||||||
|
await ha.client.post("/api/services/homeassistant/turn_on", {
|
||||||
|
entity_id: "light.living_room_living_room"
|
||||||
|
}).catch(async (err) => {
|
||||||
|
await playAudio("I have failed you father.");
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "light_off":
|
||||||
|
await playAudio("Turning off light.");
|
||||||
|
await ha.client.post("/api/services/homeassistant/turn_off", {
|
||||||
|
entity_id: "light.living_room_living_room"
|
||||||
|
}).catch(async (err) => {
|
||||||
|
await playAudio("I have failed you father.");
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
await playAudio("Command, " + String(msg.message.command) + " is undefined.")
|
await playAudio("Command, " + String(msg.message.command) + " is undefined.")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user