Page 3 of 5

Re: Dashticz - Module - Public Transport

Posted: Friday 11 August 2017 14:52
by robgeerts
Could you send me your config (the transport part) so I can test with it later?

Re: Dashticz - Module - Public Transport

Posted: Tuesday 15 August 2017 15:25
by Luxtux
I've added the real-time public transport of Luxembourg to the public transport script. It should show the time a bus or train arrives at a public transport stop in the entire country. just use the name of your stop you normally use on mobiliteit.lu

Code: Select all

var publictransport = {}
publictransport.busstop = { show_via: false, station: 'Luxembourg/Centre, Royal', provider: 'mobiliteit',title:'Royal Stop',show_lastupdate:true, icon: 'bus', width:6,  results: 4}

Code: Select all

function loadPublicTransport(random,transportobject,key){
        var width = 12;
        if(typeof(transportobject.width)!=='undefined') width=transportobject.width;
        var html='<div data-id="publictransport.'+key+'" class="col-xs-'+width+'" style="padding-left:0px !important;padding-right:0px !important;">';
        if(typeof(transportobject.title)!=='undefined') html+='<div class="col-xs-12 mh titlegroups transbg"><h3>'+transportobject.title+'</h3></div>';

        html+='<div class="publictransport publictransport'+random+' col-xs-12 transbg">';
                if(typeof(transportobject.icon)!=='undefined' && transportobject.icon!==''){
                        if(transportobject.icon.substr(0,2)!=='fa') transportobject.icon = 'fa-'+transportobject.icon;
                        html+='<div class="col-xs-2 col-icon">';
                                html+='<em class="fa '+transportobject.icon+'"></em>';
                        html+='</div>';
                        html+='<div class="col-xs-10 col-data">';
                                html+='<span class="state"></span>';
                        html+='</div>';
                }
                else {
                                html+='<div class="col-xs-12 col-data">';
                                        html+='<span class="state"></span>';
                                html+='</div>';
                }
                html+='</div>';

        html+='</div>';

        //Get data every interval and call function to create block
        var interval = 60;
        if(typeof(transportobject.interval)!=='undefined') interval = transportobject.interval;
        getData(random,transportobject);
        setTimeout(function(){$('.publictransport'+random+' .state').html(language.misc.loading);},100);

        if(transportobject.provider.toLowerCase() == 'ns'){
                if(parseFloat(interval)<60) interval=60; // limit request because of limitations in NS api for my private key ;)
        }

        setInterval(function(){
                getData(random,transportobject)
        },(interval * 1000));
        return html;
}


function getData(random,transportobject){
        var provider = transportobject.provider.toLowerCase();
        if(provider == 'vvs'){
                dataURL = 'https://efa-api.asw.io/api/v1/station/'+transportobject.station+'/departures/';
        }
        else if(provider == 'mobiliteit'){
                dataURL = 'https://cors-anywhere.herokuapp.com/http://travelplanner.mobiliteit.lu/restproxy/departureBoard?accessId=cdt&format=json&id=A=1@O$
        }
        else if(provider == '9292' || provider == '9292-train' || provider == '9292-bus' || provider == '9292-metro' || provider == '9292-tram-bus'){
                dataURL = 'https://cors-anywhere.herokuapp.com/http://api.9292.nl/0.1/locations/'+transportobject.station+'/departure-times?lang=nl-NL&time=$
        }

        $.getJSON(dataURL,function(data){
                dataPublicTransport(random,data,transportobject);
        });

}

