Unit.pm 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628
  1. ###############################################################################
  2. # $Id: Unit.pm 14136 2017-04-29 16:31:46Z loredo $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use Data::Dumper;
  7. use utf8;
  8. use Encode qw(encode_utf8 decode_utf8);
  9. use UConv;
  10. sub Unit_Initialize() { }
  11. # scale helper for metric numbers
  12. my $scales_m = {
  13. autoscale => {
  14. '0' => { format => '%i', scale => 1000, },
  15. '0.001' => { format => '%i', scale => 1000, },
  16. '0.1' => { format => '%.1f', scale => 1, },
  17. '10' => { format => '%i', scale => 1, },
  18. '1.0e3' => { format => '%.1f', scale => 0.001, },
  19. '2.0e3' => { format => '%i', scale => 0.001, },
  20. '1.0e6' => { format => '%.1f', scale => 0.001, },
  21. '2.0e6' => { format => '%i', scale => 0.001, },
  22. },
  23. '1.0e-12' => {
  24. 'scale_txt_m' => 'p',
  25. 'scale_txt_long_m' => {
  26. de => 'Piko',
  27. en => 'Pico',
  28. },
  29. },
  30. '1.0e-9' => {
  31. 'scale_txt_m' => 'n',
  32. 'scale_txt_long_m' => {
  33. de => 'Nano',
  34. en => 'Nano',
  35. },
  36. },
  37. '1.0e-6' => {
  38. 'scale_txt_m' => 'μ',
  39. 'scale_txt_long_m' => {
  40. de => 'Mikro',
  41. en => 'Micro',
  42. },
  43. },
  44. '1.0e-3' => {
  45. 'scale_txt_m' => 'm',
  46. 'scale_txt_long_m' => {
  47. de => 'Milli',
  48. en => 'Mili',
  49. },
  50. },
  51. '1.0e-2' => {
  52. 'scale_txt_m' => 'c',
  53. 'scale_txt_long_m' => {
  54. de => 'Zenti',
  55. en => 'Centi',
  56. },
  57. },
  58. '1.0e-1' => {
  59. 'scale_txt_m' => 'd',
  60. 'scale_txt_long_m' => {
  61. de => 'Dezi',
  62. en => 'Deci',
  63. },
  64. },
  65. '1.0e0' => {
  66. 'scale_txt_m' => '',
  67. 'scale_txt_long_m' => '',
  68. },
  69. '1.0e1' => {
  70. 'scale_txt_m' => 'da',
  71. 'scale_txt_long_m' => {
  72. de => 'Deka',
  73. en => 'Deca',
  74. },
  75. },
  76. '1.0e2' => {
  77. 'scale_txt_m' => 'h',
  78. 'scale_txt_long_m' => {
  79. de => 'Hekto',
  80. en => 'Hecto',
  81. },
  82. },
  83. '1.0e3' => {
  84. 'scale_txt_m' => 'k',
  85. 'scale_txt_long_m' => {
  86. de => 'Kilo',
  87. en => 'Kilo',
  88. },
  89. },
  90. '1.0e6' => {
  91. 'scale_txt_m' => 'M',
  92. 'scale_txt_long_m' => {
  93. de => 'Mega',
  94. en => 'Mega',
  95. },
  96. },
  97. '1.0e9' => {
  98. 'scale_txt_m' => 'G',
  99. 'scale_txt_long_m' => {
  100. de => 'Giga',
  101. en => 'Giga',
  102. },
  103. },
  104. '1.0e12' => {
  105. 'scale_txt_m' => 'T',
  106. 'scale_txt_long_m' => {
  107. de => 'Tera',
  108. en => 'Tera',
  109. },
  110. },
  111. '1.0e15' => {
  112. 'scale_txt_m' => 'P',
  113. 'scale_txt_long_m' => {
  114. de => 'Peta',
  115. en => 'Peta',
  116. },
  117. },
  118. };
  119. # scale helper for metric square numbers
  120. my $scales_sq = {
  121. 'scale_txt_sq' => chr(0x00B2),
  122. 'scale_txt_long_sq' => {
  123. de => 'Quadrat',
  124. en => 'Square',
  125. },
  126. };
  127. # scale helper for metric cubic numbers
  128. my $scales_cu = {
  129. 'scale_txt_cu' => chr(0x00B3),
  130. 'scale_txt_long_cu' => {
  131. de => 'Kubik',
  132. en => 'Cubic',
  133. },
  134. };
  135. # scale helper for time related numbers
  136. my $scales_t = {
  137. # second
  138. 's' => {
  139. 'scale_txt_t' => 's',
  140. 'scale_txt_long_t' => {
  141. de => 'Sekunde',
  142. en => 'second',
  143. },
  144. 'scale_txt_long_pl_t' => {
  145. de => 'Sekunden',
  146. en => 'seconds',
  147. },
  148. },
  149. # minute
  150. 'min' => {
  151. 'scale_txt_t' => {
  152. de => 'Min',
  153. en => 'min',
  154. },
  155. 'scale_txt_long_t' => {
  156. de => 'Minute',
  157. en => 'minute',
  158. },
  159. 'scale_txt_long_pl_t' => {
  160. de => 'Minuten',
  161. en => 'minutes',
  162. },
  163. },
  164. # hour
  165. 'h' => {
  166. 'scale_txt_t' => 'h',
  167. 'scale_txt_long_t' => {
  168. de => 'Stunde',
  169. en => 'hour',
  170. },
  171. 'scale_txt_long_pl_t' => {
  172. de => 'Stunden',
  173. en => 'hours',
  174. },
  175. },
  176. # day
  177. 'd' => {
  178. 'scale_txt_t' => 'd',
  179. 'scale_txt_long_t' => {
  180. de => 'Tag',
  181. en => 'day',
  182. },
  183. 'scale_txt_long_pl_t' => {
  184. de => 'Tage',
  185. en => 'days',
  186. },
  187. },
  188. # week
  189. 'w' => {
  190. 'scale_txt_t' => 'w',
  191. 'scale_txt_long_t' => {
  192. de => 'Woche',
  193. en => 'week',
  194. },
  195. 'scale_txt_long_pl_t' => {
  196. de => 'Wochen',
  197. en => 'weeks',
  198. },
  199. },
  200. # month
  201. 'm' => {
  202. 'scale_txt_t' => 'm',
  203. 'scale_txt_long_t' => {
  204. de => 'Monat',
  205. en => 'month',
  206. },
  207. 'scale_txt_long_pl_t' => {
  208. de => 'Monate',
  209. en => 'month',
  210. },
  211. },
  212. # year
  213. 'a' => {
  214. 'scale_txt_t' => 'a',
  215. 'scale_txt_long_t' => {
  216. de => 'Jahr',
  217. en => 'year',
  218. },
  219. 'scale_txt_long_pl_t' => {
  220. de => 'Jahre',
  221. en => 'years',
  222. },
  223. },
  224. };
  225. # scale helper for time related numbers
  226. # Overall structure/grouping based on
  227. # https://de.wikipedia.org/wiki/Liste_physikalischer_Gr%C3%B6%C3%9Fen
  228. #
  229. # Scientific range: 0 - 99
  230. # FHEM Builtin range: 900 - 998
  231. # FHEM User Defined range: >= 999
  232. #
  233. # rtype_base => reference to base rtype in $rtypes used for
  234. # automatic unit conversion
  235. my $rtype_base = {
  236. 0 => {
  237. dimension => 'L',
  238. formula_symbol => 'l',
  239. rtype_base => 'm',
  240. base_description => {
  241. de => 'Länge',
  242. en => 'length',
  243. },
  244. format => '%.0f',
  245. decimal_mark => {
  246. de => 2,
  247. en => 1,
  248. },
  249. scope => { minValue => 0 },
  250. },
  251. 1 => {
  252. dimension => 'M',
  253. formula_symbol => 'm',
  254. rtype_base => 'kg',
  255. base_description => {
  256. de => 'Masse',
  257. en => 'mass',
  258. },
  259. format => '%.0f',
  260. decimal_mark => {
  261. de => 2,
  262. en => 1,
  263. },
  264. scope => { minValue => 0 },
  265. },
  266. 2 => {
  267. dimension => 'T',
  268. formula_symbol => 't',
  269. rtype_base => 's',
  270. base_description => {
  271. de => 'Zeit',
  272. en => 'time',
  273. },
  274. format => '%.0f',
  275. decimal_mark => {
  276. de => 2,
  277. en => 1,
  278. },
  279. scope => { minValue => 0 },
  280. },
  281. 3 => {
  282. dimension => 'I',
  283. formula_symbol => 'i',
  284. rtype_base => 'a',
  285. base_description => {
  286. de => 'elektrische Stromstärke',
  287. en => 'electric current',
  288. },
  289. format => '%.1f',
  290. decimal_mark => {
  291. de => 2,
  292. en => 1,
  293. },
  294. scope => { minValue => 0 },
  295. },
  296. 4 => {
  297. dimension => 'θ',
  298. formula_symbol => 'T',
  299. rtype_base => 'k',
  300. base_description => {
  301. de => 'absolute Temperatur',
  302. en => 'absolute temperature',
  303. },
  304. format => '%.1f',
  305. decimal_mark => {
  306. de => 2,
  307. en => 1,
  308. },
  309. scope => { minValue => 0 },
  310. },
  311. 5 => {
  312. dimension => 'N',
  313. formula_symbol => 'n',
  314. rtype_base => 'mol',
  315. base_description => {
  316. de => 'Stoffmenge',
  317. en => 'amount of substance',
  318. },
  319. format => '%.1f',
  320. decimal_mark => {
  321. de => 2,
  322. en => 1,
  323. },
  324. scope => { minValue => 0 },
  325. },
  326. 6 => {
  327. dimension => 'J',
  328. formula_symbol => 'Iv',
  329. rtype_base => 'cd',
  330. base_description => {
  331. de => 'Lichtstärke',
  332. en => 'luminous intensity',
  333. },
  334. format => '%.1f',
  335. decimal_mark => {
  336. de => 2,
  337. en => 1,
  338. },
  339. scope => { minValue => 0 },
  340. },
  341. 7 => {
  342. dimension => 'M L^2 T^−2',
  343. formula_symbol => 'E',
  344. rtype_base => 'j',
  345. base_description => {
  346. de => 'Energie',
  347. en => 'energy',
  348. },
  349. format => '%.1f',
  350. decimal_mark => {
  351. de => 2,
  352. en => 1,
  353. },
  354. scope => { minValue => 0 },
  355. },
  356. 8 => {
  357. dimension => 'T^−1',
  358. formula_symbol => 'f',
  359. rtype_base => 'hz',
  360. base_description => {
  361. de => 'Frequenz',
  362. en => 'frequency',
  363. },
  364. format => '%i',
  365. decimal_mark => {
  366. de => 2,
  367. en => 1,
  368. },
  369. scope => { minValue => 0 },
  370. },
  371. 9 => {
  372. dimension => 'M L^2 T^−3',
  373. formula_symbol => 'P',
  374. rtype_base => 'w',
  375. base_description => {
  376. de => 'Leistung',
  377. en => 'power',
  378. },
  379. format => '%.1f',
  380. decimal_mark => {
  381. de => 2,
  382. en => 1,
  383. },
  384. scope => { minValue => 0 },
  385. },
  386. 10 => {
  387. dimension => 'M L^−1 T^−2',
  388. formula_symbol => 'p',
  389. rtype_base => 'pa',
  390. base_description => {
  391. de => 'Druck',
  392. en => 'pressure',
  393. },
  394. format => '%i',
  395. decimal_mark => {
  396. de => 2,
  397. en => 1,
  398. },
  399. scope => { minValue => 0 },
  400. },
  401. 11 => {
  402. dimension => 'M L^−1 T^−2',
  403. formula_symbol => 'pabs',
  404. rtype_base => 'pabs',
  405. base_description => {
  406. de => 'absoluter Druck',
  407. en => 'absolute pressure',
  408. },
  409. format => '%i',
  410. decimal_mark => {
  411. de => 2,
  412. en => 1,
  413. },
  414. scope => { minValue => 0 },
  415. },
  416. 12 => {
  417. dimension => 'M L^−1 T^−2',
  418. formula_symbol => 'pamb',
  419. rtype_base => 'pamb',
  420. base_description => {
  421. de => 'Luftdruck',
  422. en => 'air pressure',
  423. },
  424. format => '%i',
  425. decimal_mark => {
  426. de => 2,
  427. en => 1,
  428. },
  429. scope => { minValue => 0 },
  430. },
  431. 13 => {
  432. dimension => 'M L^2 T^−3 I^−1',
  433. formula_symbol => 'U',
  434. rtype_base => 'v',
  435. base_description => {
  436. de => 'elektrische Spannung',
  437. en => 'electric voltage',
  438. },
  439. format => '%.1f',
  440. decimal_mark => {
  441. de => 2,
  442. en => 1,
  443. },
  444. scope => { minValue => 0 },
  445. },
  446. 14 => {
  447. dimension => '1',
  448. formula_symbol => '',
  449. rtype_base => 'rad',
  450. base_description => {
  451. de => 'ebener Winkel',
  452. en => 'plane angular',
  453. },
  454. format => '%i',
  455. decimal_mark => {
  456. de => 2,
  457. en => 1,
  458. },
  459. scope => { minValue => 0 },
  460. },
  461. 15 => {
  462. dimension => 'L T^−1',
  463. formula_symbol => 'v',
  464. rtype_base => 'kmph',
  465. base_description => {
  466. de => 'Geschwindigkeit',
  467. en => 'speed',
  468. },
  469. format => '%i',
  470. decimal_mark => {
  471. de => 2,
  472. en => 1,
  473. },
  474. scope => { minValue => 0 },
  475. },
  476. 16 => {
  477. dimension => 'L^−2 J',
  478. formula_symbol => 'Ev',
  479. rtype_base => 'lx',
  480. base_description => {
  481. de => 'Beleuchtungsstärke',
  482. en => 'illumination intensity',
  483. },
  484. format => '%i',
  485. decimal_mark => {
  486. de => 2,
  487. en => 1,
  488. },
  489. scope => { minValue => 0 },
  490. },
  491. 17 => {
  492. dimension => 'J',
  493. formula_symbol => 'F',
  494. rtype_base => 'lm',
  495. base_description => {
  496. de => 'Lichtstrom',
  497. en => 'luminous flux',
  498. },
  499. format => '%i',
  500. decimal_mark => {
  501. de => 2,
  502. en => 1,
  503. },
  504. scope => { minValue => 0 },
  505. },
  506. 18 => {
  507. dimension => 'L^3',
  508. formula_symbol => 'V',
  509. rtype_base => 'm3',
  510. base_description => {
  511. de => 'Volumen',
  512. en => 'volume',
  513. },
  514. format => '%i',
  515. decimal_mark => {
  516. de => 2,
  517. en => 1,
  518. },
  519. scope => { minValue => 0 },
  520. },
  521. 19 => {
  522. dimension => '1',
  523. formula_symbol => 'B',
  524. rtype_base => 'b',
  525. base_description => {
  526. de => 'Logarithmische Größe',
  527. en => 'logarithmic level',
  528. },
  529. format => '%.1f',
  530. decimal_mark => {
  531. de => 2,
  532. en => 1,
  533. },
  534. scope => { minValue => 0 },
  535. },
  536. 20 => {
  537. dimension => 'I T',
  538. formula_symbol => 'C',
  539. rtype_base => 'coul',
  540. base_description => {
  541. de => 'elektrische Ladung',
  542. en => 'electric charge',
  543. },
  544. format => '%.1f',
  545. decimal_mark => {
  546. de => 2,
  547. en => 1,
  548. },
  549. scope => { minValue => 0 },
  550. },
  551. 21 => {
  552. dimension => '',
  553. formula_symbol => 'F',
  554. rtype_base => 'far',
  555. base_description => {
  556. de => 'elektrische Kapazität',
  557. en => 'electric capacity',
  558. },
  559. format => '%.1f',
  560. decimal_mark => {
  561. de => 2,
  562. en => 1,
  563. },
  564. scope => { minValue => 0 },
  565. },
  566. 22 => {
  567. dimension => 'M L2 T−3 I−2',
  568. formula_symbol => 'R',
  569. rtype_base => 'ohm',
  570. base_description => {
  571. de => 'elektrischer Widerstand',
  572. en => 'electric resistance',
  573. },
  574. format => '%.1f',
  575. decimal_mark => {
  576. de => 2,
  577. en => 1,
  578. },
  579. scope => { minValue => 0 },
  580. },
  581. 23 => {
  582. dimension => 'L^2',
  583. formula_symbol => 'A',
  584. rtype_base => 'm2',
  585. base_description => {
  586. de => 'Flächeninhalt',
  587. en => 'surface area',
  588. },
  589. format => '%i',
  590. decimal_mark => {
  591. de => 2,
  592. en => 1,
  593. },
  594. scope => { minValue => 0 },
  595. },
  596. 24 => {
  597. base_description => {
  598. de => 'Währung',
  599. en => 'currency',
  600. },
  601. format => '%.2f',
  602. decimal_mark => {
  603. de => 2,
  604. en => 1,
  605. },
  606. scope => '^[0-9]*(?:\.[0-9]*)?$',
  607. },
  608. 25 => {
  609. base_description => {
  610. de => 'Zahlen',
  611. en => 'Numbering',
  612. },
  613. format => '%.1f',
  614. decimal_mark => {
  615. de => 2,
  616. en => 1,
  617. },
  618. tmpl => '%value%',
  619. },
  620. 26 => {
  621. base_description => {
  622. de => 'Logische Operatoren',
  623. en => 'Logical operators',
  624. },
  625. tmpl => '%value%',
  626. },
  627. 900 => {
  628. base_description => 'FHEM Builtin Readings Type',
  629. tmpl => '%value%',
  630. },
  631. 999 => {
  632. base_description => 'FHEM User Defined Readings Type',
  633. tmpl => '%value%',
  634. },
  635. };
  636. # FHEM built-in reading types (RType).
  637. # Values will be combined into a new super-hash using
  638. # cross-references to $rtype_base, $scales_m, $scales_sq, $scales_cu, $scales_t
  639. #
  640. # ref_base => reference to $rtype_base id to include it's keys here
  641. # ref_sq => include keys from $scales_sq here; normally combined with a scale_sq reference as well
  642. # ref_cu => include keys from $scales_cu here; normally combined with a scale_cu reference as well
  643. # ref_t => reference to $scales_t id to include it's keys here; ; normally combined with a scale_t reference as well
  644. # ref => self-reference to $rtype id to include it's keys here (RType alias helper)
  645. my $rtypes = {
  646. # others
  647. url => {
  648. ref_base => 900,
  649. rtype_description => 'General URL including protocol prefix',
  650. tmpl => '<html><a href="%value%">%value%</a></html>',
  651. },
  652. url_http => {
  653. ref_base => 900,
  654. rtype_description => 'HTTP/S URL w/ or w/o protocol prefix',
  655. tmpl => '<html><a href="%value%">%value%</a></html>',
  656. },
  657. trend => {
  658. ref_base => 900,
  659. symbol => [ chr(0x2B0C), chr(0x2B08), chr(0x2B0A) ],
  660. txt => [ '=', '+', '-' ],
  661. txt_long => {
  662. de => [ 'gleichbleibend', 'steigend', 'fallend' ],
  663. en => [ 'steady', 'rising', 'falling' ],
  664. fr => [ 'stable', 'croissant', 'décroissant' ],
  665. nl => [ 'stabiel', 'stijgend', 'dalend' ],
  666. pl => [ 'stabilne', 'rośnie', 'spada' ],
  667. },
  668. scope => [
  669. '^(=|steady|stable|0)$', '^(\+|rising|up|1)$',
  670. '^(-|falling|down|2)$'
  671. ],
  672. tmpl => '%symbol%',
  673. tmpl_long => '%txt_long%',
  674. rtype_description => 'Trend',
  675. },
  676. oknok => {
  677. ref_base => 900,
  678. txt => {
  679. de => [ 'Fehler', 'ok', 'Warnung' ],
  680. en => [ 'error', 'ok', 'warning' ],
  681. },
  682. scope => [
  683. '^(nok|error|dead|invalid|0)$', '^(ok|alive|valid|1)$',
  684. '^(warning|warn|low|2)$', '^(.*)$'
  685. ],
  686. rtype_description => {
  687. de =>
  688. 'Fehlerstatus; siehe RType roknok, sofern 0<>1 vertauschte Bedeutung haben',
  689. en => 'error state',
  690. },
  691. },
  692. roknok => {
  693. ref_base => 900,
  694. txt => {
  695. de => [ 'Fehler', 'ok', 'Warnung' ],
  696. en => [ 'error', 'ok', 'warning' ],
  697. },
  698. scope => [
  699. '^(nok|error|dead|invalid|1)$', '^(ok|alive|valid|0)$',
  700. '^(warning|warn|low|2)$', '^(.*)$'
  701. ],
  702. rtype_description => {
  703. de =>
  704. 'verdrehter Fehlerstatus, bei dem 0=ok und 1=Fehler bedeutet; Gegenteil von RType oknok',
  705. en => 'reversed error state',
  706. },
  707. },
  708. onoff => {
  709. ref_base => 900,
  710. txt => {
  711. de => [ 'aus', 'an', 'nicht verfügbar' ],
  712. en => [ 'off', 'on', 'absent' ],
  713. },
  714. scope =>
  715. [ '^(off|no|standby|0)$', '^(on|yes|1)$', '^(absent|offline|2)$', ],
  716. rtype_description => {
  717. de => 'Schaltstatus',
  718. en => 'Switch state',
  719. },
  720. },
  721. reachable => {
  722. ref_base => 900,
  723. txt => {
  724. de => [ 'nicht verfügbar', 'verfügbar' ],
  725. en => [ 'unavailable', 'available' ],
  726. },
  727. scope => [
  728. '^(unavailable|absent|disappeared|false|no|0)$',
  729. '^(available|present|appeared|true|yes|1)$'
  730. ],
  731. rtype_description => {
  732. de => 'Verfügbarkeit/Erreichbarkeit',
  733. en => 'availability/reachability',
  734. },
  735. },
  736. weekday => {
  737. ref_base => 900,
  738. symbol => {
  739. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ],
  740. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ],
  741. },
  742. txt => {
  743. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ],
  744. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ],
  745. },
  746. txt_long => {
  747. de => [
  748. 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch',
  749. 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'
  750. ],
  751. en => [
  752. 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  753. 'Thursday', 'Friday', 'Saturday', 'Sunday'
  754. ],
  755. },
  756. scope => {
  757. de => [
  758. '^(So|Son|Sonntag|0|7)$', '^(Mo|Mon|Montag|1)$',
  759. '^(Di|Die|Dienstag|2)$', '^(Mi|Mit|Mittwoch|3)$',
  760. '^(Do|Don|Donnerstag|4)$', '^(Fr|Fre|Freitag|5)$',
  761. '^(Sa|Sam|Samstag|6)$',
  762. ],
  763. en => [
  764. '^(Sun|Su|Sunday|0|7)$', '^(Mon|Mo|Monday|1)$',
  765. '^(Tue|Tu|Tuesday|2)$', '^(Wed|We|Wednesday|3)$',
  766. '^(Thu|Th|Thursday|4)$', '^(Fri|Fr|Friday|5)$',
  767. '^(Sat|Sa|Saturday|6)$'
  768. ],
  769. },
  770. tmpl => '%txt%',
  771. tmpl_long => '%txt_long%',
  772. rtype_description => {
  773. de =>
  774. 'Wochentag nach englisch-amerikanischer Annahme des Wochenstarts am Sonntag',
  775. en =>
  776. 'Day of the week according to english assumption for the week to start on sunday',
  777. },
  778. },
  779. weekday_iso => {
  780. ref_base => 900,
  781. symbol => {
  782. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ],
  783. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ],
  784. },
  785. txt => {
  786. de => [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ],
  787. en => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ],
  788. },
  789. txt_long => {
  790. de => [
  791. 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch',
  792. 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'
  793. ],
  794. en => [
  795. 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  796. 'Thursday', 'Friday', 'Saturday', 'Sunday'
  797. ],
  798. },
  799. scope => {
  800. de => [
  801. '^(So|Son|Sonntag|7)$', '^(Mo|Mon|Montag|1)$',
  802. '^(Di|Die|Dienstag|2)$', '^(Mi|Mit|Mittwoch|3)$',
  803. '^(Do|Don|Donnerstag|4)$', '^(Fr|Fre|Freitag|5)$',
  804. '^(Sa|Sam|Samstag|6)$'
  805. ],
  806. en => [
  807. '^(Sun|Su|Sunday|7)$', '^(Mon|Mo|Monday|1)$',
  808. '^(Tue|Tu|Tuesday|2)$', '^(Wed|We|Wednesday|3)$',
  809. '^(Thu|Th|Thursday|4)$', '^(Fri|Fr|Friday|5)$',
  810. '^(Sat|Sa|Saturday|6)$'
  811. ],
  812. },
  813. tmpl => '%txt%',
  814. tmpl_long => '%txt_long%',
  815. rtype_description => {
  816. de => 'Wochentag nach ISO-Standard, Woche beginnend am Montag',
  817. en =>
  818. 'Day of the week according to ISO standard, week beginning on Mondays',
  819. },
  820. },
  821. weekday_night => {
  822. ref_base => 900,
  823. symbol => {
  824. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  825. en => [
  826. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  827. ],
  828. },
  829. txt => {
  830. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  831. en => [
  832. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  833. ],
  834. },
  835. txt_long => {
  836. de => [
  837. 'Sonntag Nacht',
  838. 'Montag Nacht',
  839. 'Dienstag Nacht',
  840. 'Mittwoch Nacht',
  841. 'Donnerstag Nacht',
  842. 'Freitag Nacht',
  843. 'Samstag Nacht'
  844. ],
  845. en => [
  846. 'Sunday Night',
  847. 'Monday Night',
  848. 'Tuesday Night',
  849. 'Wednesday Night',
  850. 'Thursday Night',
  851. 'Friday Night',
  852. 'Saturday Night'
  853. ],
  854. },
  855. scope => {
  856. de => [
  857. '^(\s*(Nacht|Na)?\s*(So|Son|Sonntag|0)\s*(Nacht|Na)?\s*)$',
  858. '^(\s*(Nacht|Na)?\s*(Mo|Mon|Montag|1)\s*(Nacht|Na)?\s*)$',
  859. '^(\s*(Nacht|Na)?\s*(Di|Die|Dienstag|2)\s*(Nacht|Na)?\s*)$',
  860. '^(\s*(Nacht|Na)?\s*(Mi|Mit|Mittwoch|3)\s*(Nacht|Na)?\s*)$',
  861. '^(\s*(Nacht|Na)?\s*(Do|Don|Donnerstag|4)\s*(Nacht|Na)?\s*)$',
  862. '^(\s*(Nacht|Na)?\s*(Fr|Fre|Freitag|5)\s*(Nacht|Na)?\s*)$',
  863. '^(\s*(Nacht|Na)?\s*(Sa|Sam|Samstag|6)\s*(Nacht|Na)?\s*)$'
  864. ],
  865. en => [
  866. '^(\s*(Night|Na)?\s*(Sun|Su|Sunday|0)\s*(Night|Na)?\s*)$',
  867. '^(\s*(Night|Na)?\s*(Mon|Mo|Monday|1)\s*(Night|Na)?\s*)$',
  868. '^(\s*(Night|Na)?\s*(Tue|Tu|Tuesday|2)\s*(Night|Na)?\s*)$',
  869. '^(\s*(Night|Na)?\s*(Wed|We|Wednesday|3)\s*(Night|Na)?\s*)$',
  870. '^(\s*(Night|Na)?\s*(Thu|Th|Thursday|4)\s*(Night|Na)?\s*)$',
  871. '^(\s*(Night|Na)?\s*(Fri|Fr|Friday|5)\s*(Night|Na)?\s*)$',
  872. '^(\s*(Night|Na)?\s*(Sat|Sa|Saturday|6)\s*(Night|Na)?\s*)$'
  873. ],
  874. },
  875. tmpl => '%txt%',
  876. tmpl_long => '%txt_long%',
  877. rtype_description => {
  878. de =>
  879. 'Nächtlicher Wochentag nach englisch-amerikanischem Standard des Wochenstarts am Sonntag',
  880. en =>
  881. 'Nightly day of the week according to english standard for the week to start on sunday',
  882. },
  883. },
  884. weekday_night_iso => {
  885. ref_base => 900,
  886. symbol => {
  887. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  888. en => [
  889. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  890. ],
  891. },
  892. txt => {
  893. de => [ 'So N', 'Mo N', 'Di N', 'Mi N', 'Do N', 'Fr N', 'Sa N' ],
  894. en => [
  895. 'Sun N', 'Mon N', 'Tue N', 'Wed N', 'Thu N', 'Fri N ', 'Sat N'
  896. ],
  897. },
  898. txt_long => {
  899. de => [
  900. 'Sonntag Nacht',
  901. 'Montag Nacht',
  902. 'Dienstag Nacht',
  903. 'Mittwoch Nacht',
  904. 'Donnerstag Nacht',
  905. 'Freitag Nacht',
  906. 'Samstag Nacht'
  907. ],
  908. en => [
  909. 'Sunday Night',
  910. 'Monday Night',
  911. 'Tuesday Night',
  912. 'Wednesday Night',
  913. 'Thursday Night',
  914. 'Friday Night',
  915. 'Saturday Night'
  916. ],
  917. },
  918. scope => {
  919. de => [
  920. '^(\s*(Nacht|Na)?\s*(So|Son|Sonntag|6)\s*(Nacht|Na)?\s*)$',
  921. '^(\s*(Nacht|Na)?\s*(Mo|Mon|Montag|0)\s*(Nacht|Na)?\s*)$',
  922. '^(\s*(Nacht|Na)?\s*(Di|Die|Dienstag|1)\s*(Nacht|Na)?\s*)$',
  923. '^(\s*(Nacht|Na)?\s*(Mi|Mit|Mittwoch|2)\s*(Nacht|Na)?\s*)$',
  924. '^(\s*(Nacht|Na)?\s*(Do|Don|Donnerstag|3)\s*(Nacht|Na)?\s*)$',
  925. '^(\s*(Nacht|Na)?\s*(Fr|Fre|Freitag|4)\s*(Nacht|Na)?\s*)$',
  926. '^(\s*(Nacht|Na)?\s*(Sa|Sam|Samstag|5)\s*(Nacht|Na)?\s*)$'
  927. ],
  928. en => [
  929. '^(\s*(Night|Na)?\s*(Sun|Su|Sunday|6)\s*(Night|Na)?\s*)$',
  930. '^(\s*(Night|Na)?\s*(Mon|Mo|Monday|0)\s*(Night|Na)?\s*)$',
  931. '^(\s*(Night|Na)?\s*(Tue|Tu|Tuesday|1)\s*(Night|Na)?\s*)$',
  932. '^(\s*(Night|Na)?\s*(Wed|We|Wednesday|2)\s*(Night|Na)?\s*)$',
  933. '^(\s*(Night|Na)?\s*(Thu|Th|Thursday|3)\s*(Night|Na)?\s*)$',
  934. '^(\s*(Night|Na)?\s*(Fri|Fr|Friday|4)\s*(Night|Na)?\s*)$',
  935. '^(\s*(Night|Na)?\s*(Sat|Sa|Saturday|5)\s*(Night|Na)?\s*)$'
  936. ],
  937. },
  938. tmpl => '%txt%',
  939. tmpl_long => '%txt_long%',
  940. rtype_description => {
  941. de =>
  942. 'Nächtlicher Wochentag nach ISO-Standard, Woche beginnend am Montag',
  943. en =>
  944. 'Nightly day of the week according to ISO standard, week beginning on Mondays',
  945. },
  946. },
  947. direction => {
  948. ref_base => 900,
  949. formula_symbol => 'Dir',
  950. ref => 'gon',
  951. scope => { minValue => 0, maxValue => 360 },
  952. rtype_description => {
  953. de => 'Richtungsangabe',
  954. en => 'direction',
  955. },
  956. },
  957. compasspoint => {
  958. ref_base => 900,
  959. formula_symbol => 'CP',
  960. ref => 'gon',
  961. txt => {
  962. de => [
  963. 'N', 'NNO', 'NO', 'ONO', 'O', 'OSO', 'SO', 'SSO',
  964. 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  965. ],
  966. en => [
  967. 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
  968. 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  969. ],
  970. nl => [
  971. 'N', 'NNO', 'NO', 'ONO', 'O', 'OZO', 'ZO', 'ZZO',
  972. 'Z', 'ZZW', 'ZW', 'WZW', 'W', 'WNW', 'NW', 'NNW'
  973. ],
  974. fr => [
  975. 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
  976. 'S', 'SSO', 'SO', 'OSO', 'O', 'ONO', 'NO', 'NNO'
  977. ],
  978. pl => [
  979. 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
  980. 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  981. ],
  982. },
  983. txt_long => {
  984. de => [
  985. 'Norden', 'Nord-Nordost', 'Nordost', 'Ost-Nordost',
  986. 'Osten', 'Ost-Südost', 'Südost', 'Süd-Südost',
  987. 'Süden', 'Süd-Südwest', 'Südwest', 'West-Südwest',
  988. 'Westen', 'West-Nordwest', 'Nordwest', 'Nord-Nordwest'
  989. ],
  990. en => [
  991. 'North', 'North-Northeast',
  992. 'Northeast', 'East-Northeast',
  993. 'East', 'East-Southeast',
  994. 'Southeast', 'South-Southeast',
  995. 'South', 'South-Southwest',
  996. 'Southwest', 'West-Southwest',
  997. 'West', 'West-Northwest',
  998. 'Northwest', 'North-Northwest'
  999. ],
  1000. nl => [
  1001. 'N', 'NNO', 'NO', 'ONO', 'O', 'OZO', 'ZO', 'ZZO',
  1002. 'Z', 'ZZW', 'ZW', 'WZW', 'W', 'WNW', 'NW', 'NNW'
  1003. ],
  1004. fr => [
  1005. 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
  1006. 'S', 'SSO', 'SO', 'OSO', 'O', 'ONO', 'NO', 'NNO'
  1007. ],
  1008. pl => [
  1009. 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
  1010. 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  1011. ],
  1012. },
  1013. scope => {
  1014. de => [
  1015. {
  1016. ge => 0.0,
  1017. lt => 22.5,
  1018. eq => 360,
  1019. regex => '^(N|Norden|0)$',
  1020. value_num => 0.0,
  1021. },
  1022. {
  1023. ge => 22.5,
  1024. lt => 45.0,
  1025. regex => '^(NNO|Nord-Nordost|1)$',
  1026. value_num => 22.5,
  1027. },
  1028. {
  1029. ge => 45.0,
  1030. lt => 67.5,
  1031. regex => '^(NO|Nordost|2)$',
  1032. value_num => 45.0,
  1033. },
  1034. {
  1035. ge => 67.5,
  1036. lt => 90.0,
  1037. regex => '^(ONO|Ost-Nordost|3)$',
  1038. value_num => 67.5,
  1039. },
  1040. {
  1041. ge => 90.0,
  1042. lt => 112.5,
  1043. regex => '^(O|Osten|4)$',
  1044. value_num => 90.0,
  1045. },
  1046. {
  1047. ge => 112.5,
  1048. lt => 135.0,
  1049. regex => '^(OSO|Ost-S(ü|u|ue)dost|5)$',
  1050. value_num => 112.5,
  1051. },
  1052. {
  1053. ge => 135.0,
  1054. lt => 157.5,
  1055. regex => '^(SO|S(ü|u|ue)dost|6)$',
  1056. value_num => 135.0,
  1057. },
  1058. {
  1059. ge => 157.5,
  1060. lt => 180.0,
  1061. regex => '^(SSO|S(ü|u|ue)d-S(ü|u|ue)dost|7)$',
  1062. value_num => 157.5,
  1063. },
  1064. {
  1065. ge => 180.0,
  1066. lt => 202.5,
  1067. regex => '^(S|S(ü|u|ue)den|8)$',
  1068. value_num => 180.0,
  1069. },
  1070. {
  1071. ge => 202.5,
  1072. lt => 225.0,
  1073. regex => '^(SSW|S(ü|u|ue)d-S(ü|u|ue)dwest|9)$',
  1074. value_num => 202.5,
  1075. },
  1076. {
  1077. ge => 225.0,
  1078. lt => 247.5,
  1079. regex => '^(SW|S(ü|u|ue)dwest|10)$',
  1080. value_num => 225.0,
  1081. },
  1082. {
  1083. ge => 247.5,
  1084. lt => 270.0,
  1085. regex => '^(WSW|West-S(ü|u|ue)dwest|11)$',
  1086. value_num => 247.5,
  1087. },
  1088. {
  1089. ge => 270.0,
  1090. lt => 292.5,
  1091. regex => '^(W|Westen|12)$',
  1092. value_num => 270.0,
  1093. },
  1094. {
  1095. ge => 292.5,
  1096. lt => 315.0,
  1097. regex => '^(WNW|West-Nordwest|13)$',
  1098. value_num => 292.5,
  1099. },
  1100. {
  1101. ge => 315.0,
  1102. lt => 337.5,
  1103. regex => '^(NW|Nordwest|14)$',
  1104. value_num => 315.0,
  1105. },
  1106. {
  1107. ge => 337.5,
  1108. lt => 360,
  1109. regex => '^(NNW|Nord-Nordwest|15)$',
  1110. value_num => 337.5,
  1111. },
  1112. ],
  1113. en => [
  1114. {
  1115. ge => 0.0,
  1116. lt => 22.5,
  1117. eq => 360,
  1118. regex => '^(N|North|0)$',
  1119. value_num => 0.0,
  1120. },
  1121. {
  1122. ge => 22.5,
  1123. lt => 45.0,
  1124. regex => '^(NNE|North-Northeast|1)$',
  1125. value_num => 22.5,
  1126. },
  1127. {
  1128. ge => 45.0,
  1129. lt => 67.5,
  1130. regex => '^(NE|Northeast|2)$',
  1131. value_num => 45.0,
  1132. },
  1133. {
  1134. ge => 67.5,
  1135. lt => 90.0,
  1136. regex => '^(ENE|East-Northeast|3)$',
  1137. value_num => 67.5,
  1138. },
  1139. {
  1140. ge => 90.0,
  1141. lt => 112.5,
  1142. regex => '^(E|East|4)$',
  1143. value_num => 90.0,
  1144. },
  1145. {
  1146. ge => 112.5,
  1147. lt => 135.0,
  1148. regex => '^(ESE|East-Southeast|5)$',
  1149. value_num => 112.5,
  1150. },
  1151. {
  1152. ge => 135.0,
  1153. lt => 157.5,
  1154. regex => '^(SE|Southeast|6)$',
  1155. value_num => 135.0,
  1156. },
  1157. {
  1158. ge => 157.5,
  1159. lt => 180.0,
  1160. regex => '^(SSE|South-Southeast|7)$',
  1161. value_num => 157.5,
  1162. },
  1163. {
  1164. ge => 180.0,
  1165. lt => 202.5,
  1166. regex => '^(S|South|8)$',
  1167. value_num => 180.0,
  1168. },
  1169. {
  1170. ge => 202.5,
  1171. lt => 225.0,
  1172. regex => '^(SSW|South-Southwest|9)$',
  1173. value_num => 202.5,
  1174. },
  1175. {
  1176. ge => 225.0,
  1177. lt => 247.5,
  1178. regex => '^(SW|Southwest|10)$',
  1179. value_num => 225.0,
  1180. },
  1181. {
  1182. ge => 247.5,
  1183. lt => 270.0,
  1184. regex => '^(WSW|West-Southwest|11)$',
  1185. value_num => 247.5,
  1186. },
  1187. {
  1188. ge => 270.0,
  1189. lt => 292.5,
  1190. regex => '^(W|West|12)$',
  1191. value_num => 270.0,
  1192. },
  1193. {
  1194. ge => 292.5,
  1195. lt => 315.0,
  1196. regex => '^(WNW|West-Northwest|13)$',
  1197. value_num => 292.5,
  1198. },
  1199. {
  1200. ge => 315.0,
  1201. lt => 337.5,
  1202. regex => '^(NW|Northwest|14)$',
  1203. value_num => 315.0,
  1204. },
  1205. {
  1206. ge => 337.5,
  1207. lt => 360,
  1208. regex => '^(NNW|North-Northwest|15)$',
  1209. value_num => 337.5,
  1210. },
  1211. ],
  1212. },
  1213. rtype_description => {
  1214. de => 'Himmelsrichtung',
  1215. en => 'point of the compass',
  1216. },
  1217. tmpl_long => '%txt_long%',
  1218. },
  1219. closure => {
  1220. ref_base => 900,
  1221. txt => {
  1222. de => [ 'geschlossen', 'offen', 'gekippt' ],
  1223. en => [ 'closed', 'open', 'tilted' ],
  1224. },
  1225. scope => [ '^(closed|0)$', '^(open|1)$', '^(tilted|2)$' ],
  1226. rtype_description => {
  1227. de => 'Status für Fenster und Türen',
  1228. en => 'state for windows and doors',
  1229. },
  1230. },
  1231. condition_weather => {
  1232. ref_base => 900,
  1233. txt => {
  1234. de => [ 'klar', 'sonnig', 'bewölkt', 'Regen' ],
  1235. en => [ 'clear', 'sunny', 'cloudy', 'rain' ],
  1236. },
  1237. scope => [
  1238. '^((nt_)?clear|nt_sunny|0)$', '^(sunny|1)$',
  1239. '^((nt_)?cloudy|2)$', '^((nt_)?rain|3)$'
  1240. ],
  1241. rtype_description => {
  1242. de => 'Wetterbedingung',
  1243. en => 'weather condition',
  1244. },
  1245. },
  1246. condition_hum => {
  1247. ref_base => 900,
  1248. txt => {
  1249. de => [ 'trocken', 'niedrig', 'optimal', 'hoch', 'feucht' ],
  1250. en => [ 'dry', 'low', 'ideal', 'high', 'wet' ],
  1251. },
  1252. scope => [
  1253. '^(dry|0)$', '^(low|1)$',
  1254. '^(ideal|optimal|2)$', '^(high|3)$',
  1255. '^(wet|4)$'
  1256. ],
  1257. rtype_description => {
  1258. de => 'Feuchtigkeitsbedingung',
  1259. en => 'humidity condition',
  1260. },
  1261. },
  1262. condition_uvi => {
  1263. ref_base => 900,
  1264. txt => {
  1265. de => [ 'niedrig', 'moderat', 'hoch', 'sehr hoch', 'extrem' ],
  1266. en => [ 'low', 'moderate', 'high', 'very high', 'extreme' ],
  1267. },
  1268. scope => [
  1269. '^(low|0)$', '^(moderate|1)$',
  1270. '^(high|2)$', '^(veryhigh|3)$',
  1271. '^(extreme|4)$'
  1272. ],
  1273. rtype_description => {
  1274. de => 'UV Bedingung',
  1275. en => 'UV condition',
  1276. },
  1277. },
  1278. # color
  1279. rgbhex => {
  1280. ref_base => 900,
  1281. rtype_description => {
  1282. de => 'RGB Farbwert in Hex Notation',
  1283. en => 'RGB color value in Hex notation',
  1284. },
  1285. scope => '^#?(([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2}))$',
  1286. },
  1287. rgb => {
  1288. ref_base => 900,
  1289. rtype_description => {
  1290. de => 'RGB Farbwert in Dezimal Notation',
  1291. en => 'RGB color value in decimal notation',
  1292. },
  1293. scope =>
  1294. '^[\s\t\n ]*(?:rgb|RGB)?[\s\t\n ]*\(?[\s\t\n ]*((?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])[\s\t\n ]*,?[\s\t\n ]*)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])[\s\t\n ]*,?[\s\t\n ]*)(?:([0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])))[\s\t\n ]*\)?[\s\t\n ]*$',
  1295. },
  1296. # logical operators
  1297. bool => {
  1298. ref_base => 26,
  1299. txt => {
  1300. de => [ 'falsch', 'wahr' ],
  1301. en => [ 'false', 'true' ],
  1302. },
  1303. scope => [ '^(false|n|no|0)$', '^(true|y|yes|1)$' ],
  1304. rtype_description => {
  1305. de => 'Boolesch wahr/falsch',
  1306. en => 'Boolean true/false',
  1307. },
  1308. },
  1309. yesno => {
  1310. ref_base => 26,
  1311. txt => {
  1312. de => [ 'nein', 'ja' ],
  1313. en => [ 'no', 'yes' ],
  1314. },
  1315. scope => [ '^(no|n|false|0)$', '^(yes|y|true|1)$' ],
  1316. rtype_description => {
  1317. de => 'Boolesch ja/nein',
  1318. en => 'Boolean ja/nein',
  1319. },
  1320. },
  1321. # decimal numbering
  1322. short => {
  1323. ref_base => 25,
  1324. format => '%i',
  1325. rtype_description => {
  1326. de => 'Ganzzahl zwischen -32768 und 32767',
  1327. en => 'Integer between -32768 and 32767',
  1328. },
  1329. scope => { minValue => -32768, maxValue => 32767 },
  1330. },
  1331. rshort => {
  1332. ref_base => 25,
  1333. format => '%.0f',
  1334. rtype_description => {
  1335. de => 'gerundete Ganzzahl zwischen -32768 und 32767',
  1336. en => 'rounded integer between -32768 and 32767',
  1337. },
  1338. scope => { minValue => -32768, maxValue => 32767 },
  1339. },
  1340. long => {
  1341. ref_base => 25,
  1342. format => '%i',
  1343. rtype_description => {
  1344. de => 'Ganzzahl zwischen -2147483648 und 214748364',
  1345. en => 'Integer between -2147483648 and 214748364',
  1346. },
  1347. scope => { minValue => -2147483648, maxValue => 214748364 },
  1348. },
  1349. rlong => {
  1350. ref_base => 25,
  1351. format => '%.0f',
  1352. rtype_description => {
  1353. de => 'gerundete Ganzzahl zwischen -2147483648 und 214748364',
  1354. en => 'rounded integer between -2147483648 and 214748364',
  1355. },
  1356. scope => { minValue => -2147483648, maxValue => 214748364 },
  1357. },
  1358. integer => {
  1359. ref_base => 25,
  1360. format => '%i',
  1361. rtype_description => {
  1362. de => 'Ganzzahl',
  1363. en => 'Integer',
  1364. },
  1365. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1366. },
  1367. rinteger => {
  1368. ref_base => 25,
  1369. format => '%.0f',
  1370. rtype_description => {
  1371. de => 'gerundete Ganzzahl',
  1372. en => 'rounded integer',
  1373. },
  1374. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1375. },
  1376. float => {
  1377. ref_base => 25,
  1378. format => '%.2f',
  1379. rtype_description => {
  1380. de => 'Fließkommazahl',
  1381. en => 'floating number',
  1382. },
  1383. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1384. },
  1385. pct => {
  1386. ref_base => 25,
  1387. format => '%i',
  1388. symbol => chr(0x0025),
  1389. suffix => 'pct',
  1390. tmpl => '%value%' . chr(0x202F) . '%symbol%',
  1391. tmpl_long => '%value% %txt%',
  1392. txt => {
  1393. de => 'Prozent',
  1394. en => 'percent',
  1395. },
  1396. scope => { minValue => 0, maxValue => 100 },
  1397. },
  1398. # binary numbering
  1399. bin => {
  1400. rtype_description => {
  1401. de => 'Binärnummer',
  1402. en => 'Binary number',
  1403. },
  1404. scope => '^[01]+$',
  1405. },
  1406. # octal numbering
  1407. oct => {
  1408. rtype_description => {
  1409. de => 'Oktalnummer',
  1410. en => 'Octal number',
  1411. },
  1412. scope => '^[0-7]+$',
  1413. },
  1414. # hexadecimal numbering
  1415. hex => {
  1416. rtype_description => {
  1417. de => 'Hexadezimalnummer',
  1418. en => 'Hexadecimal number',
  1419. },
  1420. scope => '^[0-9a-fA-F]+$',
  1421. },
  1422. # currency
  1423. #https://en.wikipedia.org/wiki/Euro
  1424. #https://en.wikipedia.org/wiki/Linguistic_issues_concerning_the_euro
  1425. euro => {
  1426. ref_base => 24,
  1427. format => '%.2f',
  1428. symbol => '€',
  1429. suffix => 'EUR',
  1430. txt => {
  1431. de => 'Euro',
  1432. en => 'euro',
  1433. },
  1434. tmpl => {
  1435. de => '%symbol%%value%',
  1436. de_de => '%value%' . chr(0x202F) . '%symbol%',
  1437. en => '%symbol%%value%',
  1438. },
  1439. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1440. },
  1441. pound_uk => {
  1442. ref_base => 24,
  1443. format => '%.2f',
  1444. symbol => '£',
  1445. suffix => 'GBP',
  1446. txt => {
  1447. de => 'Pfund',
  1448. en => 'pound',
  1449. },
  1450. txt_long => {
  1451. de => 'Britisches Pfund',
  1452. en => 'British pound',
  1453. },
  1454. txt_long_pl => {
  1455. de => 'Britische Pfund',
  1456. en => 'British pound',
  1457. },
  1458. tmpl => '%symbol%%value%',
  1459. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1460. },
  1461. dollar_us => {
  1462. ref_base => 24,
  1463. format => '%.2f',
  1464. symbol => '$',
  1465. suffix => 'USD',
  1466. txt => {
  1467. de => 'Dollar',
  1468. en => 'dollar',
  1469. },
  1470. txt_long => {
  1471. de => 'US Dollar',
  1472. en => 'US dollar',
  1473. },
  1474. tmpl => '%symbol%%value%',
  1475. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1476. },
  1477. cent => {
  1478. ref_base => 24,
  1479. format => '%.0f',
  1480. symbol => {
  1481. de => 'ct',
  1482. en => '¢',
  1483. },
  1484. suffix => {
  1485. de => 'ct',
  1486. en => 'c',
  1487. },
  1488. txt => {
  1489. de => 'Cent',
  1490. en => 'cent',
  1491. },
  1492. tmpl => {
  1493. de => '%value%%symbol%',
  1494. de_de => '%value%' . chr(0x202F) . '%symbol%',
  1495. en => '%value%%symbol%',
  1496. },
  1497. scope => '^([0-9]*(?:\.[0-9]*)?)$',
  1498. },
  1499. # plane angular
  1500. gon => {
  1501. ref_base => 14,
  1502. symbol => chr(0x00B0),
  1503. suffix => 'gon',
  1504. txt => {
  1505. de => 'Grad',
  1506. en => 'gradians',
  1507. },
  1508. tmpl => '%value%%symbol%',
  1509. decimal_mark => {
  1510. de => 2,
  1511. en => 1,
  1512. },
  1513. format => '%i',
  1514. },
  1515. rad => {
  1516. ref_base => 14,
  1517. suffix => 'rad',
  1518. txt => {
  1519. de => 'Radiant',
  1520. en => 'radiant',
  1521. },
  1522. decimal_mark => {
  1523. de => 2,
  1524. en => 1,
  1525. },
  1526. format => '%i',
  1527. },
  1528. # temperature
  1529. c => {
  1530. ref_base => 4,
  1531. symbol => chr(0x00B0) . 'C',
  1532. suffix => 'C',
  1533. txt => {
  1534. de => 'Grad Celsius',
  1535. en => 'Degree Celsius',
  1536. },
  1537. txt_pl => {
  1538. de => 'Grad Celsius',
  1539. en => 'Degrees Celsius',
  1540. },
  1541. scope => { minValue => -273.15 },
  1542. },
  1543. f => {
  1544. ref_base => 4,
  1545. symbol => chr(0x00B0) . 'F',
  1546. suffix => 'F',
  1547. txt => {
  1548. de => 'Grad Fahrenheit',
  1549. en => 'Degree Fahrenheit',
  1550. },
  1551. txt_pl => {
  1552. de => 'Grad Fahrenheit',
  1553. en => 'Degrees Fahrenheit',
  1554. },
  1555. scope => { minValue => -459.67 },
  1556. },
  1557. k => {
  1558. ref_base => 4,
  1559. suffix => 'K',
  1560. txt => {
  1561. de => 'Kelvin',
  1562. en => 'Kelvin',
  1563. },
  1564. },
  1565. # pressure
  1566. bar => {
  1567. ref_base => 10,
  1568. scale_m => '1.0e0',
  1569. suffix => 'bar',
  1570. txt => {
  1571. de => 'Bar',
  1572. en => 'Bar',
  1573. },
  1574. },
  1575. mbar => {
  1576. ref => 'bar',
  1577. scale_m => '1.0e-3',
  1578. },
  1579. pa => {
  1580. ref_base => 10,
  1581. scale_m => '1.0e0',
  1582. suffix => 'Pa',
  1583. txt => {
  1584. de => 'Pascal',
  1585. en => 'Pascal',
  1586. },
  1587. },
  1588. hpa => {
  1589. ref => 'pa',
  1590. scale_m => '1.0e2',
  1591. },
  1592. pamb => {
  1593. ref_base => 12,
  1594. scale_m => '1.0e0',
  1595. suffix => 'Pa',
  1596. txt => {
  1597. de => 'Pascal',
  1598. en => 'Pascal',
  1599. },
  1600. },
  1601. hpamb => {
  1602. ref => 'pamb',
  1603. scale_m => '1.0e2',
  1604. },
  1605. inhg => {
  1606. ref_base => 12,
  1607. suffix => 'inHg',
  1608. format => '%.2f',
  1609. txt => {
  1610. de => 'Zoll Quecksilbersäule',
  1611. en => 'Inches of Mercury',
  1612. },
  1613. },
  1614. mmhg => {
  1615. ref_base => 12,
  1616. suffix => 'mmHg',
  1617. txt => {
  1618. de => 'Millimeter Quecksilbersäule',
  1619. en => 'Milimeter of Mercury',
  1620. },
  1621. },
  1622. # length
  1623. km => {
  1624. ref => 'm',
  1625. scale_m => '1.0e3',
  1626. },
  1627. hm => {
  1628. ref => 'm',
  1629. scale_m => '1.0e2',
  1630. },
  1631. dam => {
  1632. ref => 'm',
  1633. scale_m => '1.0e1',
  1634. },
  1635. m => {
  1636. ref_base => 0,
  1637. scale_m => '1.0e0',
  1638. suffix => 'm',
  1639. txt => {
  1640. de => 'Meter',
  1641. en => 'meter',
  1642. },
  1643. },
  1644. dm => {
  1645. ref => 'm',
  1646. scale_m => '1.0e-1',
  1647. },
  1648. cm => {
  1649. ref => 'm',
  1650. scale_m => '1.0e-2',
  1651. },
  1652. mm => {
  1653. ref => 'm',
  1654. scale_m => '1.0e-3',
  1655. },
  1656. um => {
  1657. ref => 'm',
  1658. scale_m => '1.0e-6',
  1659. },
  1660. nm => {
  1661. ref => 'm',
  1662. scale_m => '1.0e-9',
  1663. },
  1664. pm => {
  1665. ref => 'm',
  1666. scale_m => '1.0e-12',
  1667. },
  1668. fm => {
  1669. ref => 'm',
  1670. scale_m => '1.0e-15',
  1671. },
  1672. in => {
  1673. ref_base => 0,
  1674. symbol => '″',
  1675. suffix => 'in',
  1676. txt => {
  1677. de => 'Zoll',
  1678. en => 'inch',
  1679. },
  1680. txt_pl => {
  1681. de => 'Zoll',
  1682. en => 'inches',
  1683. },
  1684. tmpl => '%value%%symbol%',
  1685. },
  1686. ft => {
  1687. ref_base => 0,
  1688. symbol => '′',
  1689. suffix => 'ft',
  1690. txt => {
  1691. de => 'Fuss',
  1692. en => 'foot',
  1693. },
  1694. txt_pl => {
  1695. de => 'Fuss',
  1696. en => 'feet',
  1697. },
  1698. tmpl => '%value%%symbol%',
  1699. },
  1700. yd => {
  1701. ref_base => 0,
  1702. suffix => 'yd',
  1703. txt => {
  1704. de => 'Yard',
  1705. en => 'yard',
  1706. },
  1707. txt_pl => {
  1708. de => 'Yards',
  1709. en => 'yards',
  1710. },
  1711. },
  1712. mi => {
  1713. ref_base => 0,
  1714. suffix => 'mi',
  1715. txt => {
  1716. de => 'Meilen',
  1717. en => 'miles',
  1718. },
  1719. },
  1720. # time
  1721. sec => {
  1722. ref_base => 2,
  1723. scale_t => 's',
  1724. suffix => {
  1725. de => 's',
  1726. en => 's',
  1727. },
  1728. txt => {
  1729. de => 'Sekunde',
  1730. en => 'second',
  1731. },
  1732. txt_pl => {
  1733. de => 'Sekunden',
  1734. en => 'seconds',
  1735. },
  1736. },
  1737. min => {
  1738. ref_base => 2,
  1739. scale_t => 'min',
  1740. suffix => {
  1741. de => 'Min',
  1742. en => 'min',
  1743. },
  1744. txt => {
  1745. de => 'Minute',
  1746. en => 'minute',
  1747. },
  1748. txt_pl => {
  1749. de => 'Minuten',
  1750. en => 'minutes',
  1751. },
  1752. },
  1753. hr => {
  1754. ref_base => 2,
  1755. scale_t => 'h',
  1756. suffix => 'h',
  1757. txt => {
  1758. de => 'Stunde',
  1759. en => 'hour',
  1760. },
  1761. txt_pl => {
  1762. de => 'Stunden',
  1763. en => 'hours',
  1764. },
  1765. },
  1766. d => {
  1767. ref_base => 2,
  1768. scale_t => 'd',
  1769. suffix => {
  1770. de => 'T',
  1771. en => 'd',
  1772. },
  1773. txt => {
  1774. de => 'Tag',
  1775. en => 'day',
  1776. },
  1777. txt_pl => {
  1778. de => 'Tage',
  1779. en => 'days',
  1780. },
  1781. },
  1782. w => {
  1783. ref_base => 2,
  1784. scale_t => 'w',
  1785. suffix => {
  1786. de => 'W',
  1787. en => 'w',
  1788. },
  1789. txt => {
  1790. de => 'Woche',
  1791. en => 'week',
  1792. },
  1793. txt_pl => {
  1794. de => 'Wochen',
  1795. en => 'weeks',
  1796. },
  1797. },
  1798. mon => {
  1799. ref_base => 2,
  1800. scale_t => 'm',
  1801. suffix => {
  1802. de => 'M',
  1803. en => 'm',
  1804. },
  1805. txt => {
  1806. de => 'Monat',
  1807. en => 'month',
  1808. },
  1809. txt_pl => {
  1810. de => 'Monate',
  1811. en => 'Monat',
  1812. },
  1813. },
  1814. y => {
  1815. ref_base => 2,
  1816. scale_t => 'a',
  1817. suffix => {
  1818. de => 'J',
  1819. en => 'y',
  1820. },
  1821. txt => {
  1822. de => 'Jahr',
  1823. en => 'year',
  1824. },
  1825. txt_pl => {
  1826. de => 'Jahre',
  1827. en => 'years',
  1828. },
  1829. },
  1830. epoch => {
  1831. ref_base => 2,
  1832. scale_t => 's',
  1833. scope => { minValue => 0 },
  1834. rtype_description => {
  1835. de => 'Unix Epoche in s seit 1970-01-01T00:00:00Z',
  1836. en => 'Unix epoch in s since 1970-01-01T00:00:00Z',
  1837. },
  1838. },
  1839. time => {
  1840. ref_base => 2,
  1841. scope => '^(([0-1]?[0-9]|[0-2]?[0-3]):([0-5]?[0-9]))$',
  1842. rtype_description => {
  1843. de => 'Uhrzeit hh:mm',
  1844. en => 'time hh:mm',
  1845. },
  1846. tmpl_long => {
  1847. de => '%value%' . chr(0x00A0) . 'Uhr',
  1848. en => '%value%',
  1849. }
  1850. },
  1851. datetime => {
  1852. ref_base => 2,
  1853. scope =>
  1854. '^(([1-2][0-9]{3})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|30|31) (0?[1-9]|1[0-9]|2[0-3]):(0?[1-9]|[1-5][0-9]))$',
  1855. rtype_description => {
  1856. de => 'Datum+Uhrzeit YYYY-mm-dd hh:mm',
  1857. en => 'date+time YYYY-mm-dd hh:mm',
  1858. },
  1859. },
  1860. timesec => {
  1861. ref_base => 900,
  1862. scope => '^(([0-1]?[0-9]|[0-2]?[0-3]):([0-5]?[0-9]):([0-5]?[0-9]))$',
  1863. rtype_description => {
  1864. de => 'Uhrzeit hh:mm:ss',
  1865. en => 'time hh:mm:ss',
  1866. },
  1867. },
  1868. datetimesec => {
  1869. ref_base => 2,
  1870. scope =>
  1871. '^(([1-2][0-9]{3})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|30|31) (0?[1-9]|1[0-9]|2[0-3]):(0?[1-9]|[1-5][0-9]):(0?[1-9]|[1-5][0-9]))$',
  1872. rtype_description => {
  1873. de => 'Datum+Uhrzeit YYYY-mm-dd hh:mm:ss',
  1874. en => 'date+time YYYY-mm-dd hh:mm:ss',
  1875. },
  1876. },
  1877. # speed
  1878. bft => {
  1879. ref_base => 15,
  1880. suffix => 'bft',
  1881. txt => {
  1882. de => 'Windstärke',
  1883. en => 'wind force',
  1884. },
  1885. tmpl_long => '%txt% %value%',
  1886. },
  1887. kn => {
  1888. ref_base => 15,
  1889. suffix => 'kn',
  1890. txt => {
  1891. de => 'Knoten',
  1892. en => 'knots',
  1893. },
  1894. },
  1895. fts => {
  1896. ref_base => 15,
  1897. ref => 'ft',
  1898. ref_t => 'sec',
  1899. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_t%',
  1900. tmpl_long => {
  1901. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1902. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1903. },
  1904. tmpl_long_pl => {
  1905. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1906. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1907. },
  1908. },
  1909. mph => {
  1910. ref_base => 15,
  1911. ref => 'mi',
  1912. ref_t => 'hr',
  1913. tmpl => '%value%' . chr(0x00A0) . 'mph',
  1914. tmpl_long => {
  1915. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1916. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1917. },
  1918. tmpl_long_pl => {
  1919. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1920. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1921. },
  1922. },
  1923. kmph => {
  1924. ref_base => 15,
  1925. ref => 'm',
  1926. ref_t => 'hr',
  1927. scale_m => '1.0e3',
  1928. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_t%',
  1929. tmpl_long => {
  1930. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1931. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1932. },
  1933. tmpl_long_pl => {
  1934. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1935. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1936. },
  1937. },
  1938. mps => {
  1939. ref_base => 15,
  1940. ref => 'm',
  1941. ref_t => 'sec',
  1942. scale_m => '1.0e0',
  1943. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_t%',
  1944. tmpl_long => {
  1945. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_t%',
  1946. en => '%value%' . chr(0x00A0) . '%txt% per %txt_t%',
  1947. },
  1948. tmpl_long_pl => {
  1949. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_t%',
  1950. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_t%',
  1951. },
  1952. },
  1953. # weight
  1954. mol => {
  1955. ref_base => 5,
  1956. suffix => 'mol',
  1957. },
  1958. pg => {
  1959. ref => 'g',
  1960. scale_m => "1.0e-12",
  1961. },
  1962. ng => {
  1963. ref => 'g',
  1964. scale_m => "1.0e-9",
  1965. },
  1966. ug => {
  1967. ref => 'g',
  1968. scale_m => "1.0e-6",
  1969. },
  1970. mg => {
  1971. ref => 'g',
  1972. scale_m => "1.0e-3",
  1973. },
  1974. cg => {
  1975. ref => 'g',
  1976. scale_m => "1.0e-2",
  1977. },
  1978. dg => {
  1979. ref => 'g',
  1980. scale_m => "1.0e-1",
  1981. },
  1982. g => {
  1983. ref_base => 1,
  1984. scale_m => "1.0e0",
  1985. suffix => 'g',
  1986. txt => {
  1987. de => 'Gramm',
  1988. en => 'gram',
  1989. },
  1990. },
  1991. kg => {
  1992. ref => 'g',
  1993. scale_m => "1.0e3",
  1994. },
  1995. t => {
  1996. ref => 'g',
  1997. scale_m => "1.0e6",
  1998. suffix => 't',
  1999. txt => {
  2000. de => 'Tonne',
  2001. en => 'ton',
  2002. },
  2003. txt_pl => {
  2004. de => 'Tonnen',
  2005. en => 'tons',
  2006. },
  2007. },
  2008. lb => {
  2009. ref_base => 1,
  2010. suffix => 'lb',
  2011. txt => {
  2012. de => 'Pfund',
  2013. en => 'pound',
  2014. },
  2015. },
  2016. lbs => {
  2017. ref_base => 1,
  2018. suffix => 'lbs',
  2019. txt => {
  2020. de => 'Pfund',
  2021. en => 'pound',
  2022. },
  2023. },
  2024. # luminous intensity
  2025. cd => {
  2026. ref_base => 6,
  2027. suffix => 'cd',
  2028. txt => {
  2029. de => 'Candela',
  2030. en => 'Candela',
  2031. },
  2032. },
  2033. # illumination intensity
  2034. lx => {
  2035. ref_base => 16,
  2036. suffix => 'lx',
  2037. txt => {
  2038. de => 'Lux',
  2039. en => 'Lux',
  2040. },
  2041. },
  2042. # luminous flux
  2043. lm => {
  2044. ref_base => 17,
  2045. suffix => 'lm',
  2046. txt => {
  2047. de => 'Lumen',
  2048. en => 'Lumen',
  2049. },
  2050. },
  2051. uvi => {
  2052. ref_base => 900,
  2053. suffix => 'UVI',
  2054. txt => {
  2055. de => 'UV-Index',
  2056. en => 'UV-Index',
  2057. },
  2058. tmpl => '%suffix%' . chr(0x00A0) . '%value%',
  2059. tmpl_long => '%txt%' . chr(0x00A0) . '%value%',
  2060. format => '%i',
  2061. },
  2062. # surface area
  2063. cm2 => {
  2064. ref_base => 23,
  2065. ref => 'm',
  2066. scale_m => '1.0e-2',
  2067. scale_sq => 1,
  2068. },
  2069. m2 => {
  2070. ref_base => 23,
  2071. ref => 'm',
  2072. scale_m => '1.0e0',
  2073. scale_sq => 1,
  2074. },
  2075. # volume
  2076. cm3 => {
  2077. ref_base => 18,
  2078. ref => 'm',
  2079. scale_m => '1.0e-2',
  2080. scale_cu => 1,
  2081. },
  2082. m3 => {
  2083. ref_base => 18,
  2084. ref => 'm',
  2085. scale_m => '1.0e0',
  2086. scale_cu => 1,
  2087. },
  2088. ml => {
  2089. ref => 'l',
  2090. scale_m => '1.0e-3',
  2091. },
  2092. l => {
  2093. ref_base => 18,
  2094. suffix => 'l',
  2095. txt => {
  2096. de => 'Liter',
  2097. en => 'liter',
  2098. },
  2099. txt_pl => {
  2100. de => 'Liter',
  2101. en => 'liters',
  2102. },
  2103. },
  2104. hl => {
  2105. ref => 'l',
  2106. scale_m => '1.0e2',
  2107. },
  2108. b => {
  2109. ref_base => 19,
  2110. scale_m => '1.0e0',
  2111. suffix => 'B',
  2112. txt => {
  2113. de => 'Bel',
  2114. en => 'Bel',
  2115. },
  2116. },
  2117. db => {
  2118. ref => 'b',
  2119. scale_m => '1.0e-1',
  2120. },
  2121. ua => {
  2122. ref => 'a',
  2123. scale_m => '1.0e-6',
  2124. },
  2125. ma => {
  2126. ref => 'a',
  2127. scale_m => '1.0e-3',
  2128. },
  2129. a => {
  2130. ref_base => 3,
  2131. scale_m => '1.0e0',
  2132. suffix => 'A',
  2133. txt => {
  2134. de => 'Ampere',
  2135. en => 'Ampere',
  2136. },
  2137. },
  2138. uv => {
  2139. ref => 'v',
  2140. scale_m => '1.0e-6',
  2141. },
  2142. mv => {
  2143. ref => 'v',
  2144. scale_m => '1.0e-3',
  2145. },
  2146. v => {
  2147. ref_base => 13,
  2148. scale_m => '1.0e0',
  2149. suffix => 'V',
  2150. txt => {
  2151. de => 'Volt',
  2152. en => 'Volt',
  2153. },
  2154. },
  2155. uj => {
  2156. ref => 'j',
  2157. scale_m => '1.0e-6',
  2158. },
  2159. mj => {
  2160. ref => 'j',
  2161. scale_m => '1.0e-3',
  2162. },
  2163. j => {
  2164. ref_base => 7,
  2165. scale_m => '1.0e0',
  2166. suffix => 'J',
  2167. txt => {
  2168. de => 'Joule',
  2169. en => 'Joule',
  2170. },
  2171. },
  2172. uw => {
  2173. ref => 'w',
  2174. scale_m => '1.0e-6',
  2175. },
  2176. mw => {
  2177. ref => 'w',
  2178. scale_m => '1.0e-3',
  2179. },
  2180. w => {
  2181. ref_base => 9,
  2182. scale_m => '1.0e0',
  2183. suffix => 'W',
  2184. txt => {
  2185. de => 'Watt',
  2186. en => 'Watt',
  2187. },
  2188. },
  2189. va => {
  2190. ref => 'w',
  2191. },
  2192. kw => {
  2193. ref => 'w',
  2194. scale_m => '1.0e3',
  2195. },
  2196. megaw => {
  2197. ref => 'w',
  2198. scale_m => '1.0e6',
  2199. },
  2200. whr => {
  2201. base_ref => 7,
  2202. ref => 'w',
  2203. scale_m => '1.0e0',
  2204. ref_t => 'hr',
  2205. scale_t => 'h',
  2206. format => '%.0f',
  2207. tmpl => '%value%' . chr(0x00A0) . '%suffix%',
  2208. tmpl_long => {
  2209. de => '%value%' . chr(0x00A0) . '%txt%',
  2210. en => '%value%' . chr(0x00A0) . '%txt%',
  2211. },
  2212. tmpl_long_pl => {
  2213. de => '%value%' . chr(0x00A0) . '%txt_pl%',
  2214. en => '%value%' . chr(0x00A0) . '%txt_pl%',
  2215. },
  2216. rtype_description => {
  2217. de => 'Wattstunde',
  2218. en => 'Watt hour',
  2219. }
  2220. },
  2221. kwhr => {
  2222. base_ref => 7,
  2223. ref => 'w',
  2224. scale_m => '1.0e3',
  2225. ref_t => 'hr',
  2226. scale_t => 'h',
  2227. format => '%.0f',
  2228. tmpl => '%value%' . chr(0x00A0) . '%suffix%',
  2229. tmpl_long => {
  2230. de => '%value%' . chr(0x00A0) . '%txt%',
  2231. en => '%value%' . chr(0x00A0) . '%txt%',
  2232. },
  2233. tmpl_long_pl => {
  2234. de => '%value%' . chr(0x00A0) . '%txt_pl%',
  2235. en => '%value%' . chr(0x00A0) . '%txt_pl%',
  2236. },
  2237. rtype_description => {
  2238. de => 'Kilowattstunde',
  2239. en => 'Kilowatt hour',
  2240. }
  2241. },
  2242. mwhr => {
  2243. base_ref => 7,
  2244. ref => 'w',
  2245. scale_m => '1.0e6',
  2246. ref_t => 'hr',
  2247. scale_t => 'h',
  2248. format => '%.0f',
  2249. tmpl => '%value%' . chr(0x00A0) . '%suffix%%suffix_t%',
  2250. tmpl_long => {
  2251. de => '%value%' . chr(0x00A0) . '%txt%%txt_t%',
  2252. en => '%value%' . chr(0x00A0) . '%txt% %txt_t%',
  2253. },
  2254. tmpl_long_pl => {
  2255. de => '%value%' . chr(0x00A0) . '%txt%%txt_pl%',
  2256. en => '%value%' . chr(0x00A0) . '%txt% %txt_pl%',
  2257. },
  2258. rtype_description => {
  2259. de => 'Megawattstunde',
  2260. en => 'Megawatt hour',
  2261. }
  2262. },
  2263. gwhr => {
  2264. base_ref => 7,
  2265. ref => 'w',
  2266. scale_m => '1.0e9',
  2267. ref_t => 'hr',
  2268. scale_t => 'h',
  2269. format => '%.0f',
  2270. tmpl => '%value%' . chr(0x00A0) . '%suffix%%suffix_t%',
  2271. tmpl_long => {
  2272. de => '%value%' . chr(0x00A0) . '%txt%%txt_t%',
  2273. en => '%value%' . chr(0x00A0) . '%txt% %txt_t%',
  2274. },
  2275. tmpl_long_pl => {
  2276. de => '%value%' . chr(0x00A0) . '%txt%%txt_pl%',
  2277. en => '%value%' . chr(0x00A0) . '%txt% %txt_pl%',
  2278. },
  2279. rtype_description => {
  2280. de => 'Gigawattstunde',
  2281. en => 'Gigawatt hour',
  2282. }
  2283. },
  2284. uwpscm => {
  2285. ref => 'w',
  2286. scale_m => '1.0e-6',
  2287. ref_sq => 'm',
  2288. scale_sq => '1.0e-2',
  2289. format => '%.0f',
  2290. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2291. tmpl_long => {
  2292. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2293. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2294. },
  2295. tmpl_long_pl => {
  2296. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2297. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2298. },
  2299. },
  2300. uwpsm => {
  2301. ref => 'w',
  2302. scale_m => '1.0e-6',
  2303. ref_sq => 'm',
  2304. scale_sq => '1.0e0',
  2305. format => '%.0f',
  2306. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2307. tmpl_long => {
  2308. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2309. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2310. },
  2311. tmpl_long_pl => {
  2312. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2313. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2314. },
  2315. },
  2316. mwpscm => {
  2317. ref => 'w',
  2318. scale_m => '1.0e-3',
  2319. ref_sq => 'm',
  2320. scale_sq => '1.0e-2',
  2321. format => '%.0f',
  2322. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2323. tmpl_long => {
  2324. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2325. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2326. },
  2327. tmpl_long_pl => {
  2328. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2329. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2330. },
  2331. },
  2332. mwpsm => {
  2333. ref => 'w',
  2334. scale_m => '1.0e-3',
  2335. ref_sq => 'm',
  2336. scale_sq => '1.0e0',
  2337. format => '%.0f',
  2338. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2339. tmpl_long => {
  2340. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2341. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2342. },
  2343. tmpl_long_pl => {
  2344. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2345. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2346. },
  2347. },
  2348. wpscm => {
  2349. ref => 'w',
  2350. scale_m => '1.0e0',
  2351. ref_sq => 'm',
  2352. scale_sq => '1.0e-2',
  2353. format => '%.0f',
  2354. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2355. tmpl_long => {
  2356. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2357. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2358. },
  2359. tmpl_long_pl => {
  2360. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2361. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2362. },
  2363. },
  2364. wpsm => {
  2365. ref => 'w',
  2366. scale_m => '1.0e0',
  2367. ref_sq => 'm',
  2368. scale_sq => '1.0e0',
  2369. format => '%.0f',
  2370. tmpl => '%value%' . chr(0x00A0) . '%suffix%/%suffix_sq%',
  2371. tmpl_long => {
  2372. de => '%value%' . chr(0x00A0) . '%txt% pro %txt_sq%',
  2373. en => '%value%' . chr(0x00A0) . '%txt% per %txt_sq%',
  2374. },
  2375. tmpl_long_pl => {
  2376. de => '%value%' . chr(0x00A0) . '%txt_pl% pro %txt_sq%',
  2377. en => '%value%' . chr(0x00A0) . '%txt_pl% per %txt_sq%',
  2378. },
  2379. },
  2380. coul => {
  2381. ref_base => 20,
  2382. suffix => 'C',
  2383. txt => {
  2384. de => 'Coulomb',
  2385. en => 'Coulomb',
  2386. },
  2387. },
  2388. far => {
  2389. ref_base => 21,
  2390. suffix => 'F',
  2391. txt => {
  2392. de => 'Farad',
  2393. en => 'Farad',
  2394. },
  2395. },
  2396. ohm => {
  2397. ref_base => 22,
  2398. symbol => 'Ω',
  2399. suffix => 'Ohm',
  2400. txt => {
  2401. de => 'Ohm',
  2402. en => 'Ohm',
  2403. },
  2404. },
  2405. };
  2406. # helps the user to assign rtypes to existing readings of modules
  2407. # w/o built-in rtype support
  2408. #
  2409. # layer 1 = module name (exception: global is valid for all modules but
  2410. # with lower preference)
  2411. # layer 2 = reading name as used by that module
  2412. # layer 3 = template for this reading to be copied to device attribute readingsDesc.
  2413. # aliasname makes a reference to another reading name to avoid duplicates
  2414. # and take the opportunity to harmonise reading names here.
  2415. my $readingsDB = {
  2416. global => {
  2417. airpress => {
  2418. aliasname => 'pressure_hpa', # alias only
  2419. },
  2420. azimuth => {
  2421. rtype => 'gon',
  2422. },
  2423. compasspoint => {
  2424. rtype => 'compasspoint'
  2425. },
  2426. daylight => {
  2427. rtype => 'yesno',
  2428. },
  2429. dewpoint => {
  2430. aliasname => 'dewpoint_c', # alias only
  2431. },
  2432. dewpoint_c => {
  2433. rtype => 'c',
  2434. },
  2435. elevation => {
  2436. rtype => 'gon',
  2437. },
  2438. feelslike => {
  2439. aliasname => 'feelslike_c', # alias only
  2440. },
  2441. feelslike_c => {
  2442. rtype => 'c',
  2443. },
  2444. humidity => {
  2445. rtype => 'pct',
  2446. formula_symbol => 'H',
  2447. },
  2448. humidityabs => {
  2449. aliasname => 'humidityabs_c', # alias only
  2450. },
  2451. humidityabs_c => {
  2452. rtype => 'c',
  2453. formula_symbol => 'H',
  2454. },
  2455. humidityabs_f => {
  2456. rtype => 'f',
  2457. formula_symbol => 'H',
  2458. },
  2459. humidityabs_k => {
  2460. rtype => 'k',
  2461. formula_symbol => 'H',
  2462. },
  2463. horizon => {
  2464. rtype => 'gon',
  2465. },
  2466. indoordewpoint => {
  2467. aliasname => 'indoordewpoint_c', # alias only
  2468. },
  2469. indoordewpoint_c => {
  2470. rtype => 'c',
  2471. },
  2472. indoorhumidity => {
  2473. rtype => 'pct',
  2474. formula_symbol => 'H',
  2475. },
  2476. indoorhumidityabs => {
  2477. aliasname => 'indoorhumidityabs_c', # alias only
  2478. },
  2479. indoorhumidityabs_c => {
  2480. rtype => 'c',
  2481. },
  2482. indoortemperature => {
  2483. aliasname => 'indoortemperature_c', # alias only
  2484. },
  2485. indoortemperature_c => {
  2486. rtype => 'c',
  2487. },
  2488. israining => {
  2489. rtype => 'yesno',
  2490. },
  2491. level => {
  2492. rtype => 'pct',
  2493. },
  2494. luminosity => {
  2495. rtype => 'lx',
  2496. },
  2497. pct => {
  2498. rtype => 'pct',
  2499. },
  2500. pressure => {
  2501. aliasname => 'pressure_hpa', # alias only
  2502. },
  2503. pressure_hpa => {
  2504. rtype => 'hpamb',
  2505. },
  2506. pressure_in => {
  2507. rtype => 'inhg',
  2508. },
  2509. pressure_mm => {
  2510. rtype => 'mmhg',
  2511. },
  2512. pressureabs => {
  2513. aliasname => 'pressureabs_hpamb', # alias only
  2514. },
  2515. pressureabs_hpamb => {
  2516. rtype => 'hpamb',
  2517. },
  2518. pressureabs_in => {
  2519. rtype => 'inhg',
  2520. },
  2521. pressureabs_mm => {
  2522. rtype => 'mmhg',
  2523. },
  2524. pressureabs_psi => {
  2525. aliasname => 'pressureabs_psia',
  2526. },
  2527. pressureabs_psia => {
  2528. rtype => 'psia',
  2529. },
  2530. rain => {
  2531. aliasname => 'rain_mm', # alias only
  2532. },
  2533. rain_mm => {
  2534. rtype => 'mm',
  2535. },
  2536. rain_day => {
  2537. aliasname => 'rain_day_mm', # alias only
  2538. },
  2539. rain_day_mm => {
  2540. rtype => 'mm',
  2541. },
  2542. rain_night => {
  2543. aliasname => 'rain_night_mm', # alias only
  2544. },
  2545. rain_night_mm => {
  2546. rtype => 'mm',
  2547. },
  2548. rain_week => {
  2549. aliasname => 'rain_week_mm', # alias only
  2550. },
  2551. rain_week_mm => {
  2552. rtype => 'mm',
  2553. },
  2554. rain_month => {
  2555. aliasname => 'rain_month_mm', # alias only
  2556. },
  2557. rain_month_mm => {
  2558. rtype => 'mm',
  2559. },
  2560. rain_year => {
  2561. aliasname => 'rain_year_mm', # alias only
  2562. },
  2563. rain_year_mm => {
  2564. rtype => 'mm',
  2565. },
  2566. snow => {
  2567. aliasname => 'snow_cm', # alias only
  2568. },
  2569. snow_cm => {
  2570. rtype => 'cm',
  2571. },
  2572. snow_day => {
  2573. aliasname => 'snow_day_cm', # alias only
  2574. },
  2575. snow_day_cm => {
  2576. rtype => 'cm',
  2577. },
  2578. snow_night => {
  2579. aliasname => 'snow_night_cm', # alias only
  2580. },
  2581. snow_night_cm => {
  2582. rtype => 'cm',
  2583. },
  2584. sunshine => {
  2585. aliasname => 'solarradiation', # alias only
  2586. },
  2587. solarradiation => {
  2588. rtype => 'wpsm',
  2589. },
  2590. temp => {
  2591. aliasname => 'temperature_c', # alias only
  2592. },
  2593. temp_c => {
  2594. aliasname => 'temperature_c', # alias only
  2595. },
  2596. temperature => {
  2597. aliasname => 'temperature_c', # alias only
  2598. },
  2599. temperature_c => {
  2600. rtype => 'c',
  2601. },
  2602. uv => {
  2603. aliasname => 'uvi', # alias only
  2604. },
  2605. uvi => {
  2606. rtype => 'uvi',
  2607. },
  2608. uvr => {
  2609. rtype => 'uwpscm',
  2610. },
  2611. valvedesired => {
  2612. aliasname => 'valve', # alias only
  2613. },
  2614. valvepos => {
  2615. aliasname => 'valve', # alias only
  2616. },
  2617. valveposition => {
  2618. aliasname => 'valve', # alias only
  2619. },
  2620. valvepostc => {
  2621. aliasname => 'valve', # alias only
  2622. },
  2623. valve => {
  2624. rtype => 'pct',
  2625. },
  2626. visibility => {
  2627. aliasname => 'visibility_km', # alias only
  2628. },
  2629. visibility_km => {
  2630. rtype => 'km',
  2631. },
  2632. wind_chill => {
  2633. aliasname => 'wind_chill_c', # alias only
  2634. },
  2635. wind_chill_c => {
  2636. rtype => 'c',
  2637. },
  2638. wind_compasspoint => {
  2639. rtype => 'compasspoint'
  2640. },
  2641. windspeeddirection => {
  2642. aliasname => 'wind_compasspoint', # alias only
  2643. },
  2644. winddirectiontext => {
  2645. aliasname => 'wind_compasspoint', # alias only
  2646. },
  2647. wind_direction => {
  2648. aliasname => 'wind_compasspoint', # alias only
  2649. },
  2650. wind_dir => {
  2651. aliasname => 'wind_compasspoint', # alias only
  2652. },
  2653. winddir => {
  2654. aliasname => 'wind_compasspoint', # alias only
  2655. },
  2656. winddirection => {
  2657. aliasname => 'wind_compasspoint', # alias only
  2658. },
  2659. wind_gust => {
  2660. aliasname => 'wind_gust_kmh', # alias only
  2661. },
  2662. wind_gust_kmh => {
  2663. rtype => 'kmh',
  2664. },
  2665. wind_speed => {
  2666. aliasname => 'wind_speed_kmh', # alias only
  2667. },
  2668. wind_speed_kmh => {
  2669. rtype => 'kmh',
  2670. },
  2671. }
  2672. };
  2673. # Find rtype through reading name
  2674. sub rname2rtype ($$@) {
  2675. my ( $name, $reading, $lang ) = @_;
  2676. my $details;
  2677. my $r = $reading;
  2678. my $l = ( $lang ? lc($lang) : "en" );
  2679. my $rt;
  2680. my $guess;
  2681. my %return;
  2682. # remove some prefix or other values to
  2683. # flatten reading name
  2684. $r =~ s/^fc\d+_//i;
  2685. $r =~ s/_(min|max|avg|sum|cum|min\d+m|max\d+m|avg\d+m|sum\d+m|cum\d+m)_/_/i;
  2686. $r =~ s/^(min|max|avg|sum|cum|min\d+m|max\d+m|avg\d+m|sum\d+m|cum\d+m)_//i;
  2687. $r =~ s/_(min|max|avg|sum|cum|min\d+m|max\d+m|avg\d+m|sum\d+m|cum\d+m)$//i;
  2688. $r =~ s/.*[-_](temp)$/$1/i;
  2689. # rename capital letter containing readings
  2690. if ( !$readingsDB->{global}{ lc($r) } ) {
  2691. $r =~ s/^([A-Z])(.*)/\l$1$2/;
  2692. $r =~ s/([A-Z][a-z0-9]+)[\/\|\-_]?/_$1/g;
  2693. }
  2694. $r = lc($r);
  2695. # known aliasname reading names
  2696. if ( $readingsDB->{global}{$r}{aliasname} ) {
  2697. my $dr = $readingsDB->{global}{$r}{aliasname};
  2698. $return{aliasname} = $dr;
  2699. $return{shortname} = $readingsDB->{global}{$dr}{shortname};
  2700. $rt = (
  2701. $readingsDB->{global}{$dr}{rtype}
  2702. ? $readingsDB->{global}{$dr}{rtype}
  2703. : "-"
  2704. );
  2705. }
  2706. # known standard reading names
  2707. elsif ( $readingsDB->{global}{$r}{shortname} ) {
  2708. $return{aliasname} = $reading;
  2709. $return{shortname} = $readingsDB->{global}{$r}{shortname};
  2710. $rt = (
  2711. $readingsDB->{global}{$r}{rtype}
  2712. ? $readingsDB->{global}{$r}{rtype}
  2713. : "-"
  2714. );
  2715. }
  2716. # just guessing the rtype from reading name format
  2717. elsif ( $r =~ /^.*_([A-Za-z0-9]+)$/i ) {
  2718. $return{guess} = 1;
  2719. $rt = $1;
  2720. }
  2721. return $rt if ( $rt && $rtypes->{$rt} );
  2722. }
  2723. ######################################
  2724. # package main
  2725. #
  2726. package main;
  2727. use utf8;
  2728. # Do the magic to generate value + unit combined text strings
  2729. # for specified language
  2730. sub replaceTemplate ($$$$;$) {
  2731. my ( $device, $reading, $odesc, $lang, $value ) = @_;
  2732. my $l = ( $lang ? lc($lang) : "en" );
  2733. my $txt;
  2734. my $txt_long;
  2735. my $r = $defs{$device}{READINGS} if ($device);
  2736. return
  2737. if ( !$odesc || ref($odesc) ne "HASH" );
  2738. $value = ${$odesc}{value}{$lang}
  2739. if (!defined($value)
  2740. && defined( $odesc->{value} )
  2741. && defined( $odesc->{value}{$lang} ) );
  2742. return $value
  2743. if ( !defined($value) || $value eq "" || !defined( $odesc->{rtype} ) );
  2744. # clone
  2745. my $desc;
  2746. foreach ( keys %{$odesc} ) {
  2747. next
  2748. if ( $_ eq "scope"
  2749. || $_ eq "format"
  2750. || $_ eq "factor"
  2751. || $_ eq "scale" );
  2752. $desc->{$_} = $odesc->{$_};
  2753. }
  2754. ##########
  2755. # language support
  2756. #
  2757. # keep only defined language if set
  2758. foreach ( keys %{$desc} ) {
  2759. next
  2760. if (!defined( $desc->{$_} )
  2761. || ref( $desc->{$_} ) ne "HASH" );
  2762. # find any direct format
  2763. if ( defined( $desc->{$_}{$l} ) ) {
  2764. my $v;
  2765. $v = $desc->{$_}{$l};
  2766. delete $desc->{$_};
  2767. $desc->{$_} = $v if ( defined($v) );
  2768. Unit_Log3( $device, $reading, $odesc, 9,
  2769. "replaceTemplate $device $reading: RAttr $_: value replaced by language specific version ($l)"
  2770. );
  2771. }
  2772. # try base language format instead
  2773. # and extract xx from xx_yz
  2774. elsif ( $l =~ /^([a-z]+)(_([a-z]+))?$/i
  2775. && defined( $desc->{$_}{$1} ) )
  2776. {
  2777. my $v;
  2778. $v = $desc->{$_}{$1};
  2779. delete $desc->{$_};
  2780. $desc->{$_} = $v if ( defined($v) );
  2781. Unit_Log3( $device, $reading, $odesc, 9,
  2782. "replaceTemplate $device $reading: RAttr $_: value replaced by base language specific version ($1)"
  2783. );
  2784. }
  2785. }
  2786. # if original value was a text string and we got value_num out of it,
  2787. # now try to find the right standardized text value from the ARRAY
  2788. my $value_num =
  2789. ref( $desc->{value_num} ) eq "ARRAY"
  2790. ? $desc->{value_num}[0]
  2791. : ( defined( $desc->{value_num} ) ? $desc->{value_num} : undef );
  2792. if ( defined($value_num) ) {
  2793. foreach ( 'suffix', 'symbol', 'txt', 'txt_pl', 'txt_long',
  2794. 'txt_long_pl' )
  2795. {
  2796. if ( ref( $desc->{$_} ) eq "ARRAY"
  2797. && $desc->{$_}[$value_num] )
  2798. {
  2799. my $v = $desc->{$_}[$value_num];
  2800. delete $desc->{$_};
  2801. $desc->{$_} = $v;
  2802. Unit_Log3( $device, $reading, $odesc, 9,
  2803. "replaceTemplate $device $reading: RAttr $_: value replaced based on ARRAY found using value from 'value_num'"
  2804. );
  2805. }
  2806. }
  2807. }
  2808. ##########
  2809. # template support
  2810. #
  2811. # add metric name to suffix and txt
  2812. if ( $desc->{suffix}
  2813. && $desc->{scale_txt_m} )
  2814. {
  2815. Unit_Log3( $device, $reading, $odesc, 9,
  2816. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_m'"
  2817. );
  2818. $desc->{suffix} = $desc->{scale_txt_m} . $desc->{suffix};
  2819. }
  2820. if ( $desc->{txt}
  2821. && $desc->{scale_txt_long_m} )
  2822. {
  2823. Unit_Log3( $device, $reading, $odesc, 9,
  2824. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_m'"
  2825. );
  2826. $desc->{txt} = $desc->{scale_txt_long_m} . lc( $desc->{txt} );
  2827. }
  2828. # add time information to suffix and txt
  2829. if ( $desc->{suffix}
  2830. && $desc->{scale_txt_t} )
  2831. {
  2832. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_t};
  2833. Unit_Log3( $device, $reading, $odesc, 9,
  2834. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_t'"
  2835. );
  2836. }
  2837. if ( $desc->{txt}
  2838. && $desc->{scale_txt_long_pl_t} )
  2839. {
  2840. $desc->{txt_pl} = $desc->{txt} . lc( $desc->{scale_txt_long_pl_t} );
  2841. Unit_Log3( $device, $reading, $odesc, 9,
  2842. "replaceTemplate $device $reading: RAttr txt_pl value rewritten by adding value from 'scale_txt_long_pl_t'"
  2843. );
  2844. }
  2845. if ( $desc->{txt}
  2846. && $desc->{scale_txt_long_t} )
  2847. {
  2848. $desc->{txt} = $desc->{txt} . lc( $desc->{scale_txt_long_t} );
  2849. Unit_Log3( $device, $reading, $odesc, 9,
  2850. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_t'"
  2851. );
  2852. }
  2853. # add square information to suffix and txt
  2854. # if no separate suffix_sq and txt_sq was found
  2855. if ( !$desc->{suffix_sq}
  2856. && $desc->{scale_txt_sq} )
  2857. {
  2858. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_sq};
  2859. Unit_Log3( $device, $reading, $odesc, 9,
  2860. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_sq'"
  2861. );
  2862. }
  2863. if ( !$desc->{txt_sq}
  2864. && $desc->{scale_txt_long_sq} )
  2865. {
  2866. $desc->{txt} = $desc->{scale_txt_long_sq} . lc( $desc->{txt} );
  2867. Unit_Log3( $device, $reading, $odesc, 9,
  2868. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_sq'"
  2869. );
  2870. }
  2871. # add cubic information to suffix and txt
  2872. # if no separate suffix_cu and txt_cu was found
  2873. if ( !$desc->{suffix_cu}
  2874. && $desc->{scale_txt_cu} )
  2875. {
  2876. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_cu};
  2877. Unit_Log3( $device, $reading, $odesc, 9,
  2878. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_cu'"
  2879. );
  2880. }
  2881. if ( !$desc->{txt_cu}
  2882. && $desc->{scale_txt_long_cu} )
  2883. {
  2884. $desc->{txt} = $desc->{scale_txt_long_cu} . lc( $desc->{txt} );
  2885. Unit_Log3( $device, $reading, $odesc, 9,
  2886. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_cu'"
  2887. );
  2888. }
  2889. # add time information to suffix and txt
  2890. # if no separate suffix_t and txt_t was found
  2891. if ( !$desc->{suffix_t}
  2892. && $desc->{scale_txt_t} )
  2893. {
  2894. $desc->{suffix} = $desc->{suffix} . $desc->{scale_txt_t};
  2895. Unit_Log3( $device, $reading, $odesc, 9,
  2896. "replaceTemplate $device $reading: RAttr suffix value rewritten by adding value from 'scale_txt_t'"
  2897. );
  2898. }
  2899. if ( !$desc->{txt_t}
  2900. && $desc->{scale_txt_long_pl_t} )
  2901. {
  2902. $desc->{txt_pl} = $desc->{txt} . lc( $desc->{scale_txt_long_pl_t} );
  2903. Unit_Log3( $device, $reading, $odesc, 9,
  2904. "replaceTemplate $device $reading: RAttr txt_pl value rewritten by adding value from 'scale_txt_long_pl_t'"
  2905. );
  2906. }
  2907. if ( !$desc->{txt_t}
  2908. && $desc->{scale_txt_long_t} )
  2909. {
  2910. $desc->{txt} = $desc->{txt} . lc( $desc->{scale_txt_long_t} );
  2911. Unit_Log3( $device, $reading, $odesc, 9,
  2912. "replaceTemplate $device $reading: RAttr txt value rewritten by adding value from 'scale_txt_long_t'"
  2913. );
  2914. }
  2915. # add metric name to suffix_sq
  2916. if ( $desc->{suffix_sq}
  2917. && $desc->{scale_txt_m_sq}
  2918. && $desc->{suffix_sq} !~ /$desc->{scale_txt_m_sq}/ )
  2919. {
  2920. $desc->{suffix_sq} = $desc->{scale_txt_m_sq} . $desc->{suffix_sq};
  2921. Unit_Log3( $device, $reading, $odesc, 9,
  2922. "replaceTemplate $device $reading: RAttr suffix_sq value rewritten by adding value from 'scale_txt_m_sq'"
  2923. );
  2924. }
  2925. if ( $desc->{txt_sq}
  2926. && $desc->{scale_txt_long_m_sq} )
  2927. {
  2928. $desc->{txt_sq} = $desc->{scale_txt_long_m_sq} . lc( $desc->{txt_sq} );
  2929. Unit_Log3( $device, $reading, $odesc, 9,
  2930. "replaceTemplate $device $reading: RAttr txt_sq value rewritten by adding value from 'scale_txt_long_m_sq'"
  2931. );
  2932. }
  2933. # add square information to suffix_sq
  2934. if ( $desc->{suffix_sq}
  2935. && $desc->{scale_txt_sq} )
  2936. {
  2937. $desc->{suffix_sq} = $desc->{suffix_sq} . $desc->{scale_txt_sq};
  2938. Unit_Log3( $device, $reading, $odesc, 9,
  2939. "replaceTemplate $device $reading: RAttr suffix_sq value rewritten by adding value from 'scale_txt_sq'"
  2940. );
  2941. }
  2942. if ( $desc->{txt_sq}
  2943. && $desc->{scale_txt_long_sq} )
  2944. {
  2945. $desc->{txt_sq} = $desc->{scale_txt_long_sq} . lc( $desc->{txt_sq} );
  2946. Unit_Log3( $device, $reading, $odesc, 9,
  2947. "replaceTemplate $device $reading: RAttr txt_sq value rewritten by adding value from 'scale_txt_long_sq'"
  2948. );
  2949. }
  2950. # add time information to suffix_sq
  2951. if ( $desc->{suffix_sq}
  2952. && $desc->{scale_txt_t} )
  2953. {
  2954. $desc->{suffix_sq} = $desc->{suffix_sq} . $desc->{scale_txt_t};
  2955. Unit_Log3( $device, $reading, $odesc, 9,
  2956. "replaceTemplate $device $reading: RAttr suffix_sq value rewritten by adding value from 'scale_txt_t'"
  2957. );
  2958. }
  2959. if ( $desc->{txt_sq}
  2960. && $desc->{scale_txt_long_pl_t} )
  2961. {
  2962. $desc->{txt_pl_sq} =
  2963. $desc->{txt_sq} . lc( $desc->{scale_txt_long_pl_t} );
  2964. Unit_Log3( $device, $reading, $odesc, 9,
  2965. "replaceTemplate $device $reading: RAttr txt_pl_sq value rewritten by adding value from 'scale_txt_long_pl_t'"
  2966. );
  2967. }
  2968. if ( $desc->{txt_sq}
  2969. && $desc->{scale_txt_long_t} )
  2970. {
  2971. $desc->{txt_sq} = $desc->{txt_sq} . lc( $desc->{scale_txt_long_t} );
  2972. Unit_Log3( $device, $reading, $odesc, 9,
  2973. "replaceTemplate $device $reading: RAttr txt_sq value rewritten by adding value from 'scale_txt_long_t'"
  2974. );
  2975. }
  2976. # add metric name to suffix_cu
  2977. if ( $desc->{suffix_cu}
  2978. && $desc->{scale_txt_m_cu} )
  2979. {
  2980. $desc->{suffix_cu} = $desc->{scale_txt_m_cu} . $desc->{suffix_cu};
  2981. Unit_Log3( $device, $reading, $odesc, 9,
  2982. "replaceTemplate $device $reading: RAttr suffix_cu value rewritten by adding value from 'scale_txt_m_cu'"
  2983. );
  2984. }
  2985. if ( $desc->{txt_cu}
  2986. && $desc->{scale_txt_long_m_cu} )
  2987. {
  2988. $desc->{txt_cu} = $desc->{scale_txt_long_m_cu} . lc( $desc->{txt_cu} );
  2989. Unit_Log3( $device, $reading, $odesc, 9,
  2990. "replaceTemplate $device $reading: RAttr txt_cu value rewritten by adding value from 'scale_txt_long_m_cu'"
  2991. );
  2992. }
  2993. # add cubic information to suffix_cu
  2994. if ( $desc->{suffix_cu}
  2995. && $desc->{scale_txt_cu} )
  2996. {
  2997. $desc->{suffix_cu} = $desc->{suffix_cu} . $desc->{scale_txt_cu};
  2998. Unit_Log3( $device, $reading, $odesc, 9,
  2999. "replaceTemplate $device $reading: RAttr suffix_cu value rewritten by adding value from 'scale_txt_cu'"
  3000. );
  3001. }
  3002. if ( $desc->{txt_cu}
  3003. && $desc->{scale_txt_long_cu} )
  3004. {
  3005. $desc->{txt_cu} = $desc->{scale_txt_long_cu} . lc( $desc->{txt_cu} );
  3006. Unit_Log3( $device, $reading, $odesc, 9,
  3007. "replaceTemplate $device $reading: RAttr txt_cu value rewritten by adding value from 'scale_txt_long_cu'"
  3008. );
  3009. }
  3010. # add time information to suffix_cu
  3011. if ( $desc->{suffix_cu}
  3012. && $desc->{scale_txt_t} )
  3013. {
  3014. $desc->{suffix_cu} = $desc->{suffix_cu} . $desc->{scale_txt_t};
  3015. Unit_Log3( $device, $reading, $odesc, 9,
  3016. "replaceTemplate $device $reading: RAttr suffix_cu value rewritten by adding value from 'scale_txt_t'"
  3017. );
  3018. }
  3019. if ( $desc->{txt_cu}
  3020. && $desc->{scale_txt_long_pl_t} )
  3021. {
  3022. $desc->{txt_pl_cu} =
  3023. $desc->{txt_cu} . lc( $desc->{scale_txt_long_pl_t} );
  3024. Unit_Log3( $device, $reading, $odesc, 9,
  3025. "replaceTemplate $device $reading: RAttr txt_pl_cu value rewritten by adding value from 'scale_txt_long_pl_t'"
  3026. );
  3027. }
  3028. if ( $desc->{txt_cu}
  3029. && $desc->{scale_txt_long_t} )
  3030. {
  3031. $desc->{txt_cu} = $desc->{txt_cu} . lc( $desc->{scale_txt_long_t} );
  3032. Unit_Log3( $device, $reading, $odesc, 9,
  3033. "replaceTemplate $device $reading: RAttr txt_cu value rewritten by adding value from 'scale_txt_long_t'"
  3034. );
  3035. }
  3036. ###############################
  3037. # generate short text string
  3038. #
  3039. # find text template
  3040. $txt = '%value%' . chr(0x00A0) . '%suffix%' if ( !$desc->{symbol} );
  3041. $txt = '%value%' . chr(0x202F) . '%symbol%' if ( $desc->{symbol} );
  3042. $txt = '%value%' . chr(0x202F) . '%symbol%' if ( $desc->{symbol} );
  3043. $txt = $desc->{tmpl} if ( $desc->{tmpl} );
  3044. $txt = '%txt%'
  3045. if ( defined( $desc->{txt} ) && !looks_like_number($value) );
  3046. Unit_Log3( $device, $reading, $odesc, 9,
  3047. "replaceTemplate $device $reading: detected txt template: $txt" );
  3048. # Replace all %text% placeholders with text value found
  3049. # in old style READINGS.
  3050. # Normally only TIME & VAL would be available but some modules might have
  3051. # extended this and we want people to be able to make use of it.
  3052. if ( $r && $reading && $r->{$reading} ) {
  3053. foreach my $k ( keys %{ $r->{$reading} } ) {
  3054. next if ( ref( $r->{$reading}{$k} ) );
  3055. $txt =~ s/%$k%/$r->{$reading}{$k}/g;
  3056. Unit_Log3( $device, $reading, $odesc, 10,
  3057. "replaceTemplate $device $reading: RAttr txt: replacing '%$k%'"
  3058. );
  3059. }
  3060. }
  3061. # Replace all %text% placeholders with text value found
  3062. # in matching reading desc hash keys
  3063. foreach my $k ( keys %{$desc} ) {
  3064. my $vdm = $desc->{$k};
  3065. next if ( ref($vdm) );
  3066. $vdm = UConv::decimal_mark( $vdm, $desc->{decimal_mark} )
  3067. if ( defined( $desc->{decimal_mark} ) );
  3068. $txt =~ s/%$k%/$vdm/g;
  3069. Unit_Log3( $device, $reading, $odesc, 10,
  3070. "replaceTemplate $device $reading: RAttr txt: replacing '%$k%'" );
  3071. }
  3072. return ($txt) unless (wantarray);
  3073. ###############################
  3074. # generate long text string in plural
  3075. #
  3076. # find text template
  3077. if ( looks_like_number($value)
  3078. && ( $value eq "0" || $value > 1 || $value < -1 )
  3079. && $desc->{txt_long_pl} )
  3080. {
  3081. $txt_long = '%value%' . chr(0x00A0) . '%txt_long_pl%';
  3082. $txt_long = $desc->{tmpl_long_pl}
  3083. if ( $desc->{tmpl_long_pl} );
  3084. }
  3085. elsif (looks_like_number($value)
  3086. && ( $value eq "0" || $value > 1 || $value < -1 )
  3087. && $desc->{txt_pl} )
  3088. {
  3089. $txt_long = '%value%' . chr(0x00A0) . '%txt_pl%';
  3090. $txt_long = $desc->{tmpl_long_pl}
  3091. if ( $desc->{tmpl_long_pl} );
  3092. }
  3093. ###############################
  3094. # generate long text string in singular
  3095. #
  3096. # find text template
  3097. elsif ( $desc->{txt_long} ) {
  3098. $txt_long = '%value%' . chr(0x00A0) . '%txt_long%';
  3099. $txt_long = $desc->{tmpl_long}
  3100. if ( $desc->{tmpl_long} );
  3101. }
  3102. elsif ( $desc->{txt} ) {
  3103. $txt_long = '%value%' . chr(0x00A0) . '%txt%';
  3104. $txt_long = $desc->{tmpl_long}
  3105. if ( $desc->{tmpl_long} );
  3106. }
  3107. # for either plural or singular long text string
  3108. if ($txt_long) {
  3109. Unit_Log3( $device, $reading, $odesc, 9,
  3110. "replaceTemplate $device $reading: detected txt_long template: $txt_long"
  3111. );
  3112. # Replace all %text% placeholders with text value found
  3113. # in old style READINGS.
  3114. # Normally only TIME & VAL would be available but some modules might have
  3115. # extended this and we want people to be able to make use of it.
  3116. if ( $r && $reading && $r->{$reading} ) {
  3117. foreach my $k ( keys %{ $r->{$reading} } ) {
  3118. next if ( ref( $r->{$reading}{$k} ) );
  3119. $txt_long =~ s/%$k%/$r->{$reading}{$k}/g;
  3120. Unit_Log3( $device, $reading, $odesc, 10,
  3121. "replaceTemplate $device $reading: RAttr txt_long: replacing '%$k%'"
  3122. );
  3123. }
  3124. }
  3125. # Replace all %text% placeholders with text value found
  3126. # in matching reading desc hash keys
  3127. foreach my $k ( keys %{$desc} ) {
  3128. my $vdm = $desc->{$k};
  3129. next if ( ref($vdm) );
  3130. $vdm = UConv::decimal_mark( $vdm, $desc->{decimal_mark} )
  3131. if ( defined( $desc->{decimal_mark} ) );
  3132. $txt_long =~ s/%$k%/$vdm/g;
  3133. Unit_Log3( $device, $reading, $odesc, 10,
  3134. "replaceTemplate $device $reading: RAttr txt_long: replacing '%$k%'"
  3135. );
  3136. }
  3137. }
  3138. my $unit =
  3139. $desc->{symbol} ? $desc->{symbol}
  3140. : (
  3141. $desc->{suffix} ? $desc->{suffix}
  3142. : ( $desc->{txt} ? $desc->{txt} : undef )
  3143. );
  3144. $txt = Encode::encode_utf8($txt) if ( defined($txt) );
  3145. $txt_long = Encode::encode_utf8($txt_long) if ( defined($txt_long) );
  3146. $unit = Encode::encode_utf8($unit) if ( defined($unit) );
  3147. return ( $txt, $txt_long, $unit );
  3148. }
  3149. sub Unit_verifyValueNumber($$) {
  3150. my ( $value, $scope ) = @_;
  3151. my $log;
  3152. my $value_num;
  3153. my $verified = 0;
  3154. foreach ( keys %{$scope} ) {
  3155. next
  3156. if ( $_ !~ /^(regex|eq|minValue|maxValue|lt|gt|le|ge)$/ );
  3157. $verified = 1;
  3158. if ( !looks_like_number($value) ) {
  3159. if ( $_ eq 'regex' ) {
  3160. $log .= " '$value' does not match regex $scope->{$_}."
  3161. if ( $value !~ /$scope->{$_}/ );
  3162. $value_num = $scope->{value_num}
  3163. if ( defined( $scope->{value_num} ) );
  3164. }
  3165. elsif ( $_ eq 'eq' ) {
  3166. if ( $value ne $scope->{eq} ) {
  3167. $log .= " $value is not equal to $scope->{eq}.";
  3168. $value = $scope->{eq}
  3169. if ( !$scope->{keep} || $scope->{strict} );
  3170. }
  3171. $value_num = $scope->{value_num}
  3172. if ( defined( $scope->{value_num} ) );
  3173. }
  3174. elsif ( !$scope->{regex} && !defined( $scope->{eq} ) ) {
  3175. $log .= " '$value' is not a number."
  3176. if ( !$scope->{empty} && !$scope->{empty_replace} );
  3177. $value = "0"
  3178. if ( !$scope->{keep} && !$scope->{empty_replace} );
  3179. $value = $scope->{empty_replace}
  3180. if ( defined( $scope->{empty_replace} ) );
  3181. last;
  3182. }
  3183. }
  3184. elsif ( $_ eq 'minValue' ) {
  3185. if ( $value < $scope->{$_} ) {
  3186. $log .= " $value is lesser than $scope->{$_}.";
  3187. $value = $scope->{$_}
  3188. if ( !$scope->{keep} || $scope->{strict} );
  3189. }
  3190. }
  3191. elsif ( $_ eq 'maxValue' ) {
  3192. if ( $value > $scope->{$_} ) {
  3193. $log .= " $value is greater than $scope->{$_}.";
  3194. $value = $scope->{$_}
  3195. if ( !$scope->{keep} || $scope->{strict} );
  3196. }
  3197. }
  3198. elsif ( $_ eq 'lt' ) {
  3199. if ( $value >= $scope->{$_} ) {
  3200. $log .= " $value is not $_ $scope->{$_}.";
  3201. $value = $scope->{$_}
  3202. if ( !$scope->{keep} || $scope->{strict} );
  3203. }
  3204. }
  3205. elsif ( $_ eq 'le' ) {
  3206. if ( $value > $scope->{$_} ) {
  3207. $log .= " $value is not $_ $scope->{$_}.";
  3208. $value = $scope->{$_}
  3209. if ( !$scope->{keep} || $scope->{strict} );
  3210. }
  3211. }
  3212. elsif ( $_ eq 'gt' ) {
  3213. if ( $value <= $scope->{$_} ) {
  3214. $log .= " $value is not $_ $scope->{$_}.";
  3215. $value = $scope->{$_}
  3216. if ( !$scope->{keep} || $scope->{strict} );
  3217. }
  3218. }
  3219. elsif ( $_ eq 'ge' ) {
  3220. if ( $value < $scope->{$_} ) {
  3221. $log .= " $value is not $_ $scope->{$_}.";
  3222. $value = $scope->{$_}
  3223. if ( !$scope->{keep} || $scope->{strict} );
  3224. }
  3225. }
  3226. elsif ( $_ eq 'eq' ) {
  3227. if ( $value ne $scope->{$_} ) {
  3228. $log .= " $value is not equal to $scope->{$_}.";
  3229. $value = $scope->{$_}
  3230. if ( !$scope->{keep} || $scope->{strict} );
  3231. }
  3232. else {
  3233. $log = undef;
  3234. last;
  3235. }
  3236. }
  3237. }
  3238. return ( $verified, $value, $value_num, $log );
  3239. }
  3240. # format a number according to desc and optional format.
  3241. sub formatValue($$$;$$$$) {
  3242. my ( $device, $reading, $value, $desc, $format, $scope, $lang ) = @_;
  3243. $lang = "en" if ( !$lang );
  3244. my $lang_base = $lang;
  3245. $lang_base =~ s/^(\w+)(_.*)$/$1/;
  3246. my $value_num;
  3247. if ( !defined($value)
  3248. || ref($value)
  3249. || AttrVal( $device, "showUnits", 1 ) eq "0" )
  3250. {
  3251. Unit_Log3( $device, $reading, $desc, 10,
  3252. "formatValue $device $reading: explicit return of original value" );
  3253. return $value;
  3254. }
  3255. $desc = readingsDesc( $device, $reading )
  3256. if ( !$desc || !ref($desc) );
  3257. if ( !$format && ( !$desc || ref($desc) ne 'HASH' )
  3258. || keys %{$desc} < 1 )
  3259. {
  3260. Unit_Log3( $device, $reading, $desc, 10,
  3261. "formatValue $device $reading: "
  3262. . "no readings description found, returning original value" );
  3263. return $value;
  3264. }
  3265. # source value language
  3266. my $slang = "en";
  3267. $slang = $desc->{lang} if ( $desc && $desc->{lang} );
  3268. my $slang_base = $slang;
  3269. $slang_base =~ s/^(\w+)(_.*)$/$1/;
  3270. # factor
  3271. if ( $desc && $desc->{factor} ) {
  3272. if ( ref( $desc->{factor} ) || !looks_like_number( $desc->{factor} ) ) {
  3273. Unit_Log3( $device, $reading, $desc, 5,
  3274. "formatValue $device $reading: ERROR: "
  3275. . "RAttr factor is not numeric" );
  3276. }
  3277. elsif ( looks_like_number($value) ) {
  3278. Unit_Log3( $device, $reading, $desc, 9,
  3279. "formatValue $device $reading: "
  3280. . "multiply original numeric value with factor "
  3281. . $desc->{factor} );
  3282. $value *= $desc->{factor};
  3283. }
  3284. else {
  3285. Unit_Log3( $device, $reading, $desc, 8,
  3286. "formatValue $device $reading: factor "
  3287. . "multiplication failed - '$value' is not a number" );
  3288. }
  3289. }
  3290. $format = $desc->{format}
  3291. if ( !$format && $desc && $desc->{format} );
  3292. $scope = $desc->{scope} if ( !$scope && $desc && $desc->{scope} );
  3293. # language handling for scope
  3294. if ( ref($scope) eq "HASH" && defined( $scope->{$slang} ) ) {
  3295. my $v;
  3296. $v = $scope->{$slang};
  3297. $scope = undef;
  3298. $scope = $v;
  3299. Unit_Log3( $device, $reading, $desc, 8,
  3300. "formatValue $device $reading: RAttr scope: "
  3301. . "value replaced by language specific version ($slang)" );
  3302. }
  3303. elsif ( ref($scope) eq "HASH" && defined( $scope->{$slang_base} ) ) {
  3304. my $v;
  3305. $v = $scope->{$slang_base};
  3306. $scope = undef;
  3307. $scope = $v;
  3308. Unit_Log3( $device, $reading, $desc, 8,
  3309. "formatValue $device $reading: RAttr scope: "
  3310. . "value replaced by language specific version ($slang_base)" );
  3311. }
  3312. Unit_Log3( $device, $reading, $desc, 9,
  3313. "formatValue $device $reading: scope dump:\n" . Dumper($scope) )
  3314. if ($scope);
  3315. ################################
  3316. # scope:
  3317. # Check for value to be in correct scope
  3318. #
  3319. # Use user defined subroutine
  3320. if ( ref($scope) eq 'CODE' && &$scope ) {
  3321. Unit_Log3( $device, $reading, $desc, 9,
  3322. "formatValue $device $reading: scope: "
  3323. . "running external subroutine $scope()" );
  3324. ( $value, $value_num ) = $scope->($value);
  3325. }
  3326. # scope was defined as HASH
  3327. elsif ( ref($scope) eq 'HASH' ) {
  3328. Unit_Log3( $device, $reading, $desc, 9,
  3329. "formatValue $device $reading: scope: "
  3330. . "verifying '$value' based on HASH structure" );
  3331. my ( $log, $verified );
  3332. ( $verified, $value, $value_num, $log ) =
  3333. Unit_verifyValueNumber( $value, $scope );
  3334. Unit_Log3( $device, $reading, $desc, 4,
  3335. "formatValue $device $reading: scope: WARNING -$log" )
  3336. if ($log);
  3337. }
  3338. # scope was defined as ARRAY so let's assume value
  3339. # to be the index for that array to convert
  3340. # this index to a text string.
  3341. # 'value_num' will be defined here to help harmonising text values over
  3342. # different reading names representing similar/comparable content in
  3343. # some way.
  3344. elsif ( ref($scope) eq 'ARRAY' ) {
  3345. Unit_Log3( $device, $reading, $desc, 9,
  3346. "formatValue $device $reading: scope: "
  3347. . "verifying value '$value' based on ARRAY structure" );
  3348. # value found as index within array.
  3349. # assuming this scope was defined as string in regex format
  3350. if ( looks_like_number($value)
  3351. && defined( $scope->[$value] )
  3352. && !ref( $scope->[$value] )
  3353. && $value =~ /$scope->[$value]/gmi )
  3354. {
  3355. $value_num = $value;
  3356. # some language handling
  3357. # to replace original value with language specific
  3358. # and FHEM harmonised value
  3359. #
  3360. # If specified language was found
  3361. if ( ref( $desc->{txt} ) eq "HASH"
  3362. && ref( $desc->{txt}{$lang} ) eq "ARRAY"
  3363. && defined( $desc->{txt}{$lang}[$value] ) )
  3364. {
  3365. Unit_Log3( $device, $reading, $desc, 8,
  3366. "formatValue $device $reading: scope: rattr value: "
  3367. . "replaced by language specific value from 'txt' ($lang)"
  3368. );
  3369. $value = $desc->{txt}{$lang}[$value];
  3370. }
  3371. # also try base language
  3372. elsif (ref( $desc->{txt} ) eq "HASH"
  3373. && ref( $desc->{txt}{$lang_base} ) eq "ARRAY"
  3374. && defined( $desc->{txt}{$lang_base}[$value] ) )
  3375. {
  3376. Unit_Log3( $device, $reading, $desc, 8,
  3377. "formatValue $device $reading: scope: rattr value: "
  3378. . "replaced by language specific value from 'txt' ($lang_base)"
  3379. );
  3380. $value = $desc->{txt}{$lang_base}[$value];
  3381. }
  3382. # fallback to english
  3383. elsif (ref( $desc->{txt} ) eq "HASH"
  3384. && ref( $desc->{txt}{en} ) eq "ARRAY"
  3385. && defined( $desc->{txt}{en}[$value] ) )
  3386. {
  3387. Unit_Log3( $device, $reading, $desc, 8,
  3388. "formatValue $device $reading: scope: rattr value: "
  3389. . "replaced by language specific value from 'txt' (en / default language)"
  3390. );
  3391. $value = $desc->{txt}{en}[$value];
  3392. }
  3393. # if there is no language defined at all
  3394. elsif ( ref( $desc->{txt} ) eq "ARRAY"
  3395. && defined( $desc->{txt}[$value] ) )
  3396. {
  3397. Unit_Log3( $device, $reading, $desc, 8,
  3398. "formatValue $device $reading: scope: rattr value: "
  3399. . "replaced by value from 'txt'" );
  3400. $value = $desc->{txt}[$value];
  3401. }
  3402. # if there is no language defined at all
  3403. elsif ( !ref( $desc->{txt} )
  3404. && defined( $desc->{txt} ) )
  3405. {
  3406. Unit_Log3( $device, $reading, $desc, 8,
  3407. "formatValue $device $reading: scope: rattr value: "
  3408. . "replaced by plane value from 'txt'" );
  3409. $value = $desc->{txt};
  3410. }
  3411. # if there is no txt definition at all
  3412. # arrays are unbalanced
  3413. else {
  3414. Unit_Log3( $device, $reading, $desc, 7,
  3415. "formatValue $device $reading: scope: ERROR - "
  3416. . "unbalanced number of items in arrays" );
  3417. }
  3418. }
  3419. else {
  3420. my $i = 0;
  3421. foreach ( @{$scope} ) {
  3422. #TODO
  3423. if ( !ref($_) && $value =~ /$_/gmi ) {
  3424. $value_num = $i;
  3425. # some language handling
  3426. # to replace original value with language specific
  3427. # and FHEM harmonised value
  3428. #
  3429. # If specified language was found
  3430. if ( ref( $desc->{txt} ) eq "HASH"
  3431. && ref( $desc->{txt}{$lang} ) eq "ARRAY"
  3432. && defined( $desc->{txt}{$lang}[$i] ) )
  3433. {
  3434. Unit_Log3( $device, $reading, $desc, 8,
  3435. "formatValue $device $reading: scope: rattr value: "
  3436. . "replaced by language specific value from 'txt' ($lang)"
  3437. );
  3438. $value = $desc->{txt}{$lang}[$i];
  3439. }
  3440. # also try base language
  3441. elsif (ref( $desc->{txt} ) eq "HASH"
  3442. && ref( $desc->{txt}{$lang_base} ) eq "ARRAY"
  3443. && defined( $desc->{txt}{$lang_base}[$i] ) )
  3444. {
  3445. Unit_Log3( $device, $reading, $desc, 8,
  3446. "formatValue $device $reading: scope: rattr value: "
  3447. . "replaced by language specific value from 'txt' ($lang_base)"
  3448. );
  3449. $value = $desc->{txt}{$lang_base}[$i];
  3450. }
  3451. # fallback to english
  3452. elsif (ref( $desc->{txt} ) eq "HASH"
  3453. && ref( $desc->{txt}{en} ) eq "ARRAY"
  3454. && defined( $desc->{txt}{en}[$i] ) )
  3455. {
  3456. Unit_Log3( $device, $reading, $desc, 8,
  3457. "formatValue $device $reading: scope: rattr value: "
  3458. . "replaced by language specific value from 'txt' (en / default language)"
  3459. );
  3460. $value = $desc->{txt}{en}[$i];
  3461. }
  3462. # if there is no language defined at all
  3463. elsif ( ref( $desc->{txt} ) eq "ARRAY"
  3464. && defined( $desc->{txt}[$i] ) )
  3465. {
  3466. Unit_Log3( $device, $reading, $desc, 8,
  3467. "formatValue $device $reading: scope: rattr value: "
  3468. . "replaced by value from 'txt'" );
  3469. $value = $desc->{txt}[$i];
  3470. }
  3471. # if there is no language defined at all
  3472. elsif ( !ref( $desc->{txt} )
  3473. && defined( $desc->{txt} ) )
  3474. {
  3475. Unit_Log3( $device, $reading, $desc, 8,
  3476. "formatValue $device $reading: scope: rattr value: "
  3477. . "replaced by plane value from 'txt'" );
  3478. $value = $desc->{txt};
  3479. }
  3480. # if there is no txt definition at all
  3481. # arrays are unbalanced
  3482. else {
  3483. $value = $1 if ( defined($1) );
  3484. if ( !defined($1) ) {
  3485. Unit_Log3( $device, $reading, $desc, 7,
  3486. "formatValue device $reading: scope: ERROR - "
  3487. . "missing txt value or regex output (i=$i)"
  3488. );
  3489. }
  3490. }
  3491. last;
  3492. }
  3493. #TODO
  3494. elsif ( ref($_) eq "HASH" ) {
  3495. if ( !looks_like_number($value) && $_->{regex} ) {
  3496. Unit_Log3( $device, $reading, $desc, 9,
  3497. "formatValue $device $reading: scope: "
  3498. . "searching numeric value for string '$value' (i=$i)"
  3499. );
  3500. if ( $value =~ /$_->{regex}/ ) {
  3501. if ( defined( $_->{value_num} ) ) {
  3502. Unit_Log3( $device, $reading, $desc, 9,
  3503. "formatValue $device $reading: scope: "
  3504. . "static numeric value found in HASH" );
  3505. $value_num->[0] = $i;
  3506. $value_num->[1] = $_->{value_num};
  3507. }
  3508. else {
  3509. Unit_Log3( $device, $reading, $desc, 9,
  3510. "formatValue $device $reading: scope: "
  3511. . "assuming indirect numeric value from ARRAY index number"
  3512. );
  3513. $value_num = $i;
  3514. }
  3515. last;
  3516. }
  3517. }
  3518. #TODO: wenn nummer out of scope, dann muss ein maximalwert gesetzt sein
  3519. else {
  3520. Unit_Log3( $device, $reading, $desc, 9,
  3521. "formatValue $device $reading: scope: "
  3522. . "verifying numeric value '$value' (i=$i)" );
  3523. my ( $verified, $tval, $tval_num, $log ) =
  3524. Unit_verifyValueNumber( $value, $_ );
  3525. if ($log) {
  3526. Unit_Log3( $device, $reading, $desc, 4,
  3527. "formatValue $device $reading: scope: WARNING -$log"
  3528. );
  3529. }
  3530. elsif ( $verified && !$log ) {
  3531. if ( defined($tval_num) ) {
  3532. Unit_Log3( $device, $reading, $desc, 9,
  3533. "formatValue $device $reading: scope: "
  3534. . "static numeric value found in HASH" );
  3535. $value_num->[0] = $i;
  3536. $value_num->[1] = $tval_num;
  3537. }
  3538. else {
  3539. Unit_Log3( $device, $reading, $desc, 9,
  3540. "formatValue $device $reading: scope: "
  3541. . "assuming indirect numeric value from ARRAY index number"
  3542. );
  3543. $value_num = $i;
  3544. }
  3545. $value = $tval;
  3546. last;
  3547. }
  3548. }
  3549. }
  3550. $i++;
  3551. }
  3552. }
  3553. }
  3554. # scope was defined as string, let's assume it's in regex format
  3555. elsif ( defined($scope) && $scope ne "" && $value =~ /$scope/gmi ) {
  3556. # if regex matches and returns a $1, let's assume this is
  3557. # by intention to replace something
  3558. if ( defined($1) ) {
  3559. Unit_Log3( $device, $reading, $desc, 9,
  3560. "formatValue $device $reading: scope: "
  3561. . "'$value' replaced by regex $scope with result from variable \$1"
  3562. );
  3563. $value = $1;
  3564. }
  3565. }
  3566. # scope definition present but value seems to be out of regex scope
  3567. elsif ( defined($scope) && $scope ne "" ) {
  3568. Unit_Log3( $device, $reading, $desc, 8,
  3569. "formatValue $device $reading: scope: WARNING - "
  3570. . "'$value' does not match regex $scope" );
  3571. }
  3572. # format
  3573. #
  3574. if ( $format && !looks_like_number($value) ) {
  3575. Unit_Log3( $device, $reading, $desc, 8,
  3576. "formatValue $device $reading: format: ERROR - $value is not a number"
  3577. )
  3578. if ( ref($scope) eq 'HASH'
  3579. && !$scope->{empty}
  3580. && !$scope->{empty_replace} );
  3581. }
  3582. elsif ( ref($format) eq 'CODE' && &$format ) {
  3583. $value = $format->($value);
  3584. }
  3585. elsif ( ref($format) eq 'HASH' ) {
  3586. my $v = $value;
  3587. foreach my $l ( sort { $b <=> $a } keys( %{$format} ) ) {
  3588. next
  3589. if ( ref( $format->{$l} ) ne 'HASH'
  3590. || !$format->{$l}{rescale} );
  3591. if ( $v >= $l ) {
  3592. my $rescale = $format->{$l}{rescale};
  3593. $value *= $rescale if ($rescale);
  3594. $value = sprintf( $format->{$l}{format}, $value )
  3595. if ( $format->{$l}{format} );
  3596. last;
  3597. }
  3598. }
  3599. }
  3600. elsif ( ref($format) eq 'ARRAY' ) {
  3601. Unit_Log3( $device, $reading, $desc, 8,
  3602. "formatValue($device:$reading:$desc->{rtype})"
  3603. . " format not implemented: ARRAY" );
  3604. }
  3605. elsif ($format) {
  3606. my $rescale = $desc->{rescale};
  3607. $value *= $rescale if ($rescale);
  3608. $value = sprintf( $format, $value );
  3609. }
  3610. $desc->{value}{$lang} = $value;
  3611. $desc->{value_num} = $value_num if ( defined($value_num) );
  3612. my ( $txt, $txt_long, $unit ) =
  3613. replaceTemplate( $device, $reading, $desc, $lang, $value );
  3614. $desc->{value_txt}{$lang} = $txt;
  3615. $desc->{value_txt_long}{$lang} = $txt_long
  3616. if ( defined($txt_long) );
  3617. delete $desc->{value_txt_long}{$lang}
  3618. if (!defined($txt_long)
  3619. && defined( $desc->{value_txt_long}{$lang} ) );
  3620. return ( $txt, $txt_long, $value, $value_num, $unit ) if (wantarray);
  3621. return $value
  3622. if ( ( defined( $desc->{showUnits} ) && $desc->{showUnits} eq "2" )
  3623. || AttrVal( $device, "showUnits", 1 ) eq "2" );
  3624. return $txt_long
  3625. if ( $desc->{showLong} && !$desc->{showShort} );
  3626. return $txt;
  3627. }
  3628. # find desc for device:reading
  3629. sub readingsDesc($;$) {
  3630. my ( $device, $reading ) = @_;
  3631. my $desc = getCombinedKeyValAttr( $device, "readingsDesc", $reading );
  3632. my $rtype;
  3633. $rtype = $desc->{rtype} if ( $desc->{rtype} );
  3634. if ( $rtype && defined( $rtypes->{$rtype} ) ) {
  3635. # copy information from other hashes until 3rd level
  3636. foreach my $k ( keys %{ $rtypes->{$rtype} } ) {
  3637. if ( ref( $rtypes->{$rtype}{$k} ) eq "HASH" ) {
  3638. foreach my $k2 ( keys %{ $rtypes->{$rtype}{$k} } ) {
  3639. if ( ref( $rtypes->{$rtype}{$k}{$k2} ) eq "HASH" ) {
  3640. foreach ( keys %{ $rtypes->{$rtype}{$k}{$k2} } ) {
  3641. delete $desc->{$k}{$k2}{$_}
  3642. if ( $desc->{$k}{$k2}{$_} );
  3643. $desc->{$k}{$k2}{$_} =
  3644. $rtypes->{$rtype}{$k}{$k2}{$_};
  3645. }
  3646. }
  3647. else {
  3648. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3649. $desc->{$k}{$k2} = $rtypes->{$rtype}{$k}{$k2};
  3650. }
  3651. }
  3652. }
  3653. else {
  3654. delete $desc->{$k} if ( $desc->{$k} );
  3655. $desc->{$k} = $rtypes->{$rtype}{$k};
  3656. }
  3657. }
  3658. foreach ( 'ref', 'ref_t', 'ref_sq', 'ref_cu' ) {
  3659. my $suffix = $_;
  3660. $suffix =~ s/^[a-z]+//;
  3661. if ( defined( $desc->{$_} ) ) {
  3662. my $ref = $desc->{$_};
  3663. if ( !defined( $rtypes->{$ref} ) ) {
  3664. Log 1, "readingsDesc($rtype) broken reference $_";
  3665. next;
  3666. }
  3667. foreach my $k ( keys %{ $rtypes->{$ref} } ) {
  3668. next
  3669. if ( $k =~ /^scale/ )
  3670. ; # exclude scales from referenced rtype
  3671. if ( !defined( $desc->{$k} ) ) {
  3672. $desc->{$k} = $rtypes->{$ref}{$k};
  3673. }
  3674. else {
  3675. $desc->{ $k . $suffix } = $rtypes->{$ref}{$k}
  3676. if ( !defined( $desc->{ $k . $suffix } ) );
  3677. }
  3678. }
  3679. }
  3680. }
  3681. if ( $desc->{scale_m} ) {
  3682. my $ref = $desc->{scale_m};
  3683. foreach my $k ( keys %{ $scales_m->{$ref} } ) {
  3684. $desc->{$k} = $scales_m->{$ref}{$k}
  3685. if ( !defined( $desc->{$k} ) );
  3686. }
  3687. }
  3688. if ( $desc->{scale_sq} ) {
  3689. foreach my $k ( keys %{$scales_sq} ) {
  3690. $desc->{$k} = $scales_sq->{$k}
  3691. if ( !defined( $desc->{$k} ) );
  3692. }
  3693. my $ref = $desc->{scale_sq};
  3694. foreach my $k ( keys %{ $scales_m->{$ref} } ) {
  3695. $desc->{ $k . "_sq" } = $scales_m->{$ref}{$k}
  3696. if ( !defined( $desc->{ $k . "_sq" } ) );
  3697. }
  3698. }
  3699. if ( $desc->{scale_cu} ) {
  3700. foreach my $k ( keys %{$scales_cu} ) {
  3701. $desc->{$k} = $scales_cu->{$k}
  3702. if ( !defined( $desc->{$k} ) );
  3703. }
  3704. my $ref = $desc->{scale_cu};
  3705. foreach my $k ( keys %{ $scales_m->{$ref} } ) {
  3706. $desc->{ $k . "_cu" } = $scales_m->{$ref}{$k}
  3707. if ( !defined( $desc->{ $k . "_cu" } ) );
  3708. }
  3709. }
  3710. if ( $desc->{scale_t} ) {
  3711. my $ref = $desc->{scale_t};
  3712. foreach my $k ( keys %{ $scales_t->{$ref} } ) {
  3713. $desc->{$k} = $scales_t->{$ref}{$k}
  3714. if ( !defined( $desc->{$k} ) );
  3715. }
  3716. }
  3717. $desc->{ref_base} = 999 if ( !defined( $desc->{ref_base} ) );
  3718. my $ref = $desc->{ref_base};
  3719. foreach my $k ( keys %{ $rtype_base->{$ref} } ) {
  3720. $desc->{$k} = $rtype_base->{$ref}{$k}
  3721. if ( !defined( $desc->{$k} ) );
  3722. }
  3723. }
  3724. Unit_Log3( $device, $reading, $desc, 10,
  3725. "readingsDesc $device $reading:\n" . Dumper($desc) );
  3726. return $desc;
  3727. }
  3728. # format device:reading with optional default value and optional desc and optional format
  3729. sub formatReading($$;$$$$$) {
  3730. my ( $device, $reading, $default, $desc, $format, $scope, $lang ) = @_;
  3731. $desc = readingsDesc( $device, $reading ) if ( !$desc );
  3732. my $value = ReadingsVal( $device, $reading, undef );
  3733. $value = $default if ( !defined($value) );
  3734. return formatValue( $device, $reading, $value, $desc, $format,
  3735. $scope, $lang );
  3736. }
  3737. # return unit symbol for device:reading
  3738. sub readingsUnit($$;$$$) {
  3739. my ( $device, $reading, $long, $combined, $desc ) = @_;
  3740. $desc = readingsDesc( $device, $reading ) if ( !$desc );
  3741. return (
  3742. $desc->{suffix} ? $desc->{suffix} : undef,
  3743. $desc->{symbol} ? $desc->{symbol} : undef,
  3744. $desc->{txt} ? $desc->{txt} : undef
  3745. ) if (wantarray);
  3746. my ( $txt, $txt_long, $value, $value_num ) =
  3747. formatReading( $device, $reading, "", $desc );
  3748. $txt =~ s/\s*$value\s*//;
  3749. $txt_long =~ s/\s*$value\s*//;
  3750. return "$txt_long ($txt)"
  3751. if ( $combined
  3752. && defined($txt_long)
  3753. && $txt_long ne ""
  3754. && defined($txt)
  3755. && $txt ne "" );
  3756. return $txt_long
  3757. if ( $long && defined($txt_long) && $txt_long ne "" );
  3758. return $txt if ( defined($txt) && $txt ne "" );
  3759. return '';
  3760. }
  3761. # return dimension symbol for device:reading
  3762. sub readingsShortname($$) {
  3763. my ( $device, $reading ) = @_;
  3764. if ( my $desc = readingsDesc( $device, $reading ) ) {
  3765. return $desc->{formula_symbol} if ( $desc->{formula_symbol} );
  3766. return $desc->{dimension}
  3767. if ( $desc->{dimension} && $desc->{dimension} =~ /^[A-Z]+$/ );
  3768. return $desc->{symbol} if ( $desc->{symbol} );
  3769. }
  3770. return $reading;
  3771. }
  3772. # format device STATE readings according to stateFormat and optional units
  3773. sub makeSTATE($;$$) {
  3774. my ( $device, $stateFormat, $withUnits ) = @_;
  3775. $stateFormat = '' if ( !$stateFormat );
  3776. my $hash = $defs{$device};
  3777. return $stateFormat if ( !$hash );
  3778. $stateFormat = AttrVal( $device, 'stateFormat', undef )
  3779. if ( !$stateFormat );
  3780. return '' if ( !$stateFormat );
  3781. # filter own function name to avoid loops
  3782. $stateFormat =~ s/{.*}//mg
  3783. if ( $stateFormat =~ /makeSTATE/ );
  3784. # use all readings if stateFormat is empty
  3785. $stateFormat = join( ' ', sort keys %{ $hash->{READINGS} } )
  3786. if ( $stateFormat !~ /\w+/ );
  3787. my $txt;
  3788. if ( $stateFormat =~ m/^{(.*)}$/ ) {
  3789. $stateFormat = eval $1;
  3790. if ($@) {
  3791. $stateFormat = "Error evaluating $device stateFormat: $@";
  3792. Log 1, $stateFormat;
  3793. }
  3794. }
  3795. else {
  3796. my $r = $hash->{READINGS};
  3797. my %usedShortnames;
  3798. while ( $stateFormat =~ /\b([A-Za-z\d_\.-]+):?([A-Za-z\d_\.-]+)?\b/g ) {
  3799. $txt .= " " if ($txt);
  3800. if ( defined( $r->{$1} ) ) {
  3801. my $sname = readingsShortname( $device, $1 );
  3802. $usedShortnames{$sname}++
  3803. if ( $usedShortnames{$sname} );
  3804. $usedShortnames{$sname} = 1
  3805. if ( !$usedShortnames{$sname} );
  3806. if ( $2 && $2 ne "" ) {
  3807. $txt .= "$2: ";
  3808. }
  3809. elsif ( $usedShortnames{$sname} > 1 ) {
  3810. $txt .= "$sname" . $usedShortnames{$sname} . ": ";
  3811. }
  3812. else {
  3813. $txt .= "$sname: ";
  3814. }
  3815. if ($withUnits) {
  3816. $txt .= formatReading( $device, $1 );
  3817. }
  3818. else {
  3819. $txt .= ( formatReading( $device, $1 ) )[2];
  3820. }
  3821. }
  3822. else {
  3823. $txt .= $1;
  3824. $txt .= ":$2" if ($2);
  3825. }
  3826. }
  3827. return $txt;
  3828. }
  3829. return $stateFormat;
  3830. }
  3831. # get combined hash for settings from module, device, global and device attributes
  3832. sub getCombinedKeyValAttr($;$$) {
  3833. my ( $name, $attribute, $reading ) = @_;
  3834. my $d = $defs{$name} if ( $defs{$name} );
  3835. my $m = $modules{ $d->{TYPE} } if ( $d && $d->{TYPE} );
  3836. my $g = $defs{"global"};
  3837. # join hashes until 3rd level
  3838. my $desc;
  3839. if ( $m && $m->{$attribute} && ref( $m->{$attribute} ) eq "HASH" ) {
  3840. Log3( $name, 5,
  3841. "getCombinedKeyValAttr $name $reading: including HASH from module X_Initialize() function"
  3842. );
  3843. foreach my $k ( keys %{ $m->{$attribute} } ) {
  3844. if ( ref( $m->{$attribute}{$k} ) eq "HASH" ) {
  3845. foreach my $k2 ( keys %{ $m->{$attribute}{$k} } ) {
  3846. if ( ref( $m->{$attribute}{$k}{$k2} ) eq "HASH" ) {
  3847. foreach ( keys %{ $m->{$attribute}{$k}{$k2} } ) {
  3848. delete $desc->{$k}{$k2}{$_}
  3849. if ( $desc->{$k}{$k2}{$_} );
  3850. $desc->{$k}{$k2}{$_} =
  3851. $m->{$attribute}{$k}{$k2}{$_};
  3852. }
  3853. }
  3854. else {
  3855. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3856. $desc->{$k}{$k2} = $m->{$attribute}{$k}{$k2};
  3857. }
  3858. }
  3859. }
  3860. else {
  3861. delete $desc->{$_} if ( $desc->{$k} );
  3862. $desc->{$_} = $m->{$attribute}{$k};
  3863. }
  3864. }
  3865. }
  3866. if ( $g && $g->{$attribute} && ref( $g->{$attribute} ) eq "HASH" ) {
  3867. Log3( $name, 5,
  3868. "getCombinedKeyValAttr $name $reading: including HASH from global attribute $attribute"
  3869. );
  3870. foreach my $k ( keys %{ $g->{$attribute} } ) {
  3871. if ( ref( $g->{$attribute}{$k} ) eq "HASH" ) {
  3872. foreach my $k2 ( keys %{ $g->{$attribute}{$k} } ) {
  3873. if ( ref( $g->{$attribute}{$k}{$k2} ) eq "HASH" ) {
  3874. foreach ( keys %{ $g->{$attribute}{$k}{$k2} } ) {
  3875. delete $desc->{$k}{$k2}{$_}
  3876. if ( $desc->{$k}{$k2}{$_} );
  3877. $desc->{$k}{$k2}{$_} =
  3878. $g->{$attribute}{$k}{$k2}{$_};
  3879. }
  3880. }
  3881. else {
  3882. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3883. $desc->{$k}{$k2} = $g->{$attribute}{$k}{$k2};
  3884. }
  3885. }
  3886. }
  3887. else {
  3888. delete $desc->{$_} if ( $desc->{$k} );
  3889. $desc->{$_} = $g->{$attribute}{$k};
  3890. }
  3891. }
  3892. }
  3893. if ( $d && $d->{$attribute} && ref( $d->{$attribute} ) eq "HASH" ) {
  3894. Log3( $name, 5,
  3895. "getCombinedKeyValAttr $name $reading: including HASH from device attribute $attribute"
  3896. );
  3897. foreach my $k ( keys %{ $d->{$attribute} } ) {
  3898. if ( ref( $d->{$attribute}{$k} ) eq "HASH" ) {
  3899. foreach my $k2 ( keys %{ $d->{$attribute}{$k} } ) {
  3900. if ( ref( $d->{$attribute}{$k}{$k2} ) eq "HASH" ) {
  3901. foreach ( keys %{ $d->{$attribute}{$k}{$k2} } ) {
  3902. delete $desc->{$k}{$k2}{$_}
  3903. if ( $desc->{$k}{$k2}{$_} );
  3904. $desc->{$k}{$k2}{$_} =
  3905. $d->{$attribute}{$k}{$k2}{$_};
  3906. }
  3907. }
  3908. else {
  3909. delete $desc->{$k}{$k2} if ( $desc->{$k}{$k2} );
  3910. $desc->{$k}{$k2} = $d->{$attribute}{$k}{$k2};
  3911. }
  3912. }
  3913. }
  3914. else {
  3915. delete $desc->{$_} if ( $desc->{$k} );
  3916. $desc->{$_} = $d->{$attribute}{$k};
  3917. }
  3918. }
  3919. }
  3920. return
  3921. if (
  3922. keys %{$desc} < 1
  3923. || (
  3924. $reading
  3925. && ( !defined( $desc->{$reading} )
  3926. || keys %{ $desc->{$reading} } < 1 )
  3927. )
  3928. );
  3929. return $desc->{$reading} if ($reading);
  3930. return $desc;
  3931. }
  3932. # save key/value pair to device attribute
  3933. sub setKeyValAttr($$$$$) {
  3934. my ( $name, $attribute, $reading, $key, $value ) = @_;
  3935. my $d = $defs{$name} if ( $defs{$name} );
  3936. my $ret;
  3937. return
  3938. if (
  3939. !$d
  3940. || ( defined( $d->{$attribute} )
  3941. && defined( $d->{$attribute}{$reading} )
  3942. && defined( $d->{$attribute}{$reading}{$key} )
  3943. && $d->{$attribute}{$reading}{$key} eq $value )
  3944. );
  3945. # rtype
  3946. if ( $key =~ /^rtype$/i ) {
  3947. $key = lc($key);
  3948. # Show all possible values
  3949. if ( $value && $value eq "?" ) {
  3950. return "CURRENTLY KNOWN READING TYPES\n\n"
  3951. . PrintHash( $rtypes, 0 );
  3952. }
  3953. # find rtype based on reading name
  3954. elsif ( !defined($value) || $value eq "" ) {
  3955. $value = rname2rtype( $name, $reading );
  3956. $ret =
  3957. "Set auto-detected $key for device $name $reading: " . $value
  3958. if ($value);
  3959. }
  3960. my $curr;
  3961. no strict "refs";
  3962. $curr = &$attribute( $name, $reading ) if (&$attribute);
  3963. use strict "refs";
  3964. return
  3965. if (
  3966. !defined($value)
  3967. || $value eq ""
  3968. || ( defined($curr)
  3969. && defined( $curr->{$key} )
  3970. && $curr->{$key} eq $value )
  3971. || ( defined( $d->{$attribute} )
  3972. && defined( $d->{$attribute}{$reading} )
  3973. && defined( $d->{$attribute}{$reading}{$key} )
  3974. && $d->{$attribute}{$reading}{$key} eq $value )
  3975. );
  3976. return
  3977. "Invalid value $value for $key: Cannot be assigned to device $name $reading"
  3978. if ( !defined( $rtypes->{$value} ) );
  3979. $ret =
  3980. "Changed value $key='"
  3981. . $d->{$attribute}{$reading}{$key}
  3982. . "' for device $name $reading to: "
  3983. . $value
  3984. if ( defined( defined( $d->{$attribute} ) )
  3985. && defined( $d->{$attribute}{$reading} )
  3986. && defined( $d->{$attribute}{$reading}{$key} )
  3987. && $d->{$attribute}{$reading}{$key} ne $value );
  3988. }
  3989. $d->{$attribute}{$reading}{$key} = $value;
  3990. # write attribute
  3991. $Data::Dumper::Terse = 1;
  3992. $Data::Dumper::Deepcopy = 1;
  3993. $Data::Dumper::Sortkeys = 1;
  3994. my $txt = Dumper( $d->{$attribute} );
  3995. $Data::Dumper::Terse = 0;
  3996. $Data::Dumper::Deepcopy = 0;
  3997. $Data::Dumper::Sortkeys = 0;
  3998. $txt =~ s/(=>\s*\{|['"],?)\s*\n\s*/$1 /gsm;
  3999. CommandAttr( undef, "$name $attribute $txt" );
  4000. return $ret;
  4001. }
  4002. sub deleteKeyValAttr($$$;$) {
  4003. my ( $name, $attribute, $reading, $key ) = @_;
  4004. my $d = $defs{$name} if ( $defs{$name} );
  4005. my $rt;
  4006. return
  4007. if ( !$d
  4008. || !defined( $d->{$attribute} )
  4009. || !defined( $d->{$attribute}{$reading} )
  4010. || ( $key && !defined( $d->{$attribute}{$reading}{$key} ) ) );
  4011. if ($key) {
  4012. $rt = " $key=" . $d->{$attribute}{$reading}{$key};
  4013. delete $d->{$attribute}{$reading}{$key};
  4014. }
  4015. delete $d->{$attribute}{$reading}
  4016. if ( !$key || keys %{ $d->{$attribute}{$reading} } < 1 );
  4017. # delete attribute
  4018. if ( keys %{ $d->{$attribute} } < 1 ) {
  4019. CommandDeleteAttr( undef, "$name $attribute" );
  4020. }
  4021. # write attribute
  4022. else {
  4023. $Data::Dumper::Terse = 1;
  4024. $Data::Dumper::Sortkeys = 1;
  4025. my $txt = Dumper( $d->{$attribute} );
  4026. $Data::Dumper::Terse = 0;
  4027. $Data::Dumper::Sortkeys = 0;
  4028. $txt =~ s/(=>\s*\{|[\'\"0-9],?)\s*\n\s*/$1 /gsm;
  4029. CommandAttr( undef, "$name $attribute $txt" );
  4030. }
  4031. return "Removed $reading$rt from attribute $name $attribute";
  4032. }
  4033. ################################################################
  4034. #
  4035. # Wrappers for commonly used core functions in device-specific modules.
  4036. #
  4037. ################################################################
  4038. # Generalized function for DbLog rtype support
  4039. sub Unit_DbLog_split($$) {
  4040. my ( $event, $name ) = @_;
  4041. my ( $reading, $value, $unit ) = "";
  4042. # exclude any multi-value events
  4043. if ( $event =~ /(.*: +.*: +.*)+/ ) {
  4044. Log3 $name, 5,
  4045. "Unit_DbLog_split $name: Ignoring multi-value event $event";
  4046. return undef;
  4047. }
  4048. # exclude sum/cum and avg events
  4049. elsif ( $event =~
  4050. /^.*(min|max|avg|sum|cum|min\d+m|max\d+m|avg\d+m|sum\d+m|cum\d+m): +.*/
  4051. )
  4052. {
  4053. Log3 $name, 5, "Unit_DbLog_split $name: Ignoring sum/avg event $event";
  4054. return undef;
  4055. }
  4056. # automatic text conversions through reading type
  4057. elsif ( $event =~ /^(.+): +(\S+) *(.*)/ ) {
  4058. $reading = $1;
  4059. my ( $txt, $txt_long, $val, $val_num, $symbol ) =
  4060. formatReading( $name, $reading, "" );
  4061. if ( defined($txt) && defined($reading) && defined($val) ) {
  4062. $txt =~ s/[\s\u202F\u00A0]*$val[\s\u202F\u00A0]*//;
  4063. $value = $val;
  4064. if ( !looks_like_number($val) && defined($val_num) ) {
  4065. if ( ref($val_num) eq "ARRAY" ) {
  4066. $value = $val_num->[1];
  4067. }
  4068. else {
  4069. $value = $val_num;
  4070. }
  4071. }
  4072. $unit = defined($symbol) ? $symbol : $txt;
  4073. }
  4074. }
  4075. # general event handling
  4076. if ( !defined($value)
  4077. && $event =~
  4078. m/^(.+): +[\D]*(\d+\.?\d*)[\s\u202F\u00A0]*[\[\{\(]?[\s\u202F\u00A0]*([\w\°\%\^\/\\]*).*/
  4079. && defined($1)
  4080. && defined($2) )
  4081. {
  4082. $reading = $1;
  4083. $value = ReadingsNum( $name, $1, $2 );
  4084. $unit = defined($3) ? $3 : "";
  4085. }
  4086. if ( !defined($value) || !looks_like_number($value) ) {
  4087. Unit_Log3( $name, $reading, undef, 10,
  4088. "Unit_DbLog_split $name: Ignoring event $event: value $value does not look like a number"
  4089. ) if ( defined($value) );
  4090. return undef;
  4091. }
  4092. Unit_Log3( $name, $reading, undef, 9,
  4093. "Unit_DbLog_split $name: Splitting event $event > reading=$reading value=$value unit=$unit"
  4094. );
  4095. return ( $reading, $value, $unit );
  4096. }
  4097. ################################################
  4098. # the new Log with integrated loglevel checking for readings
  4099. sub Unit_Log3($$$$$) {
  4100. my ( $dev, $rname, $desc, $loglevel, $text ) = @_;
  4101. $dev = $dev->{NAME} if ( defined($dev) && ref($dev) eq "HASH" );
  4102. $desc = readingsDesc( $dev, $rname )
  4103. if ( !$desc || !ref($desc) );
  4104. my $rloglevel = $loglevel;
  4105. if ( $desc
  4106. && ref($desc) eq "HASH"
  4107. && defined( my $rlevel = $desc->{verbose} ) )
  4108. {
  4109. return if ( $loglevel > $rlevel );
  4110. $rloglevel = $rloglevel - 9;
  4111. }
  4112. return Log3( $dev, $rloglevel, "RType: " . $text );
  4113. }
  4114. ################################################################
  4115. #
  4116. # User commands
  4117. #
  4118. ################################################################
  4119. # command: setreadingdesc
  4120. my %setreadingdeschash = (
  4121. Fn => "CommandSetReadingDesc",
  4122. Hlp =>
  4123. "<devspec> <readingspec> [noCheck] <key>=[<value>|?],set reading rtype information for <devspec> <reading>",
  4124. );
  4125. $cmds{setreadingdesc} = \%setreadingdeschash;
  4126. sub CommandSetReadingDesc($@) {
  4127. my ( $cl, $def ) = @_;
  4128. my $attribute = "readingsDesc";
  4129. my $namedef =
  4130. "where <devspec> is a single device name, a list separated by comma (,) or a regexp. See the devspec section in the commandref.html for details.\n"
  4131. . "<readingspec> can be a single reading name, a list separated by comma (,) or a regexp.";
  4132. my ( $a, $h ) = parseParams($def);
  4133. $a->[0] = ".*" if ( !$a->[0] );
  4134. $a->[1] = ".*" if ( !$a->[1] );
  4135. return
  4136. "Usage: setreadingdesc <devspec> <readingspec> [noCheck] <key>=[<value>|?]\n$namedef"
  4137. if ( $a->[0] eq "?" || $a->[1] eq "?" || !%{$h} );
  4138. my @rets;
  4139. my $last;
  4140. foreach my $name ( devspec2array( $a->[0], $cl ) ) {
  4141. unless ( IsDevice($name) ) {
  4142. push @rets, "Please define $name first";
  4143. next;
  4144. }
  4145. # do not check for existing reading
  4146. if ( $name eq "global"
  4147. || ( defined( $a->[2] ) && $a->[2] =~ /nocheck/i ) )
  4148. {
  4149. foreach ( keys %$h ) {
  4150. my $ret =
  4151. setKeyValAttr( $name, $attribute, $a->[1], $_, $h->{$_} );
  4152. push @rets, $ret if ( defined($ret) );
  4153. $last = 1 if ( $h->{$_} eq "?" || $h->{$_} eq "" );
  4154. }
  4155. next;
  4156. }
  4157. # check for existing reading
  4158. my $readingspec = '^' . $a->[1] . '$';
  4159. foreach my $reading (
  4160. grep { /$readingspec/ }
  4161. keys %{ $defs{$name}{READINGS} }
  4162. )
  4163. {
  4164. foreach ( keys %$h ) {
  4165. my $ret =
  4166. setKeyValAttr( $name, $attribute, $reading, $_, $h->{$_} );
  4167. push @rets, $ret if ( defined($ret) );
  4168. $last = 1 if ( $h->{$_} eq "?" || $h->{$_} eq "" );
  4169. }
  4170. }
  4171. last if ($last);
  4172. }
  4173. return join( "\n", @rets );
  4174. }
  4175. # command: deletereadingdesc
  4176. my %deletereadingdeschash = (
  4177. Fn => "CommandDeleteReadingDesc",
  4178. Hlp =>
  4179. "<devspec> <readingspec> [<keyspec>],delete key for <devspec> <reading>",
  4180. );
  4181. $cmds{deletereadingdesc} = \%deletereadingdeschash;
  4182. sub CommandDeleteReadingDesc($@) {
  4183. my ( $cl, $def ) = @_;
  4184. my $attribute = "readingsDesc";
  4185. my $namedef =
  4186. "where <devspec> is a single device name, a list separated by comma (,) or a regexp. See the devspec section in the commandref.html for details.\n"
  4187. . "<readingspec> and <keyspec> can be a single reading name, a list separated by comma (,) or a regexp.";
  4188. my ( $a, $h ) = parseParams($def);
  4189. $a->[0] = ".*" if ( !$a->[0] );
  4190. $a->[1] = ".*" if ( !$a->[1] );
  4191. $a->[2] = ".*" if ( !$a->[2] );
  4192. return
  4193. "Usage: deletereadingdesc <devspec> <readingspec> [<keyspec>]\n$namedef"
  4194. if ( $a->[0] eq "?" || $a->[1] eq "?" );
  4195. my @rets;
  4196. my $last;
  4197. foreach my $name ( devspec2array( $a->[0], $cl ) ) {
  4198. unless ( IsDevice($name) ) {
  4199. push @rets, "Please define $name first";
  4200. next;
  4201. }
  4202. my $readingspec = '^' . $a->[1] . '$';
  4203. foreach my $reading (
  4204. grep { /$readingspec/ }
  4205. keys %{ $defs{$name}{$attribute} }
  4206. )
  4207. {
  4208. my $keyspec = '^' . $a->[2] . '$';
  4209. foreach my $key (
  4210. grep { /$keyspec/ }
  4211. keys %{ $defs{$name}{$attribute}{$reading} }
  4212. )
  4213. {
  4214. my $ret = deleteKeyValAttr( $name, $attribute, $reading, $key );
  4215. push @rets, $ret if ( defined($ret) );
  4216. }
  4217. }
  4218. }
  4219. return join( "\n", @rets );
  4220. }
  4221. 1;