74_GardenaSmartDevice.pm 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. ###############################################################################
  2. #
  3. # Developed with Kate
  4. #
  5. # (c) 2017-2018 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. # - BioS Thanks for predefined start points Code
  12. # - fettgu Thanks for Debugging Irrigation Control data flow
  13. #
  14. #
  15. # This script is free software; you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation; either version 2 of the License, or
  18. # any later version.
  19. #
  20. # The GNU General Public License can be found at
  21. # http://www.gnu.org/copyleft/gpl.html.
  22. # A copy is found in the textfile GPL.txt and important notices to the license
  23. # from the author is found in LICENSE.txt distributed with these scripts.
  24. #
  25. # This script is distributed in the hope that it will be useful,
  26. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. # GNU General Public License for more details.
  29. #
  30. #
  31. # $Id: 74_GardenaSmartDevice.pm 17555 2018-10-17 20:06:58Z CoolTux $
  32. #
  33. ###############################################################################
  34. ##
  35. ##
  36. ## Das JSON Modul immer in einem eval aufrufen
  37. # $data = eval{decode_json($data)};
  38. #
  39. # if($@){
  40. # Log3($SELF, 2, "$TYPE ($SELF) - error while request: $@");
  41. #
  42. # readingsSingleUpdate($hash, "state", "error", 1);
  43. #
  44. # return;
  45. # }
  46. #
  47. #
  48. ###### Wichtige Notizen
  49. #
  50. # apt-get install libio-socket-ssl-perl
  51. # http://www.dxsdata.com/de/2016/07/php-class-for-gardena-smart-system-api/
  52. #
  53. ##
  54. ##
  55. package main;
  56. use strict;
  57. use warnings;
  58. my $version = "1.4.0";
  59. sub GardenaSmartDevice_Initialize($) {
  60. my ($hash) = @_;
  61. $hash->{Match} = '^{"id":".*';
  62. $hash->{SetFn} = "GardenaSmartDevice::Set";
  63. $hash->{DefFn} = "GardenaSmartDevice::Define";
  64. $hash->{UndefFn} = "GardenaSmartDevice::Undef";
  65. $hash->{ParseFn} = "GardenaSmartDevice::Parse";
  66. $hash->{AttrFn} = "GardenaSmartDevice::Attr";
  67. $hash->{AttrList} =
  68. "readingValueLanguage:de,en "
  69. . "model:watering_computer,sensor,mower,ic24 "
  70. . "IODev "
  71. . $readingFnAttributes;
  72. foreach my $d ( sort keys %{ $modules{GardenaSmartDevice}{defptr} } ) {
  73. my $hash = $modules{GardenaSmartDevice}{defptr}{$d};
  74. $hash->{VERSION} = $version;
  75. }
  76. }
  77. ## unserer packagename
  78. package GardenaSmartDevice;
  79. use GPUtils qw(:all)
  80. ; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
  81. my $missingModul = "";
  82. use strict;
  83. use warnings;
  84. use POSIX;
  85. use Time::Local;
  86. eval "use JSON;1" or $missingModul .= "JSON ";
  87. ## Import der FHEM Funktionen
  88. BEGIN {
  89. GP_Import(
  90. qw(readingsSingleUpdate
  91. readingsBulkUpdate
  92. readingsBulkUpdateIfChanged
  93. readingsBeginUpdate
  94. readingsEndUpdate
  95. Log3
  96. CommandAttr
  97. AttrVal
  98. ReadingsVal
  99. AssignIoPort
  100. modules
  101. IOWrite
  102. defs
  103. makeDeviceName)
  104. );
  105. }
  106. sub Define($$) {
  107. my ( $hash, $def ) = @_;
  108. my @a = split( "[ \t]+", $def );
  109. return
  110. "too few parameters: define <NAME> GardenaSmartDevice <device_Id> <model>"
  111. if ( @a < 3 );
  112. return
  113. "Cannot define Gardena Bridge device. Perl modul $missingModul is missing."
  114. if ($missingModul);
  115. my $name = $a[0];
  116. my $deviceId = $a[2];
  117. my $category = $a[3];
  118. $hash->{DEVICEID} = $deviceId;
  119. $hash->{VERSION} = $version;
  120. $hash->{helper}{STARTINGPOINTID} = '';
  121. CommandAttr( undef,
  122. "$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" )
  123. if ( AttrVal( $name, 'IODev', 'none' ) eq 'none' );
  124. my $iodev = AttrVal( $name, 'IODev', 'none' );
  125. AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} );
  126. if ( defined( $hash->{IODev}->{NAME} ) ) {
  127. Log3 $name, 3, "GardenaSmartDevice ($name) - I/O device is "
  128. . $hash->{IODev}->{NAME};
  129. }
  130. else {
  131. Log3 $name, 1, "GardenaSmartDevice ($name) - no I/O device";
  132. }
  133. $iodev = $hash->{IODev}->{NAME};
  134. my $d = $modules{GardenaSmartDevice}{defptr}{$deviceId};
  135. return
  136. "GardenaSmartDevice device $name on GardenaSmartBridge $iodev already defined."
  137. if ( defined($d)
  138. and $d->{IODev} == $hash->{IODev}
  139. and $d->{NAME} ne $name );
  140. CommandAttr( undef, $name . ' room GardenaSmart' )
  141. if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
  142. CommandAttr( undef, $name . ' model ' . $category )
  143. if ( AttrVal( $name, 'model', 'none' ) eq 'none' );
  144. Log3 $name, 3,
  145. "GardenaSmartDevice ($name) - defined GardenaSmartDevice with DEVICEID: $deviceId";
  146. readingsSingleUpdate( $hash, 'state', 'initialized', 1 );
  147. $modules{GardenaSmartDevice}{defptr}{$deviceId} = $hash;
  148. return undef;
  149. }
  150. sub Undef($$) {
  151. my ( $hash, $arg ) = @_;
  152. my $name = $hash->{NAME};
  153. my $deviceId = $hash->{DEVICEID};
  154. delete $modules{GardenaSmartDevice}{defptr}{$deviceId};
  155. return undef;
  156. }
  157. sub Attr(@) {
  158. my ( $cmd, $name, $attrName, $attrVal ) = @_;
  159. my $hash = $defs{$name};
  160. return undef;
  161. }
  162. sub Set($@) {
  163. my ( $hash, $name, $cmd, @args ) = @_;
  164. my $payload;
  165. my $abilities = '';
  166. ### mower
  167. if ( lc $cmd eq 'parkuntilfurthernotice' ) {
  168. $payload = '"name":"park_until_further_notice"';
  169. }
  170. elsif ( lc $cmd eq 'parkuntilnexttimer' ) {
  171. $payload = '"name":"park_until_next_timer"';
  172. }
  173. elsif ( lc $cmd eq 'startresumeschedule' ) {
  174. $payload = '"name":"start_resume_schedule"';
  175. }
  176. elsif ( lc $cmd eq 'startoverridetimer' ) {
  177. my $duration = join( " ", @args );
  178. $payload = '"name":"start_override_timer","parameters":{"duration":'
  179. . $duration . '}';
  180. }
  181. elsif ( lc $cmd eq 'startpoint' ) {
  182. my $err;
  183. ( $err, $payload, $abilities ) =
  184. SetPredefinedStartPoints( $hash, @args );
  185. return $err if ( defined($err) );
  186. ### watering_computer
  187. }
  188. elsif ( lc $cmd eq 'manualoverride' ) {
  189. my $duration = join( " ", @args );
  190. $payload = '"name":"manual_override","parameters":{"duration":'
  191. . $duration . '}';
  192. }
  193. elsif ( lc $cmd eq 'canceloverride' ) {
  194. $payload = '"name":"cancel_override"';
  195. ### Watering ic24
  196. }
  197. elsif ( $cmd =~ /manualDurationValve/ ) {
  198. my $valve_id;
  199. my $duration = join( " ", @args );
  200. if ( $cmd =~ m#(\d)$# ) {
  201. $valve_id = $1;
  202. }
  203. $payload =
  204. '"properties":{"name":"watering_timer_'
  205. . $valve_id
  206. . '","value":{"state":"manual","duration":'
  207. . $duration
  208. . ',"valve_id":'
  209. . $valve_id . '}}';
  210. ### Sensors
  211. }
  212. elsif ( lc $cmd eq 'refresh' ) {
  213. my $sensname = join( " ", @args );
  214. if ( lc $sensname eq 'temperature' ) {
  215. $payload = '"name":"measure_ambient_temperature"';
  216. $abilities = 'ambient_temperature';
  217. }
  218. elsif ( lc $sensname eq 'light' ) {
  219. $payload = '"name":"measure_light"';
  220. $abilities = 'light';
  221. }
  222. elsif ( lc $sensname eq 'humidity' ) {
  223. $payload = '"name":"measure_soil_humidity"';
  224. $abilities = 'humidity';
  225. }
  226. }
  227. else {
  228. my $list = '';
  229. $list .=
  230. 'parkUntilFurtherNotice:noArg parkUntilNextTimer:noArg startResumeSchedule:noArg startOverrideTimer:slider,0,60,1440 startpoint'
  231. if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
  232. $list .= 'manualOverride:slider,0,1,59 cancelOverride:noArg'
  233. if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
  234. $list .=
  235. 'manualDurationValve1:slider,1,1,59 manualDurationValve2:slider,1,1,59 manualDurationValve3:slider,1,1,59 manualDurationValve4:slider,1,1,59 manualDurationValve5:slider,1,1,59 manualDurationValve6:slider,1,1,59'
  236. if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
  237. $list .= 'refresh:temperature,light,humidity'
  238. if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' );
  239. return "Unknown argument $cmd, choose one of $list";
  240. }
  241. $abilities = 'mower'
  242. if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' )
  243. and $abilities ne 'mower_settings';
  244. $abilities = 'outlet'
  245. if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
  246. $abilities = 'watering'
  247. if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
  248. $hash->{helper}{deviceAction} = $payload;
  249. readingsSingleUpdate( $hash, "state", "send command to gardena cloud", 1 );
  250. IOWrite( $hash, $payload, $hash->{DEVICEID}, $abilities );
  251. Log3 $name, 4,
  252. "GardenaSmartBridge ($name) - IOWrite: $payload $hash->{DEVICEID} $abilities IODevHash=$hash->{IODev}";
  253. return undef;
  254. }
  255. sub Parse($$) {
  256. my ( $io_hash, $json ) = @_;
  257. my $name = $io_hash->{NAME};
  258. my $decode_json = eval { decode_json($json) };
  259. if ($@) {
  260. Log3 $name, 3,
  261. "GardenaSmartBridge ($name) - JSON error while request: $@";
  262. }
  263. Log3 $name, 4, "GardenaSmartDevice ($name) - ParseFn was called";
  264. Log3 $name, 4, "GardenaSmartDevice ($name) - JSON: $json";
  265. if ( defined( $decode_json->{id} ) ) {
  266. my $deviceId = $decode_json->{id};
  267. if ( my $hash = $modules{GardenaSmartDevice}{defptr}{$deviceId} ) {
  268. my $name = $hash->{NAME};
  269. WriteReadings( $hash, $decode_json );
  270. Log3 $name, 4,
  271. "GardenaSmartDevice ($name) - find logical device: $hash->{NAME}";
  272. return $hash->{NAME};
  273. }
  274. else {
  275. Log3 $name, 3,
  276. "GardenaSmartDevice ($name) - autocreate new device "
  277. . makeDeviceName( $decode_json->{name} )
  278. . " with deviceId $decode_json->{id}, model $decode_json->{category}";
  279. return
  280. "UNDEFINED "
  281. . makeDeviceName( $decode_json->{name} )
  282. . " GardenaSmartDevice $decode_json->{id} $decode_json->{category}";
  283. }
  284. }
  285. }
  286. sub WriteReadings($$) {
  287. my ( $hash, $decode_json ) = @_;
  288. my $name = $hash->{NAME};
  289. my $abilities = scalar( @{ $decode_json->{abilities} } );
  290. my $settings = scalar( @{ $decode_json->{settings} } );
  291. readingsBeginUpdate($hash);
  292. do {
  293. if (
  294. ref( $decode_json->{abilities}[$abilities]{properties} ) eq "ARRAY"
  295. and
  296. scalar( @{ $decode_json->{abilities}[$abilities]{properties} } ) >
  297. 0 )
  298. {
  299. foreach my $propertie (
  300. @{ $decode_json->{abilities}[$abilities]{properties} } )
  301. {
  302. readingsBulkUpdateIfChanged(
  303. $hash,
  304. $decode_json->{abilities}[$abilities]{name} . '-'
  305. . $propertie->{name},
  306. RigRadingsValue(
  307. $hash, $propertie->{value}
  308. )
  309. )
  310. if ( defined( $propertie->{value} )
  311. and $decode_json->{abilities}[$abilities]{name} . '-'
  312. . $propertie->{name} ne 'radio-quality'
  313. and $decode_json->{abilities}[$abilities]{name} . '-'
  314. . $propertie->{name} ne 'battery-level'
  315. and $decode_json->{abilities}[$abilities]{name} . '-'
  316. . $propertie->{name} ne 'internal_temperature-temperature'
  317. and $decode_json->{abilities}[$abilities]{name} . '-'
  318. . $propertie->{name} ne 'ambient_temperature-temperature'
  319. and $decode_json->{abilities}[$abilities]{name} . '-'
  320. . $propertie->{name} ne 'soil_temperature-temperature'
  321. and $decode_json->{abilities}[$abilities]{name} . '-'
  322. . $propertie->{name} ne 'humidity-humidity'
  323. and $decode_json->{abilities}[$abilities]{name} . '-'
  324. . $propertie->{name} ne 'light-light'
  325. and ref( $propertie->{value} ) ne "HASH" );
  326. readingsBulkUpdate(
  327. $hash,
  328. $decode_json->{abilities}[$abilities]{name} . '-'
  329. . $propertie->{name},
  330. RigRadingsValue(
  331. $hash, $propertie->{value}
  332. )
  333. )
  334. if (
  335. defined( $propertie->{value} )
  336. and ( $decode_json->{abilities}[$abilities]{name} . '-'
  337. . $propertie->{name} eq 'radio-quality'
  338. or $decode_json->{abilities}[$abilities]{name} . '-'
  339. . $propertie->{name} eq 'battery-level'
  340. or $decode_json->{abilities}[$abilities]{name} . '-'
  341. . $propertie->{name} eq
  342. 'internal_temperature-temperature'
  343. or $decode_json->{abilities}[$abilities]{name} . '-'
  344. . $propertie->{name} eq
  345. 'ambient_temperature-temperature'
  346. or $decode_json->{abilities}[$abilities]{name} . '-'
  347. . $propertie->{name} eq 'soil_temperature-temperature'
  348. or $decode_json->{abilities}[$abilities]{name} . '-'
  349. . $propertie->{name} eq 'humidity-humidity'
  350. or $decode_json->{abilities}[$abilities]{name} . '-'
  351. . $propertie->{name} eq 'light-light' )
  352. );
  353. readingsBulkUpdateIfChanged(
  354. $hash,
  355. $decode_json->{abilities}[$abilities]{name} . '-'
  356. . $propertie->{name},
  357. join( ',', @{ $propertie->{value} } )
  358. )
  359. if ( defined( $propertie->{value} )
  360. and $decode_json->{abilities}[$abilities]{name} . '-'
  361. . $propertie->{name} eq 'ic24-valves_connected' );
  362. readingsBulkUpdateIfChanged(
  363. $hash,
  364. $decode_json->{abilities}[$abilities]{name} . '-'
  365. . $propertie->{name},
  366. join( ',', @{ $propertie->{value} } )
  367. )
  368. if ( defined( $propertie->{value} )
  369. and $decode_json->{abilities}[$abilities]{name} . '-'
  370. . $propertie->{name} eq 'ic24-valves_master_config' );
  371. if ( ref( $propertie->{value} ) eq "HASH" ) {
  372. while ( my ( $r, $v ) = each %{ $propertie->{value} } ) {
  373. readingsBulkUpdate(
  374. $hash,
  375. $decode_json->{abilities}[$abilities]{name} . '-'
  376. . $propertie->{name} . '_'
  377. . $r,
  378. RigRadingsValue( $hash, $v )
  379. );
  380. }
  381. }
  382. }
  383. }
  384. $abilities--;
  385. } while ( $abilities >= 0 );
  386. do {
  387. if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY"
  388. and $decode_json->{settings}[$settings]{name} eq 'starting_points' )
  389. {
  390. #save the startingpointid needed to update the startingpoints
  391. if ( $hash->{helper}{STARTINGPOINTID} ne
  392. $decode_json->{settings}[$settings]{id} )
  393. {
  394. $hash->{helper}{STARTINGPOINTID} =
  395. $decode_json->{settings}[$settings]{id};
  396. }
  397. $hash->{helper}{STARTINGPOINTS} =
  398. '{ "name": "starting_points", "value": '
  399. . encode_json( $decode_json->{settings}[$settings]{value} ) . '}';
  400. my $startpoint_cnt = 0;
  401. foreach my $startingpoint (
  402. @{ $decode_json->{settings}[$settings]{value} } )
  403. {
  404. $startpoint_cnt++;
  405. readingsBulkUpdateIfChanged(
  406. $hash,
  407. 'startpoint-' . $startpoint_cnt . '-enabled',
  408. $startingpoint->{enabled}
  409. );
  410. }
  411. }
  412. $settings--;
  413. } while ( $settings >= 0 );
  414. readingsBulkUpdate( $hash, 'state',
  415. ReadingsVal( $name, 'mower-status', 'readingsValError' ) )
  416. if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
  417. readingsBulkUpdate(
  418. $hash, 'state',
  419. (
  420. ReadingsVal( $name, 'outlet-valve_open', 'readingsValError' ) == 1
  421. ? RigRadingsValue( $hash, 'open' )
  422. : RigRadingsValue( $hash, 'closed' )
  423. )
  424. ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
  425. readingsBulkUpdate(
  426. $hash, 'state',
  427. 'T: '
  428. . ReadingsVal( $name, 'ambient_temperature-temperature',
  429. 'readingsValError' )
  430. . '°C, H: '
  431. . ReadingsVal( $name, 'humidity-humidity', 'readingsValError' )
  432. . '%, L: '
  433. . ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux'
  434. ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' );
  435. readingsBulkUpdate(
  436. $hash, 'state',
  437. 'scheduled watering next start: '
  438. . (
  439. ReadingsVal(
  440. $name, 'scheduling-scheduled_watering_next_start',
  441. 'readingsValError'
  442. )
  443. )
  444. ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
  445. readingsEndUpdate( $hash, 1 );
  446. Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written}";
  447. }
  448. ##################################
  449. ##################################
  450. #### my little helpers ###########
  451. sub ReadingLangGerman($$) {
  452. my ( $hash, $readingValue ) = @_;
  453. my $name = $hash->{NAME};
  454. my %langGermanMapp = (
  455. 'ok_cutting' => 'mähen',
  456. 'paused' => 'pausiert',
  457. 'ok_searching' => 'suche Ladestation',
  458. 'ok_charging' => 'lädt',
  459. 'ok_leaving' => 'mähen',
  460. 'wait_updating' => 'wird aktualisiert ...',
  461. 'wait_power_up' => 'wird eingeschaltet ...',
  462. 'parked_timer' => 'geparkt nach Zeitplan',
  463. 'parked_park_selected' => 'geparkt',
  464. 'off_disabled' => 'der Mäher ist ausgeschaltet',
  465. 'off_hatch_open' =>
  466. 'deaktiviert. Abdeckung ist offen oder PIN-Code erforderlich',
  467. 'unknown' => 'unbekannter Status',
  468. 'error' => 'Fehler',
  469. 'error_at_power_up' => 'Neustart ...',
  470. 'off_hatch_closed' => 'Deaktiviert. Manueller Start erforderlich',
  471. 'ok_cutting_timer_overridden' => 'manuelles mähen',
  472. 'parked_autotimer' => 'geparkt durch SensorControl',
  473. 'parked_daily_limit_reached' => 'abgeschlossen',
  474. 'no_message' => 'kein Fehler',
  475. 'outside_working_area' => 'außerhalb des Arbeitsbereichs',
  476. 'no_loop_signal' => 'kein Schleifensignal',
  477. 'wrong_loop_signal' => 'falsches Schleifensignal',
  478. 'loop_sensor_problem_front' => 'Problem Schleifensensor, vorne',
  479. 'loop_sensor_problem_rear' => 'Problem Schleifensensor, hinten',
  480. 'trapped' => 'eingeschlossen',
  481. 'upside_down' => 'steht auf dem Kopf',
  482. 'low_battery' => 'niedriger Batteriestand',
  483. 'empty_battery' => 'Batterie leer',
  484. 'no_drive' => 'fährt nicht',
  485. 'lifted' => 'angehoben',
  486. 'stuck_in_charging_station' => 'eingeklemmt in Ladestation',
  487. 'charging_station_blocked' => 'Ladestation blockiert',
  488. 'collision_sensor_problem_rear' => 'Problem Stoßsensor hinten',
  489. 'collision_sensor_problem_front' => 'Problem Stoßsensor vorne',
  490. 'wheel_motor_blocked_right' => 'Radmotor rechts blockiert',
  491. 'wheel_motor_blocked_left' => 'Radmotor links blockiert',
  492. 'wheel_drive_problem_right' => 'Problem Antrieb, rechts',
  493. 'wheel_drive_problem_left' => 'Problem Antrieb, links',
  494. 'cutting_system_blocked' => 'Schneidsystem blockiert',
  495. 'invalid_sub_device_combination' => 'fehlerhafte Verbindung',
  496. 'settings_restored' => 'Standardeinstellungen',
  497. 'electronic_problem' => 'elektronisches Problem',
  498. 'charging_system_problem' => 'Problem Ladesystem',
  499. 'tilt_sensor_problem' => 'Kippsensor Problem',
  500. 'wheel_motor_overloaded_right' => 'rechter Radmotor überlastet',
  501. 'wheel_motor_overloaded_left' => 'linker Radmotor überlastet',
  502. 'charging_current_too_high' => 'Ladestrom zu hoch',
  503. 'temporary_problem' => 'vorübergehendes Problem',
  504. 'guide_1_not_found' => 'SK 1 nicht gefunden',
  505. 'guide_2_not_found' => 'SK 2 nicht gefunden',
  506. 'guide_3_not_found' => 'SK 3 nicht gefunden',
  507. 'difficult_finding_home' => 'Problem die Ladestation zu finden',
  508. 'guide_calibration_accomplished' =>
  509. 'Kalibrierung des Suchkabels beendet',
  510. 'guide_calibration_failed' =>
  511. 'Kalibrierung des Suchkabels fehlgeschlagen',
  512. 'temporary_battery_problem' => 'kurzzeitiges Batterieproblem',
  513. 'battery_problem' => 'Batterieproblem',
  514. 'alarm_mower_switched_off' => 'Alarm! Mäher ausgeschalten',
  515. 'alarm_mower_stopped' => 'Alarm! Mäher gestoppt',
  516. 'alarm_mower_lifted' => 'Alarm! Mäher angehoben',
  517. 'alarm_mower_tilted' => 'Alarm! Mäher gekippt',
  518. 'connection_changed' => 'Verbindung geändert',
  519. 'connection_not_changed' => 'Verbindung nicht geändert',
  520. 'com_board_not_available' => 'COM Board nicht verfügbar',
  521. 'slipped' => 'rutscht',
  522. 'out_of_operation' => 'ausser Betrieb',
  523. 'replace_now' => 'kritischer Batteriestand, wechseln Sie jetzt',
  524. 'low' => 'niedrig',
  525. 'ok' => 'ok',
  526. 'no_source' => 'ok',
  527. 'mower_charging' => 'Mäher wurde geladen',
  528. 'completed_cutting_autotimer' => 'Sensor Control erreicht',
  529. 'week_timer' => 'Wochentimer erreicht',
  530. 'countdown_timer' => 'Stoppuhr Timer',
  531. 'undefined' => 'unklar',
  532. 'unknown' => 'unklar',
  533. 'status_device_unreachable' => 'Gerät ist nicht in Reichweite',
  534. 'status_device_alive' => 'Gerät ist in Reichweite',
  535. 'bad' => 'schlecht',
  536. 'poor' => 'schwach',
  537. 'good' => 'gut',
  538. 'undefined' => 'unklar',
  539. 'idle' => 'nichts zu tun',
  540. 'firmware_cancel' => 'Firmwareupload unterbrochen',
  541. 'firmware_upload' => 'Firmwareupload',
  542. 'unsupported' => 'nicht unterstützt',
  543. 'up_to_date' => 'auf dem neusten Stand',
  544. 'mower' => 'Mäher',
  545. 'watering_computer' => 'Bewässerungscomputer',
  546. 'no_frost' => 'kein Frost',
  547. 'open' => 'offen',
  548. 'closed' => 'geschlossen',
  549. 'included' => 'inbegriffen',
  550. 'active' => 'aktiv',
  551. 'inactive' => 'nicht aktiv'
  552. );
  553. if (
  554. defined( $langGermanMapp{$readingValue} )
  555. and ( AttrVal( 'global', 'language', 'none' ) eq 'DE'
  556. or AttrVal( $name, 'readingValueLanguage', 'none' ) eq 'de' )
  557. and AttrVal( $name, 'readingValueLanguage', 'none' ) ne 'en'
  558. )
  559. {
  560. return $langGermanMapp{$readingValue};
  561. }
  562. else {
  563. return $readingValue;
  564. }
  565. }
  566. sub RigRadingsValue($$) {
  567. my ( $hash, $readingValue ) = @_;
  568. my $rigReadingValue;
  569. if ( $readingValue =~ /^(\d+)-(\d\d)-(\d\d)T(\d\d)/ ) {
  570. $rigReadingValue = Zulu2LocalString($readingValue);
  571. }
  572. else {
  573. $rigReadingValue =
  574. ReadingLangGerman( $hash, $readingValue );
  575. }
  576. return $rigReadingValue;
  577. }
  578. sub Zulu2LocalString($) {
  579. my $t = shift;
  580. my ( $datehour, $datemin, $rest ) = split( /:/, $t, 3 );
  581. my ( $year, $month, $day, $hour, $min ) =
  582. $datehour =~ /(\d+)-(\d\d)-(\d\d)T(\d\d)/;
  583. my $epoch = timegm( 0, 0, $hour, $day, $month - 1, $year );
  584. my ( $lyear, $lmonth, $lday, $lhour, $isdst ) =
  585. ( localtime($epoch) )[ 5, 4, 3, 2, -1 ];
  586. $lyear += 1900; # year is 1900 based
  587. $lmonth++; # month number is zero based
  588. if ( defined($rest) ) {
  589. return (
  590. sprintf(
  591. "%04d-%02d-%02d %02d:%02d:%s",
  592. $lyear, $lmonth, $lday,
  593. $lhour, $datemin, substr( $rest, 0, 2 )
  594. )
  595. );
  596. }
  597. elsif ( $lyear < 2000 ) {
  598. return "illegal year";
  599. }
  600. else {
  601. return (
  602. sprintf(
  603. "%04d-%02d-%02d %02d:%02d",
  604. $lyear, $lmonth, $lday, $lhour, substr( $datemin, 0, 2 )
  605. )
  606. );
  607. }
  608. }
  609. sub SetPredefinedStartPoints($@) {
  610. my ( $hash, $startpoint_state, $startpoint_num, @morestartpoints ) = @_;
  611. my $name = $hash->{NAME};
  612. my $payload;
  613. my $abilities;
  614. if ( defined($startpoint_state) and defined($startpoint_num) ) {
  615. if ( defined( $hash->{helper}{STARTINGPOINTS} )
  616. and $hash->{helper}{STARTINGPOINTS} ne '' )
  617. {
  618. # add needed parameters to saved settings config and change the value in request
  619. my $decode_json_settings =
  620. eval { decode_json( $hash->{helper}{STARTINGPOINTS} ) };
  621. if ($@) {
  622. Log3 $name, 3,
  623. "GardenaSmartBridge ($name) - JSON error while setting startpoint: $@";
  624. }
  625. $decode_json_settings->{device} = $hash->{DEVICEID};
  626. my $setval = $startpoint_state eq 'disable' ? \0 : \1;
  627. $decode_json_settings->{value}[ $startpoint_num - 1 ]{enabled} =
  628. $setval;
  629. #set more startpoints
  630. if (
  631. defined scalar(@morestartpoints)
  632. and ( scalar(@morestartpoints) == 2
  633. or scalar(@morestartpoints) == 4 )
  634. )
  635. {
  636. if ( scalar(@morestartpoints) == 2 ) {
  637. $setval = $morestartpoints[0] eq 'disable' ? \0 : \1;
  638. $decode_json_settings->{value}[ $morestartpoints[1] - 1 ]
  639. {enabled} = $setval;
  640. }
  641. elsif ( scalar(@morestartpoints) == 4 ) {
  642. $setval = $morestartpoints[0] eq 'disable' ? \0 : \1;
  643. $decode_json_settings->{value}[ $morestartpoints[1] - 1 ]
  644. {enabled} = $setval;
  645. $setval = $morestartpoints[2] eq 'disable' ? \0 : \1;
  646. $decode_json_settings->{value}[ $morestartpoints[3] - 1 ]
  647. {enabled} = $setval;
  648. }
  649. }
  650. $payload = '"settings": ' . encode_json($decode_json_settings);
  651. $abilities = 'mower_settings';
  652. }
  653. else {
  654. return
  655. "startingpoints not loaded yet, please wait a couple of minutes",
  656. undef, undef;
  657. }
  658. }
  659. else {
  660. return
  661. "startpoint usage: set "
  662. . $hash->{NAME}
  663. . " startpoint disable 1 [enable 2] [disable 3]", undef, undef;
  664. }
  665. return undef, $payload, $abilities;
  666. }
  667. 1;
  668. =pod
  669. =item device
  670. =item summary Modul to control GardenaSmart Devices
  671. =item summary_DE Modul zur Steuerung von GardenaSmartger&aumlten
  672. =begin html
  673. <a name="GardenaSmartDevice"></a>
  674. <h3>GardenaSmartDevice</h3>
  675. <ul>
  676. In combination with GardenaSmartBridge this FHEM Module controls the GardenaSmart Device using the GardenaCloud
  677. <br><br>
  678. Once the Bridge device is created, the connected devices are automatically recognized and created in FHEM. <br>
  679. From now on the devices can be controlled and changes in the GardenaAPP are synchronized with the state and readings of the devices.
  680. <a name="GardenaSmartDevicereadings"></a>
  681. <br><br><br>
  682. <b>Readings</b>
  683. <ul>
  684. <li>battery-charging - Indicator if the Battery is charged (0/1) or with newer Firmware (false/true)</li>
  685. <li>battery-level - load percentage of the Battery</li>
  686. <li>battery-rechargeable_battery_status - healthyness of the battery (out_of_operation/replace_now/low/ok)</li>
  687. <li>device_info-category - category of device (mower/watering_computer)</li>
  688. <li>device_info-last_time_online - timestamp of last radio contact</li>
  689. <li>device_info-manufacturer - manufacturer</li>
  690. <li>device_info-product - product type</li>
  691. <li>device_info-serial_number - serial number</li>
  692. <li>device_info-sgtin - </li>
  693. <li>device_info-version - firmware version</li>
  694. <li>firmware-firmware_command - firmware command (idle/firmware_cancel/firmware_upload/unsupported)</li>
  695. <li>firmware-firmware_status - firmware status </li>
  696. <li>firmware-firmware_update_start - indicator when a firmwareupload is started</li>
  697. <li>firmware-firmware_upload_progress - progress indicator of firmware update</li>
  698. <li>firmware-inclusion_status - inclusion status</li>
  699. <li>internal_temperature-temperature - internal device temperature</li>
  700. <li>mower-error - actual error message
  701. <ul>
  702. <li>no_message</li>
  703. <li>outside_working_area</li>
  704. <li>no_loop_signal</li>
  705. <li>wrong_loop_signal</li>
  706. <li>loop_sensor_problem_front</li>
  707. <li>loop_sensor_problem_rear</li>
  708. <li>trapped</li>
  709. <li>upside_down</li>
  710. <li>low_battery</li>
  711. <li>empty_battery</li>
  712. <li>no_drive</li>
  713. <li>lifted</li>
  714. <li>stuck_in_charging_station</li>
  715. <li>charging_station_blocked</li>
  716. <li>collision_sensor_problem_rear</li>
  717. <li>collision_sensor_problem_front</li>
  718. <li>wheel_motor_blocked_right</li>
  719. <li>wheel_motor_blocked_left</li>
  720. <li>wheel_drive_problem_right</li>
  721. <li>wheel_drive_problem_left</li>
  722. <li>cutting_system_blocked</li>
  723. <li>invalid_sub_device_combination</li>
  724. <li>settings_restored</li>
  725. <li>electronic_problem</li>
  726. <li>charging_system_problem</li>
  727. <li>tilt_sensor_problem</li>
  728. <li>wheel_motor_overloaded_right</li>
  729. <li>wheel_motor_overloaded_left</li>
  730. <li>charging_current_too_high</li>
  731. <li>temporary_problem</li>
  732. <li>guide_1_not_found</li>
  733. <li>guide_2_not_found</li>
  734. <li>guide_3_not_found</li>
  735. <li>difficult_finding_home</li>
  736. <li>guide_calibration_accomplished</li>
  737. <li>guide_calibration_failed</li>
  738. <li>temporary_battery_problem</li>
  739. <li>battery_problem</li>
  740. <li>alarm_mower_switched_off</li>
  741. <li>alarm_mower_stopped</li>
  742. <li>alarm_mower_lifted</li>
  743. <li>alarm_mower_tilted</li>
  744. <li>connection_changed</li>
  745. <li>connection_not_changed</li>
  746. <li>com_board_not_available</li>
  747. <li>slipped</li>
  748. </ul>
  749. </li>
  750. <li>mower-manual_operation - (0/1) or with newer Firmware (false/true)</li>
  751. <li>mower-override_end_time - manual override end time</li>
  752. <li>mower-source_for_next_start - source for the next start
  753. <ul>
  754. <li>no_source</li>
  755. <li>mower_charging</li>
  756. <li>completed_cutting_autotimer</li>
  757. <li>week_timer</li>
  758. <li>countdown_timer</li>
  759. <li>undefined</li>
  760. </ul>
  761. </li>
  762. <li>mower-status - mower state (see state)</li>
  763. <li>mower-timestamp_next_start - timestamp of next scheduled start</li>
  764. <li>radio-connection_status - state of connection</li>
  765. <li>radio-quality - percentage of the radio quality</li>
  766. <li>radio-state - radio state (bad/poor/good/undefined)</li>
  767. <li>state - state of the mower
  768. <ul>
  769. <li>paused</li>
  770. <li>ok_cutting</li>
  771. <li>ok_searching</li>
  772. <li>ok_charging</li>
  773. <li>ok_leaving</li>
  774. <li>wait_updating</li>
  775. <li>wait_power_up</li>
  776. <li>parked_timer</li>
  777. <li>parked_park_selected</li>
  778. <li>off_disabled</li>
  779. <li>off_hatch_open</li>
  780. <li>unknown</li>
  781. <li>error</li>
  782. <li>error_at_power_up</li>
  783. <li>off_hatch_closed</li>
  784. <li>ok_cutting_timer_overridden</li>
  785. <li>parked_autotimer</li>
  786. <li>parked_daily_limit_reached</li>
  787. </ul>
  788. </li>
  789. </ul>
  790. <br><br>
  791. <a name="GardenaSmartDeviceattributes"></a>
  792. <b>Attributes</b>
  793. <ul>
  794. <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>
  795. <li>model - </li>
  796. </ul>
  797. <br><br>
  798. <a name="GardenaSmartDeviceset"></a>
  799. <b>set</b>
  800. <ul>
  801. <li>parkUntilFurtherNotice</li>
  802. <li>parkUntilNextTimer</li>
  803. <li>startOverrideTimer - (in minutes, 60 = 1h, 1440 = 24h, 4320 = 72h)</li>
  804. <li>startResumeSchedule</li>
  805. <li>startpoint enable|disable 1|2|3 - enables or disables one or more predefined start points</li>
  806. <ul>
  807. <li>set NAME startpoint enable 1</li>
  808. <li>set NAME startpoint disable 3 enable 1</li>
  809. </ul>
  810. </ul>
  811. </ul>
  812. =end html
  813. =begin html_DE
  814. <a name="GardenaSmartDevice"></a>
  815. <h3>GardenaSmartDevice</h3>
  816. <ul>
  817. Zusammen mit dem Device GardenaSmartDevice stellt dieses FHEM Modul die Kommunikation zwischen der GardenaCloud und Fhem her.
  818. <br><br>
  819. Wenn das GardenaSmartBridge Device erzeugt wurde, werden verbundene Ger&auml;te automatisch erkannt und in Fhem angelegt.<br>
  820. 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.
  821. <a name="GardenaSmartDevicereadings"></a>
  822. </ul>
  823. <br>
  824. <ul>
  825. <b>Readings</b>
  826. <ul>
  827. <li>battery-charging - Ladeindikator (0/1) oder mit neuerer Firmware (false/true)</li>
  828. <li>battery-level - Ladezustand der Batterie in Prozent</li>
  829. <li>battery-rechargeable_battery_status - Zustand der Batterie (Ausser Betrieb/Kritischer Batteriestand, wechseln Sie jetzt/Niedrig/oK)</li>
  830. <li>device_info-category - Eigenschaft des Ger&auml;tes (M&auml;her/Bew&auml;sserungscomputer/Bodensensor)</li>
  831. <li>device_info-last_time_online - Zeitpunkt der letzten Funk&uuml;bertragung</li>
  832. <li>device_info-manufacturer - Hersteller</li>
  833. <li>device_info-product - Produkttyp</li>
  834. <li>device_info-serial_number - Seriennummer</li>
  835. <li>device_info-sgtin - </li>
  836. <li>device_info-version - Firmware Version</li>
  837. <li>firmware-firmware_command - Firmware Kommando (Nichts zu tun/Firmwareupload unterbrochen/Firmwareupload/nicht unterst&uuml;tzt)</li>
  838. <li>firmware-firmware_status - Firmware Status </li>
  839. <li>firmware-firmware_update_start - Firmwareupdate (0/1) oder mit neuerer Firmware (false/true)</li>
  840. <li>firmware-firmware_upload_progress - Firmwareupdatestatus in Prozent</li>
  841. <li>firmware-inclusion_status - Einbindungsstatus</li>
  842. <li>internal_temperature-temperature - Interne Ger&auml;te Temperatur</li>
  843. <li>mower-error - Aktuelle Fehler Meldung
  844. <ul>
  845. <li>Kein Fehler</li>
  846. <li>Au&szlig;erhalb des Arbeitsbereichs</li>
  847. <li>Kein Schleifensignal</li>
  848. <li>Falsches Schleifensignal</li>
  849. <li>Problem Schleifensensor, vorne</li>
  850. <li>Problem Schleifensensor, hinten</li>
  851. <li>Eingeschlossen</li>
  852. <li>Steht auf dem Kopf</li>
  853. <li>Niedriger Batteriestand</li>
  854. <li>Batterie ist leer</li>
  855. <li>Kein Antrieb</li>
  856. <li>Angehoben</li>
  857. <li>Eingeklemmt in Ladestation</li>
  858. <li>Ladestation blockiert</li>
  859. <li>Problem Sto&szlig;sensor hinten</li>
  860. <li>Problem Sto&szlig;sensor vorne</li>
  861. <li>Radmotor rechts blockiert</li>
  862. <li>Radmotor links blockiert</li>
  863. <li>Problem Antrieb, rechts</li>
  864. <li>Problem Antrieb, links</li>
  865. <li>Schneidsystem blockiert</li>
  866. <li>Fehlerhafte Verbindung</li>
  867. <li>Standardeinstellungen</li>
  868. <li>Elektronisches Problem</li>
  869. <li>Problem Ladesystem</li>
  870. <li>Kippsensorproblem</li>
  871. <li>Rechter Radmotor &uuml;berlastet</li>
  872. <li>Linker Radmotor &uuml;berlastet</li>
  873. <li>Ladestrom zu hoch</li>
  874. <li>Vor&uuml;bergehendes Problem</li>
  875. <li>SK 1 nicht gefunden</li>
  876. <li>SK 2 nicht gefunden</li>
  877. <li>SK 3 nicht gefunden</li>
  878. <li>Problem die Ladestation zu finden</li>
  879. <li>Kalibration des Suchkabels beendet</li>
  880. <li>Kalibration des Suchkabels fehlgeschlagen</li>
  881. <li>Kurzzeitiges Batterieproblem</li>
  882. <li>Batterieproblem</li>
  883. <li>Alarm! M&auml;her ausgeschalten</li>
  884. <li>Alarm! M&auml;her gestoppt</li>
  885. <li>Alarm! M&auml;her angehoben</li>
  886. <li>Alarm! M&auml;her gekippt</li>
  887. <li>Verbindung geändert</li>
  888. <li>Verbindung nicht ge&auml;ndert</li>
  889. <li>COM board nicht verf&uuml;gbar</li>
  890. <li>Rutscht</li>
  891. </ul>
  892. </li>
  893. <li>mower-manual_operation - Manueller Betrieb (0/1) oder mit neuerer Firmware (false/true)</li>
  894. <li>mower-override_end_time - Zeitpunkt wann der manuelle Betrieb beendet ist</li>
  895. <li>mower-source_for_next_start - Grund f&uuml;r den n&auml;chsten Start
  896. <ul>
  897. <li>Kein Grund</li>
  898. <li>M&auml;her wurde geladen</li>
  899. <li>SensorControl erreicht</li>
  900. <li>Wochentimer erreicht</li>
  901. <li>Stoppuhr Timer</li>
  902. <li>Undefiniert</li>
  903. </ul>
  904. </li>
  905. <li>mower-status - M&auml;her Status (siehe state)</li>
  906. <li>mower-timestamp_next_start - Zeitpunkt des n&auml;chsten geplanten Starts</li>
  907. <li>radio-connection_status - Status der Funkverbindung</li>
  908. <li>radio-quality - Indikator f&uuml;r die Funkverbindung in Prozent</li>
  909. <li>radio-state - radio state (schlecht/schwach/gut/Undefiniert)</li>
  910. <li>state - Staus des M&auml;hers
  911. <ul>
  912. <li>Pausiert</li>
  913. <li>M&auml;hen</li>
  914. <li>Suche Ladestation</li>
  915. <li>L&auml;dt</li>
  916. <li>M&auml;hen</li>
  917. <li>Wird aktualisiert ...</li>
  918. <li>Wird eingeschaltet ...</li>
  919. <li>Geparkt nach Zeitplan</li>
  920. <li>Geparkt</li>
  921. <li>Der M&auml;her ist ausgeschaltet</li>
  922. <li>Deaktiviert. Abdeckung ist offen oder PIN-Code erforderlich</li>
  923. <li>Unbekannter Status</li>
  924. <li>Fehler</li>
  925. <li>Neustart ...</li>
  926. <li>Deaktiviert. Manueller Start erforderlich</li>
  927. <li>Manuelles M&auml;hen</li>
  928. <li>Geparkt durch SensorControl</li>
  929. <li>Abgeschlossen</li>
  930. </ul>
  931. </li>
  932. </ul>
  933. <br><br>
  934. <a name="GardenaSmartDeviceattributes"></a>
  935. <b>Attribute</b>
  936. <ul>
  937. <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>
  938. <li>model - </li>
  939. </ul>
  940. <a name="GardenaSmartDeviceset"></a>
  941. <b>set</b>
  942. <ul>
  943. <li>parkUntilFurtherNotice - Parken des M&auml;hers unter Umgehung des Zeitplans</li>
  944. <li>parkUntilNextTimer - Parken bis zum n&auml;chsten Zeitplan</li>
  945. <li>startOverrideTimer - Manuelles m&auml;hen (in Minuten, 60 = 1h, 1440 = 24h, 4320 = 72h)</li>
  946. <li>startResumeSchedule - Weiterf&uuml;hrung des Zeitplans</li>
  947. <li>startpoint enable|disable 1|2|3 - Aktiviert oder deaktiviert einen vordefinierten Startbereich</li>
  948. <ul>
  949. <li>set NAME startpoint enable 1</li>
  950. <li>set NAME startpoint disable 3 enable 1</li>
  951. </ul>
  952. </ul>
  953. </ul>
  954. =end html_DE
  955. =cut