function dataPublicTransport(random,data,transportobject){
        var provider = transportobject.provider.toLowerCase();
        var dataPart = {}
        var i = 0;
        for(d in data){
                if(provider == '9292' || provider == '9292-train' || provider == '9292-bus' || provider =='9292-metro' || provider == '9292-tram-bus'){
                        for(t in data[d]){
                                if(provider == '9292' ||
                                   (data[d][t]['id']=='bus' && provider == '9292-bus') ||
                                   (data[d][t]['id']=='metro' && provider == '9292-metro') ||
                                   (data[d][t]['id']=='tram-bus' && provider == '9292-tram-bus') ||
                                   (data[d][t]['id']=='trein' && provider == '9292-train')
                                ){
                                        deps = data[d][t]['departures'];
                                        for(de in deps){
                                                key = deps[de]['time'];
                                                if(typeof(dataPart[key])=='undefined') dataPart[key]=[];
                                                dataPart[key][i]='';
                                                dataPart[key][i]+='<div><b>'+deps[de]['time']+'</b> ';
                                                if(deps[de]['realtimeText']!=null) dataPart[key][i]+='<span id="latetrain">'+deps[de]['realtimeText'].replac$
                                                if(deps[de]['platform']!=null) dataPart[key][i]+='- Spoor '+deps[de]['platform'];
                                                else dataPart[key][i]+='- Lijn '+deps[de]['service'];

                                                dest = deps[de]['destinationName'].split(' via ');
                                                dataPart[key][i]+=' - '+dest[0];
                                                if(typeof(transportobject.show_via)=='undefined' || transportobject.show_via==true){
                                                        if(typeof(dest[1])!=='undefined') dataPart[key][i]+=' via '+dest[1];
                                                        else if(typeof(deps[de]['RouteTekst'])!=='undefined') dataPart[key][i]+=' via '+deps[de]['viaNames'];
                                                }
                                                dataPart[key][i]+=' </div>';
                                                i++;
                                        }
                                }
                        }
                }
				                else if(provider == 'mobiliteit') {
                        for(t in data[d]) {
                                if(data[d][t]['time']==null){
                                        continue;
                                }
                                key = data[d][t]['time'];
                                if(typeof(dataPart[key])=='undefined') dataPart[key]=[];
                                BusTime = data[d][t]['time'].slice(0,-3);
                                dataPart[key][i]='';
                                dataPart[key][i]+='<div><b>'+ BusTime +'</b> ';
                                dataPart[key][i]+=' - '+data[d][t]['name']+' - ';
                                //console.log(data[d][t]['time']+ ' - ' +data[d][t]['name']+ ' - ' +data[d][t]['direction'] );
                                dest = data[d][t]['direction'].split(' via ');
                                dataPart[key][i]+=dest[0];
                                if(typeof(transportobject.show_via)=='undefined' || transportobject.show_via==true){
                                        if(typeof(dest[1])!=='undefined') dataPart[key][i]+=' via '+dest[1];
                                }

                                dataPart[key][i]+=' </div>';
                        }
                }

                else if(provider == 'vvs'){
                        arrivalTime = data[d]['departureTime']['year']+':'+data[d]['departureTime']['month']+':'+data[d]['departureTime']['day']+':'+addZero$
                        arrivalTimeShow = addZero(data[d]['departureTime']['hour'])+':'+addZero(data[d]['departureTime']['minute']);
                        if(typeof(dataPart[arrivalTime])=='undefined') dataPart[arrivalTime]=[];
                        dataPart[arrivalTime][i] = '';
                        arrivalTimeScheduled = addMinutes(arrivalTimeShow, data[d]['delay']*-1);
                        dataPart[arrivalTime][i]+='<div><b>'+arrivalTimeShow+'</b> ';
                        if(data[d]['delay'] == 0) latecolor='notlatetrain';
                        if(data[d]['delay'] > 0) latecolor='latetrain';
                        dataPart[arrivalTime][i]+='<span id="'+latecolor+'">+'+data[d]['delay']+' Min.</span> ';
                        dataPart[arrivalTime][i]+='<span id="departureScheduled">('+language.misc.scheduled+': '+arrivalTimeScheduled+')</span> ';
                        dataPart[arrivalTime][i]+='- '+data[d]['number']+' ';

                        dest = data[d]['direction'].split(' via ');
                        dataPart[arrivalTime][i]+=dest[0];
                        if(typeof(transportobject.show_via)=='undefined' || transportobject.show_via==true){
                                if(typeof(dest[1])!=='undefined') dataPart[arrivalTime][i]+=' via '+dest[1];
                        }

                        dataPart[arrivalTime][i]+='</div>';
                        i++;
                }
        }

        $('.publictransport'+random+' .state').html('');
        var c = 1;
        Object.keys(dataPart).forEach(function(d) {
        //Object.keys(dataPart).sort().forEach(function(d) {
                for(p in dataPart[d]){
                        if(c<=transportobject.results) $('.publictransport'+random+' .state').append(dataPart[d][p]);
                        c++;
                }
        });

        if(typeof(transportobject.show_lastupdate)!=='undefined' && transportobject.show_lastupdate==true){
                var dt = new Date();
                $('.publictransport'+random+' .state').append('<em>'+language.misc.last_update+': '+addZero(dt.getHours()) + ":"+addZero(dt.getMinutes())+":$
        }
}

function addZero(input){
        if(input < 10){
                return '0' + input;
        }
        else{
                return input;
        }
}
function addMinutes(time/*"hh:mm"*/, minsToAdd/*"N"*/) {
  function z(n){
    return (n<10? '0':'') + n;
  }
  var bits = time.split(':');
  var mins = bits[0]*60 + (+bits[1]) + (+minsToAdd);

  return z(mins%(24*60)/60 | 0) + ':' + z(mins%60);
}


Re: Dashticz - Module - Public Transport

Posted: Tuesday 15 August 2017 17:42
by robgeerts
Although your code didnt work immediately (forgot an ' and forgot to add a variable to te script) I fixed this and added mobiliteit.lu to the latest beta!
Thanks!

Re: Dashticz - Module - Public Transport

Posted: Tuesday 29 August 2017 19:21
by Luxtux
little update for mobiliteit. it now shows the delay if bus/train or tram is equipped with live tracking.

Code: Select all

		else if(provider == 'mobiliteit') {
			for(t in data[d]) {
				if(data[d][t]['time']==null){
					continue;
				}
				key = data[d][t]['time'];
				if(typeof(dataPart[key])=='undefined') dataPart[key]=[];
				var fullArrivalDate = data[d][t]['date'] + ' ' + data[d][t]['time'];
				var arrivalTime =  moment(fullArrivalDate);
				var delay = 'Null';
				if (data[d][t]['rtTime']) {
					var fullRealArrivalDate = data[d][t]['rtDate'] + ' ' + data[d][t]['rtTime'];
					var realArrivalTime = moment(fullRealArrivalDate);
					var delay = '+' + realArrivalTime.diff(arrivalTime, 'minutes');
				}
				dataPart[key][i]='';
				dataPart[key][i]+='<div><b>'+ arrivalTime.format('HH:mm') +'</b> ';
			
				if (delay <= 0) {
					dataPart[key][i]+='<span id="notlatetrain">'+delay+'</span> ';
				} 
				else if (delay > 0) {
					dataPart[key][i]+='<span id="latetrain">'+delay+'</span> ';
				}
				
				dataPart[key][i]+=' - '+data[d][t]['name']+' - ';
				

				dest = data[d][t]['direction'].split(' via ');
				dataPart[key][i]+=dest[0];
				if(typeof(transportobject.show_via)=='undefined' || transportobject.show_via==true){
					if(typeof(dest[1])!=='undefined') dataPart[key][i]+=' via '+dest[1];
				}

				dataPart[key][i]+=' </div>';
			}
		}

Re: Dashticz - Module - Public Transport

Posted: Tuesday 29 August 2017 20:05
by robgeerts
Added to latest beta! Thanks!

Re: Dashticz - Module - Public Transport

Posted: Sunday 03 December 2017 22:23
by Zoekm
freakshock wrote: Tuesday 16 May 2017 21:06 Idea for a configurable feature for this module:
How about making it possible to exclude results between the current time and the first departure time listed?

For instance: I have added my local trainstation near my house. It takes at least 15 minutes from my house to get there. It would be nice to be able to exclude results that show the trains leaving from the current time +15 minutes.

If I don't have this feature I have to make my list really long :lol:
Is this an option already? I would love to have the option to select an offset of for example 30 min. So I will only see trains departing 30 min or later from now. At the moment I only see trains that I will never be able to make, as I need 30 min to get to the station and the list of departures in the next 30 min is too long for my screen....

Re: Dashticz - Module - Public Transport

Posted: Thursday 01 February 2018 21:43
by Brunard
Hi everybody and special thanks to Robgeert for his huge work!

I'm trying to use the module for transportation in my city but i'm not able to develop the missing code alone :(

Is there someone to help me? I will send username and password by PM to the ones who want to help.

This is the URL :

Code: Select all

 http://opendata.cts-strasbourg.eu/webservice_v5_alpha/opendata_v5.svc/getnextdepartures/<USERNAME>/<PASSWORD>/<STATION NUMBER>
This is the JSON structure :

Code: Select all

{"departures":[{"destination":"2 Elmerforst","mode":"Bus","time":"21:03:11"},{"destination":"B Lingolsheim Tiergaertel","mode":"Tram","time":"21:05:07"},{"destination":"B Hoenheim Gare","mode":"Tram","time":"21:05:41"},{"destination":"F Elsau","mode":"Tram","time":"21:10:38"},{"destination":"2 Jardin des Deux Rives","mode":"Bus","time":"21:10:42"},{"destination":"L1 Lingolsheim Alouettes","mode":"Bus","time":"21:14:42"},{"destination":"F Place d'Islande","mode":"Tram","time":"21:15:16"}],"requestedtime":"21:01","serverdatetime":"01\/02\/2018 21:01:31","stop":"Laiterie"}
Thank you veeeery much !

Brunard

Re: Dashticz - Module - Public Transport

Posted: Sunday 04 February 2018 20:55
by clubeddie
robgeerts wrote: Tuesday 16 May 2017 13:16 Yes, use:

Code: Select all

var publictransport = {}
publictransport.ovinfobus= { station: 'andelst/bushalte-wilhelminastraat', provider: '9292-bus', icon: 'bus', results: 5 };
How can i use it with the ferry, like "https://9292.nl/alblasserdam/halte-veer-kade"

When i use station: 'alblasserdam/halte-veer-kade' it won't respond

Re: Dashticz - Module - Public Transport

Posted: Tuesday 06 February 2018 21:06
by robgeerts
Could you test this in latest beta:

Code: Select all

var publictransport = {}
publictransport.ovinfobus= { key:'ovinfobus', show_via: false, station: 'alblasserdam/bushalte-veer-kade', provider: '9292-boat', icon: 'ship', width:5, results: 6 }

Re: Dashticz - Module - Public Transport

Posted: Tuesday 06 February 2018 22:44
by clubeddie
robgeerts wrote: Tuesday 06 February 2018 21:06 Could you test this in latest beta:

Code: Select all

var publictransport = {}
publictransport.ovinfobus= { key:'ovinfobus', show_via: false, station: 'alblasserdam/bushalte-veer-kade', provider: '9292-boat', icon: 'ship', width:5, results: 6 }
Thanks for your reply. Tried it, only get "Loading..."
Edit: Don't know if it help searching, but i noticed in the publictransport.js that provider == '9292-boat' is not in all the lines as for example 9292-train is. I tried to add them if to see if it helps, but no success so far, but i am not an programmer.

Re: Dashticz - Module - Public Transport

Posted: Tuesday 13 February 2018 20:49
by clubeddie
clubeddie wrote: Tuesday 06 February 2018 22:44
robgeerts wrote: Tuesday 06 February 2018 21:06 Could you test this in latest beta:

Code: Select all

var publictransport = {}
publictransport.ovinfobus= { key:'ovinfobus', show_via: false, station: 'alblasserdam/bushalte-veer-kade', provider: '9292-boat', icon: 'ship', width:5, results: 6 }
Thanks for your reply. Tried it, only get "Loading..."
Edit: Don't know if it help searching, but i noticed in the publictransport.js that provider == '9292-boat' is not in all the lines as for example 9292-train is. I tried to add them if to see if it helps, but no success so far, but i am not an programmer.
@robgeerts, do you have any idea? Hope to get this working.

Re: Dashticz - Module - Public Transport

Posted: Friday 16 February 2018 10:08
by robgeerts
Did you update to latest beta???

Re: Dashticz - Module - Public Transport

Posted: Saturday 17 February 2018 19:32
by clubeddie
robgeerts wrote: Friday 16 February 2018 10:08 Did you update to latest beta???
Yep, latest beta. Just download it again and tried it (don't know if you have a new version), but same result. Only text "loading..."

Re: Dashticz - Module - Public Transport

Posted: Friday 23 March 2018 20:48
by Beschuitje
Train is not showing any notifications. It keeps saying “0 notifications” but when you click the button rijdendetreinen.nl does give notifications.
I checked the JS file with traffic (wich is basically the same module) but cant’t find anything why i shoudn’t work. Traffic namely does work
Anyone here have a clue?

Re: Dashticz - Module - Public Transport

Posted: Saturday 24 March 2018 17:42
by Beschuitje
Found the cause for the "0 meldingen" on "train"

In NS.js

Code: Select all

var count = 0;
			$(data).find("item").each(function () { // or "item" or whatever suits your feed
                var el = $(this);
               if(el.find("title").text().substr(0,8)!=='Opgelost'){
				count++;
Change "item" to "title". I now have 12 notifications

Code: Select all

count = 0;
			$(data).find("title").each(function () { // or "item" or whatever suits your feed
                var el = $(this);
               if(el.find("title").text().substr(0,8)!=='Opgelost'){
				count++;

Re: Dashticz - Module - Public Transport

Posted: Wednesday 04 April 2018 10:05
by angelus1753
I've finally got a new NAS capable of running Domoticz/Dashticz and I am really impressed by the great work/contributions of the developers!
I wanted a title bar in my bus, but dislike the original approach. So I started fiddling and wanted to share my result with you here:

publictransport.js
* I removed transportobject.title from the top and added it to the col-icon creation.

Code: Select all

html+='<div class="col-icon">';
	html+='<em class="fa '+transportobject.icon+'"></em>';
	html+='<div class="col-title">';
	if(typeof(transportobject.title)!=='undefined') html+=transportobject.title;			
	html+='</div>';
html+='</div>';
CSS

Code: Select all

.col-icon {	
	padding-bottom: 8px;
}
.fa {
	display: inline
}
.col-title {
	font-weight: bold;	
	font-size:15px;
	display: inline;
	padding-left: 12px;
}
@media (max-width: 1400px) {
	.transbg.col-xs-1, .transbg.col-xs-2, .transbg.col-xs-3, .transbg.col-xs-4, .transbg.col-xs-5, .transbg.col-xs-6, .transbg.col-xs-7, .transbg.col-xs-8, .transbg.col-xs-9, .transbg.col-xs-10, .transbg.col-xs-11, .transbg.col-xs-12 {
		padding-top: 8px;
	}		
	.col-icon {	
		padding-bottom: 4px;
	}	
	.fa {
		padding-right: 3px;
	}
	.col-title {
		padding-left: 4px;
		font-size: 12px;
	}
}
This also gives the col-icon some more room at the bottom when it moves to the top.
Someone more gifted with CSS can perhaps make the title text disappear when the icon is situated on the left and show the title when it's at the top perhaps.

Re: Dashticz - Module - Public Transport

Posted: Wednesday 04 April 2018 10:08
by angelus1753
On a different note;
I wonder if it perhaps is a good idea to put a busstop in the ovinfobus config example so people don't have to search for an hour to work out that the placename uses a forward slash as divider, and not a dash:
leusden/bushalte-rossenberglaan

Re: Dashticz - Module - Public Transport

Posted: Monday 23 April 2018 15:51
by robgeerts
Beschuitje wrote: Saturday 24 March 2018 17:42 Found the cause for the "0 meldingen" on "train"

In NS.js

Code: Select all

var count = 0;
			$(data).find("item").each(function () { // or "item" or whatever suits your feed
                var el = $(this);
               if(el.find("title").text().substr(0,8)!=='Opgelost'){
				count++;
Change "item" to "title". I now have 12 notifications

Code: Select all

count = 0;
			$(data).find("title").each(function () { // or "item" or whatever suits your feed
                var el = $(this);
               if(el.find("title").text().substr(0,8)!=='Opgelost'){
				count++;
Changed in latest beta!

Re: Dashticz - Module - Public Transport

Posted: Thursday 26 April 2018 15:33
by Ectholian
Hoi Rob,

allereerst complimenten voor je werk.

Ik was wat aan het neuzen, en de 9292 api is gewoon publiekelijk benaderbaar. Ik zag ook dat daar geen tijdsfiltering in zat, dus ik vermoed dat je zelf zo'n filtering in je .php hebt gebouwd? Ik zou graag een target-destination willen opgeven zodat ik alleen de bus van mijn huis naar het station in de lijst krijg, en aanvullend ook een 'aankomstlijst' zou kunnen maken. Heb je daar al iets voor op de planning staan? Anders moet ik het zelf even filteren in de javascript :)

Re: Dashticz - Module - Public Transport

Posted: Monday 30 April 2018 15:17
by robgeerts
Ectholian wrote: Thursday 26 April 2018 15:33 Hoi Rob,

allereerst complimenten voor je werk.

Ik was wat aan het neuzen, en de 9292 api is gewoon publiekelijk benaderbaar. Ik zag ook dat daar geen tijdsfiltering in zat, dus ik vermoed dat je zelf zo'n filtering in je .php hebt gebouwd? Ik zou graag een target-destination willen opgeven zodat ik alleen de bus van mijn huis naar het station in de lijst krijg, en aanvullend ook een 'aankomstlijst' zou kunnen maken. Heb je daar al iets voor op de planning staan? Anders moet ik het zelf even filteren in de javascript :)
Thanks for your compliments.
I will take this in consideration!
But, if you have some spare time, you can always add a pull request ;)