// Datum 21.07.2017
// Autor: Looxer01
// erweitern am 20.10.2017: Pax90
// Programm Steuert den Xiaomi Sauger nach Wochenplan
// Stunden, Minuten und Power können eingegeben werden.
// Einstellbereich
//
var IDFlag = "javascript.0.Xiaomi.WeekSchedule"; // Schedule Path
var xiaomiStart = "mihome-vacuum.0.control.start"; // bei true Starten des Saugvorganges
var xiaomiState = "mihome-vacuum.0.info.state"; // bei False pause - bei true fortsetzen - toggle
var xiaomiHome = "mihome-vacuum.0.control.home"; // bei state false und home true = go home
var xiaomiSpeed = "mihome-vacuum.0.control.fan_power"; // Geschwindigkeit von 1-100
// Ende einstellungen
var StateWeekSchedule;
//---------------------------------------------------------------------------------------------------
// Create States können rausgenommen werden wenn einmal gelaufen
//---------------------------------------------------------------------------------------------------
CreateStates();
//---------------------------------------------------------------------------------------------------
//Auslesen der Zeit und Power zur Einplanung in die schedules
//---------------------------------------------------------------------------------------------------
// Montags
StateWeekSchedule = IDFlag+ ".1-Monday-Start-Hour";
var cronMoStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".1-Monday-Start-Minute";
var cronMoMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".1-Monday-Power";
var cronMoPower = getState(StateWeekSchedule).val; //Power
// Dienstags
StateWeekSchedule = IDFlag+ ".2-Tuesday-Start-Hour";
var cronDiStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".2-Tuesday-Start-Minute";
var cronDiMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".2-Tuesday-Power";
var cronDiPower = getState(StateWeekSchedule).val; //Power
// Mittwochs
StateWeekSchedule = IDFlag+ ".3-Wednesday-Start-Hour";
var cronMiStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".3-Wednesday-Start-Minute";
var cronMiMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".3-Wednesday-Power";
var cronMiPower = getState(StateWeekSchedule).val; //Power
// Donnerstags
StateWeekSchedule = IDFlag+ ".4-Thursday-Start-Hour";
var cronDoStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".4-Thursday-Start-Minute";
var cronDoMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".4-Thursday-Power";
var cronDoPower = getState(StateWeekSchedule).val; //Power
// Freitags
StateWeekSchedule = IDFlag+ ".5-Friday-Start-Hour";
var cronFrStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".5-Friday-Start-Minute";
var cronFrMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".5-Friday-Power";
var cronFrPower = getState(StateWeekSchedule).val; //Power
// Samstags
StateWeekSchedule = IDFlag+ ".6-Saturday-Start-Hour";
var cronSaStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".6-Saturday-Start-Minute";
var cronSaMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".6-Saturday-Power";
var cronSaPower = getState(StateWeekSchedule).val; //Power
// Sonntags
StateWeekSchedule = IDFlag+ ".7-Sunday-Start-Hour";
var cronSoStunde = getState(StateWeekSchedule).val; //Aktivzeit stunde
StateWeekSchedule = IDFlag+ ".7-Sunday-Start-Minute";
var cronSoMinute = getState(StateWeekSchedule).val; //Aktivzeit minute
StateWeekSchedule = IDFlag+ ".7-Sunday-Power";
var cronSoPower = getState(StateWeekSchedule).val; //Power
//---------------------------------------------------------------------------------------------------
// Die Schedules für jeden Tag der Woche
//---------------------------------------------------------------------------------------------------
schedule(cronMoMinute + " " + cronMoStunde +" * * 1", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".1-Monday";
var Monday = getState(StateWeekSchedule).val;
if (Monday) {
log("Roboter eingeschaltet (Power: " + cronMoPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronMoPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
schedule(cronDiMinute + " " + cronDiStunde +" * * 2", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".2-Tuesday";
var Tuesday = getState(StateWeekSchedule).val;
if (Tuesday) {
log("Roboter eingeschaltet (Power: " + cronDiPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronDiPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
schedule(cronMiMinute + " " + cronMiStunde +" * * 3", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".3-Wednesday";
var Wednesday = getState(StateWeekSchedule).val;
if (Wednesday) {
log("Roboter eingeschaltet (Power: " + cronMiPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronMiPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
schedule(cronDoMinute + " " + cronDoStunde +" * * 4", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".4-Thursday";
var Thursday = getState(StateWeekSchedule).val;
if (Thursday) {
log("Roboter eingeschaltet (Power: " + cronDoPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronDoPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
schedule(cronFrMinute + " " + cronFrStunde +" * * 5", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".5-Friday";
var Friday = getState(StateWeekSchedule).val;
if (Friday) {
log("Roboter eingeschaltet (Power: " + cronFrPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronFrPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
schedule(cronSaMinute + " " + cronSaStunde +" * * 6", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".6-Saturday";
var Saturday = getState(StateWeekSchedule).val;
if (Saturday) {
log("Roboter eingeschaltet (Power: " + cronSaPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronSaPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
schedule(cronSoMinute + " " + cronSoStunde +" * * 7", function () { // jeden Tag um diese Uhrzeit
StateWeekSchedule = IDFlag+ ".7-Sunday";
var Sunday = getState(StateWeekSchedule).val;
if (Sunday) {
log("Roboter eingeschaltet (Power: " + cronSoPower + "%)" ,"info");
setState(xiaomiSpeed,parseInt(cronSoPower));
setStateDelayed(xiaomiStart,true,1000);
}
}); // end of schedule
//---------------------------------------------------------------------------------------------------
// Funktion zum Anlegen der States
//---------------------------------------------------------------------------------------------------
function CreateStates() {
// Montags
StateWeekSchedule = IDFlag+ ".1-Monday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".1-Monday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".1-Monday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".1-Monday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
// Dienstags
StateWeekSchedule = IDFlag+ ".2-Tuesday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".2-Tuesday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".2-Tuesday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".2-Tuesday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
// Mittwochs
StateWeekSchedule = IDFlag+ ".3-Wednesday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".3-Wednesday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".3-Wednesday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".3-Wednesday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
// Donnerstags
StateWeekSchedule = IDFlag+ ".4-Thursday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".4-Thursday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".4-Thursday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".4-Thursday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
// Freitags
StateWeekSchedule = IDFlag+ ".5-Friday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".5-Friday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".5-Friday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".5-Friday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
// Samstags
StateWeekSchedule = IDFlag+ ".6-Saturday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".6-Saturday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".6-Saturday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".6-Saturday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
// Sonntags
StateWeekSchedule = IDFlag+ ".7-Sunday";
createState(StateWeekSchedule, false, {read: true, write: true, type: 'boolean', name: 'Xiaomi Start Weekday', desc: 'Xiaomi Start Weekday'});
StateWeekSchedule = IDFlag+ ".7-Sunday-Start-Hour";
createState(StateWeekSchedule, 11, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Hour', desc: 'Xiaomi Start Starttime Hour'});
StateWeekSchedule = IDFlag+ ".7-Sunday-Start-Minute";
createState(StateWeekSchedule, 1, {read: true, write: true, type: 'number', name: 'Xiaomi Start Starttime Minute', desc: 'Xiaomi Start Starttime Minute'});
StateWeekSchedule = IDFlag+ ".7-Sunday-Power";
createState(StateWeekSchedule, 90, {read: true, write: true, type: 'number', name: 'Xiaomi Start Power', desc: 'Xiaomi Start Starttime Power'});
}