74_GardenaSmartDevice.pm 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. ###############################################################################
  2. #
  3. # Developed with Kate
  4. #
  5. # (c) 2017 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
  6. # All rights reserved
  7. #
  8. # Special thanks goes to comitters:
  9. # - Michael (mbrak) Thanks for Commandref
  10. # - Matthias (Kenneth) Thanks for Wiki entry
  11. #
  12. #
  13. # This script is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # any later version.
  17. #
  18. # The GNU General Public License can be found at
  19. # http://www.gnu.org/copyleft/gpl.html.
  20. # A copy is found in the textfile GPL.txt and important notices to the license
  21. # from the author is found in LICENSE.txt distributed with these scripts.
  22. #
  23. # This script is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. #
  28. #
  29. # $Id: 74_GardenaSmartDevice.pm 15749 2018-01-02 09:33:47Z CoolTux $
  30. #
  31. ###############################################################################
  32. ##
  33. ##
  34. ## Das JSON Modul immer in einem eval aufrufen
  35. # $data = eval{decode_json($data)};
  36. #
  37. # if($@){
  38. # Log3($SELF, 2, "$TYPE ($SELF) - error while request: $@");
  39. #
  40. # readingsSingleUpdate($hash, "state", "error", 1);
  41. #
  42. # return;
  43. # }
  44. #
  45. #
  46. ###### Wichtige Notizen
  47. #
  48. # apt-get install libio-socket-ssl-perl
  49. # http://www.dxsdata.com/de/2016/07/php-class-for-gardena-smart-system-api/
  50. #
  51. ##
  52. ##
  53. package main;
  54. my $missingModul = "";
  55. use strict;
  56. use warnings;
  57. use Time::Local;
  58. eval "use JSON;1" or $missingModul .= "JSON ";
  59. my $version = "0.4.1";
  60. # Declare functions
  61. sub GardenaSmartDevice_Attr(@);
  62. sub GardenaSmartDevice_Define($$);
  63. sub GardenaSmartDevice_Initialize($);
  64. sub GardenaSmartDevice_Set($@);
  65. sub GardenaSmartDevice_Undef($$);
  66. sub GardenaSmartDevice_WriteReadings($$);
  67. sub GardenaSmartDevice_Parse($$);
  68. sub GardenaSmartDevice_ReadingLangGerman($$);
  69. sub GardenaSmartDevice_RigRadingsValue($$);
  70. sub GardenaSmartDevice_Zulu2LocalString($);
  71. sub GardenaSmartDevice_Initialize($) {
  72. my ($hash) = @_;
  73. $hash->{Match} = '^{"id":".*';
  74. $hash->{SetFn} = "GardenaSmartDevice_Set";
  75. $hash->{DefFn} = "GardenaSmartDevice_Define";
  76. $hash->{UndefFn} = "GardenaSmartDevice_Undef";
  77. $hash->{ParseFn} = "GardenaSmartDevice_Parse";
  78. $hash->{AttrFn} = "GardenaSmartDevice_Attr";
  79. $hash->{AttrList} = "readingValueLanguage:de,en ".
  80. "model ".
  81. "IODev ".
  82. $readingFnAttributes;
  83. foreach my $d(sort keys %{$modules{GardenaSmartDevice}{defptr}}) {
  84. my $hash = $modules{GardenaSmartDevice}{defptr}{$d};
  85. $hash->{VERSION} = $version;
  86. }
  87. }
  88. sub GardenaSmartDevice_Define($$) {
  89. my ( $hash, $def ) = @_;
  90. my @a = split( "[ \t]+", $def );
  91. return "too few parameters: define <NAME> GardenaSmartDevice <device_Id> <model>" if( @a < 3 ) ;
  92. return "Cannot define Gardena Bridge device. Perl modul $missingModul is missing." if ( $missingModul );
  93. my $name = $a[0];
  94. my $deviceId = $a[2];
  95. my $category = $a[3];
  96. $hash->{DEVICEID} = $deviceId;
  97. $hash->{VERSION} = $version;
  98. CommandAttr(undef,"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}") if(AttrVal($name,'IODev','none') eq 'none');
  99. my $iodev = AttrVal($name,'IODev','none');
  100. AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
  101. if(defined($hash->{IODev}->{NAME})) {
  102. Log3 $name, 3, "GardenaSmartDevice ($name) - I/O device is " . $hash->{IODev}->{NAME};
  103. } else {
  104. Log3 $name, 1, "GardenaSmartDevice ($name) - no I/O device";
  105. }
  106. $iodev = $hash->{IODev}->{NAME};
  107. my $d = $modules{GardenaSmartDevice}{defptr}{$deviceId};
  108. return "GardenaSmartDevice device $name on GardenaSmartBridge $iodev already defined."
  109. if( defined($d) && $d->{IODev} == $hash->{IODev} && $d->{NAME} ne $name );
  110. $attr{$name}{room} = "GardenaSmart" if( not defined( $attr{$name}{room} ) );
  111. $attr{$name}{model} = $category if( not defined( $attr{$name}{model} ) );
  112. Log3 $name, 3, "GardenaSmartDevice ($name) - defined GardenaSmartDevice with DEVICEID: $deviceId";
  113. readingsSingleUpdate($hash,'state','initialized',1);
  114. $modules{GardenaSmartDevice}{defptr}{$deviceId} = $hash;
  115. return undef;
  116. }
  117. sub GardenaSmartDevice_Undef($$) {
  118. my ( $hash, $arg ) = @_;
  119. my $name = $hash->{NAME};
  120. my $deviceId = $hash->{DEVICEID};
  121. delete $modules{GardenaSmartDevice}{defptr}{$deviceId};
  122. return undef;
  123. }
  124. sub GardenaSmartDevice_Attr(@) {
  125. my ( $cmd, $name, $attrName, $attrVal ) = @_;
  126. my $hash = $defs{$name};
  127. return undef;
  128. }
  129. sub GardenaSmartDevice_Set($@) {
  130. my ($hash, $name, $cmd, @args) = @_;
  131. my ($arg, @params) = @args;
  132. my $payload;
  133. my $abilities;
  134. ### mower
  135. if( lc $cmd eq 'parkuntilfurthernotice' ) {
  136. $payload = '"name":"park_until_further_notice"';
  137. } elsif( lc $cmd eq 'parkuntilnexttimer' ) {
  138. $payload = '"name":"park_until_next_timer"';
  139. } elsif( lc $cmd eq 'startresumeschedule' ) {
  140. $payload = '"name":"start_resume_schedule"';
  141. } elsif( lc $cmd eq 'startoverridetimer' ) {
  142. my $duration = join( " ", @args );
  143. $payload = '"name":"start_override_timer","parameters":{"duration":' . $duration . '}';
  144. ### watering_computer
  145. } elsif( lc $cmd eq 'manualoverride' ) {
  146. my $duration = join( " ", @args );
  147. $payload = '"name":"manual_override","parameters":{"duration":' . $duration . '}';
  148. } elsif( lc $cmd eq 'canceloverride' ) {
  149. $payload = '"name":"cancel_override"';
  150. ### Sensors
  151. } elsif( lc $cmd eq 'refresh' ) {
  152. my $sensname = join( " ", @args );
  153. if( lc $sensname eq 'temperature' ) {
  154. $payload = '"name":"measure_ambient_temperature"';
  155. $abilities = 'ambient_temperature';
  156. } elsif( lc $sensname eq 'light' ) {
  157. $payload = '"name":"measure_light"';
  158. $abilities = 'light';
  159. } elsif( lc $sensname eq 'humidity' ) {
  160. $payload = '"name":"measure_humidity"';
  161. $abilities = 'humidity';
  162. }
  163. } elsif( lc $cmd eq '' ) {
  164. } elsif( lc $cmd eq '' ) {
  165. } elsif( lc $cmd eq '' ) {
  166. } elsif( lc $cmd eq '' ) {
  167. } elsif( lc $cmd eq '' ) {
  168. } elsif( lc $cmd eq '' ) {
  169. } else {
  170. my $list = '';
  171. $list .= 'parkUntilFurtherNotice:noArg parkUntilNextTimer:noArg startResumeSchedule:noArg startOverrideTimer:slider,0,60,1440' if( AttrVal($name,'model','unknown') eq 'mower' );
  172. $list .= 'manualOverride:slider,0,1,59 cancelOverride:noArg' if( AttrVal($name,'model','unknown') eq 'watering_computer' );
  173. $list .= 'refresh:temperature,light' if( AttrVal($name,'model','unknown') eq 'sensor' );
  174. return "Unknown argument $cmd, choose one of $list";
  175. }
  176. $abilities = 'mower' if( AttrVal($name,'model','unknown') eq 'mower' );
  177. $abilities = 'outlet' if( AttrVal($name,'model','unknown') eq 'watering_computer' );
  178. $hash->{helper}{deviceAction} = $payload;
  179. readingsSingleUpdate( $hash, "state", "send command to gardena cloud", 1);
  180. IOWrite($hash,$payload,$hash->{DEVICEID},$abilities);
  181. Log3 $name, 4, "GardenaSmartBridge ($name) - IOWrite: $payload $hash->{DEVICEID} $abilities IODevHash=$hash->{IODev}";
  182. return undef;
  183. }
  184. sub GardenaSmartDevice_Parse($$) {
  185. my ($io_hash,$json) = @_;
  186. my $name = $io_hash->{NAME};
  187. my $decode_json = eval{decode_json($json)};
  188. if($@){
  189. Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request: $@";
  190. }
  191. Log3 $name, 4, "GardenaSmartDevice ($name) - ParseFn was called";
  192. Log3 $name, 5, "GardenaSmartDevice ($name) - JSON: $json";
  193. if( defined($decode_json->{id}) ) {
  194. my $deviceId = $decode_json->{id};
  195. if( my $hash = $modules{GardenaSmartDevice}{defptr}{$deviceId} ) {
  196. my $name = $hash->{NAME};
  197. GardenaSmartDevice_WriteReadings($hash,$decode_json);
  198. Log3 $name, 4, "GardenaSmartDevice ($name) - find logical device: $hash->{NAME}";
  199. return $hash->{NAME};
  200. } else {
  201. Log3 $name, 3, "GardenaSmartDevice ($name) - autocreate new device " . makeDeviceName($decode_json->{name}) . " with deviceId $decode_json->{id}, model $decode_json->{category}";
  202. return "UNDEFINED " . makeDeviceName($decode_json->{name}) . " GardenaSmartDevice $decode_json->{id} $decode_json->{category}";
  203. }
  204. }
  205. }
  206. sub GardenaSmartDevice_WriteReadings($$) {
  207. my ($hash,$decode_json) = @_;
  208. my $name = $hash->{NAME};
  209. my $abilities = scalar (@{$decode_json->{abilities}});
  210. readingsBeginUpdate($hash);
  211. do {
  212. if( ref($decode_json->{abilities}[$abilities]{properties}) eq "ARRAY" and scalar(@{$decode_json->{abilities}[$abilities]{properties}}) > 0 ) {;
  213. foreach my $propertie (@{$decode_json->{abilities}[$abilities]{properties}}) {
  214. readingsBulkUpdateIfChanged($hash,$decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name},GardenaSmartDevice_RigRadingsValue($hash,$propertie->{value})) if( defined($propertie->{value})
  215. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'radio-quality'
  216. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'battery-level'
  217. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'internal_temperature-temperature'
  218. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'ambient_temperature-temperature'
  219. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'soil_temperature-temperature'
  220. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'humidity-humidity'
  221. and $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} ne 'light-light' );
  222. readingsBulkUpdate($hash,$decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name},GardenaSmartDevice_RigRadingsValue($hash,$propertie->{value})) if( defined($propertie->{value})
  223. and ($decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'radio-quality'
  224. or $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'battery-level'
  225. or $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'internal_temperature-temperature'
  226. or $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'ambient_temperature-temperature'
  227. or $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'soil_temperature-temperature'
  228. or $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'humidity-humidity'
  229. or $decode_json->{abilities}[$abilities]{name}.'-'.$propertie->{name} eq 'light-light') );
  230. }
  231. }
  232. $abilities--;
  233. } while ($abilities >= 0);
  234. readingsBulkUpdate($hash,'state',ReadingsVal($name,'mower-status','readingsValError')) if( AttrVal($name,'model','unknown') eq 'mower' );
  235. readingsBulkUpdate($hash,'state',(ReadingsVal($name,'outlet-valve_open','readingsValError') == 1 ? GardenaSmartDevice_RigRadingsValue($hash,'open') : GardenaSmartDevice_RigRadingsValue($hash,'closed'))) if( AttrVal($name,'model','unknown') eq 'watering_computer' );
  236. readingsBulkUpdate($hash,'state','T: ' . ReadingsVal($name,'ambient_temperature-temperature','readingsValError') . '°C, H: ' . ReadingsVal($name,'humidity-humidity','readingsValError') . '%, L: ' . ReadingsVal($name,'light-light','readingsValError') . 'lux') if( AttrVal($name,'model','unknown') eq 'sensor' );
  237. readingsEndUpdate( $hash, 1 );
  238. Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written}";
  239. }
  240. ##################################
  241. ##################################
  242. #### my little helpers ###########
  243. sub GardenaSmartDevice_ReadingLangGerman($$) {
  244. my ($hash,$readingValue) = @_;
  245. my $name = $hash->{NAME};
  246. my %langGermanMapp = (
  247. 'ok_cutting' => 'mähen',
  248. 'paused' => 'pausiert',
  249. 'ok_searching' => 'suche Ladestation',
  250. 'ok_charging' => 'lädt',
  251. 'ok_leaving' => 'mähen',
  252. 'wait_updating' => 'wird aktualisiert ...',
  253. 'wait_power_up' => 'wird eingeschaltet ...',
  254. 'parked_timer' => 'geparkt nach Zeitplan',
  255. 'parked_park_selected' => 'geparkt',
  256. 'off_disabled' => 'der Mäher ist ausgeschaltet',
  257. 'off_hatch_open' => 'deaktiviert. Abdeckung ist offen oder PIN-Code erforderlich',
  258. 'unknown' => 'unbekannter Status',
  259. 'error' => 'Fehler',
  260. 'error_at_power_up' => 'Neustart ...',
  261. 'off_hatch_closed' => 'Deaktiviert. Manueller Start erforderlich',
  262. 'ok_cutting_timer_overridden' => 'manuelles mähen',
  263. 'parked_autotimer' => 'geparkt durch SensorControl',
  264. 'parked_daily_limit_reached' => 'abgeschlossen',
  265. 'no_message' => 'kein Fehler',
  266. 'outside_working_area' => 'außerhalb des Arbeitsbereichs',
  267. 'no_loop_signal' => 'kein Schleifensignal',
  268. 'wrong_loop_signal' => 'falsches Schleifensignal',
  269. 'loop_sensor_problem_front' => 'Problem Schleifensensor, vorne',
  270. 'loop_sensor_problem_rear' => 'Problem Schleifensensor, hinten',
  271. 'trapped' => 'eingeschlossen',
  272. 'upside_down' => 'steht auf dem Kopf',
  273. 'low_battery' => 'niedriger Batteriestand',
  274. 'empty_battery' => 'Batterie leer',
  275. 'no_drive' => 'fährt nicht',
  276. 'lifted' => 'angehoben',
  277. 'stuck_in_charging_station' => 'eingeklemmt in Ladestation',
  278. 'charging_station_blocked' => 'Ladestation blockiert',
  279. 'collision_sensor_problem_rear' => 'Problem Stoßsensor hinten',
  280. 'collision_sensor_problem_front' => 'Problem Stoßsensor vorne',
  281. 'wheel_motor_blocked_right' => 'Radmotor rechts blockiert',
  282. 'wheel_motor_blocked_left' => 'Radmotor links blockiert',
  283. 'wheel_drive_problem_right' => 'Problem Antrieb, rechts',
  284. 'wheel_drive_problem_left' => 'Problem Antrieb, links',
  285. 'cutting_system_blocked' => 'Schneidsystem blockiert',
  286. 'invalid_sub_device_combination' => 'fehlerhafte Verbindung',
  287. 'settings_restored' => 'Standardeinstellungen',
  288. 'electronic_problem' => 'elektronisches Problem',
  289. 'charging_system_problem' => 'Problem Ladesystem',
  290. 'tilt_sensor_problem' => 'Kippsensor Problem',
  291. 'wheel_motor_overloaded_right' => 'rechter Radmotor überlastet',
  292. 'wheel_motor_overloaded_left' => 'linker Radmotor überlastet',
  293. 'charging_current_too_high' => 'Ladestrom zu hoch',
  294. 'temporary_problem' => 'vorübergehendes Problem',
  295. 'guide_1_not_found' => 'SK 1 nicht gefunden',
  296. 'guide_2_not_found' => 'SK 2 nicht gefunden',
  297. 'guide_3_not_found' => 'SK 3 nicht gefunden',
  298. 'difficult_finding_home' => 'Problem die Ladestation zu finden',
  299. 'guide_calibration_accomplished' => 'Kalibrierung des Suchkabels beendet',
  300. 'guide_calibration_failed' => 'Kalibrierung des Suchkabels fehlgeschlagen',
  301. 'temporary_battery_problem' => 'kurzzeitiges Batterieproblem',
  302. 'battery_problem' => 'Batterieproblem',
  303. 'alarm_mower_switched_off' => 'Alarm! Mäher ausgeschalten',
  304. 'alarm_mower_stopped' => 'Alarm! Mäher gestoppt',
  305. 'alarm_mower_lifted' => 'Alarm! Mäher angehoben',
  306. 'alarm_mower_tilted' => 'Alarm! Mäher gekippt',
  307. 'connection_changed' => 'Verbindung geändert',
  308. 'connection_not_changed' => 'Verbindung nicht geändert',
  309. 'com_board_not_available' => 'COM Board nicht verfügbar',
  310. 'slipped' => 'rutscht',
  311. 'out_of_operation' => 'ausser Betrieb',
  312. 'replace_now' => 'kritischer Batteriestand, wechseln Sie jetzt',
  313. 'low' => 'niedrig',
  314. 'ok' => 'oK',
  315. 'no_source' => 'oK',
  316. 'mower_charging' => 'Mäher wurde geladen',
  317. 'completed_cutting_autotimer' => 'Sensor Control erreicht',
  318. 'week_timer' => 'Wochentimer erreicht',
  319. 'countdown_timer' => 'Stoppuhr Timer',
  320. 'undefined' => 'unklar',
  321. 'unknown' => 'unklar',
  322. 'status_device_unreachable' => 'Gerät ist nicht in Reichweite',
  323. 'status_device_alive' => 'Gerät ist in Reichweite',
  324. 'bad' => 'schlecht',
  325. 'poor' => 'schwach',
  326. 'good' => 'gut',
  327. 'undefined' => 'unklar',
  328. 'idle' => 'nichts zu tun',
  329. 'firmware_cancel' => 'Firmwareupload unterbrochen',
  330. 'firmware_upload' => 'Firmwareupload',
  331. 'unsupported' => 'nicht unterstützt',
  332. 'up_to_date' => 'auf dem neusten Stand',
  333. 'mower' => 'Mäher',
  334. 'watering_computer' => 'Bewässerungscomputer',
  335. 'no_frost' => 'kein Frost',
  336. 'open' => 'offen',
  337. 'closed' => 'geschlossen',
  338. 'included' => 'inbegriffen',
  339. 'active' => 'aktiv',
  340. 'inactive' => 'nicht aktiv'
  341. );
  342. if( defined($langGermanMapp{$readingValue}) and (AttrVal('global','language','none') eq 'DE' or AttrVal($name,'readingValueLanguage','none') eq 'de') and AttrVal($name,'readingValueLanguage','none') ne 'en') {
  343. return $langGermanMapp{$readingValue};
  344. } else {
  345. return $readingValue;
  346. }
  347. }
  348. sub GardenaSmartDevice_RigRadingsValue($$) {
  349. my ($hash,$readingValue) = @_;
  350. my $rigReadingValue;
  351. if( $readingValue =~ /^(\d+)-(\d\d)-(\d\d)T(\d\d)/ ) {
  352. $rigReadingValue = GardenaSmartDevice_Zulu2LocalString($readingValue);
  353. } else {
  354. $rigReadingValue = GardenaSmartDevice_ReadingLangGerman($hash,$readingValue);
  355. }
  356. return $rigReadingValue;
  357. }
  358. sub GardenaSmartDevice_Zulu2LocalString($) {
  359. my $t = shift;
  360. my ($datehour,$datemin,$rest) = split(/:/,$t,3);
  361. my ($year, $month, $day, $hour,$min) = $datehour =~ /(\d+)-(\d\d)-(\d\d)T(\d\d)/;
  362. my $epoch = timegm (0,0,$hour,$day,$month-1,$year);
  363. my ($lyear,$lmonth,$lday,$lhour,$isdst) = (localtime($epoch))[5,4,3,2,-1];
  364. $lyear += 1900; # year is 1900 based
  365. $lmonth++; # month number is zero based
  366. if( defined($rest) ) {
  367. return ( sprintf("%04d-%02d-%02d %02d:%02d:%s",$lyear,$lmonth,$lday,$lhour,$datemin,substr($rest,0,2)));
  368. } elsif( $lyear < 2000 ) {
  369. return "illegal year";
  370. } else {
  371. return ( sprintf("%04d-%02d-%02d %02d:%02d",$lyear,$lmonth,$lday,$lhour,substr($datemin,0,2)));
  372. }
  373. }
  374. 1;
  375. =pod
  376. =item device
  377. =item summary Modul to control GardenaSmart Devices
  378. =item summary_DE Modul zur Steuerung von GardenaSmartger&aumlten
  379. =begin html
  380. <a name="GardenaSmartDevice"></a>
  381. <h3>GardenaSmartDevice</h3>
  382. <ul>
  383. In combination with GardenaSmartBridge this FHEM Module controls the GardenaSmart Device using the GardenaCloud
  384. <br><br>
  385. Once the Bridge device is created, the connected devices are automatically recognized and created in FHEM. <br>
  386. From now on the devices can be controlled and changes in the GardenaAPP are synchronized with the state and readings of the devices.
  387. <a name="GardenaSmartDevicereadings"></a>
  388. <br><br><br>
  389. <b>Readings</b>
  390. <ul>
  391. <li>battery-charging - Indicator if the Battery is charged (0/1) or with newer Firmware (false/true)</li>
  392. <li>battery-level - load percentage of the Battery</li>
  393. <li>battery-rechargeable_battery_status - healthyness of the battery (out_of_operation/replace_now/low/ok)</li>
  394. <li>device_info-category - category of device (mower/watering_computer)</li>
  395. <li>device_info-last_time_online - timestamp of last radio contact</li>
  396. <li>device_info-manufacturer - manufacturer</li>
  397. <li>device_info-product - product type</li>
  398. <li>device_info-serial_number - serial number</li>
  399. <li>device_info-sgtin - </li>
  400. <li>device_info-version - firmware version</li>
  401. <li>firmware-firmware_command - firmware command (idle/firmware_cancel/firmware_upload/unsupported)</li>
  402. <li>firmware-firmware_status - firmware status </li>
  403. <li>firmware-firmware_update_start - indicator when a firmwareupload is started</li>
  404. <li>firmware-firmware_upload_progress - progress indicator of firmware update</li>
  405. <li>firmware-inclusion_status - inclusion status</li>
  406. <li>internal_temperature-temperature - internal device temperature</li>
  407. <li>mower-error - actual error message
  408. <ul>
  409. <li>no_message</li>
  410. <li>outside_working_area</li>
  411. <li>no_loop_signal</li>
  412. <li>wrong_loop_signal</li>
  413. <li>loop_sensor_problem_front</li>
  414. <li>loop_sensor_problem_rear</li>
  415. <li>trapped</li>
  416. <li>upside_down</li>
  417. <li>low_battery</li>
  418. <li>empty_battery</li>
  419. <li>no_drive</li>
  420. <li>lifted</li>
  421. <li>stuck_in_charging_station</li>
  422. <li>charging_station_blocked</li>
  423. <li>collision_sensor_problem_rear</li>
  424. <li>collision_sensor_problem_front</li>
  425. <li>wheel_motor_blocked_right</li>
  426. <li>wheel_motor_blocked_left</li>
  427. <li>wheel_drive_problem_right</li>
  428. <li>wheel_drive_problem_left</li>
  429. <li>cutting_system_blocked</li>
  430. <li>invalid_sub_device_combination</li>
  431. <li>settings_restored</li>
  432. <li>electronic_problem</li>
  433. <li>charging_system_problem</li>
  434. <li>tilt_sensor_problem</li>
  435. <li>wheel_motor_overloaded_right</li>
  436. <li>wheel_motor_overloaded_left</li>
  437. <li>charging_current_too_high</li>
  438. <li>temporary_problem</li>
  439. <li>guide_1_not_found</li>
  440. <li>guide_2_not_found</li>
  441. <li>guide_3_not_found</li>
  442. <li>difficult_finding_home</li>
  443. <li>guide_calibration_accomplished</li>
  444. <li>guide_calibration_failed</li>
  445. <li>temporary_battery_problem</li>
  446. <li>battery_problem</li>
  447. <li>alarm_mower_switched_off</li>
  448. <li>alarm_mower_stopped</li>
  449. <li>alarm_mower_lifted</li>
  450. <li>alarm_mower_tilted</li>
  451. <li>connection_changed</li>
  452. <li>connection_not_changed</li>
  453. <li>com_board_not_available</li>
  454. <li>slipped</li>
  455. </ul>
  456. </li>
  457. <li>mower-manual_operation - (0/1) or with newer Firmware (false/true)</li>
  458. <li>mower-override_end_time - manual override end time</li>
  459. <li>mower-source_for_next_start - source for the next start
  460. <ul>
  461. <li>no_source</li>
  462. <li>mower_charging</li>
  463. <li>completed_cutting_autotimer</li>
  464. <li>week_timer</li>
  465. <li>countdown_timer</li>
  466. <li>undefined</li>
  467. </ul>
  468. </li>
  469. <li>mower-status - mower state (see state)</li>
  470. <li>mower-timestamp_next_start - timestamp of next scheduled start</li>
  471. <li>radio-connection_status - state of connection</li>
  472. <li>radio-quality - percentage of the radio quality</li>
  473. <li>radio-state - radio state (bad/poor/good/undefined)</li>
  474. <li>state - state of the mower
  475. <ul>
  476. <li>paused</li>
  477. <li>ok_cutting</li>
  478. <li>ok_searching</li>
  479. <li>ok_charging</li>
  480. <li>ok_leaving</li>
  481. <li>wait_updating</li>
  482. <li>wait_power_up</li>
  483. <li>parked_timer</li>
  484. <li>parked_park_selected</li>
  485. <li>off_disabled</li>
  486. <li>off_hatch_open</li>
  487. <li>unknown</li>
  488. <li>error</li>
  489. <li>error_at_power_up</li>
  490. <li>off_hatch_closed</li>
  491. <li>ok_cutting_timer_overridden</li>
  492. <li>parked_autotimer</li>
  493. <li>parked_daily_limit_reached</li>
  494. </ul>
  495. </li>
  496. </ul>
  497. <br><br>
  498. <a name="GardenaSmartDeviceattributes"></a>
  499. <b>Attributes</b>
  500. <ul>
  501. <li>readingValueLanguage - Change the Language of Readings (de,en/if not set the default is english and the global language is not set at german) </li>
  502. <li>model - </li>
  503. </ul>
  504. <br><br>
  505. <a name="GardenaSmartDeviceset"></a>
  506. <b>set</b>
  507. <ul>
  508. <li>parkUntilFurtherNotice</li>
  509. <li>parkUntilNextTimer</li>
  510. <li>startOverrideTimer - 0 to 59 Minutes</li>
  511. <li>startResumeSchedule</li>
  512. </ul>
  513. </ul>
  514. =end html
  515. =begin html_DE
  516. <a name="GardenaSmartDevice"></a>
  517. <h3>GardenaSmartDevice</h3>
  518. <ul>
  519. Zusammen mit dem Device GardenaSmartDevice stellt dieses FHEM Modul die Kommunikation zwischen der GardenaCloud und Fhem her.
  520. <br><br>
  521. Wenn das GardenaSmartBridge Device erzeugt wurde, werden verbundene Ger&auml;te automatisch erkannt und in Fhem angelegt.<br>
  522. Von nun an k&ouml;nnen die eingebundenen Ger&auml;te gesteuert werden. &Auml;nderungen in der APP werden mit den Readings und dem Status syncronisiert.
  523. <a name="GardenaSmartDevicereadings"></a>
  524. </ul>
  525. <br>
  526. <ul>
  527. <b>Readings</b>
  528. <ul>
  529. <li>battery-charging - Ladeindikator (0/1) oder mit neuerer Firmware (false/true)</li>
  530. <li>battery-level - Ladezustand der Batterie in Prozent</li>
  531. <li>battery-rechargeable_battery_status - Zustand der Batterie (Ausser Betrieb/Kritischer Batteriestand, wechseln Sie jetzt/Niedrig/oK)</li>
  532. <li>device_info-category - Eigenschaft des Ger&auml;tes (M&auml;her/Bew&auml;sserungscomputer/Bodensensor)</li>
  533. <li>device_info-last_time_online - Zeitpunkt der letzten Funk&uuml;bertragung</li>
  534. <li>device_info-manufacturer - Hersteller</li>
  535. <li>device_info-product - Produkttyp</li>
  536. <li>device_info-serial_number - Seriennummer</li>
  537. <li>device_info-sgtin - </li>
  538. <li>device_info-version - Firmware Version</li>
  539. <li>firmware-firmware_command - Firmware Kommando (Nichts zu tun/Firmwareupload unterbrochen/Firmwareupload/nicht unterst&uuml;tzt)</li>
  540. <li>firmware-firmware_status - Firmware Status </li>
  541. <li>firmware-firmware_update_start - Firmwareupdate (0/1) oder mit neuerer Firmware (false/true)</li>
  542. <li>firmware-firmware_upload_progress - Firmwareupdatestatus in Prozent</li>
  543. <li>firmware-inclusion_status - Einbindungsstatus</li>
  544. <li>internal_temperature-temperature - Interne Ger&auml;te Temperatur</li>
  545. <li>mower-error - Aktuelle Fehler Meldung
  546. <ul>
  547. <li>Kein Fehler</li>
  548. <li>Au&szlig;erhalb des Arbeitsbereichs</li>
  549. <li>Kein Schleifensignal</li>
  550. <li>Falsches Schleifensignal</li>
  551. <li>Problem Schleifensensor, vorne</li>
  552. <li>Problem Schleifensensor, hinten</li>
  553. <li>Eingeschlossen</li>
  554. <li>Steht auf dem Kopf</li>
  555. <li>Niedriger Batteriestand</li>
  556. <li>Batterie ist leer</li>
  557. <li>Kein Antrieb</li>
  558. <li>Angehoben</li>
  559. <li>Eingeklemmt in Ladestation</li>
  560. <li>Ladestation blockiert</li>
  561. <li>Problem Sto&szlig;sensor hinten</li>
  562. <li>Problem Sto&szlig;sensor vorne</li>
  563. <li>Radmotor rechts blockiert</li>
  564. <li>Radmotor links blockiert</li>
  565. <li>Problem Antrieb, rechts</li>
  566. <li>Problem Antrieb, links</li>
  567. <li>Schneidsystem blockiert</li>
  568. <li>Fehlerhafte Verbindung</li>
  569. <li>Standardeinstellungen</li>
  570. <li>Elektronisches Problem</li>
  571. <li>Problem Ladesystem</li>
  572. <li>Kippsensorproblem</li>
  573. <li>Rechter Radmotor &uuml;berlastet</li>
  574. <li>Linker Radmotor &uuml;berlastet</li>
  575. <li>Ladestrom zu hoch</li>
  576. <li>Vor&uuml;bergehendes Problem</li>
  577. <li>SK 1 nicht gefunden</li>
  578. <li>SK 2 nicht gefunden</li>
  579. <li>SK 3 nicht gefunden</li>
  580. <li>Problem die Ladestation zu finden</li>
  581. <li>Kalibration des Suchkabels beendet</li>
  582. <li>Kalibration des Suchkabels fehlgeschlagen</li>
  583. <li>Kurzzeitiges Batterieproblem</li>
  584. <li>Batterieproblem</li>
  585. <li>Alarm! M&auml;her ausgeschalten</li>
  586. <li>Alarm! M&auml;her gestoppt</li>
  587. <li>Alarm! M&auml;her angehoben</li>
  588. <li>Alarm! M&auml;her gekippt</li>
  589. <li>Verbindung geändert</li>
  590. <li>Verbindung nicht ge&auml;ndert</li>
  591. <li>COM board nicht verf&uuml;gbar</li>
  592. <li>Rutscht</li>
  593. </ul>
  594. </li>
  595. <li>mower-manual_operation - Manueller Betrieb (0/1) oder mit neuerer Firmware (false/true)</li>
  596. <li>mower-override_end_time - Zeitpunkt wann der manuelle Betrieb beendet ist</li>
  597. <li>mower-source_for_next_start - Grund f&uuml;r den n&auml;chsten Start
  598. <ul>
  599. <li>Kein Grund</li>
  600. <li>M&auml;her wurde geladen</li>
  601. <li>SensorControl erreicht</li>
  602. <li>Wochentimer erreicht</li>
  603. <li>Stoppuhr Timer</li>
  604. <li>Undefiniert</li>
  605. </ul>
  606. </li>
  607. <li>mower-status - M&auml;her Status (siehe state)</li>
  608. <li>mower-timestamp_next_start - Zeitpunkt des n&auml;chsten geplanten Starts</li>
  609. <li>radio-connection_status - Status der Funkverbindung</li>
  610. <li>radio-quality - Indikator f&uuml;r die Funkverbindung in Prozent</li>
  611. <li>radio-state - radio state (schlecht/schwach/gut/Undefiniert)</li>
  612. <li>state - Staus des M&auml;hers
  613. <ul>
  614. <li>Pausiert</li>
  615. <li>M&auml;hen</li>
  616. <li>Suche Ladestation</li>
  617. <li>L&auml;dt</li>
  618. <li>M&auml;hen</li>
  619. <li>Wird aktualisiert ...</li>
  620. <li>Wird eingeschaltet ...</li>
  621. <li>Geparkt nach Zeitplan</li>
  622. <li>Geparkt</li>
  623. <li>Der M&auml;her ist ausgeschaltet</li>
  624. <li>Deaktiviert. Abdeckung ist offen oder PIN-Code erforderlich</li>
  625. <li>Unbekannter Status</li>
  626. <li>Fehler</li>
  627. <li>Neustart ...</li>
  628. <li>Deaktiviert. Manueller Start erforderlich</li>
  629. <li>Manuelles M&auml;hen</li>
  630. <li>Geparkt durch SensorControl</li>
  631. <li>Abgeschlossen</li>
  632. </ul>
  633. </li>
  634. </ul>
  635. <br><br>
  636. <a name="GardenaSmartDeviceattributes"></a>
  637. <b>Attribute</b>
  638. <ul>
  639. <li>readingValueLanguage - &Auml;nderung der Sprache der Readings (de,en/wenn nichts gesetzt ist, dann Englisch es sei denn deutsch ist als globale Sprache gesetzt) </li>
  640. <li>model - </li>
  641. </ul>
  642. <a name="GardenaSmartDeviceset"></a>
  643. <b>set</b>
  644. <ul>
  645. <li>parkUntilFurtherNotice - Parken des M&auml;hers unter Umgehung des Zeitplans</li>
  646. <li>parkUntilNextTimer - Parken bis zum n&auml;chsten Zeitplan</li>
  647. <li>startOverrideTimer - Manuelles m&auml;hen (0 bis 59 Minuten)</li>
  648. <li>startResumeSchedule - Weiterf&uuml;hrung des Zeitplans</li>
  649. </ul>
  650. </ul>
  651. =end html_DE
  652. =cut