@tt-tom said in nspanel script: state im alias bleibt 0:
console.log(idRestmuellName);
Hallo Tom,
ich habe jetzt mal in das script die folgenden log-Befehle eingegeben:
console.log('Event2 = ' + Event2);
console.log('ID = ' + idRestmuellName);
console.log('ID = ' + idBioabfaelleName);
console.log('ID = ' + idPappePapierName);
console.log('ID = ' + idWertstoffName);
Das ist das Ergebnis in der log-Datei:
javascript.0
2023-04-01 21:30:03.730 info script.js.NSPanel.Muell_JS: ID = Wertstoffbehaelter
javascript.0
2023-04-01 21:30:03.729 info script.js.NSPanel.Muell_JS: ID = Papierbehaelter
javascript.0
2023-04-01 21:30:03.729 info script.js.NSPanel.Muell_JS: ID = Bioabfallbehaelter
javascript.0
2023-04-01 21:30:03.729 info script.js.NSPanel.Muell_JS: ID = Restabfallbehaelter
javascript.0
2023-04-01 21:30:03.729 info script.js.NSPanel.Muell_JS: Event2 = Bioabfallbehaelter
javascript.0
2023-04-01 21:30:03.728 info script.js.NSPanel.Muell_JS: ID = Wertstoffbehaelter
javascript.0
2023-04-01 21:30:03.727 info script.js.NSPanel.Muell_JS: ID = Papierbehaelter
javascript.0
2023-04-01 21:30:03.727 info script.js.NSPanel.Muell_JS: ID = Bioabfallbehaelter
javascript.0
2023-04-01 21:30:03.727 info script.js.NSPanel.Muell_JS: ID = Restabfallbehaelter
javascript.0
2023-04-01 21:30:03.727 info script.js.NSPanel.Muell_JS: Event2 = Wertstoffbehaelter
javascript.0
2023-04-01 21:30:03.726 info script.js.NSPanel.Muell_JS: ID = Wertstoffbehaelter
javascript.0
2023-04-01 21:30:03.726 info script.js.NSPanel.Muell_JS: ID = Papierbehaelter
javascript.0
2023-04-01 21:30:03.725 info script.js.NSPanel.Muell_JS: ID = Bioabfallbehaelter
javascript.0
2023-04-01 21:30:03.725 info script.js.NSPanel.Muell_JS: ID = Restabfallbehaelter
javascript.0
2023-04-01 21:30:03.725 info script.js.NSPanel.Muell_JS: Event2 = Restabfallbehaelter
javascript.0
2023-04-01 21:30:03.723 info script.js.NSPanel.Muell_JS: ID = Wertstoffbehaelter
javascript.0
2023-04-01 21:30:03.723 info script.js.NSPanel.Muell_JS: ID = Papierbehaelter
javascript.0
2023-04-01 21:30:03.722 info script.js.NSPanel.Muell_JS: ID = Bioabfallbehaelter
javascript.0
2023-04-01 21:30:03.722 info script.js.NSPanel.Muell_JS: ID = Restabfallbehaelter
javascript.0
2023-04-01 21:30:03.721 info script.js.NSPanel.Muell_JS: Event2 = Papierbehaelter
Es sieht so aus, als ob bei der ersten event2-Abfrage der string leer ist.
Hier jetzt mal das script:
const idAbfalliCal = 'ical.0'; // iCal Instanz zum Abfallkalender
const idZeichenLoeschen = 0; // x Zeichen links vom String abziehen, wenn vor dem Eventname noch Text steht z.B. Strassenname; Standard = 0
const idRestmuellName ='Restabfallbehaelter'; // Schwarze Tonne
const idWertstoffName = 'Wertstoffbehaelter'; // Gelbe Tonne / Sack
const idPappePapierName = 'Papierbehaelter'; // Blaue Tonne
const idBioabfaelleName = 'Bioabfallbehaelter'; // Braune Tonne
var i, Muell_JSON, Event2, Color = 0;
for (i = 1; i <= 4; i++) {
if (!existsState('0_userdata.0.Abfallkalender.' + parseFloat(i) + '.date')) {
log(i + '.date nicht vorhanden, wurde erstellt');
createState('0_userdata.0.Abfallkalender.' + parseFloat(i) + '.date', '',
{
name: parseFloat(i) + '.date',
role: 'state',
type: 'string',
read: true,
write: true,
def: ''
});
};
if (!existsState('0_userdata.0.Abfallkalender.' + parseFloat(i) + '.event')) {
log(i + '.event nicht vorhanden, wurde erstellt');
createState('0_userdata.0.Abfallkalender.' + parseFloat(i) + '.event', '',
{
name: parseFloat(i) + '.event',
role: 'state',
type: 'string',
read: true,
write: true,
def: ''
});
};
if (!existsState('0_userdata.0.Abfallkalender.' + parseFloat(i) + '.color')) {
log(i + '.color nicht vorhanden, wurde erstellt');
createState('0_userdata.0.Abfallkalender.' + parseFloat(i) + '.color', 31,
{
name: parseFloat(i) + '.color',
role: 'state',
type: 'number',
read: true,
write: true,
def: 0
});
};
}
function subsequenceFromStartLast(sequence, at1) {
var start = at1;
var end = sequence.length;
return sequence.slice(start, end);
}
on({ id: idAbfalliCal + '.data.table', change: "ne" }, async function () {
for (i = 0; i <= 3; i++) {
Muell_JSON = getState(idAbfalliCal + '.data.table').val;
setStateDelayed((['0_userdata.0.Abfallkalender.', parseFloat(i) + 1, '.date'].join('')), getAttr(Muell_JSON, (String(i) + '.date')), false, parseInt(((0) || "").toString(), 10), false);
Event2 = subsequenceFromStartLast(getAttr(Muell_JSON, (String(i) + '.event')), idZeichenLoeschen);
setStateDelayed((['0_userdata.0.Abfallkalender.', parseFloat(i) + 1, '.event'].join('')), Event2, false, parseInt(((0) || "").toString(), 10), false);
console.log('Event2 = ' + Event2);
console.log('ID = ' + idRestmuellName);
console.log('ID = ' + idBioabfaelleName);
console.log('ID = ' + idPappePapierName);
console.log('ID = ' + idWertstoffName);
if (Event2 == idRestmuellName) {
Color = 33840;
console.log ('Rest = true');
} else if (Event2 == idBioabfaelleName) {
Color = 2016;
console.log ('Bio = true');
} else if (Event2 == idPappePapierName) {
Color = 31;
console.log ('Papier = true');
} else if (Event2 == idWertstoffName) {
Color = 65504;
console.log ('Wert = true');
}
setStateDelayed((['0_userdata.0.Abfallkalender.', parseFloat(i) + 1, '.color'].join('')), Color, false, parseInt(((0) || "").toString(), 10), false);
}
});