Müllkalender via openHAB

Für welche Projekte verwendet Ihr OpenHAB? Was habt Ihr automatisiert? Stellt eure Projekte hier vor.

Moderatoren: Cyrelian, seppy

Antworten
Nordmann
Beiträge: 45
Registriert: 17. Sep 2017 23:43

Re: Müllkalender via openHAB

Beitrag von Nordmann »

Hallo zusammen,

ich bin beim „googeln“ auf diesen Beitrag gestoßen und würde den „Abfallkalender“ gerne auch installieren,
habe aber Probleme damit die richtige URL herauszufinden.
Den ical Kalender kann man unter der folgenden URL herunterladen: https://www.awg-rems-murr.de/generator/ ... ender1.php.

Ich habe aber keinen blassen Schimmer wie ich an die entsprechende URL komme.
Und was heißt:
Also muss ich einmal im Jahr den Download manuell machen und die Datei bei mir im Netz ablegen.
Und wo finde ich dann den Pfad:
Kann mir da jemand von Euch vielleicht helfen?! :?:
Vielen Dank im Voraus und Euch noch einen schönen Abend!

Gruß
Jörg

Benutzeravatar
alkaline
Beiträge: 173
Registriert: 20. Apr 2017 13:25

Re: Müllkalender via openHAB

Beitrag von alkaline »

Du brauchst die ics Datei bzw. den Link dazu.....frage deinen Betreiber danach, denn auf der Webseite kann man sie nicht holen.
Ich muss in der Tat einmal pro Jahr die URL anpassen auf die neue ics Datei bzw. Link, mache ich für gewöhnlich gleich zu Anfang.

Das sieht dann so aus bei mir:

Code: Alles auswählen

String ABFALL_ICAL_heute { http="<[http://www.abfallwirtschaft-ortenaukreis.de/fileadmin/ics/ical_3762.ics:360000:JS(abfall_heute.js)]" }

Dascrip
Beiträge: 2
Registriert: 5. Nov 2017 08:02

Re: Müllkalender via openHAB

Beitrag von Dascrip »

Hallo Zusammen,

dieses ist mein erster Beitrag im Forum und bewege mich ganz langsam vorwärts was Openhab2 angeht. Ich habe schon viel in FHEM gemacht und will eigentlich jetzt zu Openhab2 wechseln.

Ich quäle mich mit dem Thema Feiertagskalender und habe von alkaline im Beitrag gesehen, dass Du ähnlich wie den Müllkalender den Feiertagskalender.

Magst Du den Code mal teilen mit mir?

Danke
Dominik

Benutzeravatar
alkaline
Beiträge: 173
Registriert: 20. Apr 2017 13:25

Re: Müllkalender via openHAB

Beitrag von alkaline »

Kein Problem
Abfall items:

Code: Alles auswählen

//Abfall heute
String ABFALL_ICAL_heute { http="<[http://www.abfallwirtschaft-ortenaukreis.de/fileadmin/ics/ical_3762.ics:360000:JS(abfall_heute.js)]" }
Switch 		ABFALL_AKTIV_heute
String 		ABFALL_NAME_heute

//Abfall morgen
String ABFALL_ICAL_morgen { http="<[http://www.abfallwirtschaft-ortenaukreis.de/fileadmin/ics/ical_3762.ics:360000:JS(abfall_morgen.js)]" }
Switch 		ABFALL_AKTIV_morgen
String 		ABFALL_NAME_morgen

// Nächste Abholung
String ABF1_NAME { http="<[http://www.abfallwirtschaft-ortenaukreis.de/fileadmin/ics/ical_3762.ics:360000:JS(abfall_naechste_abholung_name.js)]" }
DateTime ABF1_DATE { http="<[http://www.abfallwirtschaft-ortenaukreis.de/fileadmin/ics/ical_3762.ics:360000:JS(abfall_naechste_abholung_datum.js)]" }
Holiday items:

Code: Alles auswählen

// Die URL muss jedes Jahr neu auf http://www.schulferien.org/deutschland/ical/ nachgeschlagen werden ?

Group gHoliday    	"Ferien & Feiertag(e)"	        (Whg)  	// zur Anzeige in Sitemap
Group gSpecialday   "Feiertage"	       	(Whg)

String GlobalSpecialDayICAL	{http="<[http://www.schulferien.org/media/ical/deutschland/ferien_baden-wuerttemberg_%1$tY.ics?k=OUsfROyB07kS4AILgtWURacIdRwdPWI55knDN4qtsGOWXaqgJxiuLloqa5uKp1RKR5BgYWS47N2BokflkoVnQNd_jRCEXpYjAEA2QDqsKY8:7200000:JS(ical_holiday.js)]"}
String GlobalHolidayICAL 	{http="<[http://www.schulferien.org/media/ical/deutschland/ferien_baden-wuerttemberg_%1$tY.ics?k=OUsfROyB07kS4AILgtWURacIdRwdPWI55knDN4qtsGOWXaqgJxiuLloqa5uKp1RKR5BgYWS47N2BokflkoVnQNd_jRCEXpYjAEA2QDqsKY8:7200000:JS(ical_holiday.js)]"}

