Open tommyMX opened 10 months ago
basically I agree, this real question is how this really makes sense to be used. new appointments would come up with new unique object IDs, so always needs to be "programmatically checked" to be used, old objects needs to be cleaned up and such
Yes, I agree with you, that would make so much sense. Is it difficult to program this?
I guess it really would make sense! For Example, if you can get the Start-Time of an Event, you can calculate time back and start (for Example) the Heater 24 hours before. So the room is warm if the Event starts. As @tommyMX said, is it difficult?
Thats something on my whishlist for a long time since using ical, but i cant think of a universal structure usable for everyone.
I for myself (Mabe not exactly what you need, but maybe helpful) wrote a script that reads all ical entries (of all ical calendars) and creates single objects for the next 8 calendar entries ordered by date and time.
Each Object contains one single calendar entry formated in html (to my own likes). each entry has the color of the calendar it comes from, the Weekday is written as a word, it displays how many days are left until the event starts
So i can display these in a Vis dashboard and position/scale it wherever i want and have a calendar like look.
The script needs 2 little changes:
1) You need do define the Calendarnames (hardcoded, in my example i have 5 calendars, you can delete or copy lines if you have fewer or more calendars in your ical-adapter) 2) each Calendar can have its own color, so just put in the HEX Colors for each calendar in the script
switch (KalenderName) { case "Ute": Kalenderfarbe = "background-color: #008800"; break; case "Bernd": Kalenderfarbe = "background-color: #E33131"; break; case "Roswita": Kalenderfarbe = "background-color: #FF69B4"; break; case "Inge": Kalenderfarbe = "background-color: #8800FF"; break; case "Arbeit": Kalenderfarbe = "background-color: #ff9900"; break;
VIS HTML Widgets (each Calendar reffers to one Object):
Java Script:
on({ id: [].concat(['ical.0.data.table']), change: 'ne' }, async (obj) => {
let value = obj.state.val;
let oldValue = obj.oldState.val;
await ausfuehren();
});
async function ausfuehren() {
var calTable = getState("ical.0.data.table");
var Objekt = "";
//Kalenderdaten initialisieren
var datumzeit = "";
for (var i = 0; i < 8; i++)
{
var Eintrag = calTable.val[i];
if(i == 0) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event1"};
if(i == 1) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event2"};
if(i == 2) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event3"};
if(i == 3) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event4"};
if(i == 4) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event5"};
if(i == 5) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event6"};
if(i == 6) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event7"};
if(i == 7) {Objekt = "0_userdata.0.PER_SKRIPT_ERSTELLTE_DATENPUNKTE.Kalenderwidgets_fur_VIS.html_event8"};
let KalenderName = Eintrag._calName;
let Kalenderfarbe= "background-color: #00FF00"; //standard grün
//hier noch die realen Kalendernamen (exakt wie im ical Adapter angelegt) eintragen und die gewünschte Farbe
switch (KalenderName) {
case "Kerstin": Kalenderfarbe = "background-color: #008800";
break;
case "Jens": Kalenderfarbe = "background-color: #E33131";
break;
case "Tabea": Kalenderfarbe = "background-color: #FF69B4";
break;
case "Oskar": Kalenderfarbe = "background-color: #8800FF";
break;
case "itsm": Kalenderfarbe = "background-color: #ff9900";
break;
}
//Datumzeit String zerhacken ;-)
let datumzeit = Eintrag.date;
const myArray1 = datumzeit.split(" ");
let Datum = myArray1[0];
let date = new Date();
let DatumHeuteDate = String(date.getDate()).padStart(2, '0') + '.' + String(date.getMonth() + 1).padStart(2, '0') + '.' + date.getFullYear();
let DatumStringAmericanHeute = DatumHeuteDate.split(".")[2] + "-" + DatumHeuteDate.split(".")[1] + "-" + DatumHeuteDate.split(".")[0];
var DatumAmericanHeute = new Date(DatumStringAmericanHeute);
let ZeitVonbis = myArray1[1];
const myArray2 = ZeitVonbis.split("-");
let ZeitVon = myArray2[0];
let ZeitBis = myArray2[1];
let DatumStringAmerican = Datum.split(".")[2] + "-" + Datum.split(".")[1] + "-" + Datum.split(".")[0];
var DatumAmerican = new Date(DatumStringAmerican);
let WochentagNumber = DatumAmerican.getDay();
let WochentagTag = "";
switch (WochentagNumber) {
case 0: WochentagTag = "Sonntag";
break;
case 1: WochentagTag = "Montag";
break;
case 2: WochentagTag = "Dienstag";
break;
case 3: WochentagTag = "Mittwoch";
break;
case 4: WochentagTag = "Donnerstag";
break;
case 5: WochentagTag = "Freitag";
break;
case 6: WochentagTag = "Samstag";
}
// Berechnen Sie die Zeitdifferenz in Millisekunden
const diffTime = DatumAmerican.getTime() - DatumAmericanHeute.getTime();
//Berechnen Sie die Anzahl der Tage
const diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24));
if (diffDays == 0)
{
WochentagTag = "HEUTE";
}
if (diffDays == 1)
{
WochentagTag = "MORGEN";
}
if (diffDays >= 2)
{
WochentagTag = WochentagTag.substring(0, 2) + " in " + diffDays + " Tagen"
}
var str = "";
str = `<table style="border-collapse: collapse; width: 215px; height: 205px;">
<tbody>
<tr>
<td class="tablerow_tag" colspan="2" style="` + Kalenderfarbe + `">
<span>`+ WochentagTag + `</span>
</td>
</tr>
<tr>
<td class="tablerow_datumzeit" style="` + Kalenderfarbe + `">` + Datum + `</td>
<td class="tablerow_datumzeit" style="` + Kalenderfarbe + `">` + ZeitVon + `</td>
</tr>
<tr>
<td class="tablerow_event" colspan="2">`
str = str + Eintrag.event; // Event
str = str + `</td>
</tr>
</tbody>
</table>`
setState(Objekt, str);
}
};
Das Script kann sicherlich noch vereinfacht werden (Ich bin nicht der Script-Profi, habe es aber so geschrieben, dass ich später mal noch weiss was ich mir gedacht habe und es auch von anderen einfach anpassbar ist). Es funktioniert jedenfalls tadellos seit über einem Jahr :-D
Hi,
es wäre super wenn man die Kalenderdaten auch als einzelne datenpunkte bekommt ;-)
man könnte sie dann schon bei dem neuen awtrix light Adapter nutzen und anzeigen lassen
danke dir