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,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
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 { 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 speakerChannels = null;
|
||||
|
||||
@ -144,6 +156,26 @@ async function processor(group, consumer, streamKey) {
|
||||
case "remind":
|
||||
await playAudio("Reminder, " + String(msg.message.value));
|
||||
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:
|
||||
await playAudio("Command, " + String(msg.message.command) + " is undefined.")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user