Switch GlobalHoliday 		(gHoliday)
String GlobalHolidayName
Abfall rules:

Code: Alles auswählen

rule "Abfallkalender heute"
when
   Item ABFALL_ICAL_heute changed
then
   //Prüfen ob heute Abfall abgeholt wird
	if (ABFALL_ICAL_heute.state != "false" && ABFALL_ICAL_heute.state != "Uninitialized"){
      postUpdate(ABFALL_AKTIV_heute,ON)
      postUpdate(ABFALL_NAME_heute,ABFALL_ICAL_heute.state)
   } else {
      postUpdate(ABFALL_AKTIV_heute,OFF)
      postUpdate(ABFALL_NAME_heute,"false")
   }
end

rule "Abfallkalender morgen"
when
   Item ABFALL_ICAL_morgen changed
then
   //Prüfen ob morgen Abfall abgeholt wird
	if (ABFALL_ICAL_morgen.state != "false" && ABFALL_ICAL_morgen.state != "Uninitialized"){
      postUpdate(ABFALL_AKTIV_morgen,ON)
      postUpdate(ABFALL_NAME_morgen,ABFALL_ICAL_morgen.state)
   } else {
      postUpdate(ABFALL_AKTIV_morgen,OFF)
      postUpdate(ABFALL_NAME_morgen,"false")
   }
end

rule "Abfallerinnerung heute" // send Nachricht auf Handy via Telegramm (Marcus) und OH App (alle Nutzer)
when
Time cron "0 30 06 ? * * *" 
then
if (ABFALL_AKTIV_heute.state == ON){
sendBroadcastNotification("An den Abfall denken: " + ABFALL_NAME_heute.state)}
//sendTelegram("Marcus", "An den Abfall denken " + ABFALL_NAME_heute.state)}
end

rule "Abfallerinnerung morgen" // send Nachricht auf Handy via Telegramm (Marcus) und OH App (alle Nutzer)
when
Time cron "0 30 18 ? * * *" 
then
if (ABFALL_AKTIV_morgen.state == ON){
sendBroadcastNotification("Morgen Abfall rausstellen: " + ABFALL_NAME_morgen.state)}
//sendTelegram("Marcus", "Morgen Abfall rausstellen " + ABFALL_NAME_morgen.state)}
end
Feiertage rules:

Code: Alles auswählen

/**
 * Ferien und Feiertage prüfen
 */

rule "Event_Holiday 1"
when
   Item GlobalHolidayICAL changed or
   Item GlobalSpecialDayICAL changed
then
   //Prüfen ob ein Feiertag ist
   if (GlobalSpecialDayICAL.state != "false" && GlobalSpecialDayICAL.state != "Uninitialized"){
      GlobalHoliday.postUpdate(ON)
      GlobalHolidayName.postUpdate(GlobalSpecialDayICAL.state)
      //sendTelegram("Marcus", "Heute ist ein Feiertag: " + GlobalSpecialDayICAL)
      //logInfo("HomeBox.SystemRules:Event_Holiday", "GlobalSpecialDayICAL changed: Updated Holiday Status: " + Feiertag.state + " (" + FeiertagName.state + ")")
   }
   // Prüfen ob Ferien sind
   else if (GlobalHolidayICAL.state != "false" && GlobalHolidayICAL.state != "Uninitialized"){
      GlobalHoliday.postUpdate(ON)
      GlobalHolidayName.postUpdate(GlobalHolidayICAL.state)
      //logInfo("HomeBox.SystemRules:Event_Holiday", "GlobalHolidayICAL changed: Updated Holiday Status: " + GlobalHoliday.state + " (" + GlobalHolidayName.state + ")")
   } else {
      GlobalHoliday.postUpdate(OFF)
      GlobalHolidayName.postUpdate("false")
      //logInfo("HomeBox.SystemRules:Event_Holiday", "Updated Holiday Status: " + GlobalHoliday.state + " (false)")
   }
end

/**
 * Ferien und Feiertage pr�fen
 */
//rule "Event_Holiday"
//when
//   Item GlobalHolidayICAL changed or
//   Item GlobalSpecialDayICAL changed
//then
//   //Pr�fen ob ein Feiertag ist
//   if (GlobalSpecialDayICAL.state != "false" && GlobalSpecialDayICAL.state != "Uninitialized"){
//      postUpdate(GlobalHoliday,ON)
//      postUpdate(GlobalHolidayName,GlobalSpecialDayICAL.state)
//      logInfo("HomeBox.SystemRules:Event_Holiday", "GlobalSpecialDayICAL changed: Updated Holiday Status: " + GlobalHoliday.state + " (" + GlobalHolidayName.state + ")")
//   }
//   // Pr�fen ob Ferien sind
//   else if (GlobalHolidayICAL.state != "false" && GlobalHolidayICAL.state != "Uninitialized"){
//      postUpdate(GlobalHoliday,ON)
//      postUpdate(GlobalHolidayName,GlobalHolidayICAL.state)
//      logInfo("HomeBox.SystemRules:Event_Holiday", "GlobalHolidayICAL changed: Updated Holiday Status: " + GlobalHoliday.state + " (" + GlobalHolidayName.state + ")")
//   } else {
//      postUpdate(GlobalHoliday,OFF)
//      postUpdate(GlobalHolidayName,"false")
//      logInfo("HomeBox.SystemRules:Event_Holiday", "Updated Holiday Status: " + GlobalHoliday.state + " (false)")
//   }
//end

