98_TRAFFIC.pm 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. #########################################################################
  2. # $Id: 98_TRAFFIC.pm 14094 2017-04-24 08:09:22Z jmike $
  3. # fhem Modul which provides traffic details with Google Distance API
  4. #
  5. # This file is part of fhem.
  6. #
  7. # Fhem is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Fhem is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # versioning: MAJOR.MINOR.PATCH, increment the:
  21. # MAJOR version when you make incompatible API changes
  22. # - includes changing CLI options, changing log-messages
  23. # MINOR version when you add functionality in a backwards-compatible manner
  24. # - includes adding new features and log-messages (as long as they don't break anything existing)
  25. # PATCH version when you make backwards-compatible bug fixes.
  26. #
  27. ##############################################################################
  28. # Changelog:
  29. #
  30. # 2016-07-26 initial release
  31. # 2016-07-28 added eta, readings in minutes
  32. # 2016-08-01 changed JSON decoding/encofing, added stateReading attribute, added outputReadings attribute
  33. # 2016-08-02 added attribute includeReturn, round minutes & smart zero'ing, avoid negative values, added update burst
  34. # 2016-08-05 fixed 3 perl warnings
  35. # 2016-08-09 added auto-update if status returns UNKOWN_ERROR, added outputReading average
  36. # 2016-09-25 bugfix Blocking, improved errormessage
  37. # 2016-10-07 version 1.0, adding to SVN
  38. # 2016-10-15 adding attribute updateSchedule to provide flexible updates, changed internal interval to INTERVAL
  39. # 2016-12-13 adding travelMode, fixing stateReading with value 0
  40. # 2016-12-15 adding reverseWaypoints attribute, adding weblink with auto create route via gmaps on verbose 5
  41. # 2017-04-21 reduced log entries if verbose is not set, fixed JSON error, Map available through FHEM-Web-toggle, and direct link
  42. # Map https, with APIKey, Traffic & customizable, new attributes GoogleMapsStyle,GoogleMapsSize,GoogleMapsLocation,GoogleMapsStroke,GoogleMapsDisableUI
  43. # 2017-04-21 added buttons to save current map settings, renamed attribute GoogleMapsLocation to GoogleMapsCenter
  44. # 2017-04-22 v1.3.2 stroke supports weight and opacity, minor fixes
  45. #
  46. ##############################################################################
  47. package main;
  48. use strict;
  49. use warnings;
  50. use Data::Dumper;
  51. use Time::HiRes qw(gettimeofday);
  52. use LWP::Simple qw($ua get);
  53. use Blocking;
  54. use POSIX;
  55. use JSON;
  56. die "MIME::Base64 missing!" unless(eval{require MIME::Base64});
  57. die "JSON missing!" unless(eval{require JSON});
  58. sub TRAFFIC_Initialize($);
  59. sub TRAFFIC_Define($$);
  60. sub TRAFFIC_Undef($$);
  61. sub TRAFFIC_Set($@);
  62. sub TRAFFIC_Attr(@);
  63. sub TRAFFIC_GetUpdate($);
  64. my %TRcmds = (
  65. 'update' => 'noArg',
  66. );
  67. my $TRVersion = '1.3.2';
  68. sub TRAFFIC_Initialize($){
  69. my ($hash) = @_;
  70. $hash->{DefFn} = "TRAFFIC_Define";
  71. $hash->{UndefFn} = "TRAFFIC_Undef";
  72. $hash->{SetFn} = "TRAFFIC_Set";
  73. $hash->{AttrFn} = "TRAFFIC_Attr";
  74. $hash->{AttrList} =
  75. "disable:0,1 start_address end_address raw_data:0,1 language waypoints returnWaypoints stateReading outputReadings travelMode:driving,walking,bicycling,transit includeReturn:0,1 updateSchedule GoogleMapsStyle:default,silver,dark,night GoogleMapsSize GoogleMapsZoom GoogleMapsCenter GoogleMapsStroke GoogleMapsTrafficLayer:0,1 GoogleMapsDisableUI:0,1 " .
  76. $readingFnAttributes;
  77. $data{FWEXT}{"/TRAFFIC"}{FUNC} = "TRAFFIC";
  78. $data{FWEXT}{"/TRAFFIC"}{FORKABLE} = 1;
  79. $hash->{FW_detailFn} = "TRAFFIC_fhemwebFn";
  80. }
  81. sub TRAFFIC_Define($$){
  82. my ($hash, $allDefs) = @_;
  83. my @deflines = split('\n',$allDefs);
  84. my @apiDefs = split('[ \t]+', shift @deflines);
  85. if(int(@apiDefs) < 3) {
  86. return "too few parameters: 'define <name> TRAFFIC <APIKEY>'";
  87. }
  88. $hash->{NAME} = $apiDefs[0];
  89. $hash->{APIKEY} = $apiDefs[2];
  90. $hash->{VERSION} = $TRVersion;
  91. delete($hash->{BURSTCOUNT}) if $hash->{BURSTCOUNT};
  92. delete($hash->{BURSTINTERVAL}) if $hash->{BURSTINTERVAL};
  93. my $name = $hash->{NAME};
  94. #clear all readings
  95. foreach my $clearReading ( keys %{$hash->{READINGS}}){
  96. Log3 $hash, 5, "TRAFFIC: ($name) READING: $clearReading deleted";
  97. delete($hash->{READINGS}{$clearReading});
  98. }
  99. #clear all helpers
  100. foreach my $helperName ( keys %{$hash->{helper}}){
  101. delete($hash->{helper}{$helperName});
  102. }
  103. # clear weblink
  104. FW_fC("delete ".$name."_weblink");
  105. # basic update INTERVAL
  106. if(scalar(@apiDefs) > 3 && $apiDefs[3] =~ m/^\d+$/){
  107. $hash->{INTERVAL} = $apiDefs[3];
  108. }else{
  109. $hash->{INTERVAL} = 3600;
  110. }
  111. Log3 $hash, 4, "TRAFFIC: ($name) defined ".$hash->{NAME}.' with interval set to '.$hash->{INTERVAL};
  112. # put in default verbose level
  113. $attr{$name}{"verbose"} = 1 if !$attr{$name}{"verbose"};
  114. $attr{$name}{"outputReadings"} = "text" if !$attr{$name}{"outputReadings"};
  115. readingsSingleUpdate( $hash, "state", "Initialized", 1 );
  116. my $firstTrigger = gettimeofday() + 2;
  117. $hash->{TRIGGERTIME} = $firstTrigger;
  118. $hash->{TRIGGERTIME_FMT} = FmtDateTime($firstTrigger);
  119. RemoveInternalTimer($hash);
  120. InternalTimer($firstTrigger, "TRAFFIC_StartUpdate", $hash, 0);
  121. Log3 $hash, 5, "TRAFFIC: ($name) InternalTimer set to call GetUpdate in 2 seconds for the first time";
  122. return undef;
  123. }
  124. sub TRAFFIC_Undef($$){
  125. my ( $hash, $arg ) = @_;
  126. RemoveInternalTimer ($hash);
  127. return undef;
  128. }
  129. sub TRAFFIC_fhemwebFn($$$$) {
  130. my ($FW_wname, $device, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  131. my $name = $device;
  132. my $hash = $defs{$name};
  133. my $mapState = ReadingsVal($device,".map", "off") eq "on" ? "off" : "on";
  134. my $web = "<span><a href=\"$FW_ME?detail=$device&amp;cmd.$device=setreading $device .map $mapState$FW_CSRF\">toggle Map</a>&nbsp;&nbsp;</span><br>";
  135. if (ReadingsVal($device,".map","off") eq "on") {
  136. $web .= TRAFFIC_GetMap($device);
  137. $web .= TRAFFIC_weblink($device);
  138. $web .= "<form method=\"$FW_formmethod\" action=\"$FW_ME$FW_subdir\" >";
  139. $web .= FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF);
  140. $web .= FW_hidden("detail", $device);
  141. $web .= FW_hidden("dev.attr$device", $device);
  142. $web .= "<input style='display:none' type='submit' value='save Zoom' class='attr' id='currentMapZoomSubmit'>";
  143. $web .= "<input type='hidden' name='val.attr$device' value='' id='currentMapZoom'>";
  144. $web .= "<input type='hidden' name='cmd.attr$device' value='attr'>";
  145. $web .= "<input type='hidden' name='arg.attr$device' value='GoogleMapsZoom'>";
  146. $web .= "</form>";
  147. $web .= "<form method=\"$FW_formmethod\" action=\"$FW_ME$FW_subdir\" >";
  148. $web .= FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF);
  149. $web .= FW_hidden("detail", $device);
  150. $web .= FW_hidden("dev.attr$device", $device);
  151. $web .= "<input style='display:none' type='submit' value='save Center' class='attr' id='currentMapCenterSubmit'>";
  152. $web .= "<input type='hidden' name='val.attr$device' value='' id='currentMapCenter'>";
  153. $web .= "<input type='hidden' name='cmd.attr$device' value='attr'>";
  154. $web .= "<input type='hidden' name='arg.attr$device' value='GoogleMapsCenter'>";
  155. $web .= "</form>";
  156. }
  157. return $web;
  158. }
  159. sub TRAFFIC_GetMap($@){
  160. my $device = shift();
  161. my $name = $device;
  162. my $hash = $defs{$name};
  163. my $debugPoly = $hash->{helper}{'Poly'};
  164. my $returnDebugPoly = $hash->{helper}{'return_Poly'};
  165. my $GoogleMapsCenter = AttrVal($name, "GoogleMapsCenter", $hash->{helper}{'GoogleMapsCenter'});
  166. if(!$debugPoly || !$GoogleMapsCenter){
  167. return "<div>please update your device first</div>";
  168. }
  169. my%GoogleMapsStyles=(
  170. 'default' => "[]",
  171. 'silver' => '[{"elementType":"geometry","stylers":[{"color":"#f5f5f5"}]},{"elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"elementType":"labels.text.fill","stylers":[{"color":"#616161"}]},{"elementType":"labels.text.stroke","stylers":[{"color":"#f5f5f5"}]},{"featureType":"administrative.land_parcel","elementType":"labels.text.fill","stylers":[{"color":"#bdbdbd"}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#eeeeee"}]},{"featureType":"poi","elementType":"labels.text.fill","stylers":[{"color":"#757575"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#e5e5e5"}]},{"featureType":"poi.park","elementType":"labels.text.fill","stylers":[{"color":"#9e9e9e"}]},{"featureType":"road","elementType":"geometry","stylers":[{"color":"#ffffff"}]},{"featureType":"road.arterial","elementType":"labels.text.fill","stylers":[{"color":"#757575"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#dadada"}]},{"featureType":"road.highway","elementType":"labels.text.fill","stylers":[{"color":"#616161"}]},{"featureType":"road.local","elementType":"labels.text.fill","stylers":[{"color":"#9e9e9e"}]},{"featureType":"transit.line","elementType":"geometry","stylers":[{"color":"#e5e5e5"}]},{"featureType":"transit.station","elementType":"geometry","stylers":[{"color":"#eeeeee"}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#c9c9c9"}]},{"featureType":"water","elementType":"labels.text.fill","stylers":[{"color":"#9e9e9e"}]}]',
  172. 'dark' => '[{"elementType":"geometry","stylers":[{"color":"#212121"}]},{"elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"elementType":"labels.text.fill","stylers":[{"color":"#757575"}]},{"elementType":"labels.text.stroke","stylers":[{"color":"#212121"}]},{"featureType":"administrative","elementType":"geometry","stylers":[{"color":"#757575"}]},{"featureType":"administrative.country","elementType":"labels.text.fill","stylers":[{"color":"#9e9e9e"}]},{"featureType":"administrative.land_parcel","stylers":[{"visibility":"off"}]},{"featureType":"administrative.locality","elementType":"labels.text.fill","stylers":[{"color":"#bdbdbd"}]},{"featureType":"poi","elementType":"labels.text.fill","stylers":[{"color":"#757575"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#181818"}]},{"featureType":"poi.park","elementType":"labels.text.fill","stylers":[{"color":"#616161"}]},{"featureType":"poi.park","elementType":"labels.text.stroke","stylers":[{"color":"#1b1b1b"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"color":"#2c2c2c"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#8a8a8a"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#373737"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#3c3c3c"}]},{"featureType":"road.highway.controlled_access","elementType":"geometry","stylers":[{"color":"#4e4e4e"}]},{"featureType":"road.local","elementType":"labels.text.fill","stylers":[{"color":"#616161"}]},{"featureType":"transit","elementType":"labels.text.fill","stylers":[{"color":"#757575"}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#000000"}]},{"featureType":"water","elementType":"labels.text.fill","stylers":[{"color":"#3d3d3d"}]}]',
  173. 'night' => '[{"elementType":"geometry","stylers":[{"color":"#242f3e"}]},{"elementType":"labels.text.fill","stylers":[{"color":"#746855"}]},{"elementType":"labels.text.stroke","stylers":[{"color":"#242f3e"}]},{"featureType":"administrative.locality","elementType":"labels.text.fill","stylers":[{"color":"#d59563"}]},{"featureType":"poi","elementType":"labels.text.fill","stylers":[{"color":"#d59563"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#263c3f"}]},{"featureType":"poi.park","elementType":"labels.text.fill","stylers":[{"color":"#6b9a76"}]},{"featureType":"road","elementType":"geometry","stylers":[{"color":"#38414e"}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#212a37"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#9ca5b3"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#746855"}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"color":"#1f2835"}]},{"featureType":"road.highway","elementType":"labels.text.fill","stylers":[{"color":"#f3d19c"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#2f3948"}]},{"featureType":"transit.station","elementType":"labels.text.fill","stylers":[{"color":"#d59563"}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#17263c"}]},{"featureType":"water","elementType":"labels.text.fill","stylers":[{"color":"#515c6d"}]},{"featureType":"water","elementType":"labels.text.stroke","stylers":[{"color":"#17263c"}]}]',
  174. );
  175. my $selectedGoogleMapsStyle = $GoogleMapsStyles{ AttrVal($name, "GoogleMapsStyle", 'default' )};
  176. if(!$selectedGoogleMapsStyle){$selectedGoogleMapsStyle = $GoogleMapsStyles{'default'}}; #catch attribute mistake here
  177. # load map scale and zoom from attr, override if empty/na
  178. my ( $GoogleMapsWidth, $GoogleMapsHeight ) = AttrVal($name, "GoogleMapsSize", '800,600') =~ m/(\d+),(\d+)/;
  179. my ( $GoogleMapsZoom ) = AttrVal($name, "GoogleMapsZoom", '10');
  180. my ( $GoogleMapsStroke1Color, $GoogleMapsStroke1Weight, $GoogleMapsStroke1Opacity, $GoogleMapsStroke2Color, $GoogleMapsStroke2Weight, $GoogleMapsStroke2Opacity ) = AttrVal($name, "GoogleMapsStroke", '#4cde44,6,100,#FF0000,1,100') =~ m/^(#[a-zA-z0-9]+),?(\d*),?(\d*),?(#[a-zA-z0-9]+)?,?(\d*),?(\d*)/;
  181. # catch incomplete configuration here and put in defaults
  182. $GoogleMapsStroke1Color = '#4cde44' if !$GoogleMapsStroke1Color;
  183. $GoogleMapsStroke1Weight = '6' if !$GoogleMapsStroke1Weight;
  184. $GoogleMapsStroke1Opacity = '100' if !$GoogleMapsStroke1Opacity;
  185. $GoogleMapsStroke2Color = '#FF0000' if !$GoogleMapsStroke2Color;
  186. $GoogleMapsStroke2Weight = '1' if !$GoogleMapsStroke2Weight;
  187. $GoogleMapsStroke2Opacity = '100' if !$GoogleMapsStroke2Opacity;
  188. # make percent value to 50 to 0.5 etc
  189. $GoogleMapsStroke1Opacity = ($GoogleMapsStroke1Opacity / 100);
  190. $GoogleMapsStroke2Opacity = ($GoogleMapsStroke2Opacity / 100);
  191. my $GoogleMapsDisableUI = '';
  192. $GoogleMapsDisableUI = "disableDefaultUI: true," if AttrVal($name, "GoogleMapsDisableUI", 0) eq 1;
  193. Log3 $hash, 4, "TRAFFIC: ($name) drawing map in style ".AttrVal($name, "GoogleMapsStyle", 'default' )." in $GoogleMapsWidth x $GoogleMapsHeight px";
  194. my $map;
  195. $map .= '<div><script type="text/javascript" src="https://maps.google.com/maps/api/js?key='.$hash->{APIKEY}.'&libraries=geometry&amp"></script>
  196. <input size="200" type="hidden" id="path" value="'.decode_base64($debugPoly).'">';
  197. $map .= '<input size="200" type="hidden" id="pathR" value="'.decode_base64($returnDebugPoly).'">' if $returnDebugPoly && decode_base64($returnDebugPoly);
  198. $map .= '
  199. <div id="map"></div>
  200. <style>
  201. #map {width:'.$GoogleMapsWidth.'px;height:'.$GoogleMapsHeight.'px;}
  202. </style>
  203. <script type="text/javascript">
  204. function initialize() {
  205. var myLatlng = new google.maps.LatLng('.$GoogleMapsCenter.');
  206. var myOptions = {
  207. zoom: '.$GoogleMapsZoom.',
  208. center: myLatlng,
  209. '.$GoogleMapsDisableUI.'
  210. mapTypeId: google.maps.MapTypeId.ROADMAP,
  211. styles: '.$selectedGoogleMapsStyle.'
  212. }
  213. var map = new google.maps.Map(document.getElementById("map"), myOptions);
  214. var decodedPath = google.maps.geometry.encoding.decodePath(document.getElementById("path").value);
  215. var decodedLevels = decodeLevels("");
  216. var setRegion = new google.maps.Polyline({
  217. path: decodedPath,
  218. levels: decodedLevels,
  219. strokeColor: "'.$GoogleMapsStroke1Color.'",
  220. strokeOpacity: '.$GoogleMapsStroke1Opacity.',
  221. strokeWeight: '.$GoogleMapsStroke1Weight.',
  222. map: map
  223. });';
  224. $map .= 'var decodedPathR = google.maps.geometry.encoding.decodePath(document.getElementById("pathR").value);
  225. var decodedLevelsR = decodeLevels("");
  226. var setRegionR = new google.maps.Polyline({
  227. path: decodedPathR,
  228. levels: decodedLevels,
  229. strokeColor: "'.$GoogleMapsStroke2Color.'",
  230. strokeOpacity: '.$GoogleMapsStroke2Opacity.',
  231. strokeWeight: '.$GoogleMapsStroke2Weight.',
  232. map: map
  233. });' if $returnDebugPoly && decode_base64($returnDebugPoly );
  234. $map .= 'var trafficLayer = new google.maps.TrafficLayer();
  235. trafficLayer.setMap(map);' if AttrVal($name, "GoogleMapsTrafficLayer", 0) eq 1;
  236. $map .='
  237. map.addListener("zoom_changed", function() {
  238. document.getElementById("currentMapZoom").value = map.getZoom();
  239. document.getElementById("currentMapZoomSubmit").style.display = "block";
  240. });
  241. map.addListener("dragend", function() {
  242. document.getElementById("currentMapCenter").value = map.getCenter().lat() + "," + map.getCenter().lng();
  243. document.getElementById("currentMapCenterSubmit").style.display = "block";
  244. });
  245. }
  246. function decodeLevels(encodedLevelsString) {
  247. var decodedLevels = [];
  248. for (var i = 0; i < encodedLevelsString.length; ++i) {
  249. var level = encodedLevelsString.charCodeAt(i) - 63;
  250. decodedLevels.push(level);
  251. }
  252. return decodedLevels;
  253. }
  254. initialize();
  255. </script></div>';
  256. return $map;
  257. }
  258. #
  259. # Attr command
  260. #########################################################################
  261. sub TRAFFIC_Attr(@){
  262. my ($cmd,$name,$attrName,$attrValue) = @_;
  263. # $cmd can be "del" or "set"
  264. # $name is device name
  265. my $hash = $defs{$name};
  266. if ($cmd eq "set") {
  267. addToDevAttrList($name, $attrName);
  268. Log3 $hash, 4, "TRAFFIC: ($name) attrName $attrName set to attrValue $attrValue";
  269. }
  270. if($attrName eq "disable" && $attrValue eq "1"){
  271. readingsSingleUpdate( $hash, "state", "disabled", 1 );
  272. }
  273. if($attrName eq "outputReadings" || $attrName eq "includeReturn" || $attrName eq "verbose"){
  274. #clear all readings
  275. foreach my $clearReading ( keys %{$hash->{READINGS}}){
  276. Log3 $hash, 5, "TRAFFIC: ($name) READING: $clearReading deleted";
  277. delete($hash->{READINGS}{$clearReading});
  278. }
  279. #clear all helpers
  280. foreach my $helperName ( keys %{$hash->{helper}}){
  281. delete($hash->{helper}{$helperName});
  282. }
  283. # start update
  284. InternalTimer(gettimeofday() + 1, "TRAFFIC_StartUpdate", $hash, 0);
  285. }
  286. return undef;
  287. }
  288. sub TRAFFIC_Set($@){
  289. my ($hash, @param) = @_;
  290. return "\"set <TRAFFIC>\" needs at least one argument: \n".join(" ",keys %TRcmds) if (int(@param) < 2);
  291. my $name = shift @param;
  292. my $set = shift @param;
  293. $hash->{VERSION} = $TRVersion if $hash->{VERSION} ne $TRVersion;
  294. if(AttrVal($name, "disable", 0 ) == 1){
  295. readingsSingleUpdate( $hash, "state", "disabled", 1 );
  296. Log3 $hash, 3, "TRAFFIC: ($name) is disabled, $set not set!";
  297. return undef;
  298. }else{
  299. Log3 $hash, 5, "TRAFFIC: ($name) set $name $set";
  300. }
  301. my $validCmds = join("|",keys %TRcmds);
  302. if($set !~ m/$validCmds/ ) {
  303. return join(' ', keys %TRcmds);
  304. }elsif($set =~ m/update/){
  305. Log3 $hash, 5, "TRAFFIC: ($name) update command recieved";
  306. # if update burst ist specified
  307. if( (my $burstCount = shift @param) && (my $burstInterval = shift @param)){
  308. Log3 $hash, 5, "TRAFFIC: ($name) update burst is set to $burstCount $burstInterval";
  309. $hash->{BURSTCOUNT} = $burstCount;
  310. $hash->{BURSTINTERVAL} = $burstInterval;
  311. }else{
  312. Log3 $hash, 5, "TRAFFIC: ($name) no update burst set";
  313. }
  314. # update internal timer and update NOW
  315. my $updateTrigger = gettimeofday() + 1;
  316. $hash->{TRIGGERTIME} = $updateTrigger;
  317. $hash->{TRIGGERTIME_FMT} = FmtDateTime($updateTrigger);
  318. RemoveInternalTimer($hash);
  319. # start update
  320. InternalTimer($updateTrigger, "TRAFFIC_StartUpdate", $hash, 0);
  321. return undef;
  322. }
  323. }
  324. sub TRAFFIC_StartUpdate($){
  325. my ( $hash ) = @_;
  326. my $name = $hash->{NAME};
  327. my ($sec,$min,$hour,$dayn,$month,$year,$wday,$yday,$isdst) = localtime(time);
  328. $wday=7 if $wday == 0; #sunday 0 -> sunday 7, monday 0 -> monday 1 ...
  329. if(AttrVal($name, "disable", 0 ) == 1){
  330. RemoveInternalTimer ($hash);
  331. Log3 $hash, 3, "TRAFFIC: ($name) is disabled";
  332. return undef;
  333. }
  334. if ( $hash->{INTERVAL}) {
  335. RemoveInternalTimer ($hash);
  336. delete($hash->{UPDATESCHEDULE});
  337. my $nextTrigger = gettimeofday() + $hash->{INTERVAL};
  338. if(defined(AttrVal($name, "updateSchedule", undef ))){
  339. Log3 $hash, 5, "TRAFFIC: ($name) flexible update Schedule defined";
  340. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  341. my @updateScheduleDef = split('\|', AttrVal($name, "updateSchedule", undef ));
  342. foreach my $upSched (@updateScheduleDef){
  343. my ($upFrom, $upTo, $upDay, $upInterval ) = $upSched =~ m/(\d+)-(\d+)\s(\d{1,})\s?(\d{1,})?/;
  344. if (!$upInterval){
  345. $upInterval = $upDay;
  346. $upDay='';
  347. }
  348. Log3 $hash, 5, "TRAFFIC: ($name) parsed schedule to upFrom $upFrom, upTo $upTo, upDay $upDay, upInterval $upInterval";
  349. if(!$upFrom || !$upTo || !$upInterval){
  350. Log3 $hash, 1, "TRAFIC: ($name) updateSchedule $upSched not defined correctly";
  351. }else{
  352. if($hour >= $upFrom && $hour < $upTo){
  353. if(!$upDay || $upDay == $wday ){
  354. $nextTrigger = gettimeofday() + $upInterval;
  355. Log3 $hash, 4, "TRAFFIC: ($name) schedule from $upFrom to $upTo (on day $upDay) every $upInterval seconds, matches (current hour $hour), nextTrigger set to $nextTrigger";
  356. $hash->{UPDATESCHEDULE} = $upSched;
  357. last;
  358. }else{
  359. Log3 $hash, 4, "TRAFFIC: ($name) $upSched does match the time but not the day ($wday)";
  360. }
  361. }else{
  362. Log3 $hash, 5, "TRAFFIC: ($name) schedule $upSched does not match ($hour)";
  363. }
  364. }
  365. }
  366. }
  367. if(defined($hash->{BURSTCOUNT}) && $hash->{BURSTCOUNT} > 0){
  368. $nextTrigger = gettimeofday() + $hash->{BURSTINTERVAL};
  369. Log3 $hash, 3, "TRAFFIC: ($name) next update defined by burst";
  370. $hash->{BURSTCOUNT}--;
  371. }elsif(defined($hash->{BURSTCOUNT}) && $hash->{BURSTCOUNT} == 0){
  372. delete($hash->{BURSTCOUNT});
  373. delete($hash->{BURSTINTERVAL});
  374. Log3 $hash, 4, "TRAFFIC: ($name) burst update is done";
  375. }
  376. $hash->{TRIGGERTIME} = $nextTrigger;
  377. $hash->{TRIGGERTIME_FMT} = FmtDateTime($nextTrigger);
  378. InternalTimer($nextTrigger, "TRAFFIC_StartUpdate", $hash, 0);
  379. Log3 $hash, 4, "TRAFFIC: ($name) internal interval timer set to call StartUpdate again at " . $hash->{TRIGGERTIME_FMT};
  380. }
  381. if(defined(AttrVal($name, "start_address", undef )) && defined(AttrVal($name, "end_address", undef ))){
  382. BlockingCall("TRAFFIC_DoUpdate",$hash->{NAME}.';;;normal',"TRAFFIC_FinishUpdate",60,"TRAFFIC_AbortUpdate",$hash);
  383. if(defined(AttrVal($name, "includeReturn", undef )) && AttrVal($name, "includeReturn", undef ) eq 1){
  384. BlockingCall("TRAFFIC_DoUpdate",$hash->{NAME}.';;;return',"TRAFFIC_FinishUpdate",60,"TRAFFIC_AbortUpdate",$hash);
  385. }
  386. }else{
  387. readingsSingleUpdate( $hash, "state", "incomplete configuration", 1 );
  388. Log3 $hash, 1, "TRAFFIC: ($name) is not configured correctly, please add start_address and end_address";
  389. }
  390. }
  391. sub TRAFFIC_AbortUpdate($){
  392. }
  393. sub TRAFFIC_DoUpdate(){
  394. my ($string) = @_;
  395. my ($hName, $direction) = split(";;;", $string); # direction is normal or return
  396. my $hash = $defs{$hName};
  397. my $dotrigger = 1;
  398. my $name = $hash->{NAME};
  399. my ($sec,$min,$hour,$dayn,$month,$year,$wday,$yday,$isdst) = localtime(time);
  400. Log3 $hash, 4, "TRAFFIC: ($name) TRAFFIC_DoUpdate start";
  401. if ( $hash->{INTERVAL}) {
  402. RemoveInternalTimer ($hash);
  403. my $nextTrigger = gettimeofday() + $hash->{INTERVAL};
  404. $hash->{TRIGGERTIME} = $nextTrigger;
  405. $hash->{TRIGGERTIME_FMT} = FmtDateTime($nextTrigger);
  406. InternalTimer($nextTrigger, "TRAFFIC_DoUpdate", $hash, 0);
  407. Log3 $hash, 4, "TRAFFIC: ($name) internal interval timer set to call GetUpdate again in " . int($hash->{INTERVAL}). " seconds";
  408. }
  409. my $returnJSON;
  410. my $TRlanguage = '';
  411. if(defined(AttrVal($name,"language",undef))){
  412. $TRlanguage = '&language='.AttrVal($name,"language","");
  413. }else{
  414. Log3 $hash, 5, "TRAFFIC: ($name) no language specified";
  415. }
  416. my $TRwaypoints = '';
  417. if(defined(AttrVal($name,"waypoints",undef))){
  418. $TRwaypoints = '&waypoints=via:' . join('|via:', split('\|', AttrVal($name,"waypoints",undef)));
  419. }else{
  420. Log3 $hash, 4, "TRAFFIC: ($name) no waypoints specified";
  421. }
  422. if($direction eq "return"){
  423. if(defined(AttrVal($name,"returnWaypoints",undef))){
  424. $TRwaypoints = '&waypoints=via:' . join('|via:', split('\|', AttrVal($name,"returnWaypoints",undef)));
  425. Log3 $hash, 4, "TRAFFIC: ($name) using returnWaypoints";
  426. }elsif(defined(AttrVal($name,"waypoints",undef))){
  427. $TRwaypoints = '&waypoints=via:' . join('|via:', reverse split('\|', AttrVal($name,"waypoints",undef)));
  428. Log3 $hash, 4, "TRAFFIC: ($name) reversing waypoints";
  429. }else{
  430. Log3 $hash, 4, "TRAFFIC: ($name) no waypoints for return specified";
  431. }
  432. }
  433. my $origin = AttrVal($name, "start_address", 0 );
  434. my $destination = AttrVal($name, "end_address", 0 );
  435. my $travelMode = AttrVal($name, "travelMode", 'driving' );
  436. if($direction eq "return"){
  437. $origin = AttrVal($name, "end_address", 0 );
  438. $destination = AttrVal($name, "start_address", 0 );
  439. }
  440. my $url = 'https://maps.googleapis.com/maps/api/directions/json?origin='.$origin.'&destination='.$destination.'&mode='.$travelMode.$TRlanguage.'&departure_time=now'.$TRwaypoints.'&key='.$hash->{APIKEY};
  441. Log3 $hash, 4, "TRAFFIC: ($name) using $url";
  442. my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } );
  443. $ua->default_header("HTTP_REFERER" => "www.google.de");
  444. my $body = $ua->get($url);
  445. # test json decode and catch error nicely
  446. eval {
  447. my $testJson = decode_json($body->decoded_content);
  448. 1;
  449. };
  450. if($@) {
  451. my $e = $@;
  452. Log3 $hash, 1, "TRAFFIC: ($name) decode_json on googles return failed, cant continue";
  453. my %errorreturn = ('status' => 'API error');
  454. return "$name;;;$direction;;;".encode_json(\%errorreturn);
  455. };
  456. my $json = decode_json($body->decoded_content);
  457. my $duration_sec = $json->{'routes'}[0]->{'legs'}[0]->{'duration'}->{'value'} ;
  458. my $duration_in_traffic_sec = $json->{'routes'}[0]->{'legs'}[0]->{'duration_in_traffic'}->{'value'};
  459. $returnJSON->{'READINGS'}->{'duration'} = $json->{'routes'}[0]->{'legs'}[0]->{'duration'}->{'text'} if AttrVal($name, "outputReadings", "" ) =~ m/text/;
  460. $returnJSON->{'READINGS'}->{'duration_in_traffic'} = $json->{'routes'}[0]->{'legs'}[0]->{'duration_in_traffic'}->{'text'} if AttrVal($name, "outputReadings", "" ) =~ m/text/;
  461. $returnJSON->{'READINGS'}->{'distance'} = $json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'text'} if AttrVal($name, "outputReadings", "" ) =~ m/text/;
  462. $returnJSON->{'READINGS'}->{'state'} = $json->{'status'};
  463. $returnJSON->{'READINGS'}->{'status'} = $json->{'status'};
  464. $returnJSON->{'READINGS'}->{'eta'} = FmtTime( gettimeofday() + $duration_in_traffic_sec ) if defined($duration_in_traffic_sec);
  465. $returnJSON->{'HELPER'}->{'Poly'} = encode_base64 ($json->{'routes'}[0]->{overview_polyline}->{points});
  466. $returnJSON->{'HELPER'}->{'GoogleMapsCenter'} = $json->{'routes'}[0]->{'legs'}[0]->{start_location}->{lat}.','.$json->{'routes'}[0]->{'legs'}[0]->{start_location}->{lng};
  467. if($duration_in_traffic_sec && $duration_sec){
  468. $returnJSON->{'READINGS'}->{'delay'} = prettySeconds($duration_in_traffic_sec - $duration_sec) if AttrVal($name, "outputReadings", "" ) =~ m/text/;
  469. Log3 $hash, 4, "TRAFFIC: ($name) delay in seconds = $duration_in_traffic_sec - $duration_sec";
  470. if (AttrVal($name, "outputReadings", "" ) =~ m/min/ && defined($duration_in_traffic_sec) && defined($duration_sec)){
  471. $returnJSON->{'READINGS'}->{'delay_min'} = int($duration_in_traffic_sec - $duration_sec);
  472. }
  473. if(defined($returnJSON->{'READINGS'}->{'delay_min'})){
  474. if( ( $returnJSON->{'READINGS'}->{'delay_min'} && $returnJSON->{'READINGS'}->{'delay_min'} =~ m/^-/ ) || $returnJSON->{'READINGS'}->{'delay_min'} < 60){
  475. Log3 $hash, 5, "TRAFFIC: ($name) delay_min was negative or less than 1min (".$returnJSON->{'READINGS'}->{'delay_min'}."), set to 0";
  476. $returnJSON->{'READINGS'}->{'delay_min'} = 0;
  477. }else{
  478. $returnJSON->{'READINGS'}->{'delay_min'} = int($returnJSON->{'READINGS'}->{'delay_min'} / 60 + 0.5); #divide 60 and round
  479. }
  480. }
  481. }else{
  482. Log3 $hash, 1, "TRAFFIC: ($name) did not receive duration_in_traffic, not able to calculate delay";
  483. }
  484. # condition based values
  485. $returnJSON->{'READINGS'}->{'error_message'} = $json->{'error_message'} if $json->{'error_message'};
  486. # output readings
  487. $returnJSON->{'READINGS'}->{'duration_min'} = int($duration_sec / 60 + 0.5) if AttrVal($name, "outputReadings", "" ) =~ m/min/ && defined($duration_sec);
  488. $returnJSON->{'READINGS'}->{'duration_in_traffic_min'} = int($duration_in_traffic_sec / 60 + 0.5) if AttrVal($name, "outputReadings", "" ) =~ m/min/ && defined($duration_in_traffic_sec);
  489. $returnJSON->{'READINGS'}->{'duration_sec'} = $duration_sec if AttrVal($name, "outputReadings", "" ) =~ m/sec/;
  490. $returnJSON->{'READINGS'}->{'duration_in_traffic_sec'} = $duration_in_traffic_sec if AttrVal($name, "outputReadings", "" ) =~ m/sec/;
  491. # raw data (seconds)
  492. $returnJSON->{'READINGS'}->{'distance'} = $json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'value'} if AttrVal($name, "raw_data", 0);
  493. # average readings
  494. if(AttrVal($name, "outputReadings", "" ) =~ m/average/){
  495. # calc average
  496. $returnJSON->{'READINGS'}->{'average_duration_min'} = int($hash->{READINGS}{'average_duration_min'}{VAL} + $returnJSON->{'READINGS'}->{'duration_min'}) / 2 if $returnJSON->{'READINGS'}->{'duration_min'};
  497. $returnJSON->{'READINGS'}->{'average_duration_in_traffic_min'} = int($hash->{READINGS}{'average_duration_in_traffic_min'}{VAL} + $returnJSON->{'READINGS'}->{'duration_in_traffic_min'}) / 2 if $returnJSON->{'READINGS'}->{'duration_in_traffic_min'};
  498. $returnJSON->{'READINGS'}->{'average_delay_min'} = int($hash->{READINGS}{'average_delay_min'}{VAL} + $returnJSON->{'READINGS'}->{'delay_min'}) / 2 if $returnJSON->{'READINGS'}->{'delay_min'};
  499. # override if this is the first average
  500. $returnJSON->{'READINGS'}->{'average_duration_min'} = $returnJSON->{'READINGS'}->{'duration_min'} if !$hash->{READINGS}{'average_duration_min'}{VAL};
  501. $returnJSON->{'READINGS'}->{'average_duration_in_traffic_min'} = $returnJSON->{'READINGS'}->{'duration_in_traffic_min'} if !$hash->{READINGS}{'average_duration_in_traffic_min'}{VAL};
  502. $returnJSON->{'READINGS'}->{'average_delay_min'} = $returnJSON->{'READINGS'}->{'delay_min'} if !$hash->{READINGS}{'average_delay_min'}{VAL};
  503. }
  504. Log3 $hash, 5, "TRAFFIC: ($name) returning from TRAFFIC_DoUpdate: ".encode_json($returnJSON);
  505. Log3 $hash, 4, "TRAFFIC: ($name) TRAFFIC_DoUpdate done";
  506. return "$name;;;$direction;;;".encode_json($returnJSON);
  507. }
  508. sub TRAFFIC_FinishUpdate($){
  509. my ($name,$direction,$rawJson) = split(/;;;/,shift);
  510. my $hash = $defs{$name};
  511. my %sensors;
  512. my $dotrigger = 1;
  513. Log3 $hash, 4, "TRAFFIC: ($name) TRAFFIC_FinishUpdate start";
  514. my $json = decode_json($rawJson);
  515. readingsBeginUpdate($hash);
  516. my $readings = $json->{'READINGS'};
  517. my $helper = $json->{'HELPER'};
  518. foreach my $helperName (keys %{$helper}){
  519. if($direction eq 'return'){
  520. Log3 $hash, 4, "TRAFFIC: ($name) HelperUpdate: return_".$helperName." - ".$helper->{$helperName};
  521. $hash->{helper}{'return_'.$helperName} = $helper->{$helperName}; #testme
  522. }else{
  523. Log3 $hash, 4, "TRAFFIC: ($name) HelperUpdate: $helperName - ".$helper->{$helperName};
  524. $hash->{helper}{$helperName} = $helper->{$helperName}; #testme
  525. }
  526. }
  527. foreach my $readingName (keys %{$readings}){
  528. Log3 $hash, 4, "TRAFFIC: ($name) ReadingsUpdate: $readingName - ".$readings->{$readingName};
  529. if($direction eq 'return'){
  530. readingsBulkUpdate($hash,'return_'.$readingName,$readings->{$readingName});
  531. }else{
  532. readingsBulkUpdate($hash,$readingName,$readings->{$readingName});
  533. }
  534. }
  535. if(defined($json->{'READINGS'}->{'status'}) && $json->{'READINGS'}->{'status'} eq 'UNKNOWN_ERROR'){ # UNKNOWN_ERROR indicates a directions request could not be processed due to a server error. The request may succeed if you try again.
  536. InternalTimer(gettimeofday() + 3, "TRAFFIC_StartUpdate", $hash, 0);
  537. }
  538. if(my $stateReading = AttrVal($name,"stateReading",undef)){
  539. Log3 $hash, 5, "TRAFFIC: ($name) stateReading defined, override state";
  540. if(defined($json->{'READINGS'}->{$stateReading})){
  541. readingsBulkUpdate($hash,'state',$json->{'READINGS'}->{$stateReading});
  542. }else{
  543. Log3 $hash, 1, "TRAFFIC: ($name) stateReading $stateReading not found";
  544. }
  545. }
  546. readingsEndUpdate($hash, $dotrigger);
  547. Log3 $hash, 4, "TRAFFIC: ($name) TRAFFIC_FinishUpdate done";
  548. Log3 $hash, 5, "TRAFFIC: ($name) Helper: ".Dumper($hash->{helper});
  549. }
  550. sub TRAFFIC_weblink{
  551. my $name = shift();
  552. return "<a href='$FW_ME/TRAFFIC?name=$name'>$FW_ME/TRAFFIC?name=$name</a><br>";
  553. }
  554. sub TRAFFIC(){
  555. my $name = $FW_webArgs{name};
  556. return if(!defined($name));
  557. $FW_RETTYPE = "text/html; charset=UTF-8";
  558. $FW_RET="";
  559. my $web .= TRAFFIC_GetMap($name);
  560. FW_pO $web;
  561. return ($FW_RETTYPE, $FW_RET);
  562. }
  563. sub prettySeconds {
  564. my $time = shift;
  565. if($time =~ m/^-/){
  566. return "0 min";
  567. }
  568. my $days = int($time / 86400);
  569. $time -= ($days * 86400);
  570. my $hours = int($time / 3600);
  571. $time -= ($hours * 3600);
  572. my $minutes = int($time / 60);
  573. my $seconds = $time % 60;
  574. $days = $days < 1 ? '' : $days .' days ';
  575. $hours = $hours < 1 ? '' : $hours .' hours ';
  576. $minutes = $minutes < 1 ? '' : $minutes . ' min ';
  577. $time = $days . $hours . $minutes;
  578. if(!$time){
  579. return "0 min";
  580. }else{
  581. return $time;
  582. }
  583. }
  584. 1;
  585. #======================================================================
  586. #======================================================================
  587. #
  588. # HTML Documentation for help and commandref
  589. #
  590. #======================================================================
  591. #======================================================================
  592. =pod
  593. =item device
  594. =item summary provide traffic details with Google Distance API
  595. =item summary_DE stellt Verkehrsdaten mittels Google Distance API bereit
  596. =begin html
  597. <a name="TRAFFIC"></a>
  598. <h3>TRAFFIC</h3>
  599. <ul>
  600. <u><b>TRAFFIC - google maps directions module</b></u>
  601. <br>
  602. <br>
  603. This FHEM module collects and displays data obtained via the google maps directions api<br>
  604. requirements:<br>
  605. perl JSON module<br>
  606. perl LWP::SIMPLE module<br>
  607. perl MIME::Base64 module<br>
  608. Google maps API key<br>
  609. <br>
  610. <b>Features:</b>
  611. <br>
  612. <ul>
  613. <li>get distance between start and end location</li>
  614. <li>get travel time for route</li>
  615. <li>get travel time in traffic for route</li>
  616. <li>define additional waypoints</li>
  617. <li>calculate delay between travel-time and travel-time-in-traffic</li>
  618. <li>choose default language</li>
  619. <li>disable the device</li>
  620. <li>5 log levels</li>
  621. <li>get outputs in seconds / meter (raw_data)</li>
  622. <li>state of google maps returned in error reading (i.e. The provided API key is invalid)</li>
  623. <li>customize update interval (default 3600 seconds)</li>
  624. <li>calculate ETA with localtime and delay</li>
  625. <li>configure the output readings with attribute outputReadings, text, min sec</li>
  626. <li>configure the state-reading </li>
  627. <li>optionally display the same route in return</li>
  628. <li>one-time-burst, specify the amount and interval between updates</li>
  629. <li>different Travel Modes (driving, walking, bicycling and transit)</li>
  630. <li>flexible update schedule</li>
  631. <li>integrated Map to visualize configured route or embed to external GUI</li>
  632. </ul>
  633. <br>
  634. <br>
  635. <a name="TRAFFICdefine"></a>
  636. <b>Define:</b>
  637. <ul><br>
  638. <code>define &lt;name&gt; TRAFFIC &lt;YOUR-API-KEY&gt; [UPDATE-INTERVAL]</code>
  639. <br><br>
  640. example:<br>
  641. <code>define muc2berlin TRAFFIC ABCDEFGHIJKLMNOPQRSTVWYZ 600</code><br>
  642. </ul>
  643. <br>
  644. <br>
  645. <b>Attributes:</b>
  646. <ul>
  647. <li>"start_address" - Street, zipcode City <b>(mandatory)</b></li>
  648. <li>"end_address" - Street, zipcode City <b>(mandatory)</b></li>
  649. <li>"raw_data" - 0:1</li>
  650. <li>"language" - de, en etc.</li>
  651. <li>"waypoints" - Lat, Long coordinates, separated by | </li>
  652. <li>"returnWaypoints" - Lat, Long coordinates, separated by | </li>
  653. <li>"disable" - 0:1</li>
  654. <li>"stateReading" - name the reading which will be used in device state</li>
  655. <li>"outputReadings" - define what kind of readings you want to get: text, min, sec, average</li>
  656. <li>"updateSchedule" - define a flexible update schedule, syntax &lt;starthour&gt;-&lt;endhour&gt; [&lt;day&gt;] &lt;seconds&gt; , multiple entries by sparated by |<br> <i>example:</i> 7-9 1 120 - Monday between 7 and 9 every 2minutes <br> <i>example:</i> 17-19 120 - every Day between 17 and 19 every 2minutes <br> <i>example:</i> 6-8 1 60|6-8 2 60|6-8 3 60|6-8 4 60|6-8 5 60 - Monday till Friday, 60 seconds between 6 and 8 am</li>
  657. <li>"travelMode" - default: driving, options walking, bicycling or transit </li>
  658. <li>"GoogleMapsStyle" - choose your colors from: default,silver,dark,night</li>
  659. <li>"GoogleMapsSize" - Map size in pixel, &lt;width&gt;,&lt;height&gt;</li>
  660. <li>"GoogleMapsCenter" - Lat, Long coordinates of your map center, spearated by ,</li>
  661. <li>"GoogleMapsZoom" - sets your map zoom level</li>
  662. <li>"GoogleMapsStroke" - customize your map poly-strokes in color, weight and opacity <br> &lt;hex-color-code&gt;,[stroke-weight],[stroke-opacity],&lt;hex-color-code-of-return&gt;,[stroke-weight-of-return],[stroke-opacity-of-return]<br>must beginn with #color of each stroke, weight and opacity is optional<br><i>example:</i> #019cdf,#ffeb19<br><i>example:</i> #019cdf,20,#ffeb19<br><i>example:</i> #019cdf,20,#ffeb19,15<br><i>example:</i> #019cdf,#ffeb19,15<br><i>example:</i> #019cdf,20,80,#ffeb19<br><i>example:</i> #019cdf,#ffeb19,15,50<br><i>example:</i> #019cdf,20,80<br><i>default:</i> #4cde44,6,100,#FF0000,1,100</li>
  663. <li>"GoogleMapsTrafficLayer" - enable the basic Google Maps Traffic Layer</li>
  664. <li>"GoogleMapsDisableUI" - hide the map controls</li>
  665. </ul>
  666. <br>
  667. <br>
  668. <a name="TRAFFICreadings"></a>
  669. <b>Readings:</b>
  670. <ul>
  671. <li>delay </li>
  672. <li>distance </li>
  673. <li>duration </li>
  674. <li>duration_in_traffic </li>
  675. <li>state </li>
  676. <li>eta</li>
  677. <li>delay_min</li>
  678. <li>duration_min</li>
  679. <li>duration_in_traffic_min</li>
  680. <li>error_message</li>
  681. </ul>
  682. <br><br>
  683. <a name="TRAFFICset"></a>
  684. <b>Set</b>
  685. <ul>
  686. <li>update [burst-update-count] [burst-update-interval] - update readings manually</li>
  687. </ul>
  688. <br><br>
  689. </ul>
  690. =end html
  691. =cut