@ekristoffe/node-red-contrib-nature-remo
Version:
Node-RED Nature Remo Controller
108 lines (89 loc) • 3.05 kB
JavaScript
// Launch this file to use the node outside of Node-RED
const NatureRemo = require("nature-remo");
// Pass null for usage outside of node red
/*
snmpTrapListener(null, {
port: 162,
snmpV1: true,
});
*/
const token = process.argv[2];
// Instantiate Nature Remo client with an API token
const client = new NatureRemo.Cloud(token);
async function listAppliances() {
// Get a list of the appliances
const appliances = await client.getAppliances();
console.log("appliances", appliances);
appliances.forEach((appliance) => {
const { id, nickname, type } = appliance;
console.log({
id,
nickname,
type,
});
});
}
// Print the value of the sensor of an Nature Remo
async function printSensorValue() {
// Get a list of Nature Remo devices
const allDevices = await client.getDevices();
console.log("allDevices", allDevices);
// Print a value of each sensors
allDevices.forEach((device) => {
console.log({
name: device.name,
version: device.firmware_version,
temperature: device.newest_events.te.val,
humidity: device.newest_events.hu.val,
illumination: device.newest_events.il.val,
offsets: {
temperature: device.temperature_offset,
humidity: device.humidity_offset,
},
});
});
}
// Turn on/off air conditioner.
async function toggleAirconSwitch() {
// Get a list of available air conditioners
const airconList = await client.listAircon();
console.log("airconList", airconList);
// Use an air conditioner in the first of the list
const aircon = airconList[0];
console.log(aircon);
// Check if air conditioner is powered on
const isPoweredOn = aircon.settings.button === "power-off" ? false : true;
console.log(isPoweredOn);
// Toggle air conditioner's switch
if (isPoweredOn) {
// Turn off aircon
await client.updateAirconSettings(aircon.id, { button: "power-off" });
} else {
// Turn on aircon with specific operation mode
await client.updateAirconSettings(aircon.id, {
operation_mode: aircon.settings.mode,
});
}
}
listAppliances().catch((err) => console.log(err));
printSensorValue().catch((err) => console.log(err));
toggleAirconSwitch().catch((err) => console.log(err));
async function turnOffAirConditioner() {
const airconList = await client.listAircon();
console.log("airconList", airconList);
const aircon = airconList[0];
await client.updateAirconSettings(aircon.id, {
button: "power-off",
});
console.log("Aircon: turned off");
}
async function turnOnAirConditioner() {
const airconList = await client.listAircon();
console.log("airconList", airconList);
const aircon = airconList[0];
await client.updateAirconSettings(aircon.id, {
operation_mode: "cool",
temperature: 24,
});
console.log("Aircon: turned on");
}