Dascrip
Beiträge: 2
Registriert: 5. Nov 2017 08:02

Re: Müllkalender via openHAB

Beitrag von Dascrip »

Super vielen Dank!

Benutzeravatar
alkaline
Beiträge: 173
Registriert: 20. Apr 2017 13:25

Re: Müllkalender via openHAB

Beitrag von alkaline »

Habe was vergessen, die brauchst du auch noch:
abfall_heute.js:

Code: Alles auswählen

var abfall = false;
(function(i) {
 
	var Ical = function Ical(){
		this.version = '';
		this.prodid = '';
		this.events = [];
		this.todos = [];
		this.journals = [];
		this.freebusys = [];
	}
	var xprops = 'x-[^:;]+';
	var ianaprops = '[\\w]+[^:;]+'
	var icalParser = {
		icals : [],
		propsList : {
			'event':'(dtstamp|uid|dtstart|class|created|description|geo|last-mod|location|organizer|priority|seq|status|summary|transp|url|recurid|rrule|dtend|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')',
			'freebusy':'(dtstamp|uid|contact|dtstart|dtend|organizer|url|attendee|comment|freebusy|rstatus|'+xprops+'|'+ianaprops+')',
			'journal':'(dtstamp|uid|class|created|dtstart|last-mod|organizer|recurid|seq|status|summary|url|rrule|attach|attendee|categories|comment|contact|description|exdate|related|rdate|rstatus|'+xprops+'|'+ianaprops+')',
			'todo':'(dtstamp|uid|class|completed|created|description|dtstart|geo|last-mod|location|organizer|percent|priority|recurid|seq|status|summary|url|rrule|due|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')'
		},
		parseIcal : function(icsString){
			var cals = icsString.match(/BEGIN:VCALENDAR\r?\n(.*\r?\n)+?END:VCALENDAR/ig);
			for(var index in cals){
				//console.log("--->"+index+" "+cals[index]);
				var ical = new Ical(); 
				ical.version = this.getValue('VERSION',cals[index]);
				ical.prodid = this.getValue('PRODID',cals[index]);
				cals[index] = cals[index].replace(/\r\n /g,'');
				cals[index] = cals[index].replace(/BEGIN:VCALENDAR\r?\n/ig,'');
				var reg = /BEGIN:(V.*?)\r?\n(.*\r?\n)+?END:\1/gi;
				matches = cals[index].match(reg);
				if(matches){
					for(i=0;i<matches.length;i++){
						//console.log('---------->'+matches[i]+"\n<------------");
						this.parseVComponent(matches[i],ical);
					}
				}
				this.icals[this.icals.length] = ical;
			}
		},
		parseVComponent : function(vComponent,ical){
			var nameComponent = vComponent.match(/BEGIN:V([^\s]+)/i)[1].toLowerCase();
			vComponent = vComponent.replace(/\r?\n[\s]+/igm,''); //unfolding
			vComponent = vComponent.replace(/(^begin|^end):.*/igm,'');
			//console.log(nameComponent+' ++++ '+vComponent);
			var props = vComponent.match(new RegExp(this.propsList[nameComponent]+'[:;].*','gim'));
			if(props){
				var component=[];
				for(var index in props){
					var nom = props[index].replace(/[:;].*$/,'');
					//console.log("--vcompo "+index+" "+nom);
					var propKey = /*'prop_'+*/nom.toLowerCase();
					if(component[propKey]===undefined) component[propKey] = [];
					component[propKey][component[propKey].length] = this.getValue(nom,props[index]);
					component['raw'] = vComponent;
				}
				if(ical[nameComponent+'s'] !== undefined)
					ical[nameComponent+'s'][ical[nameComponent+'s'].length] = component;
			}
		},
		getValue: function(propName,line){
			//console.log(line);
			var prop={};
			line = line.replace(/^\s+/g,'').replace(/\s+$/gi,'');
			reg = new RegExp('('+propName+')((?:;[^=]*=[^;:\n]*)*):([^\n\r]*)','gi');
			var matches = reg.exec(line);
			if(matches){ //on a trouvé la propriété cherchée
				//console.log(propName+' ==] params='+RegExp.$2+' / valeur='+RegExp.$3);
				var valeur = RegExp.$3;
				var tab_params=[];
				if(RegExp.$2.length>0){ //il y a des paramètres associés
					var params = RegExp.$2.substr(1).split(';');
					var pair;
					for(k=0;k<params.length;k++){
						pair = params[k].split('=');
						if(!pair[1]) pair[1] = pair[0];
						tab_params[pair[0]] = pair[1];
					}
				}
				prop = { value:valeur,name:propName };
				if(Object.keys(tab_params).length>0)
					prop.params = tab_params;
			}
			return prop;
		},
	}
	
	
	/**
	* Funktion um ical Datumsstring (YYYYMMDD) in Date Objekt zu wandeln
	*/
	function calenDateFrom(icalStr)  {
		var strYear = icalStr.substr(0,4);
		var strMonth = parseInt(icalStr.substr(4,2),10)-1;
		var strDay = icalStr.substr(6,2);
		var strHour = 0;
		var strMin = 0;
		var strSec = 0;
 
		var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
		return oDate;
	}
	
	function calenDateTo(icalStr)  {
		var strYear = icalStr.substr(0,4);
		var strMonth = parseInt(icalStr.substr(4,2),10)-1;
		var strDay = icalStr.substr(6,2);
		var strHour = 23;
		var strMin = 59;
		var strSec = 59;
 
		var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
		return oDate;
	}
	
    icalParser.parseIcal(input);
	var event = icalParser.icals[0].events[0];
	icalParser.icals[0].events.forEach(function (currentValue, index, originalArray) {
		/**
		*	Prüfen ob das aktuelle Datum zwischen zwei Daten liegt, bzw. auf einen Tag fällt
		*/
		var dateFrom = calenDateFrom(currentValue.dtstart[0].value);
		var dateTo = calenDateTo(currentValue.dtend[0].value);
		var dateCheck = new Date();
 
		if (dateCheck >= dateFrom && dateCheck <= dateTo){
			abfall = currentValue.summary[0].value;
		}
	});
    return abfall;
	//return dateCheck;
	
	
	
})(input);
abfall_morgen.js:

