forked from vxmppb/vxmppb
Adding Tuya for lights (Uses Tuya API)
Removed app_port from config, as it's depreciated.
This commit is contained in:
parent
2056c5a7f2
commit
5ec19de979
|
@ -1,7 +1,6 @@
|
|||
api_pass =
|
||||
api_url =
|
||||
api_user =
|
||||
app_port =
|
||||
asterisk_callfrom =
|
||||
asterisk_callto =
|
||||
asterisk_callerID =
|
||||
|
@ -29,6 +28,9 @@ mqtt_server =
|
|||
mqtt_topic =
|
||||
mqtt_user =
|
||||
rss_url =
|
||||
tuya_name =
|
||||
tuya_status_url =
|
||||
tuya_toggle_url =
|
||||
user_jid =
|
||||
user_name =
|
||||
vfc_url =
|
||||
|
|
95
index.js
95
index.js
|
@ -44,6 +44,9 @@ const mqtt_topic = config.mqtt_topic;
|
|||
const mqtt_user = config.mqtt_user;
|
||||
const rpc_url = config.rpc_url;
|
||||
const rss_url = config.rss_url;
|
||||
const tuya_name = config.tuya_name;
|
||||
const tuya_status_url = config.tuya_status_url;
|
||||
const tuya_toggle_url = config.tuya_toggle_url;
|
||||
const user_jid = config.user_jid;
|
||||
const user_name = config.user_name;
|
||||
const vfc_url = config.vfc_url;
|
||||
|
@ -121,6 +124,95 @@ xmpp.on('chat', function(from, message) {
|
|||
});
|
||||
console.log('unlocks');
|
||||
}
|
||||
// Tuya light control
|
||||
else if (message === 'lights' || message === 'Lights') {
|
||||
request(tuya_status_url,(error, res, body) => {
|
||||
if (error) {
|
||||
return console.log(error)
|
||||
};
|
||||
|
||||
if (!error && res.statusCode == 200) {
|
||||
if (res.body === "true"){
|
||||
const stat = tuya_name + ": On";
|
||||
xmpp.send(from, stat);
|
||||
console.log(stat);
|
||||
} else if (res.body === "false") {
|
||||
const stat = tuya_name + ": Off";
|
||||
xmpp.send(from, stat);
|
||||
console.log(stat);
|
||||
} else {
|
||||
xmpp.send(from, "Unknown reply. Please reply ping to reach an admin.");
|
||||
console.log("Tuya API: Unknown reply!");
|
||||
}
|
||||
}
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
console.log('lights status');
|
||||
}
|
||||
|
||||
else if (message === tuya_name + ' on') {
|
||||
request(tuya_toggle_url + "?stat=true&devname=" + tuya_name,(error, res, body) => {
|
||||
if (error) {
|
||||
return console.log(error)
|
||||
};
|
||||
|
||||
if (!error && res.statusCode == 200) {
|
||||
const stat = tuya_name + " has been turned on";
|
||||
xmpp.send(from, stat);
|
||||
console.log(stat);
|
||||
}
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
console.log('lights on');
|
||||
}
|
||||
else if (message === tuya_name + ' off') {
|
||||
request(tuya_toggle_url + "?stat=false&devname=" + tuya_name,(error, res, body) => {
|
||||
if (error) {
|
||||
return console.log(error)
|
||||
};
|
||||
|
||||
if (!error && res.statusCode == 200) {
|
||||
const stat = tuya_name + " has been turned off";
|
||||
xmpp.send(from, stat);
|
||||
console.log(stat);
|
||||
}
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
console.log('lights on');
|
||||
}
|
||||
|
||||
// Check VFC balance
|
||||
else if (message === "vfc" || message === "Vfc") {
|
||||
|
@ -238,7 +330,8 @@ xmpp.on('chat', function(from, message) {
|
|||
}
|
||||
|
||||
// If the user sends something we don't have logic for, send them info about the project
|
||||
else { xmpp.send(from, "This is an auto replying bot. Reply \"help\" for more info, or https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:start");
|
||||
else {
|
||||
xmpp.send(from, "This is an auto replying bot. Reply \"help\" for more info, or https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:start");
|
||||
console.log('autoreply');
|
||||
}
|
||||
});
|
||||
|
|
Reference in New Issue
Block a user