jetzt habe ich mir mit VisualStudioCode ein funktionierendes JavaScript gebaut. Im VSC funktioniert er auch. Kopiere ich diesen 1:1 in openHAB, siehe da läuft nicht. Warum läuft der Code unter openHAB nicht, aber unter VSC schon.
Code: Alles auswählen
var ButtonStatus = itemRegistry.getItem('Badezimmer_Oben_Regelung_ON_OFF').getState();
var Status = 'TEST_Status_Badezimmer_oben';
/*ANFANG */
function HeatingPeriod(today)
{
const NOVEMBER = 10;
/*UHRZEIT WOCHENTAG*/
const MONDAY = 1;
const BeginHeatingPeriode_WeekHour = 4;
const EndHeatingPeriode_WeekHour = 5;
const FRIDAY = 5;
/*WOCHENENDE */
const SUNDAY = 0;
const BeginHeatingPeriode_WeekendHour = 8;
const EndHeatingPeriode_WeekendHour = 9;
const SATURDAY = 6;
/*ENDE HEIZPERIODE */
const EndHeatingPeriode_Day = 15;
const APRIL = 3;
if((today.getMonth() >= NOVEMBER) ||
(today.getMonth() <= APRIL))
{
/* WOCHE */
if((today.getDay() >= MONDAY) &&
(today.getDay() <= FRIDAY) &&
(today.getHours() >= BeginHeatingPeriode_WeekHour)&&
(today.getHours() < EndHeatingPeriode_WeekHour))
{
return state = "Wochentag, Heizbetrieb";
}
if((today.getDay() === SATURDAY || today.getDay() === SUNDAY) &&
(today.getHours() >= BeginHeatingPeriode_WeekendHour) &&
(today.getHours() < EndHeatingPeriode_WeekendHour))
{
return state = "Wochenende, Heizberieb";
}else{
return state = "Tagbetrieb";
}
}
else
{
return state = "keine Heizperiode";
}
}
var currentDate = new Date();
/*ENDE*/
if(ButtonStatus == 'ON')
{
events.sendCommand(Status, 'ON');
} else {
events.postUpdate(Status, 'OFF');
}
Der Code soll mir ein Zustand ausgeben, welche ich später weiterverarbeiten möchte. Betätige ich die Taste ButtonStatus so funktioniert dieser nicht. Lösche ich die Funktion zwischen /*ANFANG*/ und /*ENDE*/, dann funktioniert die Tasterabfrage. Gibt es ein Debugger, wo ich sehen kann, warum der Code nicht läuft? Irgendwie habe ich auch das Gefühl das oH langsamer läuft...
Gruß