Code: Alles auswählen

var abfall = false;
(function(i) {
 
	var Ical = function Ical(){
		this.version = '';
		this.prodid = '';
		this.events = [];
		this.todos = [];
		this.journals = [];
		this.freebusys = [];
	}
	var xprops = 'x-[^:;]+';
	var ianaprops = '[\\w]+[^:;]+'
	var icalParser = {
		icals : [],
		propsList : {
			'event':'(dtstamp|uid|dtstart|class|created|description|geo|last-mod|location|organizer|priority|seq|status|summary|transp|url|recurid|rrule|dtend|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')',
			'freebusy':'(dtstamp|uid|contact|dtstart|dtend|organizer|url|attendee|comment|freebusy|rstatus|'+xprops+'|'+ianaprops+')',
			'journal':'(dtstamp|uid|class|created|dtstart|last-mod|organizer|recurid|seq|status|summary|url|rrule|attach|attendee|categories|comment|contact|description|exdate|related|rdate|rstatus|'+xprops+'|'+ianaprops+')',
			'todo':'(dtstamp|uid|class|completed|created|description|dtstart|geo|last-mod|location|organizer|percent|priority|recurid|seq|status|summary|url|rrule|due|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')'
		},
		parseIcal : function(icsString){
			var cals = icsString.match(/BEGIN:VCALENDAR\r?\n(.*\r?\n)+?END:VCALENDAR/ig);
			for(var index in cals){
				//console.log("--->"+index+" "+cals[index]);
				var ical = new Ical(); 
				ical.version = this.getValue('VERSION',cals[index]);
				ical.prodid = this.getValue('PRODID',cals[index]);
				cals[index] = cals[index].replace(/\r\n /g,'');
				cals[index] = cals[index].replace(/BEGIN:VCALENDAR\r?\n/ig,'');
				var reg = /BEGIN:(V.*?)\r?\n(.*\r?\n)+?END:\1/gi;
				matches = cals[index].match(reg);
				if(matches){
					for(i=0;i<matches.length;i++){
						//console.log('---------->'+matches[i]+"\n<------------");
						this.parseVComponent(matches[i],ical);
					}
				}
				this.icals[this.icals.length] = ical;
			}
		},
		parseVComponent : function(vComponent,ical){
			var nameComponent = vComponent.match(/BEGIN:V([^\s]+)/i)[1].toLowerCase();
			vComponent = vComponent.replace(/\r?\n[\s]+/igm,''); //unfolding
			vComponent = vComponent.replace(/(^begin|^end):.*/igm,'');
			//console.log(nameComponent+' ++++ '+vComponent);
			var props = vComponent.match(new RegExp(this.propsList[nameComponent]+'[:;].*','gim'));
			if(props){
				var component=[];
				for(var index in props){
					var nom = props[index].replace(/[:;].*$/,'');
					//console.log("--vcompo "+index+" "+nom);
					var propKey = /*'prop_'+*/nom.toLowerCase();
					if(component[propKey]===undefined) component[propKey] = [];
					component[propKey][component[propKey].length] = this.getValue(nom,props[index]);
					component['raw'] = vComponent;
				}
				if(ical[nameComponent+'s'] !== undefined)
					ical[nameComponent+'s'][ical[nameComponent+'s'].length] = component;
			}
		},
		getValue: function(propName,line){
			//console.log(line);
			var prop={};
			line = line.replace(/^\s+/g,'').replace(/\s+$/gi,'');
			reg = new RegExp('('+propName+')((?:;[^=]*=[^;:\n]*)*):([^\n\r]*)','gi');
			var matches = reg.exec(line);
			if(matches){ //on a trouvé la propriété cherchée
				//console.log(propName+' ==] params='+RegExp.$2+' / valeur='+RegExp.$3);
				var valeur = RegExp.$3;
				var tab_params=[];
				if(RegExp.$2.length>0){ //il y a des paramètres associés
					var params = RegExp.$2.substr(1).split(';');
					var pair;
					for(k=0;k<params.length;k++){
						pair = params[k].split('=');
						if(!pair[1]) pair[1] = pair[0];
						tab_params[pair[0]] = pair[1];
					}
				}
				prop = { value:valeur,name:propName };
				if(Object.keys(tab_params).length>0)
					prop.params = tab_params;
			}
			return prop;
		},
	}
	
	
	/**
	* Funktion um ical Datumsstring (YYYYMMDD) in Date Objekt zu wandeln
	*/
	function calenDateFrom(icalStr)  {
		var strYear = icalStr.substr(0,4);
		var strMonth = parseInt(icalStr.substr(4,2),10)-1;
		var strDay = icalStr.substr(6,2)-1;
		var strHour = 0;
		var strMin = 0;
		var strSec = 0;
 
		var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
		return oDate;
	}
	
	function calenDateTo(icalStr)  {
		var strYear = icalStr.substr(0,4);
		var strMonth = parseInt(icalStr.substr(4,2),10)-1;
		var strDay = icalStr.substr(6,2)-1;
		var strHour = 23;
		var strMin = 59;
		var strSec = 59;
 
		var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
		return oDate;
	}
	
    icalParser.parseIcal(input);
	var event = icalParser.icals[0].events[0];
	icalParser.icals[0].events.forEach(function (currentValue, index, originalArray) {
		/**
		*	Prüfen ob das aktuelle Datum zwischen zwei Daten liegt, bzw. auf einen Tag fällt
		*/
		var dateFrom = calenDateFrom(currentValue.dtstart[0].value);
		var dateTo = calenDateTo(currentValue.dtend[0].value);
		var dateCheck = new Date();
 
		if (dateCheck >= dateFrom && dateCheck <= dateTo){
			abfall = currentValue.summary[0].value;
		}
	});
    return abfall;
	//return dateCheck;
	
	
	
})(input);
abfall_naechste_abholung_datum.js:

