S
S
shvedoffsky2017-10-10 20:00:58
JavaScript
shvedoffsky, 2017-10-10 20:00:58

I can't figure out how to correctly set the condition?

Please help, I can't figure out how to correctly set the condition.
The bottom line is this:
There are heating modes (Standby, day, night),
It is necessary that the Standby mode work from Sunday 18:00 to Friday 12:00.
Friday after 12:00 pm Daytime
Sunday after 6:00 pm
Standby Day mode from 6:00 to 00:00
Night mode from 00:00 to 6:00
Accordingly, day and night mode should change from Friday to Sunday

var now     = new Date(); 
var year    = now.getFullYear();
var month   = now.getMonth()+1; 
var day     = now.getDay();
var hour    = now.getHours();
var minute  = now.getMinutes();
var second  = now.getSeconds();
//var day = 6;

if(msg.topic === "/KotelTemperatura/DHT22/Temperatura"){
    if (day >= 0 && day <= 5 && hour <= 12 && hour >= 18)
        {
        return [msg,null,null];			//Режим ожидания
        }
  else if(day >= 5 && hour >= 12 && hour <=0)
      {return [null,msg,null];}	//Режим день
  else if(day > 5 && hour >= 0 && hour <= 6)
      {return [null,null,msg];}	//Режим ночь
  else if(day > 5 && hour >= 6 && hour <= 0)
      {return [null,msg,null];}	//Режим день
  else if(day >= 0 && hour >= 18)
      {return [msg,null,null];}	//Режим ожидания

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-10-10
@shvedoffsky

So?

if (day==5 && hour>12) {
 // В Пятницу после 12:00 Дневной
} else if (day==6) { // суббота
  if (hour<6) {
    // ночной
  } else {
    // дневной
  }
} else if (day==0) { // воскресенье
  if (hour<6) {
    // ночной
  } else if(hour<18) {
    // дневной
  } else {
    // ожидание
  }
} else {
  // все остальное время - ожидание
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question