// A scene: Alexa.SceneController. A scene is an endpoint that is not a device. It reports no state, and Activate // and Deactivate are answered with ActivationStarted and DeactivationStarted, which ctx.respond() sends. // // ALEX2MQTT_USERNAME=... ALEX2MQTT_PASSWORD=... ALEX2MQTT_ROOT_TOPIC=... node examples/scene.js // // "alex2node" is the installed package; inside this checkout it resolves to the built dist/. const { Alex2MQTT, SceneController } = require("alex2node"); const missing = ["ALEX2MQTT_USERNAME", "ALEX2MQTT_PASSWORD", "ALEX2MQTT_ROOT_TOPIC"].filter((name) => !process.env[name]); if (missing.length > 0) { console.error(`${missing.join(", ")} not set. Set the MQTT user name, the password and the root topic of your Alex2MQTT account.`); process.exit(1); } const { ALEX2MQTT_USERNAME, ALEX2MQTT_PASSWORD, ALEX2MQTT_ROOT_TOPIC } = process.env; const bridge = new Alex2MQTT(ALEX2MQTT_USERNAME, ALEX2MQTT_PASSWORD, ALEX2MQTT_ROOT_TOPIC); bridge.on("connect", () => console.log("connected, discover the devices in the Alexa app")); bridge.on("error", (err) => console.error("bridge:", err.message)); // What the scene sets. Replace it with your devices. const room = { lights: "bright", blind: "open" }; // Alexa wants the word "scene" in the description, and the category SCENE_TRIGGER or ACTIVITY_TRIGGER const device = bridge.addDevice({ endpointId: "movie-night", name: "Movie Night", categories: ["SCENE_TRIGGER"], description: "Movie night scene by Alex2Node", }); const scene = device.add(SceneController, { supportsDeactivation: true }); scene.on("Activate", (ctx) => { Object.assign(room, { lights: "dim", blind: "closed" }); console.log("movie night on", room); return ctx.respond(); }); scene.on("Deactivate", (ctx) => { Object.assign(room, { lights: "bright", blind: "open" }); console.log("movie night off", room); return ctx.respond(); }); bridge.connect();