Code: Alles auswählen

var abfall = false;
(function(i) {
 
    var Ical = function Ical(){
        this.version = '';
        this.prodid = '';
        this.events = [];
        this.todos = [];
        this.journals = [];
        this.freebusys = [];
    }
    var xprops = 'x-[^:;]+';
    var ianaprops = '[\\w]+[^:;]+'
    var icalParser = {
        icals : [],
        propsList : {
            'event':'(dtstamp|uid|dtstart|class|created|description|geo|last-mod|location|organizer|priority|seq|status|summary|transp|url|recurid|rrule|dtend|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')',
            'freebusy':'(dtstamp|uid|contact|dtstart|dtend|organizer|url|attendee|comment|freebusy|rstatus|'+xprops+'|'+ianaprops+')',
            'journal':'(dtstamp|uid|class|created|dtstart|last-mod|organizer|recurid|seq|status|summary|url|rrule|attach|attendee|categories|comment|contact|description|exdate|related|rdate|rstatus|'+xprops+'|'+ianaprops+')',
            'todo':'(dtstamp|uid|class|completed|created|description|dtstart|geo|last-mod|location|organizer|percent|priority|recurid|seq|status|summary|url|rrule|due|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')'
        },
        parseIcal : function(icsString){
            var cals = icsString.match(/BEGIN:VCALENDAR\r?\n(.*\r?\n)+?END:VCALENDAR/ig);
            for(var index in cals){
                //console.log("--->"+index+" "+cals[index]);
                var ical = new Ical();
                ical.version = this.getValue('VERSION',cals[index]);
                ical.prodid = this.getValue('PRODID',cals[index]);
                cals[index] = cals[index].replace(/\r\n /g,'');
                cals[index] = cals[index].replace(/BEGIN:VCALENDAR\r?\n/ig,'');
                var reg = /BEGIN:(V.*?)\r?\n(.*\r?\n)+?END:\1/gi;
                matches = cals[index].match(reg);
                if(matches){
                    for(i=0;i<matches.length;i++){
                        //console.log('---------->'+matches[i]+"\n<------------");
                        this.parseVComponent(matches[i],ical);
                    }
                }
                this.icals[this.icals.length] = ical;
            }
        },
        parseVComponent : function(vComponent,ical){
            var nameComponent = vComponent.match(/BEGIN:V([^\s]+)/i)[1].toLowerCase();
            vComponent = vComponent.replace(/\r?\n[\s]+/igm,''); //unfolding
            vComponent = vComponent.replace(/(^begin|^end):.*/igm,'');
            //console.log(nameComponent+' ++++ '+vComponent);
            var props = vComponent.match(new RegExp(this.propsList[nameComponent]+'[:;].*','gim'));
            if(props){
                var component=[];
                for(var index in props){
                    var nom = props[index].replace(/[:;].*$/,'');
                    //console.log("--vcompo "+index+" "+nom);
                    var propKey = /*'prop_'+*/nom.toLowerCase();
                    if(component[propKey]===undefined) component[propKey] = [];
                    component[propKey][component[propKey].length] = this.getValue(nom,props[index]);
                    component['raw'] = vComponent;
                }
                if(ical[nameComponent+'s'] !== undefined)
                    ical[nameComponent+'s'][ical[nameComponent+'s'].length] = component;
            }
        },
        getValue: function(propName,line){
            //console.log(line);
            var prop={};
            line = line.replace(/^\s+/g,'').replace(/\s+$/gi,'');
            reg = new RegExp('('+propName+')((?:;[^=]*=[^;:\n]*)*):([^\n\r]*)','gi');
            var matches = reg.exec(line);
            if(matches){ //on a trouvé la propriété cherchée
                //console.log(propName+' ==] params='+RegExp.$2+' / valeur='+RegExp.$3);
                var valeur = RegExp.$3;
                var tab_params=[];
                if(RegExp.$2.length>0){ //il y a des paramètres associés
                    var params = RegExp.$2.substr(1).split(';');
                    var pair;
                    for(k=0;k<params.length;k++){
                        pair = params[k].split('=');
                        if(!pair[1]) pair[1] = pair[0];
                        tab_params[pair[0]] = pair[1];
                    }
                }
                prop = { value:valeur,name:propName };
                if(Object.keys(tab_params).length>0)
                    prop.params = tab_params;
            }
            return prop;
        },
    }
   
   
    /**
    * Funktion um ical Datumsstring (YYYYMMDD) in Date Objekt zu wandeln
    */
    function calenDateFrom(icalStr)  {
        var strYear = icalStr.substr(0,4);
        var strMonth = parseInt(icalStr.substr(4,2),10)-1;
        var strDay = icalStr.substr(6,2);
        var strHour = 0;
        var strMin = 0;
        var strSec = 0;
 
        var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
        return oDate;
    }
   
    function calenDateTo(icalStr)  {
        var strYear = icalStr.substr(0,4);
        var strMonth = parseInt(icalStr.substr(4,2),10)-1;
        var strDay = icalStr.substr(6,2);
        var strHour = 23;
        var strMin = 59;
        var strSec = 59;
 
        var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
        return oDate;
    }
   
   
    var stopper = 0;
    icalParser.parseIcal(input);
    var event = icalParser.icals[0].events[0];
    icalParser.icals[0].events.forEach(function (currentValue, index, originalArray) {
        /**
        *   Prüfen ob das aktuelle Datum zwischen zwei Daten liegt, bzw. auf einen Tag fällt
        */
        var dateFrom = calenDateFrom(currentValue.dtstart[0].value);
        var dateTo = calenDateTo(currentValue.dtend[0].value);
        var dateCheck = new Date();
 
        if (dateFrom >= dateCheck && stopper == 0){
            //var dateTo2 = dateTo.toString();
            //var dateTo2 = new Date(dateTo).toLocaleString();
            abfall = dateTo.getFullYear() + "-" + (dateTo.getMonth() + 1) + "-" + dateTo.getDate() + "T00:00:00"
            stopper = 1;
        }
       
    });
    return abfall;
   
   
   
})(input);
abfall_naechste_abholung_name.js:

Code: Alles auswählen

var abfall = false;
(function(i) {
 
    var Ical = function Ical(){
        this.version = '';
        this.prodid = '';
        this.events = [];
        this.todos = [];
        this.journals = [];
        this.freebusys = [];
    }
    var xprops = 'x-[^:;]+';
    var ianaprops = '[\\w]+[^:;]+'
    var icalParser = {
        icals : [],
        propsList : {
            'event':'(dtstamp|uid|dtstart|class|created|description|geo|last-mod|location|organizer|priority|seq|status|summary|transp|url|recurid|rrule|dtend|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')',
            'freebusy':'(dtstamp|uid|contact|dtstart|dtend|organizer|url|attendee|comment|freebusy|rstatus|'+xprops+'|'+ianaprops+')',
            'journal':'(dtstamp|uid|class|created|dtstart|last-mod|organizer|recurid|seq|status|summary|url|rrule|attach|attendee|categories|comment|contact|description|exdate|related|rdate|rstatus|'+xprops+'|'+ianaprops+')',
            'todo':'(dtstamp|uid|class|completed|created|description|dtstart|geo|last-mod|location|organizer|percent|priority|recurid|seq|status|summary|url|rrule|due|duration|attach|attendee|categories|comment|contact|exdate|rstatus|related|resources|rdate|'+xprops+'|'+ianaprops+')'
        },
        parseIcal : function(icsString){
            var cals = icsString.match(/BEGIN:VCALENDAR\r?\n(.*\r?\n)+?END:VCALENDAR/ig);
            for(var index in cals){
                //console.log("--->"+index+" "+cals[index]);
                var ical = new Ical();
                ical.version = this.getValue('VERSION',cals[index]);
                ical.prodid = this.getValue('PRODID',cals[index]);
                cals[index] = cals[index].replace(/\r\n /g,'');
                cals[index] = cals[index].replace(/BEGIN:VCALENDAR\r?\n/ig,'');
                var reg = /BEGIN:(V.*?)\r?\n(.*\r?\n)+?END:\1/gi;
                matches = cals[index].match(reg);
                if(matches){
                    for(i=0;i<matches.length;i++){
                        //console.log('---------->'+matches[i]+"\n<------------");
                        this.parseVComponent(matches[i],ical);
                    }
                }
                this.icals[this.icals.length] = ical;
            }
        },
        parseVComponent : function(vComponent,ical){
            var nameComponent = vComponent.match(/BEGIN:V([^\s]+)/i)[1].toLowerCase();
            vComponent = vComponent.replace(/\r?\n[\s]+/igm,''); //unfolding
            vComponent = vComponent.replace(/(^begin|^end):.*/igm,'');
            //console.log(nameComponent+' ++++ '+vComponent);
            var props = vComponent.match(new RegExp(this.propsList[nameComponent]+'[:;].*','gim'));
            if(props){
                var component=[];
                for(var index in props){
                    var nom = props[index].replace(/[:;].*$/,'');
                    //console.log("--vcompo "+index+" "+nom);
                    var propKey = /*'prop_'+*/nom.toLowerCase();
                    if(component[propKey]===undefined) component[propKey] = [];
                    component[propKey][component[propKey].length] = this.getValue(nom,props[index]);
                    component['raw'] = vComponent;
                }
                if(ical[nameComponent+'s'] !== undefined)
                    ical[nameComponent+'s'][ical[nameComponent+'s'].length] = component;
            }
        },
        getValue: function(propName,line){
            //console.log(line);
            var prop={};
            line = line.replace(/^\s+/g,'').replace(/\s+$/gi,'');
            reg = new RegExp('('+propName+')((?:;[^=]*=[^;:\n]*)*):([^\n\r]*)','gi');
            var matches = reg.exec(line);
            if(matches){ //on a trouvé la propriété cherchée
                //console.log(propName+' ==] params='+RegExp.$2+' / valeur='+RegExp.$3);
                var valeur = RegExp.$3;
                var tab_params=[];
                if(RegExp.$2.length>0){ //il y a des paramètres associés
                    var params = RegExp.$2.substr(1).split(';');
                    var pair;
                    for(k=0;k<params.length;k++){
                        pair = params[k].split('=');
                        if(!pair[1]) pair[1] = pair[0];
                        tab_params[pair[0]] = pair[1];
                    }
                }
                prop = { value:valeur,name:propName };
                if(Object.keys(tab_params).length>0)
                    prop.params = tab_params;
            }
            return prop;
        },
    }
   
   
    /**
    * Funktion um ical Datumsstring (YYYYMMDD) in Date Objekt zu wandeln
    */
    function calenDateFrom(icalStr)  {
        var strYear = icalStr.substr(0,4);
        var strMonth = parseInt(icalStr.substr(4,2),10)-1;
        var strDay = icalStr.substr(6,2);
        var strHour = 0;
        var strMin = 0;
        var strSec = 0;
 
        var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
        return oDate;
    }
   
    function calenDateTo(icalStr)  {
        var strYear = icalStr.substr(0,4);
        var strMonth = parseInt(icalStr.substr(4,2),10)-1;
        var strDay = icalStr.substr(6,2);
        var strHour = 23;
        var strMin = 59;
        var strSec = 59;
 
        var oDate =  new Date(strYear,strMonth, strDay, strHour, strMin, strSec)
 
        return oDate;
    }
   
   
    var stopper = 0;
    icalParser.parseIcal(input);
    var event = icalParser.icals[0].events[0];
    icalParser.icals[0].events.forEach(function (currentValue, index, originalArray) {
        /**
        *   Prüfen ob das aktuelle Datum zwischen zwei Daten liegt, bzw. auf einen Tag fällt
        */
        var dateFrom = calenDateFrom(currentValue.dtstart[0].value);
        var dateTo = calenDateTo(currentValue.dtend[0].value);
        var dateCheck = new Date();
 
       
       
        if (dateFrom >= dateCheck && stopper == 0){
            abfall = currentValue.summary[0].value;
            stopper = 1;
        }
       
    });
    return abfall;
   
   
   
})(input);

mig81
Beiträge: 1
Registriert: 9. Nov 2017 22:37

Re: Müllkalender via openHAB

Beitrag von mig81 »

Hallo zusammen,

ich bin gerade dabei den Müllkalender in meinem Openhab Panel darzustellen.

Habe mein Betreibe gefragt ob er mir den Url Link rausgibt, leider war es nicht möglich :-( mir den Link zu geben.

Gibt es noch eine andere Möglichkeit die .ics Datei einzubinden?

Vielen Dank

Benutzeravatar
seppy
Beiträge: 738
Registriert: 24. Sep 2015 20:25
Answers: 4
Wohnort: Bonn

Re: Müllkalender via openHAB

Beitrag von seppy »

Hi,
hast Du die ICS Datei?
Grüße,
Seppy
Homematic und HomematicIP über Raspberrymatic (RaspPi 4 4GB) mit 2x HMLAN. Steuerung und Visualisierung durch OpenHAB2 auf RaspPi in Hutschienengehäuse im Sicherungskasten. Rund 100 Aktoren/Sensoren

- Abgesichert durch APC USV
- Bewässerungssteuerung mit Hunter Magnetventilen (HM-LC-Sw4-DR)
- Beleuchtungssteuerung Innen und Aussen (HM-LC-Sw4-DR + HM-LC-SW1-FM + HMW-IO-12-SW7-DR)
- Rolladensteuerung mit Beschattungsautomatik über Temperaturdifferenzsensor (HM-LC-Bl1PBU-FM)
- Wetter und Unwetterinformationen von wunderground
- Benachrichtigung der Bewohner via Pushover
- Multimediawand und Dreambox Steuerung (HM-LC-SW1-FM)
- Heizungssteuerung mit Komfort und Energiesparfunktionen (HM-CC-RT-DN + HM-Sec-SC-2 + HMIP-eTRV-2)
- Werkstatt Kompressorsteuerung (HMW-IO-12-SW7-DR)
- Weihnachtsbeleuchtung außen
- Präsenzerkennung über Geolocation (iCloud Binding), iBeacon und WLAN (Unifi Binding)
- Philips HUE & Tasmota Devices (Tuya) Einbindung

pariegl
Beiträge: 3
Registriert: 25. Nov 2017 15:23

Re: Müllkalender via openHAB

Beitrag von pariegl »

Hallo

Bin ziemlich neu unterwegs min Openhab2
Hab mir den Ferien & Feiertagskalender hier mal abgeschaut und dieser läuft bei mir
nun wollte ich den Müllkalender auch noch hinzufügen.
leider bietet meine Gemeinde die Termine nur als PDF an also hab ich mir selber einen ICS Kalender mit diesen Terminen erstellt.
Nun aber die Frage wie ich diesen in openhab einbinden kann?

Hoffe es kann mir einer von euch helfen

Lg,
Patrick

Benutzeravatar
seppy
Beiträge: 738
Registriert: 24. Sep 2015 20:25
Answers: 4
Wohnort: Bonn

Re: Müllkalender via openHAB

Beitrag von seppy »

Hi,
genau wie ich im ersten Post geschrieben habe. Du ersetzt eben im Item alles (http://URL.local/static/RSAG_Abfuhrtermine_%1$tY.ics) durch Deinen Pfad zum ICS:

Code: Alles auswählen

String GlobalGarbageICAL
	{http="<[http://URL.local/static/RSAG_Abfuhrtermine_%1$tY.ics:1800000:JS(ical_garbage.js)]"}
Grüße,
Seppy
Homematic und HomematicIP über Raspberrymatic (RaspPi 4 4GB) mit 2x HMLAN. Steuerung und Visualisierung durch OpenHAB2 auf RaspPi in Hutschienengehäuse im Sicherungskasten. Rund 100 Aktoren/Sensoren

- Abgesichert durch APC USV
- Bewässerungssteuerung mit Hunter Magnetventilen (HM-LC-Sw4-DR)
- Beleuchtungssteuerung Innen und Aussen (HM-LC-Sw4-DR + HM-LC-SW1-FM + HMW-IO-12-SW7-DR)
- Rolladensteuerung mit Beschattungsautomatik über Temperaturdifferenzsensor (HM-LC-Bl1PBU-FM)
- Wetter und Unwetterinformationen von wunderground
- Benachrichtigung der Bewohner via Pushover
- Multimediawand und Dreambox Steuerung (HM-LC-SW1-FM)
- Heizungssteuerung mit Komfort und Energiesparfunktionen (HM-CC-RT-DN + HM-Sec-SC-2 + HMIP-eTRV-2)
- Werkstatt Kompressorsteuerung (HMW-IO-12-SW7-DR)
- Weihnachtsbeleuchtung außen
- Präsenzerkennung über Geolocation (iCloud Binding), iBeacon und WLAN (Unifi Binding)
- Philips HUE & Tasmota Devices (Tuya) Einbindung

Antworten