10_ZWave.pm 207 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338
  1. ##############################################
  2. # $Id: 10_ZWave.pm 13395 2017-02-11 21:31:18Z rudolfkoenig $
  3. # See ZWDongle.pm for inspiration
  4. package main;
  5. use strict;
  6. use warnings;
  7. use SetExtensions;
  8. use Compress::Zlib;
  9. use Time::HiRes qw( gettimeofday );
  10. use HttpUtils;
  11. use ZWLib;
  12. sub ZWave_Cmd($$@);
  13. sub ZWave_Get($@);
  14. sub ZWave_Parse($$@);
  15. sub ZWave_Set($@);
  16. sub ZWave_SetClasses($$$$);
  17. sub ZWave_addToSendStack($$$);
  18. sub ZWave_secStart($);
  19. sub ZWave_secEnd($);
  20. sub ZWave_configParseModel($;$);
  21. sub ZWave_callbackId($);
  22. sub ZWave_setEndpoints($);
  23. our ($FW_ME,$FW_tp,$FW_ss);
  24. our %zwave_id2class;
  25. my %zwave_class = (
  26. NO_OPERATION => { id => '00' }, # lowlevel
  27. ZWAVE => { id => '01', # lowlevel
  28. set => { zwaveAssignId => "03%02x%08x" },
  29. parse => { "..0101(....)..(..)..(.*)" =>
  30. '"zwaveNIF:baseClass:$2 flags:$1 classes:$3"',
  31. "..0103(..)(........)" =>
  32. '"zwaveAssignId:homeId:$2 nodeIdHex:$1"',
  33. "..0104(.*)"=> '"zwaveFindNodesInRange:$1"',
  34. "..0105" => '"zwaveGetNodesInRange:noarg"',
  35. "..0106(.*)"=> '"zwaveNodeRangeInfo:$1"',
  36. "..0107(.*)"=> '"zwaveCommandComplete:$1"',
  37. "..010801" => '"zwaveTransferPresentation"',
  38. "..010c(.*)"=> '"zwaveAssignRoute:$1"'
  39. }},
  40. BASIC => { id => '20', # V1, V2
  41. set => { basicValue => "01%02x", # V1, V2
  42. basicSet => "01%02x" }, # Alias, Forum #38200
  43. get => { basicStatus => "02", }, # V1, V2
  44. parse => { "..2001(.*)"=> '"basicSet:".hex($1)', # Forum #36980
  45. "..2002" => "basicGet:request", # sent by the remote
  46. "032003(..)"=> '"basicReport:".hex($1)', # V1
  47. "052003(..)(..)(..)" => 'ZWave_BASIC_03_report($1,$2,$3)',
  48. }},
  49. CONTROLLER_REPLICATION => { id => '21' },
  50. APPLICATION_STATUS => { id => '22', # V1
  51. parse => { "..2201(..)(..)" =>
  52. 'ZWave_APPLICATION_STATUS_01_Report($hash, $1, $2)', # V1
  53. "03220200" => "applicationStatus:cmdRejected", # V1
  54. }},
  55. ZIP_SERVICES => { id => '23' },
  56. ZIP_SERVER => { id => '24' },
  57. SWITCH_BINARY => { id => '25',
  58. set => { off => "0100",
  59. on => "01FF" },
  60. get => { swbStatus => "02", },
  61. parse => { "..250300" => "state:off",
  62. "..2503ff" => "state:on",
  63. "052503(..)(..)(..)" => 'sprintf("swbStatus:%s target %s '.
  64. 'duration %s", hex($1), hex($2), ZWave_duration($3))',
  65. "03250100" => "state:setOff",
  66. "032501ff" => "state:setOn" } } ,
  67. SWITCH_MULTILEVEL => { id => '26',
  68. set => { off => "0100",
  69. on => "01FF",
  70. dim => "01%02x",
  71. dimWithDuration => "01%02x%02x",
  72. stop => "05" },
  73. get => { swmStatus => "02", },
  74. parse => { "032603(.*)"=> '($1 eq "00" ? "state:off" :
  75. ($1 eq "ff" ? "state:on" :
  76. "state:dim ".hex($1)))',
  77. "..260100.."=> "state:setOff",
  78. "..2601ff.."=> "state:setOn",
  79. "..260420" => "state:swmBeginUp",
  80. "..260460" => "state:swmBeginDown",
  81. "..2604(..)(..)(..)(..)" => 'ZWave_swmParse($1,$2,$3,$4)',
  82. "..2605" => "state:swmEnd" } },
  83. SWITCH_ALL => { id => '27',
  84. set => { swaIncludeNone => "0100",
  85. swaIncludeOff => "0101",
  86. swaIncludeOn => "0102",
  87. swaIncludeOnOff => "01ff",
  88. swaOn => "04",
  89. swaOff => "05" },
  90. get => { swaInclude => "02" },
  91. parse => { "03270300" => "swa:none",
  92. "03270301" => "swa:off",
  93. "03270302" => "swa:on",
  94. "032703ff" => "swa:on off" } },
  95. SWITCH_TOGGLE_BINARY => { id => '28' },
  96. SWITCH_TOGGLE_MULTILEVEL => { id => '29' },
  97. CHIMNEY_FAN => { id => '2a' },
  98. SCENE_ACTIVATION => { id => '2b',
  99. set => { sceneActivate => "01%02x%02x" },
  100. parse => { "042b01(..)(..)" => '"scene_".hex($1).":".hex($2)',
  101. "042b01(..)ff" => 'ZWave_sceneParse($1)'} },
  102. SCENE_ACTUATOR_CONF => { id => '2c',
  103. set => { sceneConfig => "01%02x%02x80%02x" },
  104. get => { sceneConfig => "02%02x" },
  105. parse => { "052c03(..)(..)(..)" =>
  106. '"scene_".hex($1).":level ".hex($2)."duration ".hex($3)' } },
  107. SCENE_CONTROLLER_CONF => { id => '2d',
  108. set => { sceneConfig => "01%02x%02x%02x" },
  109. get => { sceneConfig => "02%02x" },
  110. parse => { "052d03(..)(..)(..)" =>
  111. '"group_".hex($1).":scene ".hex($2)."duration ".hex($3)' } },
  112. ZIP_CLIENT => { id => '2e' },
  113. ZIP_ADV_SERVICES => { id => '2f' },
  114. SENSOR_BINARY => { id => '30',
  115. get => { sbStatus => "02" },
  116. parse => { "03300300" => "state:closed",
  117. "033003ff" => "state:open",
  118. "043003(..)(..)"=> 'ZWave_sensorbinaryV2Parse($1,$2)' } },
  119. SENSOR_MULTILEVEL => { id => '31',
  120. get => { smStatus => "04" },
  121. parse => { "..3105(..)(..)(.*)" => 'ZWave_multilevelParse($1,$2,$3)'} },
  122. METER => { id => '32',
  123. set => { meterReset => "05" },
  124. get => { meter => 'ZWave_meterGet("%s")',
  125. meterSupported => "03" },
  126. parse => { "..3202(.*)"=> 'ZWave_meterParse($hash, $1)',
  127. "..3204(.*)"=> 'ZWave_meterSupportedParse($hash, $1)' } },
  128. COLOR_CONTROL => { id => '33',
  129. get => { ccCapability=> '01', # no more args
  130. ccStatus => '03%02x' },
  131. set => { # Forum #36050
  132. rgb => '05050000010002%02x03%02x04%02x', # Forum #44014
  133. wcrgb => '050500%02x01%02x02%02x03%02x04%02x' },
  134. parse => { "043302(..)(..)"=> 'ZWave_ccCapability($1,$2)',
  135. "043304(..)(.*)"=> '"ccStatus_".hex($1).":".hex($2)' } },
  136. ZIP_ADV_CLIENT => { id => '34' },
  137. METER_PULSE => { id => '35' },
  138. BASIC_TARIFF_INFO => { id => '36' },
  139. HRV_STATUS => { id => '37',
  140. get => { hrvStatus => "01%02x",
  141. hrvStatusSupported => "03" },
  142. parse => { "0637020042(....)" =>
  143. 'sprintf("outdoorTemperature: %0.1f C", s2Hex($1)/100)',
  144. "0637020142(....)" =>
  145. 'sprintf("supplyAirTemperature: %0.1f C", s2Hex($1)/100)',
  146. "0637020242(....)" =>
  147. 'sprintf("exhaustAirTemperature: %0.1f C", s2Hex($1)/100)',
  148. "0637020342(....)" =>
  149. 'sprintf("dischargeAirTemperature: %0.1f C",s2Hex($1)/100)',
  150. "0637020442(....)" =>
  151. 'sprintf("indoorTemperature: %0.1f C", s2Hex($1)/100)',
  152. "0537020501(..)" =>
  153. 'sprintf("indoorHumidity: %s %%", hex($1))',
  154. "0537020601(..)" =>
  155. 'sprintf("remainingFilterLife: %s %%", hex($1))',
  156. "033704(..)" =>
  157. 'sprintf("supportedStatus: %s", ZWave_HrvStatus($1))',
  158. } },
  159. THERMOSTAT_HEATING => { id => '38' },
  160. HRV_CONTROL => { id => '39',
  161. set => { bypassOff => "0400",
  162. bypassOn => "04FF",
  163. ventilationRate => "07%02x" },
  164. get => { bypass => "05",
  165. ventilationRate => "08" },
  166. parse => { "033906(..)"=> '($1 eq "00" ? "bypass:off" : '.
  167. '($1 eq "ff" ? "bypass:on" : '.
  168. '"bypass:dim ".hex($1)))',
  169. "033909(..)"=> 'sprintf("ventilationRate: %s",hex($1))' } },
  170. DCP_CONFIG => { id => '3a' },
  171. DCP_MONITOR => { id => '3b' },
  172. METER_TBL_CONFIG => { id => '3c' },
  173. METER_TBL_MONITOR => { id => '3d' },
  174. METER_TBL_PUSH => { id => '3e' },
  175. PREPAYMENT => { id => '3f' },
  176. THERMOSTAT_MODE => { id => '40',
  177. set => { tmOff => "0100",
  178. tmHeating => "0101",
  179. tmEnergySaveHeating => "010b",
  180. tmManual => "011f" },
  181. get => { thermostatMode => "02" },
  182. parse => { "03400300" => "thermostatMode:off",
  183. "0340030b" => "thermostatMode:energySaveHeating",
  184. "03400301" => "thermostatMode:heating",
  185. "0340031f" => "thermostatMode:manual",
  186. "03400100" => "thermostatMode:setTmOff",
  187. "03400101" => "thermostatMode:setTmHeating",
  188. "0340010b" => "thermostatMode:setTmEnergySaveHeating",
  189. "0340011f" => "thermostatMode:setTmManual",
  190. } } ,
  191. PREPAYMENT_ENCAPSULATION => { id => '41' },
  192. THERMOSTAT_OPERATING_STATE=>{ id => '42' },
  193. THERMOSTAT_SETPOINT => { id => '43',
  194. set => { setpointHeating => "010101%02x",
  195. setpointCooling => "010201%02x",
  196. thermostatSetpointSet
  197. => 'ZWave_thermostatSetpointSet($hash, "%s")',
  198. "desired-temp" => # alias
  199. => 'ZWave_thermostatSetpointSet($hash, "%s")'},
  200. get => { setpoint => 'ZWave_thermostatSetpointGet("%s")',
  201. thermostatSetpointSupported => '04' },
  202. parse => { "..4303(.*)" => 'ZWave_thermostatSetpointParse($hash, $1)',
  203. "..4305(.*)" =>
  204. 'ZWave_thermostatSetpointSupportedParse($hash, $1)' } },
  205. THERMOSTAT_FAN_MODE => { id => '44' },
  206. THERMOSTAT_FAN_STATE => { id => '45' },
  207. CLIMATE_CONTROL_SCHEDULE => { id => '46',
  208. set => { ccs => 'ZWave_ccsSet("%s")' ,
  209. ccsOverride => 'ZWave_ccsSetOverride("%s")'},
  210. get => { ccs => 'ZWave_ccsGet("%s")',
  211. ccsAll => 'ZWave_ccsAllGet($hash)',
  212. ccsChanged => "04",
  213. ccsOverride => "07" },
  214. parse => { "..46(..)(.*)" => 'ZWave_ccsParse($1,$2)' }},
  215. THERMOSTAT_SETBACK => { id => '47' },
  216. RATE_TBL_CONFIG => { id => '48' },
  217. RATE_TBL_MONITOR => { id => '49' },
  218. TARIFF_CONFIG => { id => '4a' },
  219. TARIFF_TBL_MONITOR => { id => '4b' },
  220. DOOR_LOCK_LOGGING => { id => '4c' },
  221. NETWORK_MANAGEMANT_BASIC => { id => '4d' },
  222. SCHEDULE_ENTRY_LOCK => { id => '4e', # V1, V2, V3
  223. get => { scheduleEntryLockTypeSupported => '09',
  224. scheduleEntryLockWeekDay => "04%02x%02x",
  225. scheduleEntryLockYearDay => "07%02x%02x",
  226. scheduleEntryLockDailyRepeating => "0e%02x%02x",
  227. scheduleEntryLockTimeOffset => '0b'
  228. },
  229. set => { scheduleEntryLockSet =>
  230. 'ZWave_scheduleEntryLockSet($hash, "%s")',
  231. scheduleEntryLockAllSet =>
  232. 'ZWave_scheduleEntryLockAllSet($hash, "%s")',
  233. scheduleEntryLockWeekDaySet =>
  234. 'ZWave_scheduleEntryLockWeekDaySet($hash, "%s")',
  235. scheduleEntryLockYearDaySet =>
  236. 'ZWave_scheduleEntryLockYearDaySet($hash, "%s")',
  237. scheduleEntryLockTimeOffsetSet =>
  238. 'ZWave_scheduleEntryLockTimeOffsetSet($hash, "%s")',
  239. scheduleEntryLockYearDailyRepeatingSet =>
  240. 'ZWave_scheduleEntryLockDailyRepeatingSet($hash, "%s")'
  241. },
  242. parse => { "..4e0a(.*)" =>
  243. 'ZWave_scheduleEntryLockTypeSupportedParse($hash, $1)',
  244. "..4e05(.{14})" =>
  245. 'ZWave_scheduleEntryLockWeekDayParse($hash, $1)',
  246. "..4e08(.{24})" =>
  247. 'ZWave_scheduleEntryLockYearDayParse($hash, $1)',
  248. "..4e0c(.{6})" =>
  249. 'ZWave_scheduleEntryLockTimeOffsetParse($hash, $1)',
  250. "..4e0f(.{14})" =>
  251. 'ZWave_scheduleEntryLockDailyRepeatingParse($hash, $1)'
  252. }},
  253. ZI_6LOWPAN => { id => '4f' },
  254. BASIC_WINDOW_COVERING => { id => '50',
  255. set => { coveringClose => "0140",
  256. coveringOpen => "0100",
  257. coveringStop => "02" },
  258. parse => { "03500140" => "covering:close",
  259. "03500100" => "covering:open",
  260. "03500200" => "covering:stop",
  261. "03500240" => "covering:stop" } },
  262. MTP_WINDOW_COVERING => { id => '51' },
  263. NETWORK_MANAGEMENT_PROXY => { id => '52' },
  264. NETWORK_SCHEDULE => { id => '53', # V1, Schedule
  265. get => { scheduleSupported => "01",
  266. schedule => "04%02x",
  267. scheduleState => "08"},
  268. set => { scheduleRemove => "06%02x",
  269. schedule => 'ZWave_scheduleSet($hash, "%s")',
  270. scheduleState => "07%02x%02x"},
  271. parse => { "..5302(.*)" => 'ZWave_scheduleSupportedParse($hash, $1)',
  272. "..5305(.*)" => 'ZWave_scheduleParse($hash, $1)',
  273. "..5309(.*)" => 'ZWave_scheduleStateParse($hash, $1)' } },
  274. NETWORK_MANAGEMENT_PRIMARY=>{ id => '54' },
  275. TRANSPORT_SERVICE => { id => '55' },
  276. CRC_16_ENCAP => { id => '56' }, # Parse is handled in the code
  277. APPLICATION_CAPABILITY => { id => '57' },
  278. ZIP_ND => { id => '58' },
  279. ASSOCIATION_GRP_INFO => { id => '59',
  280. get => { associationGroupName => "01%02x",
  281. associationGroupCmdList => "0500%02x" },
  282. parse => { "..5902(..)(.*)"=> '"assocGroupName_".hex($1).":".pack("H*", $2)',
  283. "..5906(..)..(.*)"=> '"assocGroupCmdList_".hex($1).":".$2' } },
  284. DEVICE_RESET_LOCALLY => { id => '5a',
  285. parse => { "025a01" => "deviceResetLocally:yes" } },
  286. CENTRAL_SCENE => { id => '5b',
  287. parse => { "055b03..00(..)" => '"cSceneSet:".hex($1)',
  288. "055b03..01(..)" => '"cSceneDimEnd:".hex($1)',
  289. "055b03..02(..)" => '"cSceneDim:".hex($1)',
  290. "055b03..03(..)" => '"cSceneDouble:".hex($1)',
  291. "055b03..0([4-6])(..)" => '"cSceneMultiple_".
  292. (hex($1)-1).":".hex($2)'} },
  293. IP_ASSOCIATION => { id => '5c' },
  294. ANTITHEFT => { id => '5d' },
  295. ZWAVEPLUS_INFO => { id => '5e',
  296. get => { zwavePlusInfo=>"01"},
  297. parse => { "095e02(..)(..)(..)(....)(....)"
  298. => 'ZWave_plusInfoParse($1,$2,$3,$4,$5)'} },
  299. ZIP_GATEWAY => { id => '5f' },
  300. MULTI_CHANNEL => { id => '60', # Version 2, aka MULTI_INSTANCE
  301. set => { mcCreateAll => 'ZWave_mcCreateAll($hash,"")' },
  302. get => { mcEndpoints => "07",
  303. mcCapability=> "09%02x"},
  304. parse => { "^0[45]6008(..)(..)" => '"mcEndpoints:total ".hex($2).'.
  305. '(hex($1)&0x80 ? ", dynamic":"").'.
  306. '(hex($1)&0x40 ? ", identical":", different")',
  307. "^..600a(.*)"=> 'ZWave_mcCapability($hash, $1)' },
  308. init => { ORDER=>49, CMD => '"set $NAME mcCreateAll"' } },
  309. ZIP_PORTAL => { id => '61' },
  310. DOOR_LOCK => { id => '62', # V2
  311. set => { doorLockOperation => 'ZWave_DoorLockOperationSet($hash, "%s")',
  312. doorLockConfiguration =>
  313. 'ZWave_DoorLockConfigSet($hash, "%s")' },
  314. get => { doorLockOperation => '02',
  315. doorLockConfiguration => '05'},
  316. parse => { "..6203(.*)" => 'ZWave_DoorLockOperationReport($hash, $1)',
  317. "..6206(.*)" => 'ZWave_DoorLockConfigReport($hash, $1)'} },
  318. USER_CODE => { id => '63',
  319. set => { userCode => 'ZWave_userCodeSet("%s")' },
  320. get => { userCode => "02%02x" ,
  321. userCodeUsersNumber => "04"},
  322. parse => { "..6303(..)(..)(.*)" =>
  323. 'sprintf("userCode:id %d status %d code %s", $1, $2, $3)' ,
  324. "..6305(..)" => '"userCodeUsersNumber:".hex($1)'}
  325. },
  326. APPLIANCE => { id => '64' },
  327. DMX => { id => '65' },
  328. BARRIER_OPERATOR => { id => '66' },
  329. CONFIGURATION => { id => '70',
  330. set => { configDefault=>"04%02x80",
  331. configByte => "04%02x01%02x",
  332. configWord => "04%02x02%04x",
  333. configLong => "04%02x04%08x" },
  334. get => { config => "05%02x",
  335. configAll => 'ZWave_configAllGet($hash)' },
  336. parse => { "^..70..(..)(..)(.*)" => 'ZWave_configParse($hash,$1,$2,$3)'} },
  337. ALARM => { id => '71',
  338. set => {
  339. alarmnotification => 'ZWave_ALARM_06_Set("%s")', # >=V2
  340. },
  341. get => {
  342. alarmEventSupported => 'ZWave_ALARM_01_Get("%s")', # >=V3
  343. alarm => 'ZWave_ALARM_04_Get(1, "%s")', # >=V1
  344. alarmWithType => 'ZWave_ALARM_04_Get(2, "%s")', # >=V2
  345. alarmWithTypeEvent => 'ZWave_ALARM_04_Get(3, "%s")', # >=V3
  346. alarmTypeSupported => "07", # >=V2
  347. },
  348. parse => {
  349. "..7102(.*)" => 'ZWave_ALARM_02_Report($1)', # >=V3
  350. "..7105(..)(..)(.*)" =>
  351. 'ZWave_ALARM_05_Report($hash, $1, $2, $3)', # >=V1
  352. "..7108(.*)" => 'ZWave_ALARM_08_Report($1)', # >=V2
  353. },
  354. },
  355. MANUFACTURER_SPECIFIC => { id => '72',
  356. get => { model => "04" },
  357. parse => { "0[8a]7205(....)(....)(....)(.*)"
  358. => 'ZWave_mfsParse($hash,$1,$2,$3,0)',
  359. "0[8a]7205(....)(....)(.{4})(.*)"
  360. => 'ZWave_mfsParse($hash,$1,$2,$3,1)',
  361. "0[8a]7205(....)(.{4})(.{4})(.*)"
  362. => 'ZWave_mfsParse($hash,$1,$2,$3,2)' },
  363. init => { ORDER=>49, CMD => '"get $NAME model"' } },
  364. POWERLEVEL => { id => '73',
  365. set => { powerlevel => "01%02x%02x",
  366. powerlevelTest => "04%02x%02x%04x" },
  367. get => { powerlevel => "02",
  368. powerlevelTest => "05" },
  369. parse => { "047303(..)(..)" =>
  370. '"powerlvl:current ".hex($1)." remain ".hex($2)',
  371. "067306(..)(..)(....)" =>
  372. '"powerlvlTest:node ".hex($1)." status ".hex($2).
  373. " frameAck ".hex($3)',} },
  374. PROTECTION => { id => '75',
  375. set => { protectionOff => "0100",
  376. protectionSeq => "0101",
  377. protectionOn => "0102",
  378. protectionBytes => "01%02x%02x" },
  379. get => { protection => "02" },
  380. parse => { "03750300" => "protection:off",
  381. "03750301" => "protection:seq",
  382. "03750302" => "protection:on",
  383. "047503(..)(..)" => 'ZWave_protectionParse($1, $2)'} },
  384. LOCK => { id => '76' },
  385. NODE_NAMING => { id => '77',
  386. set => { name => '(undef, "0100".unpack("H*", "%s"))',
  387. location => '(undef, "0400".unpack("H*", "%s"))' },
  388. get => { name => '02',
  389. location => '05' },
  390. parse => { '..770300(.*)' => '"name:".pack("H*", $1)',
  391. '..770600(.*)' => '"location:".pack("H*", $1)' } },
  392. FIRMWARE_UPDATE_MD => { id => '7a' },
  393. GROUPING_NAME => { id => '7b' },
  394. REMOTE_ASSOCIATION_ACTIVATE=>{id => '7c' },
  395. REMOTE_ASSOCIATION => { id => '7d' },
  396. BATTERY => { id => '80',
  397. get => { battery => "02" },
  398. parse => { "0.8003(..)"=> '"battery:".($1 eq "ff" ? "low":hex($1)." %")'} },
  399. CLOCK => { id => '81',
  400. get => { clock => "05" },
  401. set => { clock => 'ZWave_clockSet()' },
  402. parse => { "028105" => "clock:get",
  403. "048106(..)(..)"=> 'ZWave_clockParse($1,$2)' }},
  404. HAIL => { id => '82',
  405. parse => { "028201" => "hail:01"}},
  406. WAKE_UP => { id => '84',
  407. set => { wakeupInterval => "04%06x%02x",
  408. wakeupNoMoreInformation => "08" },
  409. get => { wakeupInterval => "05",
  410. wakeupIntervalCapabilities => "09" },
  411. parse => { "..8404(.*)"=> '"cmdSet:wakeupInterval $1"',
  412. "..8405" => 'cmdGet:wakeupInterval',
  413. "..8406(......)(..)" =>
  414. '"wakeupReport:interval ".hex($1)." target ".hex($2)',
  415. "..8407" => 'wakeup:notification',
  416. "..8408" => 'cmdSet:wakeupNoMoreInformation',
  417. "..8409" => 'cmdGet:wakeupIntervalCapabilities',
  418. "..840a(......)(......)(......)(......)" =>
  419. '"wakeupIntervalCapabilitiesReport:min ".hex($1).'.
  420. '" max ".hex($2)." default ".hex($3)." step ".hex($4)'},
  421. init => { ORDER=>11, CMD => '"set $NAME wakeupInterval 86400 $CTRLID"' } },
  422. ASSOCIATION => { id => '85',
  423. set => { associationAdd => "01%02x%02x*",
  424. associationDel => "04%02x%02x*" },
  425. get => { association => "02%02x",
  426. associationGroups => "05",
  427. associationAll => 'ZWave_associationAllGet($hash,"")' },
  428. parse => { "..8503(..)(..)..(.*)" => 'ZWave_assocGroup($homeId,$1,$2,$3)',
  429. "..8506(..)" => '"assocGroups:".hex($1)' },
  430. init => { ORDER=>10, CMD=> '"set $NAME associationAdd 1 $CTRLID"' } },
  431. VERSION => { id => '86',
  432. get => { version => "11",
  433. versionClass => 'ZWave_versionClassGet($hash, "%s")',
  434. versionClassAll => 'ZWave_versionClassAllGet($hash)'},
  435. parse => { "028611" => "cmdGet:version",
  436. "078612(..........)" => 'sprintf("version:Lib %d Prot '.
  437. '%d.%02d App %d.%d", unpack("C*",pack("H*","$1")))',
  438. "098612(..............)" => 'sprintf("version:Lib %d Prot '.
  439. '%d.%02d App %d.%d HW %d FWCounter %d",'.
  440. 'unpack("C*",pack("H*","$1")))',
  441. "0b8612(..................)" => 'sprintf("version:Lib %d Prot '.
  442. '%d.%02d App %d.%d HW %d FWCounter %d FW %d.%d",'.
  443. 'unpack("C*",pack("H*","$1")))',
  444. "048614(..)(..)" => '"versionClass_".hex($1).":".hex($2)' },
  445. init => { ORDER=> 1, CMD => '"get $NAME versionClassAll"' } },
  446. INDICATOR => { id => '87',
  447. set => { indicatorOff => "0100",
  448. indicatorOn => "01FF",
  449. indicatorDim => "01%02x" },
  450. get => { indicatorStatus => "02", },
  451. parse => { "038703(..)" => '($1 eq "00" ? "indState:off" :
  452. ($1 eq "ff" ? "indState:on" :
  453. "indState:dim ".hex($1)))'} },
  454. PROPRIETARY => { id => '88' },
  455. LANGUAGE => { id => '89' },
  456. TIME => { id => '8a' ,
  457. set => { timeOffset => 'ZWave_timeOffsetSet($hash, "%s")' },
  458. get => { time => "01",
  459. date => "03",
  460. timeOffset => "06" },
  461. parse => { "..8a04(.*)" => 'ZWave_dateReport($hash,$1)',
  462. "..8a02(.*)" => 'ZWave_timeReport($hash,$1)',
  463. "..8a07(.*)" => 'ZWave_timeOffsetReport($hash,$1)'} },
  464. TIME_PARAMETERS => { id => '8b',
  465. set => { timeParameters => 'ZWave_timeParametersSet($hash, "%s")'},
  466. get => { timeParameters => "02"},
  467. parse => { "..8b02" => 'timeParametersGet',
  468. "..8b03(.*)" => 'ZWave_timeParametersReport($hash, $1)' } },
  469. GEOGRAPHIC_LOCATION => { id => '8c' },
  470. COMPOSITE => { id => '8d' },
  471. MULTI_CHANNEL_ASSOCIATION=> { id => '8e', # aka MULTI_INSTANCE_ASSOCIATION
  472. set => { mcaAdd => "01%02x%02x*",
  473. mcaDel => "04%02x*" },
  474. get => { mca => "02%02x",
  475. mcaGroupings=> "05",
  476. mcaAll => 'ZWave_mcaAllGet($hash,"")' },
  477. parse => { "..8e03(..)(..)..(.*)" => 'ZWave_mcaReport($homeId,$1,$2,$3)',
  478. "..8e06(.*)"=> '"mcaGroups:".hex($1)' } },
  479. MULTI_CMD => { id => '8f' }, # Handled in Parse
  480. ENERGY_PRODUCTION => { id => '90' },
  481. MANUFACTURER_PROPRIETARY => { id => '91' }, # see also zwave_deviceSpecial
  482. SCREEN_MD => { id => '92' },
  483. SCREEN_ATTRIBUTES => { id => '93' },
  484. SIMPLE_AV_CONTROL => { id => '94' },
  485. AV_CONTENT_DIRECTORY_MD => { id => '95' },
  486. AV_RENDERER_STATUS => { id => '96' },
  487. AV_CONTENT_SEARCH_MD => { id => '97' },
  488. SECURITY => { id => '98',
  489. set => { "secSupportedReport" => 'ZWave_sec($hash, "02")', },
  490. parse => { "..9803(.*)"=> 'ZWave_secSupported($hash, $1)',
  491. "..9840" => 'ZWave_secNonceRequestReceived($hash)',
  492. "..9880(.*)"=> 'ZWave_secNonceReceived($hash, $1)',
  493. "..9881(.*)"=> 'ZWave_secDecrypt($hash, $1, 0)',
  494. "..98c1(.*)"=> 'ZWave_secDecrypt($hash, $1, 1)' } },
  495. AV_TAGGING_MD => { id => '99' },
  496. IP_CONFIGURATION => { id => '9a' },
  497. ASSOCIATION_COMMAND_CONFIGURATION
  498. => { id => '9b' },
  499. SENSOR_ALARM => { id => '9c',
  500. get => { alarm => "01%02x" },
  501. parse => { "..9c02(..)(..)(..)(....)" =>
  502. '"alarm_type_$2:level ".hex($3)." node ".hex($1)." seconds ".hex($4)'} },
  503. SILENCE_ALARM => { id => '9d' },
  504. SENSOR_CONFIGURATION => { id => '9e' },
  505. MARK => { id => 'ef' },
  506. NON_INTEROPERABLE => { id => 'f0' },
  507. );
  508. my %zwave_classVersion = (
  509. dimWithDuration => { min => 2 },
  510. meterReset => { min => 2 },
  511. meterSupported => { min => 2 },
  512. wakeupIntervalCapabilities => { min => 2 },
  513. alarmTypeSupported => { min => 2 },
  514. alarmnotification => { min => 2 },
  515. alarmWithType => { min => 2 },
  516. alarmWithTypeEvent => { min => 3 },
  517. alarmEventSupported => { min => 3 },
  518. );
  519. my %zwave_cmdArgs = (
  520. set => {
  521. dim => "slider,0,1,99",
  522. indicatorDim => "slider,0,1,99",
  523. rgb => "colorpicker,RGB",
  524. configRGBLedColorForTesting => "colorpicker,RGB", # Aeon SmartSwitch 6
  525. },
  526. get => {
  527. },
  528. parse => {
  529. }
  530. );
  531. use vars qw(%zwave_parseHook);
  532. #my %zwave_parseHook; # nodeId:regexp => fn, used by assocRequest
  533. my %zwave_modelConfig;
  534. my %zwave_modelIdAlias = ( "0175-0004-000a" => "devolo_Siren",
  535. "010f-0301-1001" => "Fibaro_FGRM222",
  536. "010f-0302-1000" => "Fibaro_FGRM222", # FGR 222
  537. "010f-0203-1000" => "Fibaro_FGS223",
  538. "0108-0004-000a" => "Philio_PSE02", # DLink DCH-Z510
  539. "013c-0004-000a" => "Philio_PSE02", # Zipato Siren
  540. "0115-0100-0102" => "ZME_KFOB" );
  541. # Patching certain devices.
  542. our %zwave_deviceSpecial;
  543. %zwave_deviceSpecial = (
  544. devolo_Siren => {
  545. ALARM => {
  546. set => { alarmSmokeOn =>"050000000001010000",
  547. alarmEmergencyOn=>"050000000007010000",
  548. alarmFireOn =>"05000000000a020000",
  549. alarmAmbulanceOn=>"05000000000a030000",
  550. alarmPoliceOn =>"05000000000a010000",
  551. alarmSilentOn =>"05000000000afe0000",
  552. alarmDoorchimeOn=>"050000000006160000",
  553. alarmArmOn =>"050000000006030000",
  554. alarmDisarmOn =>"050000000006040000",
  555. alarmBeepOn =>"05000000000a050000" } } },
  556. Fibaro_FGRM222 => {
  557. MANUFACTURER_PROPRIETARY => {
  558. set => { positionSlat=>"010f26010100%02x",
  559. positionBlinds=>"010f260102%02x00"},
  560. get => { position=>"010f2602020000", },
  561. parse => { "0891010f260303(..)(..)" =>
  562. 'sprintf("position:Blind %d Slat %d",hex($1),hex($2))',
  563. "0891010f260302(..)00" =>'"position:".hex($1)' } } },
  564. Fibaro_FGS223 => {
  565. ASSOCIATION => {
  566. init => {ORDER=>50, CMD => '"set $NAME associationDel 1 $CTRLID"'} },
  567. MULTI_CHANNEL_ASSOCIATION => {
  568. init => {ORDER=>51, CMD => '"set $NAME mcaAdd 1 0 $CTRLID 1"'} } },
  569. Philio_PSE02 => {
  570. ALARM => {
  571. set => { alarmEmergencyOn=>"050000000007010000",
  572. alarmFireOn =>"05000000000a020000",
  573. alarmAmbulanceOn=>"05000000000a030000",
  574. alarmPoliceOn =>"05000000000a010000",
  575. alarmDoorchimeOn=>"050000000006160000",
  576. alarmBeepOn =>"05000000000a050000" } } },
  577. ZME_KFOB => {
  578. ZWAVEPLUS_INFO => {
  579. # Example only. ORDER must be >= 50
  580. init => { ORDER=>50, CMD => '"get $NAME zwavePlusInfo"' } } }
  581. );
  582. my $zwave_cryptRijndael = 0;
  583. my $zwave_lastHashSent;
  584. my (%zwave_link, %zwave_img);
  585. my $zwave_helpSites = "alliance,pepper";
  586. # standard definitions for regular expression
  587. # naming scheme: p<number of returned groups>_name
  588. my $p1_m = "([0-5][0-9])"; # mm 00-59
  589. my $p2_hm = "([01][0-9]|2[0-3]):([0-5][0-9])"; # hh:mm
  590. my $p3_hms = "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])"; # hh:mm:ss
  591. my $p1_b = "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])"; # byte:0-255, 1-3 digits
  592. my $p1_wd = "(mon|tue|wed|thu|fri|sat|sun)"; # 3 letter weekday
  593. # ymd: yyyy-mm-dd, yyyy 4 digits, mm 2 digits 01-12, dd 2 digits 01-31
  594. my $p3_ymd = "([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])";
  595. sub
  596. ZWave_Initialize($)
  597. {
  598. my ($hash) = @_;
  599. $hash->{Match} = ".*";
  600. $hash->{SetFn} = "ZWave_Set";
  601. $hash->{GetFn} = "ZWave_Get";
  602. $hash->{DefFn} = "ZWave_Define";
  603. $hash->{UndefFn} = "ZWave_Undef";
  604. $hash->{AttrFn} = "ZWave_Attr";
  605. $hash->{ParseFn} = "ZWave_Parse";
  606. no warnings 'qw';
  607. my @attrList = qw(
  608. IODev
  609. WNMI_delay
  610. classes
  611. do_not_notify:noArg
  612. dummy:noArg
  613. eventForRaw
  614. extendedAlarmReadings:0,1,2
  615. ignore:noArg
  616. ignoreDupMsg:noArg
  617. neighborListPos
  618. noExplorerFrames:noArg
  619. noWakeupForApplicationUpdate:noArg
  620. secure_classes
  621. showtime:noArg
  622. vclasses
  623. useMultiCmd:noArg
  624. zwaveRoute
  625. );
  626. use warnings 'qw';
  627. $hash->{AttrList} = join(" ", @attrList)." ".$readingFnAttributes;
  628. map { $zwave_id2class{lc($zwave_class{$_}{id})} = $_ } keys %zwave_class;
  629. $hash->{FW_detailFn} = "ZWave_fhemwebFn";
  630. $hash->{FW_deviceOverview} = 1;
  631. eval { require Crypt::Rijndael; };
  632. if($@) {
  633. Log 3, "ZWave: cannot load Crypt::Rijndael, SECURITY class disabled";
  634. } else {
  635. $zwave_cryptRijndael = 1;
  636. }
  637. ################
  638. # Read in the pepper/alliance translation table
  639. for my $n (split(",", $zwave_helpSites)) {
  640. my $fn = $attr{global}{modpath}."/FHEM/lib/zwave_${n}links.csv.gz";
  641. my $gz = gzopen($fn, "rb");
  642. if($gz) {
  643. my $line;
  644. while($gz->gzreadline($line)) {
  645. chomp($line);
  646. my @a = split(",",$line);
  647. $zwave_link{$n}{lc($a[0])} = $a[1];
  648. $zwave_img{$n}{lc($a[0])} = $a[2];
  649. }
  650. $gz->gzclose();
  651. } else {
  652. Log 3, "Can't open $fn: $!";
  653. }
  654. }
  655. # Create cache directory
  656. my $fn = $attr{global}{modpath}."/www/deviceimages";
  657. if(! -d $fn) { mkdir($fn) || Log 3, "Can't create $fn"; }
  658. $fn .= "/zwave";
  659. if(! -d $fn) { mkdir($fn) || Log 3, "Can't create $fn"; }
  660. }
  661. #############################
  662. my $zw_init_ordered;
  663. sub
  664. ZWave_Define($$)
  665. {
  666. my ($hash, $def) = @_;
  667. my @a = split("[ \t][ \t]*", $def);
  668. my $name = shift @a;
  669. my $type = shift @a; # always ZWave
  670. my $u = "wrong syntax for $name: define <name> ZWave homeId id [classes]";
  671. return $u if(int(@a) < 2 || int(@a) > 3);
  672. my $homeId = lc(shift @a);
  673. my $id = shift @a;
  674. return "define $name: wrong homeId ($homeId): need an 8 digit hex value"
  675. if( ($homeId !~ m/^[a-f0-9]{8}$/i) );
  676. return "define $name: wrong id ($id): need a number"
  677. if( ($id !~ m/^\d+$/i) );
  678. $hash->{ZWaveSubDevice} = ($id > 255 ? "yes" : "no");
  679. $id = sprintf("%0*x", ($id > 255 ? 4 : 2), $id);
  680. $hash->{homeId} = $homeId;
  681. $hash->{nodeIdHex} = $id;
  682. $modules{ZWave}{defptr}{"$homeId $id"} = $hash;
  683. my $proposed;
  684. if($init_done) { # Use the right device while inclusion is running
  685. for my $p (devspec2array("TYPE=ZWDongle|ZWCUL|FHEM2FHEM")) {
  686. $proposed = $p if($defs{$p}{homeId} && $defs{$p}{homeId} eq $homeId);
  687. }
  688. }
  689. AssignIoPort($hash, $proposed);
  690. $hash->{".vclasses"} = {};
  691. if(@a) { # Autocreate: set the classes, execute the init calls
  692. asyncOutput($hash->{IODev}{addCL}, "created $name") if($hash->{IODev});
  693. ZWave_SetClasses($homeId, $id, undef, $a[0]);
  694. }
  695. if($init_done) {
  696. ZWave_setEndpoints($hash);
  697. } else {
  698. if(!$zw_init_ordered) {
  699. $zw_init_ordered = 1;
  700. InternalTimer(1, "ZWave_setEndpoints", $hash, 0);
  701. }
  702. }
  703. return undef;
  704. }
  705. sub
  706. ZWave_setEndpoints($)
  707. {
  708. my $mp = $modules{ZWave}{defptr};
  709. for my $k (sort keys %{$mp}) {
  710. my $h = $mp->{$k};
  711. delete($h->{endpointParent});
  712. delete($h->{endpointChildren});
  713. }
  714. for my $k (sort keys %{$mp}) {
  715. my $h = $mp->{$k};
  716. next if($h->{nodeIdHex} !~ m/(..)(..)/);
  717. my ($root, $lid) = ($1, $2);
  718. my $rd = $mp->{$h->{homeId}." ".$root};
  719. $h->{endpointParent} = ($rd ? $rd->{NAME} : "unknown");
  720. $h->{".vclasses"} = ($rd ? $rd->{".vclasses"} : {} );
  721. if($rd) {
  722. if($rd->{endpointChildren}) {
  723. $rd->{endpointChildren} .= ",".$h->{NAME};
  724. } else {
  725. $rd->{endpointChildren} = $h->{NAME};
  726. }
  727. }
  728. }
  729. }
  730. sub
  731. ZWave_initFromModelfile($$$)
  732. {
  733. my ($name, $ctrlId, $cfg) = @_;
  734. my @res;
  735. ZWave_configParseModel($cfg) if(!$zwave_modelConfig{$cfg});
  736. my $mc = $zwave_modelConfig{$cfg};
  737. return @res if(!$mc);
  738. for my $grp (keys %{$mc->{group}}) {
  739. next if($grp eq '1');
  740. next if($mc->{group}{$grp} !~ m/auto="true"/);
  741. push @res, "set $name associationAdd $grp $ctrlId";
  742. }
  743. return @res;
  744. }
  745. sub
  746. ZWave_execInits($$;$)
  747. {
  748. my ($hash, $min, $cfg) = @_; # min = 50 for model-specific stuff
  749. my $cl = $attr{$hash->{NAME}}{classes};
  750. return "" if(!$cl);
  751. my @clList = split(" ", $cl);
  752. my (@initList, %seen);
  753. foreach my $cl (@clList) {
  754. next if($seen{$cl});
  755. $seen{$cl} = 1;
  756. my $ptr = ZWave_getHash($hash, $cl, "init");
  757. $ptr->{CC} = $cl if($ptr);
  758. push @initList, $ptr if($ptr && $ptr->{ORDER} >= $min);
  759. }
  760. my $NAME = $hash->{NAME};
  761. my $iodev = $hash->{IODev};
  762. my $homeReading = ReadingsVal($iodev->{NAME}, "homeId", "") if($iodev);
  763. my $CTRLID=hex($1) if($homeReading && $homeReading =~ m/CtrlNodeIdHex:(..)/);
  764. my @cmd;
  765. foreach my $i (sort { $a->{ORDER}<=>$b->{ORDER} } @initList) {
  766. my $version = $hash->{".vclasses"}{$i->{CC}};
  767. push @cmd, eval $i->{CMD} if(!defined($version) || $version > 0);
  768. }
  769. push @cmd, ZWave_initFromModelfile($hash->{NAME}, $CTRLID, $cfg)
  770. if($cfg); # model specific init, called from "get model"
  771. foreach my $cmd (@cmd) {
  772. my $ret = AnalyzeCommand(undef, $cmd);
  773. Log 1, "ZWAVE INIT: $cmd: $ret" if ($ret);
  774. }
  775. return "";
  776. }
  777. sub
  778. ZWave_neighborList($)
  779. {
  780. my ($hash) = @_;
  781. my $id = $hash->{nodeIdHex};
  782. # GET_ROUTING_TABLE_LINE, no dead links, include routing neighbors
  783. IOWrite($hash, "", "0080${id}0100");
  784. no strict "refs";
  785. my $iohash = $hash->{IODev};
  786. my $fn = $modules{$iohash->{TYPE}}{ReadAnswerFn};
  787. my ($err, $data) = &{$fn}($iohash, "neighborList", "^0180") if($fn);
  788. use strict "refs";
  789. return $err if($err);
  790. $data =~ s/^0180//;
  791. $data = zwlib_parseNeighborList($iohash, $data);
  792. readingsSingleUpdate($hash, "neighborList", $data, 1) if($hash);
  793. return $data;
  794. }
  795. ###################################
  796. sub
  797. ZWave_Cmd($$@)
  798. {
  799. my ($type, $hash, @a) = @_;
  800. return "no $type argument specified" if(int(@a) < 2);
  801. my $name = shift(@a);
  802. my $cmd = shift(@a);
  803. # Collect the commands from the distinct classes
  804. my %cmdList;
  805. my $classes = AttrVal($name, "classes", "");
  806. foreach my $cl (split(" ", $classes)) {
  807. my $ptr = ZWave_getHash($hash, $cl, $type);
  808. next if(!$ptr);
  809. foreach my $k (keys %{$ptr}) {
  810. if(!$cmdList{$k}) {
  811. $cmdList{$k}{fmt} = $ptr->{$k};
  812. $cmdList{$k}{id} = $zwave_class{$cl}{id};
  813. }
  814. }
  815. }
  816. my $id = $hash->{nodeIdHex};
  817. my $isMc = ($id =~ m/(....)/);
  818. if(!$isMc) {
  819. if($type eq "set") {
  820. $cmdList{neighborUpdate} = { fmt=>"48$id", id=>"" };
  821. $cmdList{returnRouteAdd} = { fmt=>"46$id%02x", id=>"" };
  822. $cmdList{returnRouteDel} = { fmt=>"47$id", id=>"" };
  823. my $iohash = $hash->{IODev};
  824. if($iohash && ReadingsVal($iohash->{NAME}, "sucNodeId","no") ne "no") {
  825. $cmdList{sucRouteAdd} = { fmt=>"51$id", id=>"" };
  826. $cmdList{sucRouteDel} = { fmt=>"55$id", id=>"" };
  827. }
  828. }
  829. $cmdList{neighborList}{fmt} = "x" if($type eq "get"); # Add meta command
  830. }
  831. if($type eq "set" && $cmd eq "rgb") {
  832. if($a[0] && $a[0] =~ m/^[0-9A-F]+$/i && $a[0] =~ /^(..)(..)(..)$/) {
  833. @a = (hex($1), hex($2), hex($3));
  834. } else {
  835. return "set rgb: a 6-digit hex number is required";
  836. }
  837. }
  838. if(!$cmdList{$cmd}) {
  839. my @list;
  840. my $mc = ReadingsVal($hash->{NAME}, "modelConfig", "");
  841. foreach my $lcmd (sort keys %cmdList) {
  842. if($mc && $zwave_cmdArgs{$type}{"$mc$lcmd"}) {
  843. push @list, "$lcmd:".$zwave_cmdArgs{$type}{"$mc$lcmd"};
  844. } elsif($zwave_cmdArgs{$type}{$lcmd}) {
  845. push @list, "$lcmd:$zwave_cmdArgs{$type}{$lcmd}";
  846. } elsif($cmdList{$lcmd}{fmt} !~ m/%/) {
  847. push @list, "$lcmd:noArg";
  848. } else {
  849. push @list, $lcmd;
  850. }
  851. }
  852. my $list = join(" ",@list);
  853. if($type eq "set") {
  854. unshift @a, $name, $cmd;
  855. return SetExtensions($hash, $list, @a);
  856. } else {
  857. return "Unknown argument $cmd, choose one of $list";
  858. }
  859. }
  860. SetExtensionsCancel($hash) if($type eq "set");
  861. return ZWave_neighborList($hash) if($cmd eq "neighborList");
  862. ################################
  863. # ZW_SEND_DATA,nodeId,CMD,ACK|AUTO_ROUTE
  864. my $cmdFmt = $cmdList{$cmd}{fmt};
  865. my $cmdId = $cmdList{$cmd}{id};
  866. # 0x05=AUTO_ROUTE+ACK, 0x20: ExplorerFrames
  867. my $nArg = 0;
  868. if($cmdFmt =~ m/%/) {
  869. my @ca = split("%", $cmdFmt);
  870. $nArg = int(@ca)-1;
  871. }
  872. my $parTxt = ($nArg == 0 ? "no parameter" :
  873. ($nArg == 1 ? "one parameter" :
  874. "$nArg parameters"));
  875. if($cmdFmt =~ m/^(.*)\*$/) {
  876. $cmdFmt = $1;
  877. return "$type $cmd needs at least $parTxt" if($nArg > int(@a));
  878. $cmdFmt .= ("%02x" x (int(@a)-$nArg));
  879. } elsif($cmdFmt =~ m/%s/) { # vararg for functions
  880. $nArg = 0 if(!@a);
  881. @a = (join(" ", @a));
  882. } else {
  883. return "$type $cmd needs $parTxt" if($nArg != int(@a));
  884. }
  885. if($cmdFmt !~ m/%s/ && $cmd !~ m/^config/) {
  886. for(my $i1 = 0; $i1<int(@a); $i1++) {
  887. return "Error: $a[$i1] is not a decimal number"
  888. if($a[$i1] !~ m/^[-\d]+$/);
  889. }
  890. }
  891. if($cmd =~ m/^config/ && $cmd ne "configAll") {
  892. my ($err, $lcmd) =
  893. ZWave_configCheckParam($hash, $type, $cmd, $cmdFmt, @a);
  894. return $err if($err);
  895. $cmdFmt = $lcmd;
  896. } else {
  897. $cmdFmt = sprintf($cmdFmt, @a) if($nArg);
  898. $@ = undef;
  899. my ($err, $ncmd) = eval($cmdFmt) if($cmdFmt !~ m/^\d/);
  900. return $err if($err);
  901. return $@ if($@);
  902. $cmdFmt = $ncmd if(defined($ncmd));
  903. return "" if($ncmd && $ncmd eq "EMPTY"); # configAll
  904. }
  905. Log3 $name, 3, "ZWave $type $name $cmd ".join(" ", @a);
  906. my ($baseClasses, $baseHash) = ($classes, $hash);
  907. if($id =~ m/(..)(..)/) { # Multi-Channel, encapsulate
  908. my ($baseId,$ch) = ($1, $2);
  909. $id = $baseId;
  910. $cmdFmt = "0d00$ch$cmdId$cmdFmt";
  911. $cmdId = "60"; # MULTI_CHANNEL
  912. $baseHash = $modules{ZWave}{defptr}{"$hash->{homeId} $baseId"};
  913. $baseClasses = AttrVal($baseHash->{NAME}, "classes", "");
  914. }
  915. my $data;
  916. if(!$cmdId) {
  917. $data = $cmdFmt;
  918. $data .= ZWave_callbackId($baseHash);
  919. } else {
  920. my $len = sprintf("%02x", length($cmdFmt)/2+1);
  921. my $cmdEf = (AttrVal($name, "noExplorerFrames", 0) == 0 ? "25" : "05");
  922. $data = "13$id$len$cmdId${cmdFmt}$cmdEf"; # 13==SEND_DATA
  923. $data .= ZWave_callbackId($baseHash);
  924. }
  925. if($type eq "get" && $hash->{CL} && !ZWave_isWakeUp($hash)) {
  926. if(!$hash->{asyncGet}) { # Wait for the result for frontend cmd
  927. my $tHash = { hash=>$hash, CL=>$hash->{CL}, re=>"^000400${id}..$cmdId"};
  928. $hash->{asyncGet} = $tHash;
  929. InternalTimer(gettimeofday()+4, sub {
  930. asyncOutput($tHash->{CL}, "Timeout reading answer for $cmd");
  931. delete($hash->{asyncGet});
  932. }, $tHash, 0);
  933. }
  934. }
  935. if ($data =~ m/(......)(....)(.*)(....)/) {
  936. my $cc_cmd=$2;
  937. my $payload=$3;
  938. #check message here for needed encryption (SECURITY)
  939. if(ZWave_secIsSecureClass($hash, $cc_cmd)) {
  940. ZWave_secStart($hash);
  941. # message stored in hash, will be processed when nonce arrives
  942. my $cmd2 = "$type $name $cmd";
  943. $cmd2 .= " ".join(" ", @a) if(@a);
  944. ZWave_secPutMsg($hash, $cc_cmd . $payload, $cmd2);
  945. ZWave_secAddToSendStack($baseHash, '9840');
  946. return;
  947. }
  948. }
  949. my $r = ZWave_addToSendStack($baseHash, $type, $data);
  950. return (AttrVal($name,"verbose",3) > 2 ? $r : undef) if($r);
  951. if($type ne "get") {
  952. if(!$cmdId) {
  953. ZWave_processSendStack($baseHash, "next");
  954. }
  955. $cmd .= " ".join(" ", @a) if(@a);
  956. readingsSingleUpdate($hash, "state", $cmd, 1);
  957. }
  958. return undef;
  959. }
  960. sub
  961. ZWave_SCmd($$@)
  962. {
  963. my ($type, $hash, @a) = @_;
  964. if($hash->{secInProgress} && !(@a < 2 || $a[1] eq "?")) {
  965. my %h = ( T => $type, A => \@a );
  966. push @{$hash->{secStack}}, \%h;
  967. return ($type eq "get" ?
  968. "Secure operation in progress, executing in background" : "");
  969. }
  970. return ZWave_Cmd($type, $hash, @a);
  971. }
  972. sub ZWave_Set($@) { return ZWave_SCmd("set", shift, @_); }
  973. sub ZWave_Get($@) { return ZWave_SCmd("get", shift, @_); }
  974. # returns supported Parameters by hrvStatus
  975. sub
  976. ZWave_HrvStatus($)
  977. {
  978. my ($p) = @_;
  979. $p = hex($p);
  980. my @hrv_status = ( "outdoorTemperature", "supplyAirTemperature",
  981. "exhaustAirTemperature", "dischargeAirTemperature",
  982. "indoorTemperature", "indoorHumidity",
  983. "remainingFilterLife" );
  984. my @l;
  985. for(my $i=0; $i < 7; $i++) {
  986. push @l, "$i = $hrv_status[$i]" if($p & (1<<$i));
  987. }
  988. return join("\n", @l);
  989. }
  990. sub
  991. ZWave_ccCapability($$)
  992. {
  993. my ($l,$h) = @_;
  994. my @names = ("WarmWhite","ColdWhite","Red","Green",
  995. "Blue","Amber","Cyan","Purple","Indexed");
  996. my $x = hex($l)+256*hex($h);
  997. my @ret = "ccCapability:";
  998. for(my $i=0; $i<int(@names); $i++) {
  999. push @ret,$names[$i] if($x & (1<<$i));
  1000. }
  1001. return join(" ",@ret);
  1002. }
  1003. sub
  1004. ZWave_scheduleEntryLockSet ($$)
  1005. {
  1006. my ($hash, $arg) = @_;
  1007. my $name = $hash->{NAME};
  1008. return ("wrong format, see commandref", "")
  1009. if($arg !~ m/([0-2]?[0-9]?[0-9]) ((en|dis)abled)/);
  1010. return ("User Identifier: only 0-255 allowed", "") if (($1<0) || ($1>255));
  1011. my $rt = sprintf("01%02x%02x", $1, ($2 eq "enabled") ? "01" : "02");
  1012. return ("",$rt);
  1013. }
  1014. sub
  1015. ZWave_scheduleEntryLockAllSet ($$)
  1016. {
  1017. my ($hash, $arg) = @_;
  1018. my $name = $hash->{NAME};
  1019. return ("wrong format, see commandref", "")
  1020. if($arg !~ m/((en|dis)abled)/);
  1021. my $rt = sprintf("02%02x", ($1 eq "enabled") ? "01" : "02");
  1022. return ("",$rt);
  1023. }
  1024. sub
  1025. ZWave_scheduleEntryLockWeekDayParse ($$)
  1026. {
  1027. my ($hash, $val) = @_;
  1028. return if($val !~ m/^(..)(..)(..)(..)(..)(..)(..)/);
  1029. my $userId = sprintf("userID: %d", hex($1));
  1030. my $scheduleSlotId = sprintf("slotID: %d", hex($2));
  1031. # Attention! scheduleEntryLock use different definition of weekday!
  1032. my @dow = ("sun","mon","tue","wed","thu","fri","sat");
  1033. my $dayOfWeek = (hex($3) < 7) ? $dow[hex($3)] : "invalid";
  1034. my $start = sprintf("%02d:%02d", hex($4), hex($5));
  1035. my $end = sprintf("%02d:%02d", hex($6), hex($7));
  1036. my $rt1 = sprintf ("weekDaySchedule_%d:", hex($1));
  1037. $rt1 .= "$userId $scheduleSlotId $dayOfWeek $start $end";
  1038. return ($rt1);
  1039. }
  1040. sub
  1041. ZWave_scheduleEntryLockWeekDaySet ($$)
  1042. {
  1043. my ($hash, $arg) = @_;
  1044. my $name = $hash->{NAME};
  1045. if($arg !~
  1046. m/([01]) $p1_b $p1_b $p1_wd $p2_hm $p2_hm/) {
  1047. return ("wrong format, see commandref", "");
  1048. }
  1049. if (($2>255) || ($3>255)) {
  1050. return ("values our of range, see commandref", "");
  1051. }
  1052. # Attention! scheduleEntryLock use different definition of weekday!
  1053. my @dow = ("sun","mon","tue","wed","thu","fri","sat");
  1054. my $wd;
  1055. map { $wd=sprintf("%02x",$_) if($dow[$_] eq $4) }(0..int($#dow));
  1056. return ("Unknown weekday $4, use one of ".join(" ", @dow), "")
  1057. if(!defined($wd));
  1058. my $rt = sprintf("03%02x%02x%02x%02x%02x%02x%02x%02x",
  1059. $1,$2,$3,$wd,$5,$6,$7,$8);
  1060. return ("",$rt);
  1061. }
  1062. sub
  1063. ZWave_scheduleEntryLockDailyRepeatingParse ($$)
  1064. {
  1065. my ($hash, $val) = @_;
  1066. return if($val !~ m/^(..)(..)(..)(..)(..)(..)(..)/);
  1067. my $userID = sprintf ("userID: %d", hex($1));
  1068. my $scheduleID = sprintf ("slotID: %d", hex($2));
  1069. # bit field for week day: b7 reserved, b6 sat, b5 fri, ..., b0 sun
  1070. my $w = hex($3);
  1071. #my $wd = sprintf("weekDaySchedule: %07b ", $w);
  1072. my $wd = "weekDaySchedule: ";
  1073. my $nu = "...";
  1074. $wd .= (($w & 0x02) == 0x02) ? "mon" : $nu;
  1075. $wd .= (($w & 0x04) == 0x04) ? "tue" : $nu;
  1076. $wd .= (($w & 0x08) == 0x08) ? "wed" : $nu;
  1077. $wd .= (($w & 0x10) == 0x10) ? "thu" : $nu;
  1078. $wd .= (($w & 0x20) == 0x20) ? "fri" : $nu;
  1079. $wd .= (($w & 0x40) == 0x40) ? "sat" : $nu;
  1080. $wd .= (($w & 0x01) == 0x01) ? "sun" : $nu;
  1081. my $start = sprintf("Start: %02d:%02d" , hex($4), hex($5));
  1082. my $duration = sprintf("Duration: %02d:%02d" , hex($6), hex($7));
  1083. my $rt1 = sprintf ("scheduleEntryLockDailyRepeating_%d:", hex($1));
  1084. $rt1 .= "$userID $scheduleID $wd $start $duration";
  1085. return ($rt1);
  1086. }
  1087. sub
  1088. ZWave_scheduleEntryLockDailyRepeatingSet ($$)
  1089. {
  1090. my ($hash, $arg) = @_;
  1091. my $name = $hash->{NAME};
  1092. if($arg !~
  1093. m/([01]) $p1_b $p1_b ((?:[\.a-zA-Z]{3}){1,7}) $p2_hm $p2_hm/) {
  1094. return ("wrong format, see commandref", "");
  1095. }
  1096. my $rt1 = sprintf("%02x%02x%02x", $1, $2, $3);
  1097. my $rt2 = sprintf("%02x%02x%02x%02x", $5, $6, $7, $8);
  1098. my $w = $4;
  1099. my $wd = 0x00;
  1100. $wd |= 0x02 if ($w =~ /mon/i);
  1101. $wd |= 0x04 if ($w =~ /tue/i);
  1102. $wd |= 0x08 if ($w =~ /wed/i);
  1103. $wd |= 0x10 if ($w =~ /thu/i);
  1104. $wd |= 0x20 if ($w =~ /fri/i);
  1105. $wd |= 0x40 if ($w =~ /sat/i);
  1106. $wd |= 0x01 if ($w =~ /sun/i);
  1107. my $rt = sprintf("10$rt1%02x$rt2", $wd);
  1108. return ("",$rt);
  1109. }
  1110. sub
  1111. ZWave_scheduleEntryLockYearDayParse ($$)
  1112. {
  1113. my ($hash, $val) = @_;
  1114. return if($val !~ m/^(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)/);
  1115. my $userID = sprintf ("userID: %d", hex($1));
  1116. my $scheduleID = sprintf ("slotID: %d", hex($2));
  1117. my $startdate = sprintf ("start: %4d-%02d-%02d %02d:%02d",
  1118. 2000+hex($3),hex($4),hex($5),hex($6),hex($7));
  1119. my $enddate = sprintf ("end: %4d-%02d-%02d %02d:%02d",
  1120. 2000+hex($8),hex($9),hex($10),hex($11),hex($12));
  1121. my $rt1 = sprintf ("yearDaySchedule_%d:", hex($1));
  1122. $rt1 .= "$userID $scheduleID $startdate $enddate";
  1123. return ($rt1);
  1124. }
  1125. sub
  1126. ZWave_scheduleEntryLockYearDaySet ($$)
  1127. {
  1128. my ($hash, $arg) = @_;
  1129. my $name = $hash->{NAME};
  1130. if($arg !~
  1131. m/([01]) $p1_b $p1_b $p3_ymd $p2_hm $p3_ymd $p2_hm/) {
  1132. return ("wrong format, see commandref", "");
  1133. }
  1134. my $sy = $4-2000;
  1135. my $ey = $9-2000;
  1136. if (($sy < 0) || ($sy > 255) || ($ey < 0) || ($ey > 255)) {
  1137. Log3 $name, 1, "$name: year out of range";
  1138. return ("wrong value for year, only 2000-2255 allowed","");
  1139. }; # no sanity check of date (e.g. 2016-02-31 will pass)
  1140. my $rt = sprintf("06%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  1141. $1, $2, $3, $sy, $5, $6, $7, $8, $ey, $10, $11, $12, $13);
  1142. return ("",$rt);
  1143. }
  1144. sub
  1145. ZWave_scheduleEntryLockTimeOffsetParse ($$)
  1146. {
  1147. my ($hash, $val) = @_;
  1148. return if($val !~ m/^(..)(..)(..)/);
  1149. my $sTZO = ((hex($1) & 0x80) == 0x80) ? '-' : '+';
  1150. my $TZO = sprintf("TZO: %s%02d:%02d", $sTZO, (hex($1) & 0x7f), hex($2));
  1151. my $sDST = ((hex($3) & 0x80) == 0x80) ? '-' : '+';
  1152. my $DST = sprintf("DST: %s%02d", $sDST, (hex($3) & 0x7f));
  1153. my $rt1 = "scheduleEntryLockTimeOffset: $TZO $DST";
  1154. return ($rt1);
  1155. }
  1156. sub
  1157. ZWave_scheduleEntryLockTimeOffsetSet ($$)
  1158. {
  1159. my ($hash, $arg) = @_;
  1160. my $name = $hash->{NAME};
  1161. if($arg !~ m/([\+\-])$p2_hm ([\+\-])$p1_b/) {
  1162. return ("wrong format, see commandref", "");
  1163. }
  1164. my $hTZO = $2 | (($1 eq '-') ? 0x80 : 0x00);
  1165. my $mTZO = $3;
  1166. my $mDST = $5 | (($4 eq '-') ? 0x80 : 0x00);
  1167. my $rt = sprintf("0d%02x%02x%02x", $hTZO, $mTZO, $mDST);
  1168. return ("",$rt);
  1169. }
  1170. sub
  1171. ZWave_scheduleEntryLockTypeSupportedParse ($$)
  1172. {
  1173. my ($hash, $val) = @_;
  1174. return if($val !~ m/^(..)(..)(.*)/);
  1175. my $numWDslots = sprintf ("WeekDaySlots: %d", hex($1));
  1176. my $numYDslots = sprintf ("YearDaySlots: %d", hex($2));
  1177. # only for V3
  1178. my $numDailySlots = '';
  1179. $numDailySlots = sprintf (" DailyRepeatingSlots: %d", hex($3)) if ($3);
  1180. my $rt1 = "scheduleEntryLockEntryTypeSupported:"
  1181. ." $numWDslots $numYDslots$numDailySlots";
  1182. return ($rt1);
  1183. }
  1184. sub
  1185. ZWave_thermostatSetpointGet($)
  1186. {
  1187. my ($type) = @_;
  1188. $type = (($type eq "%s") ? "1" : $type);
  1189. return ("wrong format, only 1-15 allowed","")
  1190. if ($type !~ m/^(1[0-5]?|[0]?[1-9])$/);
  1191. return("",sprintf('02%02x', $type & 0x0f));
  1192. }
  1193. sub
  1194. ZWave_thermostatSetpointSet ($$)
  1195. {
  1196. my ($hash, $arg) = @_;
  1197. my $name = $hash->{NAME};
  1198. my $p1_temp = "([\+\-]?(?:(?:[0-9]+(?:\.[0-9]*)?)|(?:\.[0-9]+)))";
  1199. my $p1_scale = "([cC|fF])";
  1200. my $p1_type = "(1[0-5]?|[0]?[1-9])";
  1201. my $p1_prec = "([0-7])";
  1202. my $p1_size = "([124])";
  1203. if($arg !~
  1204. m/$p1_temp+ ?$p1_scale?+ ?$p1_type?+ ?$p1_prec?+ ?$p1_size?+/) {
  1205. return ("wrong format, see commandref", "");
  1206. }
  1207. my $temp = $1;
  1208. my $scale = (defined $2) ? $2 : "c"; # default to c = celsius
  1209. $scale = (lc($scale) eq "f") ? 1 : 0;
  1210. my $type = ((defined $3) ? $3 : 1) & 0x0f; # default to 1 = heating
  1211. my $prec = ((defined $4) ? $4 : 1) & 0x07; # default to 1 decimal
  1212. my $size = ((defined $5) ? $5 : 2) & 0x07; # default to 2 byte size
  1213. my $sp = int($temp * (10 ** $prec));
  1214. my $max = (2 ** (8*$size-1)) - 1;
  1215. my $min = -1 * (2 ** (8*$size-1));
  1216. if (($sp > $max) || ($sp < $min)) {
  1217. my $rt = sprintf("temperature value out of range for given "
  1218. ."size and precision [%0.*f, %0.*f]",
  1219. $prec, $min/(10**$prec), $prec, $max/(10**$prec));
  1220. return ($rt, "");
  1221. }
  1222. $sp = ($sp < 0) ? $sp + 2**(8*$size) : $sp;
  1223. $sp = sprintf("%0*x", 2*$size, $sp);
  1224. $type = sprintf("%02x", $type);
  1225. my $precScaleSize = sprintf("%02x", ($size | ($scale<<3) | ($prec<<5)));
  1226. my $rt = "01$type$precScaleSize$sp";
  1227. return ("",$rt);
  1228. }
  1229. sub
  1230. ZWave_thermostatSetpointParse ($$)
  1231. {
  1232. my ($hash, $val) = @_;
  1233. my $name = $hash->{NAME};
  1234. return if($val !~ m/^(..)(..)(.*)/);
  1235. my @setpointtype = ( # definition from V3
  1236. "notSupported",
  1237. "heating",
  1238. "cooling",
  1239. "notSupported1",
  1240. "notSupported2",
  1241. "notSupported3",
  1242. "notSupported4",
  1243. "furnance",
  1244. "dryAir",
  1245. "moistAir",
  1246. "autoChangeover",
  1247. "energySaveHeating",
  1248. "energySaveCooling",
  1249. "awayHeating",
  1250. "awayCooling",
  1251. "fullPower"
  1252. );
  1253. my $type = $setpointtype[(hex($1) & 0x0f)];
  1254. my $prec = (hex($2) & 0xe0)>>5;
  1255. my $scale = (((hex($2) & 0x18)>>3) == 1) ? "F": "C";
  1256. my $size = (hex($2) & 0x07);
  1257. if (length($3) != $size*2) {
  1258. Log3 $name, 1, "$name: THERMOSTAT_SETPOINT_REPORT "
  1259. ."wrong number of bytes received";
  1260. return;
  1261. }
  1262. my $sp = hex($3);
  1263. $sp -= (2 ** ($size*8)) if $sp >= (2 ** ($size*8-1));
  1264. $sp = $sp / (10 ** $prec);
  1265. # output temperature with variable decimals as reported (according to $prec)
  1266. my $rt = sprintf("setpointTemp:%0.*f %s %s", $prec, $sp, $scale, $type);
  1267. return ($rt);
  1268. }
  1269. sub
  1270. ZWave_thermostatSetpointSupportedParse ($$)
  1271. {
  1272. # only defined for version >= V3
  1273. my ($hash, $val) = @_;
  1274. my $name = $hash->{NAME};
  1275. return if($val !~ m/^(.*)/);
  1276. my $n = length($val)/2;
  1277. my @supportedType = ( # definition from V3
  1278. "none", # 0x00
  1279. "heating", # 0x01
  1280. "cooling", # 0x02
  1281. "furnance", # 0x07 !type 3 to 6 left out!
  1282. "dryAir", # 0x08
  1283. "moistAir", # 0x09
  1284. "autoChangeover", # 0x0a
  1285. "energySaveHeating", # 0x0b
  1286. "energySaveCooling", # 0x0c
  1287. "awayHeating", # 0x0d
  1288. "awayCooling", # 0x0e
  1289. "fullPower" # 0x0f
  1290. );
  1291. my $numTypes = @supportedType;
  1292. my $delimeter = '';
  1293. my $rt = "thermostatSetpointSupported:";
  1294. for (my $i=0; $i<$n; $i++) {
  1295. # loop over all supplied bytes
  1296. my $supported = hex(substr($val, $i*2, 2));
  1297. for (my $j=$i*8; $j<$i*8+8; $j++) {
  1298. # loop over all bits
  1299. last if $j >= $numTypes;
  1300. if ($supported & (2 ** ($j-$i*8))) {
  1301. $rt .= sprintf("$delimeter$supportedType[$j]");
  1302. $delimeter = " ";
  1303. }
  1304. }
  1305. }
  1306. return ($rt);
  1307. }
  1308. sub
  1309. ZWave_scheduleSupportedParse ($$)
  1310. {
  1311. my ($hash, $val) = @_;
  1312. return if($val !~ m/^(..)(..)(..)(.*)(..)/);
  1313. my $numSupported = sprintf("num: %d", hex($1));
  1314. my $sTimeSupport = sprintf("startTimeSupport: %06b", (hex($2) & 0x3f));
  1315. my $fbSupport = sprintf("fallbackSupport: %1b", (hex($2) & 0x40));
  1316. my $sEnaDis = sprintf("enableDisableSupport: %1b", (hex($2) & 0x80));
  1317. my $numSupportedCC = sprintf("numCCs: %d", hex($3));
  1318. my $OverrideTypes = sprintf("overrideTypes: %07b", (hex($5) & 0x7f));
  1319. my $overrideSupport = sprintf("overrideSupport: %1b", (hex($5) & 0x80));
  1320. my $supportedCCs = "";
  1321. if (hex($3)>0) {
  1322. $val = $4;
  1323. for (my $i=0;$i<hex($3); $i++) {
  1324. $val =~ m/(..)(..)(.*)/;
  1325. my $supportedCC = sprintf ("CC_%d: %d CCname_%d: %s",
  1326. $i+1, hex($1), $i+1, $zwave_id2class{lc($1)});
  1327. my $supportedCCmask = sprintf (" CCmask_%d: %02b",
  1328. $i+1, (hex($2) & 0x03));
  1329. $supportedCCs .= " " if $i >0;
  1330. $supportedCCs .= $supportedCC . $supportedCCmask;
  1331. $val = $3;
  1332. }
  1333. }
  1334. my $rt1 = "scheduleEntryLockScheduleSupported:"
  1335. ."$numSupported $sTimeSupport $fbSupport "
  1336. ."$sEnaDis $numSupportedCC $OverrideTypes $overrideSupport";
  1337. my $rt2 = "scheduleEntryLockScheduleSupportedCC:$supportedCCs";
  1338. return ($rt1, $rt2);
  1339. }
  1340. sub
  1341. ZWave_scheduleStateSet ($$)
  1342. {
  1343. my ($hash, $arg) = @_;
  1344. my $name = $hash->{NAME};
  1345. return ("wrong format, see commandref", "") if($arg !~ m/(.*?) (.*?)/);
  1346. my $rt = sprintf("07%02x%02x", $1, $2);
  1347. return ("",$rt);
  1348. }
  1349. sub
  1350. ZWave_scheduleSet ($$)
  1351. {
  1352. my ($hash, $arg) = @_;
  1353. my $name = $hash->{NAME};
  1354. if($arg !~
  1355. # 1 2 3 4 5 6 7 8 9 10 11 12
  1356. m/(.*?) (.*?) (....)-(..)-(..) (.*?) (.*?) (..):(..) (.*?) (.*?) (.*)/) {
  1357. return ("wrong format, see commandref", "");
  1358. }
  1359. my $ID = sprintf("%02x", $1);
  1360. my $uID = sprintf("%02x", $2);
  1361. my $sYear = sprintf("%02x", $3 - 2000);
  1362. my $sMonth = sprintf("%02x", $4 & 0x0f);
  1363. my $sDay = sprintf("%02x", $5 & 0x1f);
  1364. my $sWDay = sprintf("%02x", $6 & 0x7f);
  1365. my $durationType = ($7<<5) & 0xe0;
  1366. my $sHour = sprintf("%02x", (($8 & 0x1f) | $durationType));
  1367. my $sMinute = sprintf("%02x", $9 & 0x3f);
  1368. my $duration = sprintf("%04x", $10);
  1369. my $numReports = sprintf("%02x", $11);
  1370. my $cmdgroup ="";
  1371. my @param;
  1372. if (length($12)>0) { # cmd(s) given
  1373. @param = split (" ", $12);
  1374. Log3 $name, 1, "$name: param: $#param $12";
  1375. for (my $i=0; $i<=$#param; $i++) {
  1376. $cmdgroup .= sprintf("%02x%s", length($param[$i])/2, $param[$i]);
  1377. }
  1378. }
  1379. my $numCmd = sprintf("%02x", $#param+1);
  1380. my $rt = "03" .$ID .$uID .$sYear .$sMonth .$sDay .$sWDay;
  1381. $rt .= $sHour .$sMinute .$duration .$numReports .$numCmd .$cmdgroup;
  1382. #~ Log3 $name, 1, "$name: $rt";
  1383. return ("",$rt);
  1384. }
  1385. sub
  1386. ZWave_scheduleParse ($$)
  1387. {
  1388. my ($hash, $val) = @_;
  1389. return if($val !~ m/^(..)(..)(..)(..)(..)(..)(..)(..)(....)(..)(..)(..)(.*)/);
  1390. my $scheduleID = sprintf ("ID: %d", hex($1));
  1391. my $userID = sprintf ("userID: %d", hex($2));
  1392. my $startYear = sprintf ("sYear: %d", 2000 + hex($3));
  1393. my $startMonth = sprintf ("sMonth: %d", (hex($4) & 0x0f));
  1394. my $activeID = sprintf ("activeID: %d", (hex($4) & 0xf0)>>4);
  1395. my $startDay = sprintf ("sDay: %d", (hex($5) & 0x1f));
  1396. my $sWeekDay = sprintf ("sWeekDay: %d", (hex($6) & 0x7f));
  1397. my $startHour = sprintf ("sHour: %d", (hex($7) & 0x1f));
  1398. my $durationType = sprintf ("durationType: %d", (hex($7) & 0x1f)>>5);
  1399. my $startMinute = sprintf ("sMinute: %d", (hex($8) & 0x3f));
  1400. my $duration = sprintf ("duration: %d", hex($9));
  1401. my $numReports = sprintf ("numReportsToFollow: %d", hex($10));
  1402. my $numCmds = sprintf ("numCmds: %d", hex ($11));
  1403. my $cmdlen = sprintf ("cmdLen: %d", hex($12));
  1404. my $cmd = sprintf ("cmd: %s", $13);
  1405. my $rt1 = sprintf ("schedule_%d:", hex($1));
  1406. $rt1 .= "$scheduleID $userID $startYear $startMonth $activeID ".
  1407. "$startDay $sWeekDay $startHour $durationType $startMinute ".
  1408. "$duration $numReports $numCmds $cmdlen $cmd";
  1409. return ($rt1);
  1410. }
  1411. sub
  1412. ZWave_scheduleStateParse ($$)
  1413. {
  1414. my ($hash, $val) = @_;
  1415. return if($val !~ m/^(..)(..)(..)(..)/);
  1416. my $numSupportedIDs = sprintf ("numIDs: %d", hex($1));
  1417. my $override = sprintf ("overried: %b", (hex($2) & 0x01));
  1418. my $numReports = sprintf ("numReportsToFollow: %d", (hex($2) & 0xfe)>>1);
  1419. my $ID1 = sprintf ("ID1: %d", (hex($3) & 0x0f));
  1420. my $ID2 = sprintf ("ID2: %d", (hex($3) & 0xf0)>>4);
  1421. my $ID3 = sprintf ("ID3: %d", (hex($4) & 0x0f));
  1422. my $IDN = sprintf ("IDn: %d", (hex($4) & 0xf0)>>4);
  1423. my $rt1 .= "scheduleState:$numSupportedIDs $override $numReports ".
  1424. "$ID1 $ID2 $ID3 $IDN";
  1425. return ($rt1);
  1426. }
  1427. my %zwm_unit = (
  1428. energy=> ["kWh", "kVAh", "W", "pulseCount", "V", "A", "PowerFactor"],
  1429. gas => ["m3", "feet3", "undef", "pulseCount"],
  1430. water => ["m3", "feet3", "USgallons", "pulseCount"]
  1431. );
  1432. sub
  1433. ZWave_meterParse($$)
  1434. {
  1435. my ($hash,$val) = @_;
  1436. return if($val !~ m/^(..)(..)(.*)$/);
  1437. my ($v1, $v2, $v3) = (hex($1), hex($2), $3);
  1438. my $name = $hash->{NAME};
  1439. # rate_type currently not used / not reported
  1440. my $rate_type = ($v1 >> 5) & 0x3;
  1441. my @rate_type_text =("undef","consumed", "produced");
  1442. my $rate_type_text = ($rate_type > $#rate_type_text ?
  1443. "undef" : $rate_type_text[$rate_type]);
  1444. my $meter_type = ($v1 & 0x1f);
  1445. my @meter_type_text =("undef", "energy", "gas", "water", "undef");
  1446. my $meter_type_text = ($meter_type > $#meter_type_text ?
  1447. "undef" : $meter_type_text[$meter_type]);
  1448. my $precision = ($v2 >>5) & 0x7;
  1449. # no definition for text or numbers, used as -> (10 ** hex($precision))
  1450. # V3 use 3 bit, in V2 there are only 2 bit available
  1451. # V3 use bit 7 of first byte as bit 3 of scale
  1452. my $scale = ($v2 >> 3) & 0x3;
  1453. $scale |= (($v1 & 0x80) >> 5);
  1454. my $unit_text = ($meter_type_text eq "undef" ?
  1455. "undef" : $zwm_unit{$meter_type_text}[$scale]);
  1456. my $size = $v2 & 0x7;
  1457. $meter_type_text = "power" if ($unit_text eq "W");
  1458. $meter_type_text = "voltage" if ($unit_text eq "V");
  1459. $meter_type_text = "current" if ($unit_text eq "A");
  1460. my $mv = hex(substr($v3, 0, 2*$size));
  1461. $mv = $mv / (10 ** $precision);
  1462. $mv -= (2 ** ($size*8)) if $mv >= (2 ** ($size*8-1));
  1463. $v3 = substr($v3, 2*$size, length($v3)-(2*$size));
  1464. if (length($v3) < 4) { # V1 report
  1465. return "$meter_type_text: $mv $unit_text";
  1466. } else { # V2 or greater report
  1467. my $delta_time = hex(substr($v3, 0, 4));
  1468. $v3 = substr($v3, 4, length($v3)-4);
  1469. if ($delta_time == 0) { # no previous meter value
  1470. return "$meter_type_text: $mv $unit_text";
  1471. } else { # previous meter value present
  1472. my $pmv = hex(substr($v3, 0, 2*$size));
  1473. $pmv = $pmv / (10 ** $precision);
  1474. $pmv -= (2 ** ($size*8)) if $pmv >= (2 ** ($size*8-1));
  1475. if ($delta_time == 65535) {
  1476. $delta_time = "unknown";
  1477. } else {
  1478. $delta_time .= " s";
  1479. };
  1480. return "$meter_type_text: $mv $unit_text previous: $pmv delta_time: ".
  1481. "$delta_time"; # V2 report
  1482. }
  1483. }
  1484. }
  1485. sub
  1486. ZWave_meterGet($)
  1487. {
  1488. my ($scale) = @_;
  1489. if ($scale eq "%s") { # no parameter specified, use V1 get without scale
  1490. return("", "01");
  1491. };
  1492. if (($scale < 0) || ($scale > 6)) {
  1493. return("argument must be one of: 0 to 6","");
  1494. } else {
  1495. $scale = $scale << 3;
  1496. return("",sprintf('01%02x', $scale));
  1497. };
  1498. }
  1499. sub
  1500. ZWave_meterSupportedParse($$)
  1501. {
  1502. my ($hash,$val) = @_;
  1503. return if($val !~ m/^(..)(..)$/);
  1504. my ($v1, $v2) = (hex($1), hex($2));
  1505. my $name = $hash->{NAME};
  1506. my $meter_reset = $v1 & 0x80;
  1507. my $meter_reset_text = $meter_reset ? "yes" : "no";
  1508. my $meter_type = ($v1 & 0x1f);
  1509. my @meter_type_text =("undef", "energy", "gas", "water", "undef");
  1510. my $meter_type_text = ($meter_type > $#meter_type_text ?
  1511. "undef" : $meter_type_text[$meter_type]);
  1512. my $scale = $v2 & 0x7f;
  1513. my $unit_text="";
  1514. for (my $i=0; $i <= 6; $i++) {
  1515. if ($scale & 2**$i) {
  1516. $unit_text .= ", " if (length($unit_text)>0);
  1517. $unit_text .= $i.":".$zwm_unit{$meter_type_text}[$i];
  1518. };
  1519. };
  1520. return "meterSupported: type: $meter_type_text scales: $unit_text resetable:".
  1521. " $meter_reset_text";
  1522. }
  1523. sub
  1524. ZWave_versionClassGet($$)
  1525. {
  1526. my ($hash, $class) = @_;
  1527. delete $zwave_parseHook{"$hash->{nodeIdHex}:..8614"} if ($hash->{CL});
  1528. return("", sprintf('13%02x', $class))
  1529. if($class =~ m/^\d+$/);
  1530. return("", sprintf('13%02x', hex($zwave_class{$class}{id})))
  1531. if($zwave_class{$class});
  1532. return ("versionClass needs a class as parameter", "") if($class eq "%s");
  1533. return ("Unknown class $class", "");
  1534. }
  1535. sub
  1536. ZWave_versionClassAllGet($@)
  1537. {
  1538. my ($hash, $data) = @_;
  1539. my $name = $hash->{NAME};
  1540. if(!$data) { # called by the user
  1541. delete($hash->{CL});
  1542. my %h = map { $_=>1 } split(" ", AttrVal($name, "classes", ""));
  1543. foreach my $c (sort keys %h) {
  1544. next if($c eq "MARK");
  1545. ZWave_Get($hash, $name, "versionClass", $c);
  1546. }
  1547. $zwave_parseHook{"$hash->{nodeIdHex}:..8614"} = \&ZWave_versionClassAllGet;
  1548. return("working the background, check the vclasses attribute", "EMPTY");
  1549. }
  1550. $zwave_parseHook{"$hash->{nodeIdHex}:..8614"} = \&ZWave_versionClassAllGet;
  1551. my %h = map { $_=>1 } split(" ", AttrVal($name, "vclasses", ""));
  1552. return 0 if($data !~ m/^048614(..)(..)$/i); # ??
  1553. if($zwave_id2class{lc($1)}) {
  1554. $h{$zwave_id2class{lc($1)}.":".hex($2)} = 1;
  1555. $hash->{".vclasses"}{$zwave_id2class{lc($1)}} = hex($2);
  1556. $attr{$name}{vclasses} = join(" ", sort keys %h);
  1557. }
  1558. return !$hash->{asyncGet}; # "veto" for parseHook/getAll
  1559. }
  1560. sub
  1561. ZWave_multilevelParse($$$)
  1562. {
  1563. my ($type,$fl,$arg) = @_;
  1564. my %ml_tbl = (
  1565. '01' => { n => 'temperature', st => ['C', 'F'] },
  1566. '02' => { n => 'generalPurpose', st => ['%', ''] },
  1567. '03' => { n => 'luminance', st => ['%', 'Lux'] },
  1568. '04' => { n => 'power', st => ['W', 'Btu/h'] },
  1569. '05' => { n => 'humidity', st => ['%'] },
  1570. '06' => { n => 'velocity', st => ['m/s', 'mph'] },
  1571. '07' => { n => 'direction', st => [] },
  1572. '08' => { n => 'atmosphericPressure', st => ['kPa', 'inchHg'] },
  1573. '09' => { n => 'barometricPressure', st => ['kPa', 'inchHg'] },
  1574. '0a' => { n => 'solarRadiation', st => ['W/m2'] },
  1575. '0b' => { n => 'dewpoint', st => ['C', 'F'] },
  1576. '0c' => { n => 'rain', st => ['mm/h', 'in/h'] },
  1577. '0d' => { n => 'tideLevel', st => ['m', 'feet'] },
  1578. '0e' => { n => 'weight', st => ['kg', 'pound'] },
  1579. '0f' => { n => 'voltage', st => ['V', 'mV'] },
  1580. '10' => { n => 'current', st => ['A', 'mA'] },
  1581. '11' => { n => 'CO2-level', st => ['ppm']},
  1582. '12' => { n => 'airFlow', st => ['m3/h', 'cfm'] },
  1583. '13' => { n => 'tankCapacity', st => ['l', 'cbm', 'usgal'] },
  1584. '14' => { n => 'distance', st => ['m', 'cm', 'feet'] },
  1585. '15' => { n => 'anglePosition', st => ['%', 'relN', 'relS'] },
  1586. '16' => { n => 'rotation', st => ['rpm', 'Hz'] },
  1587. '17' => { n => 'waterTemperature', st => ['C', 'F'] },
  1588. '18' => { n => 'soilTemperature', st => ['C', 'F'] },
  1589. '19' => { n => 'seismicIntensity', st => ['mercalli', 'EU macroseismic',
  1590. 'liedu', 'shindo'] },
  1591. '1a' => { n => 'seismicMagnitude', st => ['local', 'moment',
  1592. 'surface wave', 'body wave'] },
  1593. '1b' => { n => 'ultraviolet', st => ['UV'] },
  1594. '1c' => { n => 'electricalResistivity',st => ['ohm'] },
  1595. '1d' => { n => 'electricalConductivity',st => ['siemens/m'] },
  1596. '1e' => { n => 'loudness', st => ['dB', 'dBA'] },
  1597. '1f' => { n => 'moisture', st => ['%', 'content', 'k ohms',
  1598. 'water activity'] },
  1599. '20' => { n => 'frequency', st => ['Hz', 'kHz'] },
  1600. '21' => { n => 'time', st => ['seconds'] },
  1601. '22' => { n => 'targetTemperature', st => ['C', 'F'] },
  1602. '23' => { n => 'particulateMatter', st => ['mol/m3', 'micro-g/m3'] },
  1603. '24' => { n => 'formaldehydeLevel', st => ['mol/m3'] },
  1604. '25' => { n => 'radonConcentration', st => ['bq/m3', 'pCi/L'] },
  1605. '26' => { n => 'methaneDensity', st => ['mol/m3'] },
  1606. '27' => { n => 'volatileOrganicCompound',st => ['mol/m3'] },
  1607. '28' => { n => 'carbonMonoxide', st => ['mol/m3'] },
  1608. '29' => { n => 'soilHumidity', st => ['%'] },
  1609. '2a' => { n => 'soilReactivity', st => ['pH'] },
  1610. '2b' => { n => 'soilSalinity', st => ['mol/m3'] },
  1611. '2c' => { n => 'heartRate', st => ['Bpm'] },
  1612. '2d' => { n => 'bloodPressure', st => ['Systolic mmHg',
  1613. 'Diastolic mmHg'] },
  1614. '2e' => { n => 'muscleMass', st => ['Kg'] },
  1615. '2f' => { n => 'fatMass', st => ['Kg'] },
  1616. '30' => { n => 'boneMass', st => ['Kg'] },
  1617. '31' => { n => 'totalBodyWater', st => ['Kg'] },
  1618. '32' => { n => 'basicMetabolicRate', st => ['J'] },
  1619. '33' => { n => 'bodyMassIndex', st => ['BMI'] },
  1620. );
  1621. my $pr = (hex($fl)>>5)&0x07; # precision
  1622. my $sc = (hex($fl)>>3)&0x03; # scale
  1623. my $bc = (hex($fl)>>0)&0x07; # bytecount
  1624. $arg = substr($arg, 0, 2*$bc);
  1625. my $msb = (hex($arg)>>8*$bc-1); # most significant bit ( 0 = pos, 1 = neg )
  1626. my $val = $msb ? -( 2 ** (8 * $bc) - hex($arg) ) : hex($arg); # 2's complement
  1627. my $ml = $ml_tbl{$type};
  1628. return "UNKNOWN multilevel type: $type fl: $fl arg: $arg" if(!$ml);
  1629. return sprintf("%s:%.*f %s", $ml->{n}, $pr, $val/(10**$pr),
  1630. int(@{$ml->{st}}) > $sc ? $ml->{st}->[$sc] : "");
  1631. }
  1632. sub
  1633. ZWave_timeParametersReport($$)
  1634. {
  1635. my ($hash, $arg) = @_;
  1636. my $name = $hash->{NAME};
  1637. if($arg !~ m/(....)(..)(..)(..)(..)(..)/) {
  1638. Log3 $name,1,"$name: timeParametersReport with wrong format received: $arg";
  1639. return;
  1640. }
  1641. return
  1642. sprintf("timeParameters:date: %04d-%02d-%02d time(UTC): %02d:%02d:%02d",
  1643. hex($1), hex($2), hex($3), hex($4), (hex$5), hex($6));
  1644. }
  1645. sub
  1646. ZWave_timeParametersSet($$)
  1647. {
  1648. my ($hash, $arg) = @_;
  1649. my $name = $hash->{NAME};
  1650. return ("wrong format, see commandref", "")
  1651. if($arg !~ m/(....)-(..)-(..) (..):(..):(..)/);
  1652. my $rt = sprintf("%04x%02x%02x%02x%02x%02x", $1, $2, $3, $4, $5, $6);
  1653. return ("", sprintf("01%s", $rt));
  1654. }
  1655. sub
  1656. ZWave_dateReport($$)
  1657. {
  1658. my ($hash, $arg) = @_;
  1659. my $name = $hash->{NAME};
  1660. if ($arg !~ m/(....)(..)(..)/) {
  1661. Log3 $name, 1, "$name: dateReport with wrong format received: $arg";
  1662. return;
  1663. }
  1664. return (sprintf("date:%04d-%02d-%02d", hex($1), hex($2), hex($3)));
  1665. }
  1666. sub
  1667. ZWave_timeReport($$)
  1668. {
  1669. my ($hash, $arg) = @_;
  1670. my $name = $hash->{NAME};
  1671. if ($arg !~ m/(..)(..)(..)/) {
  1672. Log3 $name, 1, "$name: timeReport with wrong format received: $arg";
  1673. return;
  1674. }
  1675. return (sprintf("time:%02d:%02d:%02d RTC: %s",
  1676. (hex($1) & 0x1f), hex($2), hex($3),
  1677. (hex($1) & 0x80) ? "failed" : "working"));
  1678. }
  1679. sub
  1680. ZWave_timeOffsetReport($$)
  1681. {
  1682. my ($hash, $arg) = @_;
  1683. my $name = $hash->{NAME};
  1684. if ($arg !~ m/(..)(..)(..)(..)(..)(..)(..)(..)(..)/) {
  1685. Log3 $name, 1, "$name: timeOffsetReport with wrong format received: $arg";
  1686. return;
  1687. }
  1688. my $hourTZO = hex($1) & 0x7f;
  1689. my $signTZO = hex($1) & 0x80;
  1690. my $minuteTZO = hex($2);
  1691. my $minuteOffsetDST = hex($3) & 0x7f;
  1692. my $signOffsetDST = hex($3) & 0x80;
  1693. my $monthStartDST = hex($4);
  1694. my $dayStartDST = hex($5);
  1695. my $hourStartDST = hex($6);
  1696. my $monthEndDST = hex($7);
  1697. my $dayEndDST = hex($8);
  1698. my $hourEndDST = hex($9);
  1699. my $UTCoffset = "UTC-Offset: ";
  1700. $UTCoffset .= ($signTZO ? "-" : "+");
  1701. $UTCoffset .= sprintf ("%02d:%02d", $hourTZO, $minuteTZO);
  1702. my $DSToffset = "DST-Offset(minutes): ";
  1703. $DSToffset .= ($signOffsetDST ? "-" : "+");
  1704. $DSToffset .= sprintf ("%02d", $minuteOffsetDST);
  1705. my $startDST = "DST-Start: ";
  1706. $startDST .= sprintf ("%02d-%02d_%02d:00",
  1707. $monthStartDST, $dayStartDST, $hourStartDST);
  1708. my $endDST = "DST-End: ";
  1709. $endDST .= sprintf ("%02d-%02d_%02d:00",
  1710. $monthEndDST, $dayEndDST, $hourEndDST);
  1711. return (sprintf("timeOffset:$UTCoffset $DSToffset $startDST $endDST"));
  1712. }
  1713. sub
  1714. ZWave_timeOffsetSet($$)
  1715. {
  1716. my ($hash, $arg) = @_;
  1717. my $name = $hash->{NAME};
  1718. if($arg !~
  1719. m/([+-])(..):(..) ([+-])(..) (..)-(..)_(..):00 (..)-(..)_(..):00/) {
  1720. return ("wrong format $arg, see commandref", "");
  1721. }
  1722. my $signTZO = $1;
  1723. my $hourTZO = $2;
  1724. my $minuteTZO = $3;
  1725. my $signOffsetDST = $4;
  1726. my $minuteOffsetDST = $5;
  1727. my $monthStartDST = $6;
  1728. my $dayStartDST = $7;
  1729. my $hourStartDST = $8;
  1730. my $monthEndDST = $9;
  1731. my $dayEndDST = $10;
  1732. my $hourEndDST = $11;
  1733. my $rt = sprintf("%02x%02x",
  1734. ($hourTZO | ($signTZO eq "-" ? 0x01 : 0x00)), $minuteTZO);
  1735. $rt .= sprintf("%02x",
  1736. ($minuteOffsetDST | ($signOffsetDST eq "-" ? 0x01 : 0x00)));
  1737. $rt .= sprintf("%02x%02x%02x",
  1738. $monthStartDST, $dayStartDST, $hourStartDST);
  1739. $rt .= sprintf("%02x%02x%02x", $monthEndDST, $dayEndDST, $hourEndDST);
  1740. return ("", sprintf("05%s", $rt));
  1741. }
  1742. sub
  1743. ZWave_DoorLockOperationReport($$)
  1744. {
  1745. my ($hash, $arg) = @_;
  1746. my $name = $hash->{NAME};
  1747. if ($arg !~ m/(..)(..)(..)(..)(..)/) {
  1748. Log3 $name, 1, "$name: doorLockOperationReport with wrong ".
  1749. "format received: $arg";
  1750. return;
  1751. }
  1752. my $DLM = hex($1); # DoorLockMode
  1753. my $DLHM = hex($2); # DoorLockHandleModes
  1754. my $DC = hex($3); # DoorCondition
  1755. my $DLTM = hex($4); # DoorLockTimeoutMinutes
  1756. my $DLTS = hex($5); # DoorLockTimeoutSeconds
  1757. my $DLMtext = "mode: ";
  1758. if ($DLM == 0xff) {
  1759. $DLMtext .= "secured";
  1760. } elsif ($DLM == 0xfe) {
  1761. $DLMtext .= "lockStateUnknown";
  1762. }
  1763. else {
  1764. $DLMtext .= "unsecured";
  1765. $DLMtext .= (($DLM & 0x10) ? "_inside" :"");
  1766. $DLMtext .= (($DLM & 0x20) ? "_outside" :"");
  1767. $DLMtext .= (($DLM & 0x01) ? "_withTimeout" :"");
  1768. };
  1769. my $odlhm = sprintf ("outsideHandles: %04b", ($DLHM & 0xf0)>>4);
  1770. my $idlhm = sprintf ("insideHandles: %04b", ($DLHM & 0x0f));
  1771. my $dc_door = "door: " . (($DC & 0x01) ? "closed" : "open");
  1772. my $dc_bolt = "bolt: " . (($DC & 0x02) ? "unlocked" : "locked");
  1773. my $dc_latch = "latch: " . (($DC & 0x04) ? "closed" : "open");
  1774. my $to = "timeoutSeconds: ";
  1775. if (($DLTM == 0xfe) && ($DLTS == 0xfe)) {
  1776. $to .= 'not_supported';
  1777. } else {
  1778. $to .= sprintf ("%d", ($DLTM * 60 + $DLTS));
  1779. }
  1780. return "doorLockOperation:$DLMtext $odlhm $idlhm $dc_door ".
  1781. "$dc_bolt $dc_latch $to";
  1782. }
  1783. sub
  1784. ZWave_DoorLockConfigReport($$)
  1785. {
  1786. my ($hash, $arg) = @_;
  1787. my $name = $hash->{NAME};
  1788. if ($arg !~ m/(..)(..)(..)(..)/) {
  1789. Log3 $name, 1, "$name: doorLockOperationReport with wrong ".
  1790. "format received: $arg";
  1791. return;
  1792. }
  1793. my $OpMode = $1; # OperationMode
  1794. my $DLHS = hex($2); # DoorLockHandleStates
  1795. my $DLTM = hex($3); # DoorLockTimeoutMinutes
  1796. my $DLTS = hex($4); # DoorLockTimeoutSeconds
  1797. my $ot = "mode: ";
  1798. if ($OpMode eq '01') {
  1799. $ot .= "constant";
  1800. } elsif ($OpMode eq '02') {
  1801. $ot .= "timed";
  1802. } else {
  1803. $ot .= "unknown";
  1804. }
  1805. my $odlhs = sprintf ("outsideHandles: %04b", ($DLHS & 0xf0)>>4);
  1806. my $idlhs = sprintf ("insideHandles: %04b", ($DLHS & 0x0f));
  1807. my $to = "timeoutSeconds: ";
  1808. if (($DLTM == 0xfe) && ($DLTS == 0xfe)) {
  1809. $to .= 'not_supported';
  1810. } else {
  1811. $to .= sprintf ("%d", ($DLTM * 60 + $DLTS));
  1812. }
  1813. return "doorLockConfiguration: $ot $odlhs $idlhs $to";
  1814. }
  1815. sub
  1816. ZWave_DoorLockOperationSet($$)
  1817. {
  1818. my ($hash, $arg) = @_;
  1819. my $name = $hash->{NAME};
  1820. my $rt;
  1821. $rt = ($arg eq 'open') ? "00" :
  1822. ($arg eq 'close') ? "FF" :
  1823. ($arg eq "00") ? "00" :
  1824. ($arg eq "01") ? "01" :
  1825. ($arg eq "10") ? "10" :
  1826. ($arg eq "11") ? "11" :
  1827. ($arg eq "20") ? "20" :
  1828. ($arg eq "21") ? "21" :
  1829. ($arg eq "FF") ? "FF" : "";
  1830. return ("DoorLockOperationSet: wrong parameter, see commandref")
  1831. if ($rt eq "");
  1832. return ("", "01".$rt);
  1833. }
  1834. sub
  1835. ZWave_DoorLockConfigSet($$)
  1836. {
  1837. # 0x62 V1, V2
  1838. # userinput: operationType, ohandles, ihandles, seconds_dez
  1839. my ($hash, $arg) = @_;
  1840. my $name = $hash->{NAME};
  1841. if ($arg !~ m/\b(.+)\b \b([01]{4})\b \b([01]{4})\b \b([0-9]+)$/) {
  1842. #~ Log3 $name, 1, "$name: doorLockConfigurationSet wrong ".
  1843. #~ "format, see commandref: $arg";
  1844. return ("doorLockConfigurationSet: wrong format, see commandref","");
  1845. }
  1846. my $oT;
  1847. if (lc($1) eq "constant") {
  1848. $oT = 1;
  1849. } elsif (lc($1) eq "timed") {
  1850. $oT = 2;
  1851. } else {
  1852. return ("wrong operationType: only [constant|timed] is allowed","");
  1853. }
  1854. my $handles = ((oct("0b".$2))<<4 | oct("0b".$3));
  1855. if (($4 < 1) || ($4) > 15239) { # max. 253 * 60 + 59 seconds
  1856. return ("doorLockConfigurationSet: 1-15238 seconds allowed","");
  1857. }
  1858. return ("", sprintf("04%02x%02x%02x%02x",
  1859. $oT,$handles, int($4 / 60) ,($4 % 60)));
  1860. }
  1861. sub
  1862. ZWave_SetClasses($$$$)
  1863. {
  1864. my ($homeId, $id, $type6, $classes) = @_;
  1865. my $def = $modules{ZWave}{defptr}{"$homeId $id"};
  1866. if(!$def) {
  1867. $type6 = $zw_type6{$type6} if($type6 && $zw_type6{lc($type6)});
  1868. $id = hex($id);
  1869. return "UNDEFINED ZWave_${type6}_$id ZWave $homeId $id $classes"
  1870. }
  1871. my @classes;
  1872. for my $classId (grep /../, split(/(..)/, lc($classes))) {
  1873. push @classes, $zwave_id2class{lc($classId)} ?
  1874. $zwave_id2class{lc($classId)} : "UNKNOWN_".lc($classId);
  1875. }
  1876. my $name = $def->{NAME};
  1877. $attr{$name}{classes} = join(" ", @classes)
  1878. if(@classes && !$attr{$name}{classes});
  1879. $def->{DEF} = "$homeId ".hex($id);
  1880. return "";
  1881. }
  1882. sub
  1883. ZWave_swmParse($$$$)
  1884. {
  1885. my ($fl, $sl, $dur, $step)=@_;
  1886. my $fl1 = (hex($fl) & 0x18)>>3;
  1887. my $fl2 = (hex($fl) & 0xc0)>>6;
  1888. $fl = ($fl1==0 ? "Increment": $fl1==1 ? "Decrement" : "")." ".
  1889. ($fl2==0 ? "Up": $fl1==1 ? "Down" : "");
  1890. return sprintf("state:swm %s Start: %d Duration: %d Step: %d",
  1891. $fl, hex($sl), hex($dur), hex($step));
  1892. }
  1893. sub
  1894. ZWave_sceneParse($)
  1895. {
  1896. my ($p)=@_;
  1897. my @arg = ("unknown", "on", "off",
  1898. "dim up start", "dim down start", "dim up end", "dim down end");
  1899. return sprintf("sceneEvent%s:%s", int(hex($p)/10), $arg[hex($p)%10]);
  1900. }
  1901. sub
  1902. ZWave_mcCapability($$)
  1903. {
  1904. my ($hash, $caps) = @_;
  1905. #Caps:= channelId,genericDeviceClass,specificDeviceClass,Class1,Class2,...
  1906. my $name = $hash->{NAME};
  1907. my $iodev = $hash->{IODev};
  1908. return "Missing IODev for $name" if(!$iodev);
  1909. my $homeId = $iodev->{homeId};
  1910. my @l = grep /../, split(/(..)/, lc($caps));
  1911. my $chid = sprintf("%02x", hex(shift(@l)) & 0x7f); # Forum #50176
  1912. my $id = $hash->{nodeIdHex};
  1913. my @classes;
  1914. my $genericClass = shift(@l);
  1915. my $specificClass = shift(@l);
  1916. for my $classId (@l) {
  1917. push @classes, $zwave_id2class{lc($classId)} ?
  1918. $zwave_id2class{lc($classId)} : "UNKNOWN_".uc($classId);
  1919. }
  1920. return "mcCapability_$chid:no classes" if(!@classes);
  1921. if($chid ne "00" && !$modules{ZWave}{defptr}{"$homeId $id$chid"}) {
  1922. my $lid = hex("$id$chid");
  1923. my $lcaps = substr($caps, 6);
  1924. $id = hex($id);
  1925. DoTrigger("global",
  1926. "UNDEFINED ZWave_${genericClass}_$id.$chid ZWave $homeId $lid $lcaps", 1);
  1927. }
  1928. return "mcCapability_$chid:".join(" ", @classes);
  1929. }
  1930. sub
  1931. ZWave_mcCreateAll($$)
  1932. {
  1933. my ($hash, $data) = @_;
  1934. if(!$data) { # called by the user
  1935. $zwave_parseHook{"$hash->{nodeIdHex}:0[45]6008...."} = \&ZWave_mcCreateAll;
  1936. ZWave_Get($hash, $hash->{NAME}, "mcEndpoints");
  1937. return("", "EMPTY");
  1938. }
  1939. $data =~ m/^0[45]6008(..)(..)/; # 4 vs. 5: Forum #50895
  1940. my $nGrp = hex($2);
  1941. for(my $c = 1; $c <= $nGrp; $c++) {
  1942. ZWave_Get($hash, $hash->{NAME}, "mcCapability", $c);
  1943. }
  1944. return undef;
  1945. }
  1946. sub
  1947. ZWave_mfsAddClasses($$)
  1948. {
  1949. my ($hash, $cfgFile) = @_;
  1950. my $name = $hash->{NAME};
  1951. my $attr = $attr{$name}{classes};
  1952. return if(!$cfgFile || !$attr);
  1953. my $changed;
  1954. ZWave_configParseModel($cfgFile);
  1955. my $ci = $zwave_modelConfig{$cfgFile}{classInfo};
  1956. foreach my $id (keys %{$ci}) {
  1957. my $v = $ci->{$id};
  1958. if($v =~ m/setasreport="true"/ || $v =~ m/action="add"/) {
  1959. $id = sprintf("%02x", $id);
  1960. my $cn = $zwave_id2class{$id};
  1961. next if($attr =~ m/$cn/);
  1962. $attr .= " $cn";
  1963. $changed = 1;
  1964. }
  1965. }
  1966. return if(!$changed);
  1967. addStructChange("attr", $name, "$name classes $attr");
  1968. $attr{$name}{classes} = $attr;
  1969. }
  1970. sub
  1971. ZWave_mfsParse($$$$$)
  1972. {
  1973. my ($hash, $mf, $prod, $id, $config) = @_;
  1974. if($config == 2) {
  1975. setReadingsVal($hash, "modelId", "$mf-$prod-$id", TimeNow());
  1976. return "modelId:$mf-$prod-$id";
  1977. }
  1978. my $xml = $attr{global}{modpath}.
  1979. "/FHEM/lib/openzwave_manufacturer_specific.xml";
  1980. ($mf, $prod, $id) = (lc($mf), lc($prod), lc($id)); # Just to make it sure
  1981. if(open(FH, $xml)) {
  1982. my ($lastMf, $mName, $ret) = ("","");
  1983. while(my $l = <FH>) {
  1984. if($l =~ m/<Manufacturer.*id="([^"]*)".*name="([^"]*)"/) {
  1985. $lastMf = lc($1);
  1986. $mName = $2;
  1987. next;
  1988. }
  1989. if($l =~ m/<Product type\s*=\s*"([^"]*)".*id\s*=\s*"([^"]*)".*name\s*=\s*"([^"]*)"/) {
  1990. if($mf eq $lastMf && $prod eq lc($1) && $id eq lc($2)) {
  1991. if($config) {
  1992. $ret = (($l =~ m/config\s*=\s*"([^"]*)"/) ? $1 : "unknown");
  1993. ZWave_mfsAddClasses($hash, $1);
  1994. # execInits needs the modelId
  1995. setReadingsVal($hash, "modelId", "$mf-$prod-$id", TimeNow());
  1996. ZWave_execInits($hash, 50, $ret);
  1997. return "modelConfig:$ret";
  1998. } else {
  1999. $ret = "model:$mName $3";
  2000. }
  2001. last;
  2002. }
  2003. }
  2004. }
  2005. close(FH);
  2006. return $ret if($ret);
  2007. } else {
  2008. Log 1, "can't open $xml: $!";
  2009. }
  2010. return sprintf("model:0x%s 0x%s 0x%s", $mf, $prod, $id);
  2011. }
  2012. my @zwave_wd = ("none","mon","tue","wed","thu","fri","sat","sun");
  2013. sub
  2014. ZWave_ccsSet($)
  2015. {
  2016. my ($spec) = @_;
  2017. my @arg = split(/[ ,]/, $spec);
  2018. my $usage = "wrong arg, need: <weekday> HH:MM relTemp HH:MM relTemp ...";
  2019. return ($usage,"") if(@arg < 1 || int(@arg) > 19 || (int(@arg)-1)%2 != 0);
  2020. my $wds = shift(@arg);
  2021. my $ret;
  2022. map { $ret=sprintf("%02x",$_) if($zwave_wd[$_] eq $wds) }(1..int($#zwave_wd));
  2023. return ("Unknown weekday $wds, use one of ".join(" ", @zwave_wd), "")
  2024. if(!defined($ret));
  2025. for(my $i=0; $i<@arg; $i+=2) {
  2026. return ($usage, "") if($arg[$i] !~ m/^(\d+):(\d\d)$/);
  2027. $ret .= sprintf("%02x%02x", $1, $2);
  2028. return ($usage, "") if($arg[$i+1] !~ m/^([-.\d]+)$/ || $1 < -12 || $1 > 12);
  2029. $ret .= sprintf("%02x", $1 < 0 ? (255+$1*10) : ($1*10));
  2030. }
  2031. for(my $i=@arg; $i<18; $i+=2) {
  2032. $ret .= "00007f";
  2033. }
  2034. return ("", "01$ret");
  2035. }
  2036. sub
  2037. ZWave_ccsSetOverride($)
  2038. {
  2039. my ($arg) = @_;
  2040. my $override_type;
  2041. my $override_state;
  2042. my $err = "wrong arguments, see commandref for details";
  2043. if ($arg =~ m/(no|temporary|permanent) (.*)/) {
  2044. $override_type = (lc($1) eq "no" ? 0 : (lc($1) eq "temporary" ? 1 : 2));
  2045. my $state = $2;
  2046. if ($state =~ m/(frost|energy)/) {
  2047. $override_state = (lc($state) eq "frost" ? 0x79 : 0x7a);
  2048. } elsif ($state =~ m/[-+]?[0-9]*\.?[0-9]+/) {
  2049. $state *= 10;
  2050. $state = 120 if ($state > 120);
  2051. $state = -128 if ($state < -128);
  2052. $state += 256 if ($state < 0);
  2053. $override_state = $state;
  2054. } else {
  2055. return($err, "");
  2056. }
  2057. return ("", sprintf("06%02x%02x", $override_type, $override_state));
  2058. }
  2059. return($err, "");
  2060. }
  2061. sub
  2062. ZWave_ccsGet($)
  2063. {
  2064. my ($wds, $wdn) = @_;
  2065. $wds = "" if($wds eq "%s"); # No parameter specified
  2066. map { $wdn = $_ if($zwave_wd[$_] eq $wds) } (1..int($#zwave_wd));
  2067. return ("Unknown weekday $wds, use one of ".join(" ", @zwave_wd), "")
  2068. if(!$wdn);
  2069. return ("", sprintf("02%02x", $wdn));
  2070. }
  2071. sub
  2072. ZWave_ccsAllGet ($)
  2073. {
  2074. my ($hash) = @_;
  2075. foreach my $idx (1..int($#zwave_wd)) {
  2076. ZWave_Get($hash, $hash->{NAME}, "ccs", $zwave_wd[$idx]);
  2077. }
  2078. return ("working in the background","EMPTY");
  2079. }
  2080. sub
  2081. ZWave_ccsParse($$)
  2082. {
  2083. my ($t, $p) = @_;
  2084. return "ccsChanged:$p" if($t == "05");
  2085. if($t == "08" && $p =~ m/^(..)(..)$/) {
  2086. my $ret = ($1 eq "00" ? "no" : ($1 eq "01" ? "temporary" : "permanent"));
  2087. $ret .= ", ". ($2 eq "79" ? "frost protection" :
  2088. ($2 eq "7a" ? "energy saving" : "unused"));
  2089. return "ccsOverride:$ret";
  2090. }
  2091. if($t == "03") {
  2092. $p =~ /^(..)(.*$)/;
  2093. my $n = "ccs_".$zwave_wd[hex($1)];
  2094. $p = $2;
  2095. my @v;
  2096. while($p =~ m/^(..)(..)(..)(.*)$/) {
  2097. last if($3 eq "7f"); # unused
  2098. $p = $4;
  2099. my $t = hex($3);
  2100. $t = ($t == 0x7a ? "energySave" : $t >= 0x80 ? -(255-$t)/10 : $t/10);
  2101. push @v, sprintf("%02d:%02d %0.1f", hex($1), hex($2), $t);
  2102. }
  2103. return "$n:".(@v ? join(" ",@v) : "N/A");
  2104. }
  2105. return "ccs: UNKNOWN $t$p";
  2106. }
  2107. sub
  2108. ZWave_userCodeSet($)
  2109. {
  2110. my ($spec) = @_;
  2111. my @arg = split(" ", $spec);
  2112. return ("wrong arg, need: id status usercode","")
  2113. if(@arg != 3 || $spec !~ m/^[A-F0-9 ]*$/i);
  2114. return ("", sprintf("01%02x%02x%s", $arg[0],$arg[1],$arg[2]));
  2115. }
  2116. sub
  2117. ZWave_clockAdjust($$)
  2118. {
  2119. my ($hash, $d) = @_;
  2120. return $d if($d !~ m/^13(..)048104....$/);
  2121. my ($err, $nd) = ZWave_clockSet();
  2122. my $cmdEf = (AttrVal($hash->{NAME},"noExplorerFrames",0) == 0 ? "25" : "05");
  2123. return "13${1}0481${nd}${cmdEf}${1}";
  2124. }
  2125. sub
  2126. ZWave_clockSet()
  2127. {
  2128. my @l = localtime();
  2129. return ("", sprintf("04%02x%02x", (($l[6] ? $l[6]:7)<<5)|$l[2], $l[1]));
  2130. }
  2131. sub
  2132. ZWave_clockParse($$)
  2133. {
  2134. my ($p1,$p2) = @_;
  2135. $p1 = hex($p1); $p2 = hex($p2);
  2136. return sprintf("clock:%s %02d:%02d", $zwave_wd[$p1>>5], $p1 & 0x1f, $p2);
  2137. }
  2138. sub
  2139. ZWave_cleanString($$$)
  2140. {
  2141. my ($c, $postfix, $isValue) = @_;
  2142. my $shortened = 0;
  2143. $c =~ s/^[0-9.]+ //g if(!$isValue);
  2144. $c =~ s/Don.t/Dont/g; # Bugfix
  2145. if($c =~ m/^(.+)\.(.+)$/ && $2 !~ m/^[ \d]+$/) { # delete second sentence
  2146. $c = $1; $shortened++;
  2147. }
  2148. $c =~ s/[^A-Z0-9]+/ /ig;
  2149. $c =~ s/ *$//g;
  2150. $c =~ s/ (.)/uc($1)/gei;
  2151. while(length($c) > 32 && $shortened < 999) {
  2152. $c =~ s/[A-Z][^A-Z]*$//;
  2153. $shortened++;
  2154. }
  2155. $c .= $postfix if($shortened);
  2156. return ($c, $shortened);;
  2157. }
  2158. ###################################
  2159. # Poor mans XML-Parser
  2160. sub
  2161. ZWave_configParseModel($;$)
  2162. {
  2163. my ($cfg, $my) = @_;
  2164. return if(!$my && ZWave_configParseModel($cfg, 1));
  2165. my $fn = $attr{global}{modpath}."/FHEM/lib/".($my ? "fhem_":"open").
  2166. "zwave_deviceconfig.xml.gz";
  2167. my $gz = gzopen($fn, "rb");
  2168. if(!$gz) {
  2169. Log 3, "Can't open $fn: $!" if(!$my);
  2170. return 0;
  2171. }
  2172. my ($ret, $line, $class, %hash, $cmdName, %classInfo, %group);
  2173. while($gz->gzreadline($line)) { # Search the "file" entry
  2174. if($line =~ m/^\s*<Product.*sourceFile="$cfg"/) {
  2175. $ret = 1;
  2176. last;
  2177. }
  2178. }
  2179. my $partial="";
  2180. while($gz->gzreadline($line)) {
  2181. last if($line =~ m+^\s*</Product>+);
  2182. if($line =~ m/^\s*<CommandClass.*id="([^"]*)"(.*)$/) {
  2183. $class = $1;
  2184. $classInfo{$class} = $2;
  2185. }
  2186. $group{$1} = $line if($line =~ m/^\s*<Group.*index="([^"]*)".*$/);
  2187. next if(!$class || $class ne "112");
  2188. if($line =~ m/^\s*<Value /) {
  2189. my %h;
  2190. $h{type} = $1 if($line =~ m/type="([^"]*)"/i);
  2191. $h{size} = $1 if($line =~ m/size="([^"]*)"/i);
  2192. $h{genre} = $1 if($line =~ m/genre="([^"]*)"/i); # config, user
  2193. $h{label} = $1 if($line =~ m/label="([^"]*)"/i);
  2194. $h{min} = $1 if($line =~ m/min="([^"]*)"/i);
  2195. $h{max} = $1 if($line =~ m/max="([^"]*)"/i);
  2196. $h{value} = $1 if($line =~ m/value="([^"]*)"/i);
  2197. $h{index} = $1 if($line =~ m/index="([^"]*)"/i); # 1, 2, etc
  2198. $h{read_only} = $1 if($line =~ m/read_only="([^"]*)"/i); # true,false
  2199. $h{write_only} = $1 if($line =~ m/write_only="([^"]*)"/i); # true,false
  2200. my ($cmd,$shortened) = ZWave_cleanString($h{label}, $h{index}, 0);
  2201. $cmdName = "config$cmd";
  2202. $h{Help} = "";
  2203. $h{Help} .= "Full text for $cmdName is: $h{label}<br>" if($shortened);
  2204. $hash{$cmdName} = \%h;
  2205. }
  2206. if($line =~ m,<Help>, && $line !~ m,</Help>,) { # Multiline Help
  2207. $partial = $line;
  2208. next;
  2209. }
  2210. if($partial) {
  2211. if($line =~ m,</Help>,) {
  2212. $line = $partial.$line;
  2213. $line =~ s/[\r\n]//gs;
  2214. $partial = "";
  2215. } else {
  2216. $partial .= $line;
  2217. next;
  2218. }
  2219. }
  2220. $hash{$cmdName}{Help} .= "$1<br>" if($line =~ m+<Help>(.*)</Help>+s);
  2221. if($line =~ m/^\s*<Item/) {
  2222. my $label = $1 if($line =~ m/label="([^"]*)"/i);
  2223. my $value = $1 if($line =~ m/value="([^"]*)"/i);
  2224. my ($item, $shortened) = ZWave_cleanString($label, $value, 1);
  2225. $hash{$cmdName}{Item}{$item} = $value;
  2226. $hash{$cmdName}{type} = "list"; # Forum #42604
  2227. $hash{$cmdName}{Help} .= "Full text for $item is $label<br>"
  2228. if($shortened);
  2229. }
  2230. }
  2231. $gz->gzclose();
  2232. my %mc = (set=>{}, get=>{}, config=>{},classInfo=>\%classInfo,group=>\%group);
  2233. foreach my $cmd (keys %hash) {
  2234. my $h = $hash{$cmd};
  2235. my $arg = ($h->{type} eq "button" ? "a" : "a%b");
  2236. $mc{set}{$cmd} = $arg if(!$h->{read_only} || $h->{read_only} ne "true");
  2237. $mc{get}{$cmd} ="noArg" if(!$h->{write_only} || $h->{write_only} ne "true");
  2238. $mc{config}{$cmd} = $h;
  2239. my $caName = "$cfg$cmd";
  2240. $zwave_cmdArgs{set}{$caName} = join(",", keys %{$h->{Item}}) if($h->{Item});
  2241. $zwave_cmdArgs{set}{$caName} = "noArg" if($h->{type} eq "button");
  2242. $zwave_cmdArgs{get}{$caName} = "noArg";
  2243. }
  2244. $zwave_modelConfig{$cfg} = \%mc;
  2245. Log 3, "ZWave got config for $cfg from $fn" if($ret);
  2246. return $ret;
  2247. }
  2248. ###################################
  2249. sub
  2250. ZWave_configGetHash($)
  2251. {
  2252. my ($hash) = @_;
  2253. return undef if(!$hash);
  2254. my $mc = ReadingsVal($hash->{NAME}, "modelConfig", "");
  2255. ZWave_configParseModel($mc) if($mc && !$zwave_modelConfig{$mc});
  2256. return $zwave_modelConfig{$mc};
  2257. }
  2258. sub
  2259. ZWave_configCheckParam($$$$@)
  2260. {
  2261. my ($hash, $type, $cmd, $fmt, @arg) = @_;
  2262. my $mc = ZWave_configGetHash($hash);
  2263. return ("", sprintf($fmt, @arg)) if(!$mc);
  2264. my $h = $mc->{config}{$cmd};
  2265. return ("", sprintf($fmt, @arg)) if(!$h);
  2266. return ("", sprintf("05%02x", $h->{index})) if($type eq "get");
  2267. if($cmd eq "configRGBLedColorForTesting") {
  2268. return ("6 digit hext number needed","") if($arg[0] !~ m/^[0-9a-f]{6}$/i);
  2269. return ("", sprintf("04%02x03%s", $h->{index}, $arg[0]));
  2270. }
  2271. my $t = $h->{type};
  2272. if($t eq "list") {
  2273. my $v = $h->{Item}{$arg[0]};
  2274. return ("Unknown parameter $arg[0] for $cmd, use one of ".
  2275. join(",", keys %{$h->{Item}}), "") if(!defined($v));
  2276. my $len = ($v > 65535 ? 8 : ($v > 255 ? 4 : 2));
  2277. return ("", sprintf("04%02x%02d%0*x", $h->{index}, $len/2, $len, $v));
  2278. }
  2279. if($t eq "button") {
  2280. return ("", sprintf("04%02x01%02x", $h->{index}, $h->{value}));
  2281. }
  2282. return ("Parameter is not decimal", "") if($arg[0] !~ m/^-?[0-9]+$/);
  2283. if($h->{size}) { # override type by size
  2284. $t = ($h->{size} eq "1" ? "byte" : ($h->{size} eq "2" ? "short" : "int"));
  2285. }
  2286. my $len = ($t eq "int" ? 8 : ($t eq "short" ? 4 : 2));
  2287. $arg[0] += 2**($len==8 ? 32 : ($len==4 ? 16 : 8)) if($arg[0] < 0); #F:41709
  2288. return ("", sprintf("04%02x%02x%0*x", $h->{index}, $len/2, $len, $arg[0]));
  2289. }
  2290. ##############################################
  2291. ### START: 0x20 BASIC
  2292. sub
  2293. ZWave_BASIC_03_report ($$$)
  2294. { # 0x2003 BASIC_REPORT V2
  2295. my ($value, $target, $duration) = @_;;
  2296. my $time = hex($duration);
  2297. if (($time > 0x7F) && ($time <= 0xFD)) {
  2298. $time = (hex($duration) - 0x7F) * 60;
  2299. };
  2300. $time .= " seconds";
  2301. $time = "unknown" if (hex($duration) == 0xFE);
  2302. $time = "255" if (hex($duration) == 0xFF);
  2303. my $rt = "basicReport:".hex($value)
  2304. ." target: ".hex($target)
  2305. ." duration: ".$time;
  2306. return $rt;
  2307. }
  2308. ##############################################
  2309. ### START: 0x21 APPLICATION_STATUS
  2310. sub
  2311. ZWave_APPLICATION_STATUS_01_Report($$$)
  2312. { # 0x2101 ApplicationStatus ApplicationBusyReport >= V1
  2313. my ($hash, $st, $wTime) = @_;
  2314. my $name = $hash->{NAME};
  2315. my $status = hex($st);
  2316. my $rt .= $status==0 ? "tryAgainLater " :
  2317. $status==1 ? "tryAgainInWaitTimeSeconds " :
  2318. $status==2 ? "RequestQueued " : "unknownStatusCode ";
  2319. $rt .= sprintf("waitTime: %d", hex($wTime));
  2320. return ("applicationBusy:$rt");
  2321. }
  2322. ##############################################
  2323. ### START: 0x71 ALARM (NOTIFICATION)
  2324. ### Renamed from ALARM to NOTIFICATION in V3 specification,
  2325. ### for backward compatibility the name ALARM will be used
  2326. ### regardless of the version of the class.
  2327. my %zwave_alarmType = (
  2328. "01"=>"Smoke",
  2329. "02"=>"CO",
  2330. "03"=>"CO2",
  2331. "04"=>"Heat",
  2332. "05"=>"Water",
  2333. "06"=>"AccessControl",
  2334. "07"=>"HomeSecurity",
  2335. "08"=>"PowerManagement",
  2336. "09"=>"System",
  2337. "0a"=>"Emergency",
  2338. "0b"=>"Clock",
  2339. "0c"=>"Appliance",
  2340. "0d"=>"HomeHealth"
  2341. );
  2342. my %zwave_alarmEvent = ( # no comma allowed in strings
  2343. "0101"=>"detected",
  2344. "0102"=>"detected - Unknown Location",
  2345. "0103"=>"Alarm Test",
  2346. "0201"=>"detected",
  2347. "0202"=>"detected - Unknown Location",
  2348. "0301"=>"detected",
  2349. "0302"=>"detected - Unknown Location",
  2350. "0401"=>"Overheat detected",
  2351. "0402"=>"Overheat detected - Unknown Location",
  2352. "0403"=>"Rapid Temperature Rise",
  2353. "0404"=>"Rapid Temperature Rise - Unknown Location",
  2354. "0405"=>"Underheat detected",
  2355. "0406"=>"Underheat detected - Unknown Location",
  2356. "0501"=>"Leak detected",
  2357. "0502"=>"Leak detected - Unknown Location",
  2358. "0503"=>"Level Dropped",
  2359. "0504"=>"Level Dropped - Unknown Location",
  2360. "0505"=>"Replace Filter",
  2361. "0601"=>"Manual Lock Operation",
  2362. "0602"=>"Manual Unlock Operation",
  2363. "0603"=>"RF Lock Operation",
  2364. "0604"=>"RF Unlock Operation",
  2365. "0605"=>"Keypad Lock Operation",
  2366. "0606"=>"Keypad Unlock Operation",
  2367. "0607"=>"Manual Not Fully Locked Operation",
  2368. "0608"=>"RF Not Fully Locked Operation",
  2369. "0609"=>"Auto Lock Locked Operation",
  2370. "060a"=>"Auto Lock Not Fully Operation",
  2371. "060b"=>"Lock Jammed",
  2372. "060c"=>"All user codes deleted",
  2373. "060d"=>"Single user code deleted",
  2374. "060e"=>"New user code added",
  2375. "060f"=>"New user code not added due to duplicate code",
  2376. "0610"=>"Keypad temporary disabled",
  2377. "0611"=>"Keypad busy",
  2378. "0612"=>"New Program code Entered - Unique code for lock configuration",
  2379. "0613"=>"Manually Enter user Access code exceeds code limit",
  2380. "0614"=>"Unlock By RF with invalid user code",
  2381. "0615"=>"Locked by RF with invalid user codes",
  2382. "0616"=>"Window/Door is open",
  2383. "0617"=>"Window/Door is closed",
  2384. "0640"=>"Barrier performing Initialization process",
  2385. "0641"=>"Barrier operation (Open / Close) force has been exceeded.",
  2386. "0642"=>"Barrier motor has exceeded manufacturer's operational time limit",
  2387. "0643"=>"Barrier operation has exceeded physical mechanical limits.",
  2388. "0644"=>"Barrier unable to perform requested operation due to UL requirements.",
  2389. "0645"=>"Barrier Unattended operation has been disabled per UL requirements.",
  2390. "0646"=>"Barrier failed to perform Requested operation, device malfunction",
  2391. "0647"=>"Barrier Vacation Mode",
  2392. "0648"=>"Barrier Safety Beam Obstacle",
  2393. "0649"=>"Barrier Sensor Not Detected / Supervisory Error",
  2394. "064a"=>"Barrier Sensor Low Battery Warning",
  2395. "064b"=>"Barrier detected short in Wall Station wires",
  2396. "064c"=>"Barrier associated with non-Z-wave remote control.",
  2397. "0700"=>"Previous Events cleared",
  2398. "0701"=>"Intrusion",
  2399. "0702"=>"Intrusion - Unknown Location",
  2400. "0703"=>"Tampering - product covering removed",
  2401. "0704"=>"Tampering - Invalid Code",
  2402. "0705"=>"Glass Breakage",
  2403. "0706"=>"Glass Breakage - Unknown Location",
  2404. "0707"=>"Motion Detection",
  2405. "0708"=>"Motion Detection - Unknown Location",
  2406. "0800"=>"Previous Events cleared",
  2407. "0801"=>"Power has been applied",
  2408. "0802"=>"AC mains disconnected",
  2409. "0803"=>"AC mains re-connected",
  2410. "0804"=>"Surge Detection",
  2411. "0805"=>"Voltage Drop/Drift",
  2412. "0806"=>"Over-current detected",
  2413. "0807"=>"Over-voltage detected",
  2414. "0808"=>"Over-load detected",
  2415. "0809"=>"Load error",
  2416. "080a"=>"Replace battery soon",
  2417. "080b"=>"Replace battery now",
  2418. "080c"=>"Battery is charging",
  2419. "080d"=>"Battery is fully charged",
  2420. "080e"=>"Charge battery soon",
  2421. "080f"=>"Charge battery now!",
  2422. "0901"=>"hardware failure",
  2423. "0902"=>"software failure",
  2424. "0903"=>"hardware failure with OEM proprietary failure code",
  2425. "0904"=>"software failure with OEM proprietary failure code",
  2426. "0a01"=>"Contact Police",
  2427. "0a02"=>"Contact Fire Service",
  2428. "0a03"=>"Contact Medical Service",
  2429. "0b01"=>"Wake Up Alert",
  2430. "0b02"=>"Timer Ended",
  2431. "0b03"=>"Time remaining",
  2432. "0c01"=>"Program started",
  2433. "0c02"=>"Program in progress",
  2434. "0c03"=>"Program completed",
  2435. "0c04"=>"Replace main filter",
  2436. "0c05"=>"Failure to set target temperature",
  2437. "0c06"=>"Supplying water",
  2438. "0c07"=>"Water supply failure",
  2439. "0c08"=>"Boiling",
  2440. "0c09"=>"Boiling failure",
  2441. "0c0a"=>"Washing",
  2442. "0c0b"=>"Washing failure",
  2443. "0c0c"=>"Rinsing",
  2444. "0c0d"=>"Rinsing failure",
  2445. "0c0e"=>"Draining",
  2446. "0c0f"=>"Draining failure",
  2447. "0c10"=>"Spinning",
  2448. "0c11"=>"Spinning failure",
  2449. "0c12"=>"Drying",
  2450. "0c13"=>"Drying failure",
  2451. "0c14"=>"Fan failure",
  2452. "0c15"=>"Compressor failure",
  2453. "0d00"=>"Previous Events cleared",
  2454. "0d01"=>"Leaving Bed",
  2455. "0d02"=>"Sitting on bed",
  2456. "0d03"=>"Lying on bed",
  2457. "0d04"=>"Posture changed",
  2458. "0d05"=>"Sitting on edge of bed",
  2459. "0d06"=>"Volatile Organic Compound level"
  2460. );
  2461. sub
  2462. ZWave_ALARM_01_Get($) {
  2463. # 0x7101 Alarm/Notification EventSupportedGet >= V3
  2464. # alarmEventSupported
  2465. my ($arg) = @_;
  2466. foreach my $t (keys %zwave_alarmType) {
  2467. if (lc($zwave_alarmType{$t}) eq lc($arg)) {
  2468. return ("", "01".$t);
  2469. }
  2470. }
  2471. return ("unknown notification type entered, see commandref", "");
  2472. }
  2473. sub
  2474. ZWave_ALARM_02_Report($) {
  2475. # 0x7102 Alarm/Notification EventSupportedReport >= V3
  2476. # additional flagname "Appliance" in V4
  2477. my ($arg) = @_;
  2478. if($arg !~ m/(..)(..)(.*)/) {
  2479. return ("wrong format received");
  2480. }
  2481. my $t = $1;
  2482. my $rt = "alarmEventSupported_";
  2483. $rt .= ($zwave_alarmType{$t}) ? $zwave_alarmType{$t}.":" :
  2484. hex($t)."_unknown:";
  2485. my $numBitMasks = $2 & 0x1f;
  2486. #my $res = ($2 & 0xe0) >> 5; # reserved field
  2487. my $e = "";
  2488. my $val = $3;
  2489. my $delimeter = "";
  2490. for (my $i=0; $i<$numBitMasks; $i++) {
  2491. my $supported = hex(substr($val, $i*2, 2));
  2492. for (my $j=$i*8; $j<$i*8+8; $j++) {
  2493. if ($supported & (2 ** ($j-$i*8))) {
  2494. $e = sprintf("%s%02x", $t, $j);
  2495. $rt .= $delimeter;
  2496. $rt .= "(" . $j . ") ";
  2497. if (!$zwave_alarmEvent{$e}) {
  2498. $rt .= "unknown event";
  2499. } else {
  2500. $rt .= $zwave_alarmEvent{$e};
  2501. }
  2502. $delimeter = ", ";
  2503. }
  2504. }
  2505. }
  2506. return $rt;
  2507. }
  2508. sub
  2509. ZWave_ALARM_04_Get($$)
  2510. {
  2511. # 0x7104 Alarm/Notification alarmGet >= V1
  2512. # alarm (V1), alarmWithType (V2), alarmWithTypeEvent (>=V3)
  2513. my ($v, $arg) = @_;
  2514. my $rt = "04";
  2515. if ($v == 1) {
  2516. if($arg !~ m/^$p1_b$/) {
  2517. return ("wrong format, see commandref", "");
  2518. }
  2519. $rt .= sprintf("%02x", $1);
  2520. return ("",$rt);
  2521. } elsif ($v == 2) {
  2522. if($arg !~ m/(.*)/) {
  2523. return ("wrong format, see commandref", "");
  2524. }
  2525. foreach my $t (keys %zwave_alarmType) {
  2526. if (lc($zwave_alarmType{$t}) eq lc($1)) {
  2527. $rt .= sprintf("00%s", $t);
  2528. return ("", $rt);
  2529. }
  2530. }
  2531. } elsif ($v >= 3) { # V3=V4
  2532. if($arg !~ m/(.*) $p1_b/) {
  2533. return ("wrong format, see commandref", "");
  2534. }
  2535. foreach my $t (keys %zwave_alarmType) {
  2536. if (lc($zwave_alarmType{$t}) eq lc($1)) {
  2537. $rt .= sprintf("00%s%02x", $t, $2);
  2538. return ("", $rt);
  2539. }
  2540. }
  2541. }
  2542. }
  2543. sub
  2544. ZWave_ALARM_05_Report($$$$)
  2545. {
  2546. # 0x7105 Alarm/Notification Report >= V1
  2547. # additional parameter in V2 and V3
  2548. my ($hash, $t, $l, $r) = @_;
  2549. my $name = $hash->{NAME};
  2550. my $rt0 = "";
  2551. my $rt1 = "";
  2552. my $at = "";
  2553. my $level = "";
  2554. my $eventname = "";
  2555. my $ar = AttrVal($name, "extendedAlarmReadings",0);
  2556. if (!$r) { #V1 Answer
  2557. $at = $zwave_alarmType{$t} ? $zwave_alarmType{$t} :
  2558. sprintf("%d_unknown", hex($t));
  2559. $rt0 = "alarm_type_$t:level $l";
  2560. $rt1 = "alarm_$at:level $l";
  2561. } elsif ($r =~ m/(..)(..)(..)(..)(..)(.*)/) {
  2562. my ($zid, $ns, $t2, $e, $prop, $opt) = ($1, $2, $3, $4, $5, $6);
  2563. if ($e ne "00") {
  2564. if (($t ne "00") && ($l eq "00")) {
  2565. $level = "Event cleared: ";
  2566. }
  2567. } else {
  2568. $level = "Event cleared: ";
  2569. my $len = hex($prop & 0x1f);
  2570. if (($len >= 1) && ($opt =~ m/(..)(.*)/)) {
  2571. $e = $1;
  2572. }
  2573. }
  2574. $eventname = $zwave_alarmEvent{"$t2$e"} ? $zwave_alarmEvent{"$t2$e"}
  2575. : sprintf("unknown event %d", hex($e));
  2576. $at = $zwave_alarmType{$t2} ? $zwave_alarmType{$t2} :
  2577. sprintf("%d_unknown", hex($t2));
  2578. my $nst = ($ns eq "ff") ? "notificationIsOn" : "notificationIsOff";
  2579. my $o = ($opt && ($e ne "00")) ? ", arg $prop$opt" : "";
  2580. $rt0 = "alarm:$at: $level$eventname$o";
  2581. $rt1 = "alarm_$at:$level$eventname$o, $nst";
  2582. }
  2583. if ($ar == 0) {
  2584. return ($rt0);
  2585. } elsif ($ar == 1) {
  2586. return ($rt1);
  2587. } elsif ($ar == 2) {
  2588. return ($rt0, $rt1);
  2589. }
  2590. }
  2591. sub
  2592. ZWave_ALARM_06_Set($) {
  2593. # 0x7106 Alarm/Notification alarmSet (>=V2)
  2594. # alarmnotification
  2595. my ($arg) = @_;
  2596. if($arg !~ m/^(.*) (on|off)$/i) {
  2597. return ("wrong format, see commandref", "");
  2598. }
  2599. my $status = (lc($2) eq "on") ? "FF" : "00";
  2600. foreach my $t (keys %zwave_alarmType) {
  2601. if (lc($zwave_alarmType{$t}) eq lc($1)) {
  2602. return ("", "06".$t.$status);
  2603. }
  2604. }
  2605. return ("alarm/notification type not defined","");
  2606. }
  2607. sub
  2608. ZWave_ALARM_08_Report($) {
  2609. # 0x7108 Alarm/Notification TypeSupportedReport >= V2
  2610. # additional flagname "Appliance" in V4
  2611. my ($arg) = @_;
  2612. if($arg !~ m/(..)(.*)/) {
  2613. return ("wrong format received");
  2614. }
  2615. my $numBitMasks = $1 & 0x1f;
  2616. #my $res = ($1 & 0x60) >> 5; # reserved field
  2617. my $alarm_v1 = $1 & 0x80; # 0:standard types, 1:V1 non-standard
  2618. if ($alarm_v1) {
  2619. return ("alarmTypeSupported:non-standard V1 Alarm Types used");
  2620. } else {
  2621. my $rt = "alarmTypeSupported:";
  2622. my $t = "";
  2623. my $val = $2;
  2624. my $delimeter = "";
  2625. for (my $i=0; $i<$numBitMasks; $i++) {
  2626. my $supported = hex(substr($val, $i*2, 2));
  2627. for (my $j=$i*8; $j<$i*8+8; $j++) {
  2628. if ($supported & (2 ** ($j-$i*8))) {
  2629. $t = sprintf("%02x", $j);
  2630. $rt .= sprintf("$delimeter$zwave_alarmType{$t}");
  2631. $delimeter = " ";
  2632. }
  2633. }
  2634. }
  2635. return $rt;
  2636. }
  2637. }
  2638. ### END: 0x71 ALARM/NOTIFICATION
  2639. ##############################################
  2640. sub
  2641. ZWave_protectionParse($$)
  2642. {
  2643. my ($lp, $rp) = @_;
  2644. my $lpt = "Local: ". ($lp eq "00" ? "unprotected" :
  2645. ($lp eq "01" ? "by sequence" : "No operation possible"));
  2646. my $rpt = "RF: ". ($rp eq "00" ? "unprotected" :
  2647. ($rp eq "01" ? "No control" : "No response"));
  2648. return "protection:$lpt $rpt";
  2649. }
  2650. sub
  2651. ZWave_configParse($$$$)
  2652. {
  2653. my ($hash, $cmdId, $size, $val) = @_;
  2654. $val = substr($val, 0, 2*$size);
  2655. $val = hex($val);
  2656. $cmdId = hex($cmdId);
  2657. my $mc = ZWave_configGetHash($hash);
  2658. return "config_$cmdId:$val" if(!$mc);
  2659. my $h = $mc->{config};
  2660. foreach my $cmd (keys %{$h}) {
  2661. if($h->{$cmd}{index} == $cmdId) {
  2662. my $hi = $h->{$cmd}{Item};
  2663. if($hi) {
  2664. foreach my $item (keys %{$hi}) {
  2665. return "$cmd:$item" if($hi->{$item} == $val);
  2666. }
  2667. }
  2668. return "$cmd:$val";
  2669. }
  2670. }
  2671. return "config_$cmdId:$val";
  2672. }
  2673. sub
  2674. ZWave_configAllGet($)
  2675. {
  2676. my ($hash) = @_;
  2677. my $mc = ZWave_configGetHash($hash);
  2678. return ("configAll: no model specific configs found", undef)
  2679. if(!$mc || !$mc->{config});
  2680. delete($hash->{CL});
  2681. foreach my $c (sort keys %{$mc->{get}}) {
  2682. ZWave_Get($hash, $hash->{NAME}, $c);
  2683. }
  2684. return ("working in the background","EMPTY");
  2685. }
  2686. sub
  2687. ZWave_associationAllGet($$)
  2688. {
  2689. my ($hash, $data) = @_;
  2690. if(!$data) { # called by the user
  2691. $zwave_parseHook{"$hash->{nodeIdHex}:..85"} = \&ZWave_associationAllGet;
  2692. delete($hash->{CL});
  2693. ZWave_Get($hash, $hash->{NAME}, "associationGroups");
  2694. return("working in the background", "EMPTY");
  2695. }
  2696. my $nGrp = ($data =~ m/..8506(..)/ ? hex($1) :
  2697. ReadingsVal($hash->{NAME}, "assocGroups", 0));
  2698. my $grp = 0;
  2699. $grp = hex($1) if($data =~ m/..8503(..)/);
  2700. return if($grp >= $nGrp);
  2701. $zwave_parseHook{"$hash->{nodeIdHex}:..85"} = \&ZWave_associationAllGet;
  2702. ZWave_Get($hash, $hash->{NAME}, "association", $grp+1);
  2703. return;
  2704. }
  2705. sub
  2706. ZWave_mcaAllGet($$)
  2707. {
  2708. my ($hash, $data) = @_;
  2709. if(!$data) { # called by the user
  2710. $zwave_parseHook{"$hash->{nodeIdHex}:..8e"} = \&ZWave_mcaAllGet;
  2711. delete($hash->{CL});
  2712. ZWave_Get($hash, $hash->{NAME}, "mcaGroupings");
  2713. return("working in the background", "EMPTY");
  2714. }
  2715. my $nGrp = ($data =~ m/..8e06(..)/ ? hex($1) :
  2716. ReadingsVal($hash->{NAME}, "mcaGroups", 0));
  2717. my $grp = 0;
  2718. $grp = hex($1) if($data =~ m/..8e03(..)/);
  2719. return if($grp >= $nGrp);
  2720. $zwave_parseHook{"$hash->{nodeIdHex}:..8e"} = \&ZWave_mcaAllGet;
  2721. ZWave_Get($hash, $hash->{NAME}, "mca", $grp+1);
  2722. return;
  2723. }
  2724. my %zwave_roleType = (
  2725. "00"=>"CentralStaticController",
  2726. "01"=>"SubStaticController",
  2727. "02"=>"PortableController",
  2728. "03"=>"PortableReportingController",
  2729. "04"=>"PortableSlave",
  2730. "05"=>"AlwaysOnSlave",
  2731. "06"=>"SleepingReportingSlave",
  2732. "07"=>"SleepingListeningSlave"
  2733. );
  2734. my %zwave_nodeType = (
  2735. "00"=>"Z-Wave+Node",
  2736. "01"=>"Z-Wave+IpRouter",
  2737. "02"=>"Z-Wave+IpGateway",
  2738. "03"=>"Z-Wave+IpClientAndIpNode",
  2739. "04"=>"Z-Wave+IpClientAndZwaveNode"
  2740. );
  2741. sub
  2742. ZWave_plusInfoParse($$$$$)
  2743. {
  2744. my ($version, $roleType, $nodeType, $installerIconType, $userIconType) = @_;
  2745. return "zwavePlusInfo: " .
  2746. "version:" . $version .
  2747. " role:" .
  2748. ($zwave_roleType{"$roleType"} ? $zwave_roleType{"$roleType"} :"unknown") .
  2749. " node:" .
  2750. ($zwave_nodeType{"$nodeType"} ? $zwave_nodeType{"$nodeType"} :"unknown") .
  2751. " installerIcon:". $installerIconType .
  2752. " userIcon:". $userIconType;
  2753. }
  2754. my %zwave_sensorBinaryTypeV2 = (
  2755. "01"=>"generalPurpose",
  2756. "02"=>"smoke",
  2757. "03"=>"CO",
  2758. "04"=>"CO2",
  2759. "05"=>"heat",
  2760. "06"=>"water",
  2761. "07"=>"freeze",
  2762. "08"=>"tamper",
  2763. "09"=>"aux",
  2764. "0a"=>"doorWindow",
  2765. "0b"=>"tilt",
  2766. "0c"=>"motion",
  2767. "0d"=>"glassBreak"
  2768. );
  2769. sub
  2770. ZWave_sensorbinaryV2Parse($$)
  2771. {
  2772. my ($value, $sensorType) = @_;
  2773. return ($zwave_sensorBinaryTypeV2{"$sensorType"} ?
  2774. $zwave_sensorBinaryTypeV2{"$sensorType"} :"unknown") .
  2775. ":".($value eq "00" ? "off" : ($value eq "ff" ? "on" : hex($value)));
  2776. }
  2777. sub
  2778. ZWave_assocGroup($$$$)
  2779. {
  2780. my ($homeId, $gId, $max, $nodes) = @_;
  2781. my %list = map { $defs{$_}{nodeIdHex} => $_ }
  2782. grep { $defs{$_}{homeId} &&
  2783. $defs{$_}{nodeIdHex} &&
  2784. $defs{$_}{homeId} eq $homeId }
  2785. keys %defs;
  2786. $nodes = join(" ",
  2787. map { $list{$_} ? $list{$_} : "UNKNOWN_".hex($_); }
  2788. ($nodes =~ m/../g));
  2789. return sprintf("assocGroup_%d:Max %d Nodes %s", hex($gId),hex($max), $nodes);
  2790. }
  2791. sub
  2792. ZWave_mcaReport($$$$)
  2793. {
  2794. my ($homeId, $gId, $max, $arg) = @_;
  2795. my %list = map { $defs{$_}{nodeIdHex} => $_ }
  2796. grep { $defs{$_}{homeId} &&
  2797. $defs{$_}{nodeIdHex} &&
  2798. $defs{$_}{homeId} eq $homeId }
  2799. keys %defs;
  2800. my ($ret, $step) = ("", 1);
  2801. my @arg = ($arg =~ m/../g);
  2802. for(my $idx = 0; $idx < @arg; $idx += $step) {
  2803. my $a = $arg[$idx];
  2804. if($step == 1 && $a eq "00") {
  2805. $step = 2;
  2806. $idx--;
  2807. next;
  2808. }
  2809. my $n = ($list{$a} ? $list{$a} : sprintf("UNKNOWN_%d", hex($a)));
  2810. $ret .= " ".($step == 1 ? $n : ($n.":".hex($arg[$idx+1])));
  2811. }
  2812. return sprintf("mca_%d:Max %d %s",
  2813. hex($gId), hex($max), ($ret ? "Nodes$ret" : ""));
  2814. }
  2815. sub
  2816. ZWave_CRC16($)
  2817. {
  2818. my ($msg) = @_;
  2819. my $buf = pack 'H*', $msg;
  2820. my $len = length($buf);
  2821. my $poly = 0x1021; #CRC-CCITT (CRC-16) x16 + x12 + x5 + 1
  2822. my $crc16 = 0x1D0F; #Startvalue
  2823. for(my $i=0; $i<$len; $i++) {
  2824. my $byte = ord(substr($buf, $i, 1));
  2825. $byte = $byte * 0x100; # expand to 16 Bit
  2826. for(0..7) {
  2827. if(($byte & 0x8000) ^ ($crc16 & 0x8000)) { # if Hi-bits are different
  2828. $crc16 <<= 1;
  2829. $crc16 ^= $poly;
  2830. } else {
  2831. $crc16 <<= 1;
  2832. }
  2833. $crc16 &= 0xFFFF;
  2834. $byte <<= 1;
  2835. $byte &= 0xFFFF;
  2836. }
  2837. }
  2838. return sprintf "%x", $crc16;
  2839. }
  2840. ##############################################
  2841. # SECURITY (start)
  2842. ##############################################
  2843. sub
  2844. ZWave_secIncludeStart($$)
  2845. {
  2846. my ($hash, $iodev) = @_;
  2847. my $name = $hash->{NAME};
  2848. my $ioName = $iodev->{NAME};
  2849. readingsSingleUpdate($hash, "SECURITY",
  2850. "INITIALIZING (starting secure inclusion)", 0);
  2851. my $classes = AttrVal($name, "classes", "");
  2852. if($classes =~ m/SECURITY/) {
  2853. if ($zwave_cryptRijndael == 1) {
  2854. my $key = AttrVal($ioName, "networkKey", "");
  2855. if($key) {
  2856. $iodev->{secInitName} = $name;
  2857. Log3 $ioName, 2, "ZWAVE Starting secure init for $name";
  2858. #~ ZWave_secIncludeStart($dh);
  2859. #~ return "";
  2860. # starting secure inclusion by setting the scheme
  2861. $zwave_parseHook{"$hash->{nodeIdHex}:..9805"} = \&ZWave_secSchemeReport;
  2862. ZWave_secAddToSendStack($hash, "980400"); # only scheme "00" is defined
  2863. return 1;
  2864. } else {
  2865. Log3 $ioName,1,"No secure inclusion as $ioName has no networkKey";
  2866. readingsSingleUpdate($hash, "SECURITY",
  2867. 'DISABLED (Networkkey not found)', 0);
  2868. Log3 $name, 1, "$name: SECURITY disabled, ".
  2869. "networkkey not found";
  2870. }
  2871. } else {
  2872. readingsSingleUpdate($hash, "SECURITY",
  2873. 'DISABLED (Module Crypt::Rijndael not found)', 0);
  2874. Log3 $name, 1, "$name: SECURITY disabled, module ".
  2875. "Crypt::Rijndael not found";
  2876. }
  2877. } else {
  2878. readingsSingleUpdate($hash, "SECURITY",
  2879. 'DISABLED (SECURITY not supported by device)', 0);
  2880. Log3 $name, 1, "$name: secure inclusion failed, ".
  2881. "SECURITY disabled, device does not support SECURITY command class";
  2882. }
  2883. return 0;
  2884. }
  2885. sub
  2886. ZWave_secSchemeReport($$) # only called by zwave_parseHook during Include
  2887. {
  2888. my ($hash, $arg) = @_;
  2889. my $name = $hash->{NAME};
  2890. if ($arg =~ m/..9805(..)/) { # 03980500 is expected
  2891. if ($1 == 0) { # supported SECURITY-Scheme, prepare for setting networkkey
  2892. $zwave_parseHook{"$hash->{nodeIdHex}:..9880"} = \&ZWave_secNetworkkeySet;
  2893. ZWave_secAddToSendStack($hash, '9840');
  2894. #ZWave_Cmd("set", $hash, $name, "secNonceReport");
  2895. } else {
  2896. Log3 $name, 1, "$name: Unsupported SECURITY-Scheme received: $1"
  2897. .", please report";
  2898. }
  2899. } else {
  2900. Log3 $name, 1, "$name: Unknown SECURITY-SchemeReport received: $arg";
  2901. }
  2902. return 1; # "veto" for parseHook
  2903. }
  2904. sub
  2905. ZWave_secNetworkkeySet($$) # only called by zwave_parseHook during Include
  2906. {
  2907. my ($hash, $arg) = @_;
  2908. my $name = $hash->{NAME};
  2909. my $iodev = $hash->{IODev};
  2910. my $r_nonce_hex;
  2911. if ($arg =~ m/..9880(................)/) {
  2912. $r_nonce_hex = $1;
  2913. } else {
  2914. Log3 $name, 1, "$name: Unknown SECURITY-NonceReport received: $arg";
  2915. }
  2916. my $key_hex = AttrVal($iodev->{NAME}, "networkKey", "");
  2917. my $mynonce_hex = substr (ZWave_secCreateNonce($hash), 2, 16);
  2918. my $cryptedNetworkKeyMsg = ZWave_secNetworkkeyEncode($r_nonce_hex,
  2919. $mynonce_hex, $key_hex, $hash->{nodeIdHex});
  2920. $zwave_parseHook{"$hash->{nodeIdHex}:..9807"} = \&ZWave_secNetWorkKeyVerify;
  2921. ZWave_secAddToSendStack($hash, '98'.$cryptedNetworkKeyMsg);
  2922. readingsSingleUpdate($hash, "SECURITY", 'INITIALIZING (Networkkey sent)',0);
  2923. Log3 $name, 5, "$name: SECURITY initializing, networkkey sent";
  2924. # start timer here to check state if networkkey was not verified
  2925. $hash->{networkkeyTimer} = { hash => $hash };
  2926. InternalTimer(gettimeofday()+25, "ZWave_secTestNetworkkeyVerify",
  2927. $hash->{networkkeyTimer}, 0);
  2928. return 1; # "veto" for parseHook
  2929. }
  2930. sub
  2931. ZWave_secNetWorkKeyVerify ($$) # only called by zwave_parseHook during Include
  2932. {
  2933. my ($hash, $arg) = @_;
  2934. my $name = $hash->{NAME};
  2935. my $iodev = $hash->{IODev};
  2936. if (!ZWave_secIsEnabled($hash)) {
  2937. return 1;
  2938. }
  2939. RemoveInternalTimer($hash->{networkkeyTimer});
  2940. delete $hash->{networkkeyTimer};
  2941. readingsSingleUpdate($hash, "SECURITY", 'ENABLED', 0);
  2942. Log3 $name, 3, "$name: SECURITY enabled, networkkey was verified";
  2943. $zwave_parseHook{"$hash->{nodeIdHex}:..9803"} = \&ZWave_secIncludeFinished;
  2944. ZWave_Cmd("set", $hash, $name, ("secSupportedReport"));
  2945. return 1; # "veto" for parseHook
  2946. }
  2947. sub
  2948. ZWave_secIncludeFinished($$) # only called by zwave_parseHook during Include
  2949. {
  2950. my ($hash, $arg) = @_;
  2951. my $iodev = $hash->{IODev};
  2952. my $name = $hash->{NAME};
  2953. if ($arg =~ m/..9803(.*)/) {
  2954. ZWave_secSupported($hash, $1);
  2955. } else {
  2956. Log3 $name, 2, "$name: unknown answer for secSupported received";
  2957. }
  2958. if ($iodev->{secInitName}) {
  2959. # Secure inclusion is finished, remove readings and execute "normal" init
  2960. delete $iodev->{secInitName};
  2961. ZWave_execInits($hash, 0);
  2962. }
  2963. return 1; # "veto" for parseHook -> secSupported to be called before execInits
  2964. }
  2965. sub
  2966. ZWave_secTestNetworkkeyVerify ($)
  2967. {
  2968. my ($p) = @_;
  2969. my $hash = $p->{hash};
  2970. my $name = $hash->{NAME};
  2971. my $sec_status = ReadingsVal($name, "SECURITY", undef);
  2972. delete $hash->{networkkeyTimer};
  2973. if ($sec_status !~ m/ENABLED/) {
  2974. readingsSingleUpdate($hash, "SECURITY",
  2975. 'DISABLED (networkkey not verified and timer expired)', 0);
  2976. Log3 $name, 1, "$name: SECURITY disabled, networkkey was not verified ".
  2977. "and timer expired";
  2978. }
  2979. }
  2980. sub
  2981. ZWave_secAddToSendStack($$)
  2982. {
  2983. my ($hash, $cmd) = @_;
  2984. my $name = $hash->{NAME};
  2985. my $id = $hash->{nodeIdHex};
  2986. my $len = sprintf("%02x", (length($cmd)-2)/2+1);
  2987. my $cmdEf = (AttrVal($name, "noExplorerFrames", 0) == 0 ? "25" : "05");
  2988. my $data = "13$id$len$cmd$cmdEf" . ZWave_callbackId($hash);
  2989. ZWave_addToSendStack($hash, "set", $data);
  2990. }
  2991. sub
  2992. ZWave_secStart($)
  2993. {
  2994. my ($hash) = @_;
  2995. my $dt = gettimeofday();
  2996. $hash->{secTime} = $dt;
  2997. $hash->{secTimer} = { hash => $hash };
  2998. InternalTimer($dt+7, "ZWave_secUnlock", $hash->{secTimer}, 0);
  2999. return if($hash->{secInProgress});
  3000. $hash->{secInProgress} = 1;
  3001. my @empty;
  3002. $hash->{secStack} = \@empty;
  3003. }
  3004. sub
  3005. ZWave_secUnlock($)
  3006. {
  3007. my ($p) = @_;
  3008. my $hash= $p->{hash};
  3009. my $dt = gettimeofday();
  3010. if (($hash->{secInProgress}) && ($dt > ($hash->{secTime} + 6))) {
  3011. Log3 $hash->{NAME}, 3, "$hash->{NAME}: secStart older than "
  3012. ."6 seconds detected, secUnlock will call Zwave_secEnd";
  3013. ZWave_secEnd($hash);
  3014. }
  3015. }
  3016. sub
  3017. ZWave_secEnd($)
  3018. {
  3019. my ($hash) = @_;
  3020. return if(!$hash->{secInProgress});
  3021. RemoveInternalTimer($hash->{secTimer});
  3022. my $secStack = $hash->{secStack};
  3023. delete $hash->{secInProgress};
  3024. delete $hash->{secStack};
  3025. delete $hash->{secTimer};
  3026. foreach my $cmd (@{$secStack}) {
  3027. ZWave_SCmd($cmd->{T}, $hash, @{$cmd->{A}});
  3028. }
  3029. }
  3030. sub
  3031. ZWave_secIsSecureClass($$)
  3032. {
  3033. my ($hash, $cc_cmd) = @_;
  3034. my $name = $hash->{NAME};
  3035. if ($cc_cmd =~m/(..)(..)/) {
  3036. my ($cc, $cmd) = ($1, $2);
  3037. my $cc_name = $zwave_id2class{lc($cc)};
  3038. my $sec_classes = AttrVal($name, "secure_classes", "");
  3039. if (($sec_classes =~ m/$cc_name/) && ($cc_name ne 'SECURITY')){
  3040. Log3 $name, 5, "$name: $cc_name is a secured class!";
  3041. return 1;
  3042. }
  3043. # some SECURITY commands need to be encrypted allways
  3044. if ($cc eq '98') {
  3045. if ($cmd eq '02' || # SupportedGet
  3046. $cmd eq '06' || # NetworkKeySet
  3047. $cmd eq '08' ){ # SchemeInherit
  3048. Log3 $name, 5, "$name: Security commands will be encrypted!";
  3049. return 1;
  3050. }
  3051. }
  3052. # these SECURITY commands should not be encrypted
  3053. # SchemeGet = 0x04, NonceGet = 0x40, NonceReport = 0x80
  3054. # MessageEncap = 0x81 is already encrypted
  3055. # MessageEncapNonceGet = 0xc1 is already encrypted
  3056. }
  3057. return 0;
  3058. }
  3059. sub
  3060. ZWave_secSupported($$)
  3061. {
  3062. my ($hash, $arg) = @_;
  3063. my $name = $hash->{NAME};
  3064. my $id = $hash->{nodeIdHex};
  3065. if (!ZWave_secIsEnabled($hash)) {
  3066. return;
  3067. };
  3068. Log3 $name, 5, "$name: Secured Classes Supported: $arg";
  3069. if ($arg =~ m/(..)(.*)/) {
  3070. if ($1 ne '00') {
  3071. Log3 $name, 1, "$name: Multi part message report for secure classes ".
  3072. "can not be handled!";
  3073. }
  3074. my @sec_classes;
  3075. my $sec_classes = $2;
  3076. for my $sec_classId (grep /../, split(/(..)/, lc($sec_classes))) {
  3077. push @sec_classes, $zwave_id2class{lc($sec_classId)} ?
  3078. $zwave_id2class{lc($sec_classId)} : "UNKNOWN_".lc($sec_classId);
  3079. }
  3080. $attr{$name}{secure_classes} = join(" ", @sec_classes)
  3081. if (@sec_classes);
  3082. }
  3083. # Add new secure_classes to classes if not already present
  3084. # Needed for classes that are only supported with SECURITY
  3085. if ($attr{$name}{secure_classes} && $attr{$name}{classes}) {
  3086. my $classes = $attr{$name}{classes};
  3087. my $secure_classes = $attr{$name}{secure_classes};
  3088. my $c1;
  3089. my $c2;
  3090. my $s1;
  3091. my $s2;
  3092. my $classname;
  3093. if ($classes =~ m/(.*)(MARK)(.*)/) {
  3094. ($c1, $c2) = ($1, $2 . $3);
  3095. } else {
  3096. ($c1, $c2) = ($classes, "");
  3097. }
  3098. if ($secure_classes =~ m/(.*)(MARK)(.*)/) {
  3099. ($s1, $s2) = ($1, $2 . $3);
  3100. } else {
  3101. ($s1, $s2) = ($secure_classes, "");
  3102. }
  3103. foreach $classname (split(" ", $s1)) {
  3104. if ($c1 !~ m/\b$classname\b/) {
  3105. $c1 = join (" ", $c1, $classname);
  3106. }
  3107. }
  3108. foreach $classname (split(" ", $s2)) {
  3109. if ($c2 !~ m/\b$classname\b/) {
  3110. $c2 = join (" ", $c2, $classname);
  3111. }
  3112. }
  3113. $classes = join (" ", $c1, $c2);
  3114. $classes =~ s/ +/ /gs;
  3115. $attr{$name}{classes} = $classes;
  3116. }
  3117. }
  3118. sub
  3119. ZWave_secNonceReceived($$)
  3120. {
  3121. my ($hash, $r_nonce_hex) = @_;
  3122. my $iodev = $hash->{IODev};
  3123. my $name = $hash->{NAME};
  3124. if (!ZWave_secIsEnabled($hash))
  3125. {
  3126. return;
  3127. }
  3128. # if nonce is received, we should have stored a message for encryption
  3129. my $getSecMsg = ZWave_secGetMsg($hash);
  3130. my @secArr = split / /, $getSecMsg, 4;
  3131. my $secMsg = $secArr[0];
  3132. my $type = $secArr[1];
  3133. my $cmd = $secArr[3];
  3134. if (!$secMsg) {
  3135. Log3 $name, 1, "$name: Error, nonce reveived but no stored command for ".
  3136. "encryption found";
  3137. return undef;
  3138. }
  3139. my $enc = ZWave_secEncrypt($hash, $r_nonce_hex, $secMsg);
  3140. ZWave_secAddToSendStack($hash, '98'.$enc);
  3141. if ($type eq "set" && $cmd && $cmd !~ m/^config.*request$/) {
  3142. readingsSingleUpdate($hash, "state", $cmd, 1);
  3143. Log3 $name, 5, "$name: type=$type, cmd=$cmd ($getSecMsg)";
  3144. ZWave_secEnd($hash) if ($type eq "set");
  3145. }
  3146. return undef;
  3147. }
  3148. sub
  3149. ZWave_secPutMsg ($$$)
  3150. {
  3151. my ($hash, $s, $cmd) = @_;
  3152. my $name = $hash->{NAME};
  3153. if (!$hash->{secMsg}) {
  3154. my @arr = ();
  3155. $hash->{secMsg} = \@arr;
  3156. }
  3157. push @{$hash->{secMsg}}, $s . " ". $cmd;
  3158. Log3 $name, 5, "$name SECURITY: $s stored for encryption";
  3159. }
  3160. sub
  3161. ZWave_secGetMsg ($)
  3162. {
  3163. my ($hash) = @_;
  3164. my $name = $hash->{NAME};
  3165. my $secMsg = $hash->{secMsg};
  3166. if ($secMsg && @{$secMsg}) {
  3167. my $ret = shift(@{$secMsg});
  3168. if ($ret) {
  3169. Log3 $name, 5, "$name SECURITY: $ret retrieved for encryption";
  3170. return $ret;
  3171. }
  3172. }
  3173. Log3 $name, 1, "$name: no stored commands in Internal secMsg found";
  3174. return "";
  3175. }
  3176. sub
  3177. ZWave_secNonceRequestReceived ($)
  3178. {
  3179. my ($hash) = @_;
  3180. if (!ZWave_secIsEnabled($hash)) {
  3181. return;
  3182. }
  3183. ZWave_secStart($hash);
  3184. ZWave_secAddToSendStack($hash, '98'.ZWave_secCreateNonce($hash));
  3185. }
  3186. sub
  3187. ZWave_secIsEnabled ($)
  3188. {
  3189. my ($hash) = @_;
  3190. my $secStatus = ReadingsVal($hash->{NAME}, "SECURITY", "DISABLED");
  3191. if ($secStatus =~ m/DISABLED/) {
  3192. Log3 $hash->{NAME}, 1, "$hash->{NAME} SECURITY $secStatus (command dropped)";
  3193. return (0);
  3194. }
  3195. return (1);
  3196. }
  3197. sub
  3198. ZWave_sec ($$)
  3199. {
  3200. my ($hash, $arg) = @_;
  3201. return (ZWave_secIsEnabled($hash) ? ("", $arg) : ("",'00'));
  3202. }
  3203. sub
  3204. ZWave_secCreateNonce($)
  3205. {
  3206. my ($hash) = @_;
  3207. if (ZWave_secIsEnabled($hash)) {
  3208. my $nonce;
  3209. my $nonce_id;
  3210. my $n=0;
  3211. $hash->{secNonce} = {} if (!$hash->{secNonce});
  3212. foreach my $id (sort keys %{$hash->{secNonce}}) {
  3213. $n++;
  3214. }
  3215. my $time = gettimeofday();
  3216. if ($n>50) { #clean up only if more than 50 nonce are active
  3217. foreach my $id (sort keys %{$hash->{secNonce}}) {
  3218. my $dt = $time - $hash->{secNonce}{$id}{timeStamp};
  3219. if ($dt > 10) {
  3220. Log3 $hash->{NAME}, 3, "$hash->{NAME}: SECURITY: nonce "
  3221. .$hash->{secNonce}{$id}{nonce} ."is too old ("
  3222. .sprintf("%d seconds", $dt)
  3223. .") and is removed from list";
  3224. delete($hash->{secNonce}{$id});
  3225. $n--;
  3226. }
  3227. }
  3228. }
  3229. if ($n >10) {
  3230. Log3 $hash->{NAME}, 2, "$hash->{NAME}: SECURITY: multiple nonce warning, "
  3231. ."there are $n nonce active";
  3232. }
  3233. $n=0;
  3234. do {
  3235. $nonce = ZWave_secGetNonce();
  3236. $nonce_id = substr($nonce, 0, 2);
  3237. $n++;
  3238. } until ((!$hash->{secNonce}{$nonce_id}) || $n>512);
  3239. if ($n >512) {
  3240. Log3 $hash->{NAME}, 1, "$hash->{NAME}: SECURITY: could not generate "
  3241. ."unique nonce, ignoring request!";
  3242. return ('00');
  3243. }
  3244. my $id = substr($nonce, 0 ,2);
  3245. $hash->{secNonce} = {} if (!$hash->{secNonce});
  3246. $hash->{secNonce}{$id}{nonce} = $nonce;
  3247. $hash->{secNonce}{$id}{timeStamp} = gettimeofday();
  3248. return ('80'.$nonce);
  3249. } else {
  3250. return ('00');
  3251. }
  3252. }
  3253. sub
  3254. ZWave_secRetrieveNonce($$)
  3255. {
  3256. my ($hash, $s_nonce_id_hex) = @_;
  3257. my $s_nonce_hex;
  3258. my $n=0;
  3259. return undef if (!$hash->{secNonce});
  3260. # remove old (>10 seconds) entries BEFORE trying to retrieve nonce
  3261. my $time = gettimeofday();
  3262. foreach my $id (sort keys %{$hash->{secNonce}}) {
  3263. $n++;
  3264. my $dt = $time - $hash->{secNonce}{$id}{timeStamp};
  3265. if ($dt > 10) {
  3266. Log3 $hash->{NAME}, 5, "$hash->{NAME}: SECURITY: nonce "
  3267. .$hash->{secNonce}{$id}{nonce} ."is too old ("
  3268. .sprintf("%d seconds", $dt)
  3269. .") and is removed from list";
  3270. delete($hash->{secNonce}{$id});
  3271. $n--;
  3272. }
  3273. }
  3274. if ($n >1) {
  3275. Log3 $hash->{NAME}, 5, "$hash->{NAME}: SECURITY: multiple nonce warning, "
  3276. ."there are $n nonce active";
  3277. }
  3278. if ($hash->{secNonce}{$s_nonce_id_hex}) {
  3279. $s_nonce_hex = $hash->{secNonce}{$s_nonce_id_hex}{nonce};
  3280. delete($hash->{secNonce}{$s_nonce_id_hex});
  3281. return $s_nonce_hex;
  3282. } else {
  3283. return undef;
  3284. }
  3285. }
  3286. sub
  3287. ZWave_secGetNonce()
  3288. {
  3289. my $nonce='';
  3290. for (my $i = 0; $i <8; $i++) {
  3291. $nonce .= sprintf "%02x",int(rand(256));
  3292. }
  3293. return $nonce;
  3294. }
  3295. sub
  3296. ZWave_secEncrypt($$$)
  3297. {
  3298. my ($hash, $r_nonce_hex, $plain) = @_;
  3299. my $name = $hash->{NAME};
  3300. my $iodev = $hash->{IODev};
  3301. my $id = $hash->{nodeIdHex};
  3302. my $init_enc_key = pack 'H*', 'a' x 32;
  3303. my $init_auth_key = pack 'H*', '5' x 32;
  3304. my $s_nonce_hex = ZWave_secGetNonce();
  3305. my $iv = pack 'H*', $s_nonce_hex . $r_nonce_hex;
  3306. my $key = pack 'H*', AttrVal($iodev->{NAME}, "networkKey", "");
  3307. my $enc_key = ZWave_secEncryptECB($key, $init_enc_key);
  3308. my $auth_key = ZWave_secEncryptECB($key, $init_auth_key);
  3309. my $seq = '00'; # Sequencebyte -> need to be calculated for longer messages
  3310. my $msg_hex = $seq . $plain;
  3311. my $out_hex = ZWave_secEncryptOFB ($enc_key, $iv, $msg_hex);
  3312. my $auth_msg_hex = '8101';
  3313. $auth_msg_hex .= sprintf "%02x", hex($hash->{nodeIdHex});
  3314. $auth_msg_hex .= sprintf "%02x", (length ($out_hex))/2;
  3315. $auth_msg_hex .= $out_hex;
  3316. Log3 $name, 5, "$name: secEncrypt plain:$msg_hex enc:$out_hex";
  3317. my $auth_code_hex = ZWave_secGenerateAuth($auth_key, $iv, $auth_msg_hex);
  3318. my $enc_msg_hex = '81' . $s_nonce_hex . $out_hex . substr($r_nonce_hex, 0, 2)
  3319. . $auth_code_hex;
  3320. return $enc_msg_hex;
  3321. }
  3322. sub
  3323. ZWave_secDecrypt($$$)
  3324. {
  3325. my ($hash, $data, $newnonce) = @_;
  3326. my $name = $hash->{NAME};
  3327. my $iodev = $hash->{IODev};
  3328. if (!ZWave_secIsEnabled($hash)) {
  3329. return;
  3330. }
  3331. my $init_enc_key = pack 'H*', 'a' x 32;
  3332. my $init_auth_key = pack 'H*', '5' x 32;
  3333. my $key = pack 'H*', AttrVal($iodev->{NAME}, "networkKey", "");
  3334. my $enc_key = ZWave_secEncryptECB($key, $init_enc_key);
  3335. my $auth_key = ZWave_secEncryptECB($key, $init_auth_key);
  3336. # encrypted message format:
  3337. # data= bcb328fe5d924a402b2901fc2699cc3bcacd30e0
  3338. # bcb328fe5d924a40 = 8 byte r_nonce
  3339. # 2b2901 = encrypted message, variable length
  3340. # fc = s_nonce-Id (= first byte of s_nonce)
  3341. # 2699cc3bcacd30e0 = 8 byte authentification code
  3342. if ($data !~ m/^(................)(.*)(..)(................)$/) {
  3343. Log3 $name, 1, "$name: Error, wrong format of encrypted msg";
  3344. ZWave_secEnd($hash);
  3345. return "";
  3346. }
  3347. my ($r_nonce_hex, $msg_hex, $s_nonce_id_hex, $auth_code_hex) = ($1, $2, $3, $4);
  3348. my $s_nonce_hex = ZWave_secRetrieveNonce($hash, $s_nonce_id_hex);
  3349. if (!$s_nonce_hex) {
  3350. Log3 $name, 1, "$name: Error, no send_nonce to decrypt message available";
  3351. ZWave_secEnd($hash);
  3352. return "";
  3353. }
  3354. Log3 $name, 5, "$name: secDecrypt: send_nonce $s_nonce_hex with "
  3355. ."nonce_id $s_nonce_id_hex retrieved";
  3356. my $iv = pack 'H*', $r_nonce_hex . $s_nonce_hex;
  3357. my $out_hex = ZWave_secEncryptOFB ($enc_key, $iv, $msg_hex);
  3358. Log3 $name, 5, "$name: secDecrypt: decrypted cmd $out_hex";
  3359. # decoding sequence information
  3360. # bit 76 reseved
  3361. # bit 5 second frame (0x20)
  3362. # bit 4 sequenced (0x10)
  3363. # bit 3210 sequenceCounter (0x0f)
  3364. my $seq = hex(substr ($out_hex, 0,2));
  3365. my $sequenced = (($seq & 0x10) ? 1 : 0);
  3366. my $secondFrame = (($seq & 0x20) ? 1 : 0);
  3367. my $sequenceCounter = sprintf "%02x", ($seq & 0x0f);
  3368. Log3 $name, 5, "$name: secDecrypt: Sequencebyte $seq, sequenced ".
  3369. "$sequenced, secondFrame $secondFrame, sequenceCounter $sequenceCounter";
  3370. # Rebuild message for authentification check
  3371. # 81280103 '81' . <from-id> . <to-id> . <len> . <encrMsg>
  3372. my $my_msg_hex = ($newnonce ? 'c1' : '81');
  3373. $my_msg_hex .= sprintf "%02x", hex($hash->{nodeIdHex});
  3374. $my_msg_hex .= '01';
  3375. $my_msg_hex .= sprintf "%02x", (length ($msg_hex))/2;
  3376. $my_msg_hex .= $msg_hex;
  3377. my $my_auth_code_hex = ZWave_secGenerateAuth($auth_key, $iv, $my_msg_hex);
  3378. Log3 $name, 5, "$name: secDecrypt: calculated Authentication code ".
  3379. "$my_auth_code_hex";
  3380. $out_hex = substr($out_hex, 2,length($out_hex)-2);
  3381. if ($auth_code_hex eq $my_auth_code_hex) {
  3382. if ($sequenced && !$secondFrame){ # first frame of sequence message
  3383. ZWave_secStoreFirstFrame($hash, $sequenceCounter, $out_hex);
  3384. } else { # not first frame or not sequenced
  3385. if ($sequenced && $secondFrame){
  3386. my $firstFrame = ZWave_secRetrieveFirstFrame ($hash, $sequenceCounter);
  3387. if ($firstFrame) {
  3388. $out_hex = $firstFrame . $out_hex;
  3389. } else {
  3390. Log3 $name, 1, "$name: secDecrypt: first frame of message (sequence ".
  3391. "$sequenceCounter) for decryption not found!";
  3392. }
  3393. }
  3394. my $decryptedCmd = '000400';
  3395. $decryptedCmd .= sprintf "%02x", hex($hash->{nodeIdHex});
  3396. $decryptedCmd .= sprintf "%02x", (length ($out_hex))/2;
  3397. $decryptedCmd .= $out_hex;
  3398. Log3 $name, 5, "$name: secDecrypt: parsing $decryptedCmd";
  3399. ZWave_Parse($iodev, $decryptedCmd, undef);
  3400. ZWave_secEnd($hash);
  3401. }
  3402. } else {
  3403. Log3 $name, 1, "$name: secDecrypt: Authentification code not verified, "
  3404. ."command $out_hex will be dropped!";
  3405. if ($sequenced && $secondFrame){
  3406. ZWave_secRetrieveFirstFrame ($hash, $sequenceCounter);
  3407. }
  3408. ZWave_secEnd($hash);
  3409. }
  3410. if ($newnonce == 1) {
  3411. ZWave_secAddToSendStack($hash, '98'.ZWave_secCreateNonce($hash));
  3412. #ZWave_Cmd("set", $hash, $hash->{NAME}, "secNonce");
  3413. }
  3414. return "";
  3415. }
  3416. sub
  3417. ZWave_secStoreFirstFrame ($$$) {
  3418. my ($hash, $seqcnt, $framedata) = @_;
  3419. my $framename = "Frame_$seqcnt";
  3420. $hash->{$framename} = $framedata;
  3421. }
  3422. sub
  3423. ZWave_secRetrieveFirstFrame ($$) {
  3424. my ($hash, $seqcnt) = @_;
  3425. my $framename = "Frame_$seqcnt";
  3426. if ($hash->{$framename}) {
  3427. my $ret = $hash->{$framename};
  3428. if ($ret) {
  3429. $hash->{$framename} = undef;
  3430. return $ret;
  3431. }
  3432. }
  3433. Log3 $hash->{NAME}, 1, "$hash->{NAME}: first frame of message (sequence ".
  3434. "$seqcnt) for decryption not found!";
  3435. return undef;
  3436. }
  3437. sub
  3438. ZWave_secEncryptECB ($$)
  3439. {
  3440. my ($key, $iv) = @_;
  3441. # $key and $iv as 'packed' hex-strings
  3442. my $cipher_ecb = Crypt::Rijndael->new ($key, Crypt::Rijndael::MODE_ECB() );
  3443. return $cipher_ecb->encrypt($iv);
  3444. }
  3445. sub
  3446. ZWave_secEncryptOFB ($$$)
  3447. {
  3448. my ($key, $iv, $in_hex) = @_;
  3449. # $key and $iv as 'packed' hex-strings, $in_hex as hex-string
  3450. my $cipher_ofb = Crypt::Rijndael->new($key,
  3451. Crypt::Rijndael::MODE_OFB() );
  3452. $cipher_ofb->set_iv($iv);
  3453. # make sure that the blocksize is 16 bytes / 32 characters
  3454. my $in_len = length($in_hex);
  3455. if ($in_len % 32) {
  3456. $in_hex .= '0' x (32 - ($in_len % 32));
  3457. }
  3458. my $out_hex = unpack 'H*', $cipher_ofb->encrypt(pack 'H*', $in_hex);
  3459. return (substr ($out_hex, 0, $in_len));
  3460. }
  3461. sub
  3462. ZWave_secGenerateAuth ($$$)
  3463. {
  3464. my ($key, $iv, $msg_hex) = @_;
  3465. my $cipher_ecb = Crypt::Rijndael->new ($key, Crypt::Rijndael::MODE_ECB() );
  3466. my $enc_iv = ZWave_secEncryptECB($key, $iv);
  3467. # make sure that the blocksize is 16 bytes / 32 characters
  3468. my $msg_len = length($msg_hex);
  3469. if ($msg_len % 32) {
  3470. $msg_hex .= '0' x (32 - ($msg_len % 32));
  3471. }
  3472. my $temp=0;
  3473. my $buff=0;
  3474. my $buff_hex="";
  3475. # xOR first block with encrypted iv
  3476. # encrypt the result, repeat for all blocks using encrypted output
  3477. # as input for xOR of next block
  3478. for (my $i = 0; $i < (length($msg_hex)/32); $i++) {
  3479. $buff_hex = substr($msg_hex, $i*32, 32);
  3480. $buff = pack 'H*', $buff_hex;
  3481. $temp = $buff ^ $enc_iv;
  3482. $enc_iv = $cipher_ecb->encrypt($temp);
  3483. };
  3484. # only 8 byte used for message authentification code
  3485. return unpack 'H16', $enc_iv;
  3486. }
  3487. sub
  3488. ZWave_secNetworkkeyEncode ($$$$)
  3489. {
  3490. my ($nonce_hex, $mynonce_hex, $key_plain_hex, $id_hex) = @_;
  3491. #my $name ="ZWave_secNetworkkeySet";
  3492. # The NetworkKeySet command message will be encrcpted and authentificated
  3493. # with temporary keys that are created with the networkkey and default
  3494. # keys for encryption and authentification as given below.
  3495. my $init_enc_key = pack 'H*', 'a' x 32;
  3496. my $init_auth_key = pack 'H*', '5' x 32;
  3497. my $key_zero = pack 'H*', '0' x 32;
  3498. my $nonce = pack 'H*', $nonce_hex;
  3499. my $mynonce = pack 'H*', $mynonce_hex;
  3500. my $enc_key = ZWave_secEncryptECB($key_zero, $init_enc_key);
  3501. my $auth_key = ZWave_secEncryptECB($key_zero, $init_auth_key);
  3502. my $iv = pack 'H*', $mynonce_hex . $nonce_hex;
  3503. # build 'plain-text' message to be encrypted
  3504. # 0x00 = sequence byte -> only one frame
  3505. # 0x98 = Security Class
  3506. # 0x06 = NetworkKeySet
  3507. $key_plain_hex = '009806'.$key_plain_hex;
  3508. my $out_hex = ZWave_secEncryptOFB($enc_key, $iv, $key_plain_hex);
  3509. ############ MAC generation ############################
  3510. # build message for encryption
  3511. # command, source-id, target-id
  3512. # 0x81="Security_Message_Encapsulation" 0x01=Souce-ID (Controller = 0x01)
  3513. my $in_hex = '8101' . $id_hex;
  3514. $in_hex .= sprintf "%02x", length($out_hex)/2; # length of command
  3515. $in_hex .= $out_hex; # encrypted network key
  3516. my $auth_hex = ZWave_secGenerateAuth ($auth_key, $iv, $in_hex);
  3517. # build encrypted message
  3518. # Command Class will be added during sending -> do not prepend
  3519. # 0x81 = Security_Message_Encapsulation
  3520. $out_hex = '81' . $mynonce_hex . $out_hex . substr($nonce_hex, 0, 2) .
  3521. $auth_hex;
  3522. return $out_hex;
  3523. }
  3524. ##############################################
  3525. # SECURITY (end)
  3526. ##############################################
  3527. sub
  3528. ZWave_getHash($$$)
  3529. {
  3530. my ($hash, $cl, $type) = @_;
  3531. my $ptr; # must be standalone, as there is a $ptr in the calling fn.
  3532. $ptr = $zwave_class{$cl}{$type}
  3533. if($zwave_class{$cl} && $zwave_class{$cl}{$type});
  3534. if($cl eq "CONFIGURATION" && $type ne "parse") {
  3535. my $mc = ZWave_configGetHash($hash);
  3536. if($mc) {
  3537. my $mcp = $mc->{$type};
  3538. if($mcp) {
  3539. my %nptr = ();
  3540. map({$nptr{$_} = $ptr->{$_}} keys %{$ptr});
  3541. map({$nptr{$_} = $mcp->{$_}} keys %{$mcp});
  3542. $ptr = \%nptr;
  3543. }
  3544. }
  3545. }
  3546. my $modelId = ReadingsVal($hash->{NAME}, "modelId", "");
  3547. $modelId = $zwave_modelIdAlias{$modelId} if($zwave_modelIdAlias{$modelId});
  3548. my $p = $zwave_deviceSpecial{$modelId};
  3549. if($p && $p->{$cl}) {
  3550. $ptr = $p->{$cl}{$type} if($p->{$cl}{$type});
  3551. my $add = $p->{$cl}{$type."_ADD"};
  3552. $ptr = {} if($add && !$ptr);
  3553. map { $ptr->{$_} = $add->{$_} } keys %{$add} if($add);
  3554. }
  3555. my $version = $hash->{".vclasses"}{$cl};
  3556. if(defined($version) && ($type eq "get" || $type eq "set")) {
  3557. my %h;
  3558. if($version > 0) {
  3559. map {
  3560. my $zv = $zwave_classVersion{$_};
  3561. if(!$zv || ((!$zv->{min} || $zv->{min} <= $version) &&
  3562. (!$zv->{max} || $zv->{max} >= $version))) {
  3563. $h{$_} = $ptr->{$_};
  3564. }
  3565. } keys %{$ptr};
  3566. }
  3567. $ptr = \%h;
  3568. }
  3569. return $ptr;
  3570. }
  3571. my $zwave_cbid = 0;
  3572. my %zwave_cbid2dev;
  3573. sub
  3574. ZWave_callbackId($)
  3575. {
  3576. my ($p) = @_;
  3577. if(ref($p) eq "HASH") {
  3578. $zwave_cbid = 0 if($zwave_cbid == 255);
  3579. $zwave_cbid2dev{++$zwave_cbid} = $p;
  3580. return sprintf("%02x", $zwave_cbid);
  3581. }
  3582. return $zwave_cbid2dev{hex($p)};
  3583. }
  3584. sub
  3585. ZWave_wakeupTimer($$)
  3586. {
  3587. my ($hash, $direct) = @_;
  3588. my $now = gettimeofday();
  3589. my $wnmi_delay = AttrVal($hash->{NAME}, "WNMI_delay", 2);
  3590. if(!$hash->{wakeupAlive}) {
  3591. $hash->{wakeupAlive} = 1;
  3592. $hash->{lastMsgSent} = $now;
  3593. InternalTimer($now+0.1, "ZWave_wakeupTimer", $hash, 0);
  3594. } elsif(!$direct && $now - $hash->{lastMsgSent} > $wnmi_delay) {
  3595. if(!$hash->{SendStack}) {
  3596. my $nodeId = $hash->{nodeIdHex};
  3597. my $cmdEf = (AttrVal($hash->{NAME},"noExplorerFrames",0)==0 ? "25":"05");
  3598. # wakeupNoMoreInformation
  3599. IOWrite($hash,
  3600. $hash->{homeId}.($hash->{route} ? ",".$hash->{route} : ""),
  3601. "0013${nodeId}028408${cmdEf}".ZWave_callbackId($hash));
  3602. $hash->{lastMsgSent} = $now;
  3603. }
  3604. delete $hash->{wakeupAlive};
  3605. } else {
  3606. return if($direct);
  3607. InternalTimer($now+0.1, "ZWave_wakeupTimer", $hash, 0);
  3608. }
  3609. }
  3610. sub
  3611. ZWave_isWakeUp($)
  3612. {
  3613. my ($h) = @_;
  3614. $h->{isWakeUp} = (index(AttrVal($h->{NAME}, "classes", ""), "WAKE_UP") >= 0)
  3615. if(!defined($h->{isWakeUp}));
  3616. return $h->{isWakeUp};
  3617. }
  3618. # stack contains type:hexcode
  3619. # type is: set / sentset, get / sentget / sentackget
  3620. # sentset will be discarded after ack, sentget needs ack (->sentackget) then msg
  3621. # next discards either state.
  3622. # acktpye: retry, next, ack or msg
  3623. sub
  3624. ZWave_processSendStack($$;$)
  3625. {
  3626. my ($hash,$ackType, $omsg) = @_;
  3627. delete($hash->{delayedProcessing});
  3628. my $ss = $hash->{SendStack};
  3629. if(!$ss) {
  3630. readingsSingleUpdate($hash, "timeToAck",
  3631. sprintf("%0.3f", gettimeofday()-$hash->{lastMsgSent}), 0)
  3632. if($ackType eq "ack" && $hash->{lastMsgSent});
  3633. return;
  3634. }
  3635. #Log 1, "pSS: $hash->{NAME}, $ackType $ss->[0]".($omsg ? " omsg:$omsg" : "");
  3636. if ($ackType eq "next") {
  3637. if($ss->[0] =~ m/^sent(.*?):13....98(.*)$/) { # only for security commands
  3638. my $secMsg = $hash->{secMsg};
  3639. if ($secMsg && @{$secMsg}) {
  3640. Log3 $hash->{NAME}, 1, "$hash->{NAME}: NO_ACK received during secured "
  3641. ."command: $secMsg->[0], command will be removed from security stack";
  3642. shift(@{$secMsg});
  3643. ZWave_secEnd($hash);
  3644. }
  3645. }
  3646. }
  3647. if($ackType eq "retry") {
  3648. $ss->[0] =~ m/^(.*)(set|get):(.*)$/;
  3649. $ss->[0] = "$2:$3";
  3650. return;
  3651. }
  3652. my $now = gettimeofday();
  3653. if($ss->[0] =~ m/^sent(.*?):(.*)(..)$/) {
  3654. my ($stype,$smsg, $cbid) = ($1,$2,$3);
  3655. if($ackType eq "ack") {
  3656. if($cbid ne $omsg) {
  3657. Log 4, "ZWave: wrong callbackid $omsg received, expecting $cbid";
  3658. return;
  3659. }
  3660. readingsSingleUpdate($hash, "timeToAck",
  3661. sprintf("%0.3f", $now-$hash->{lastMsgSent}), 0)
  3662. if($hash->{lastMsgSent});
  3663. if($stype eq "get") {
  3664. $ss->[0] = "sentackget:$smsg$cbid";
  3665. return;
  3666. }
  3667. } elsif($stype eq "ackget" && $ackType eq "msg") {# compare answer class
  3668. $smsg = "13xxxx$1" if($smsg =~ /^......600d....(.*)/);
  3669. my $cs = substr($smsg, 6, 2);
  3670. my $cg = substr($omsg, 2, 2);
  3671. return if($cs ne $cg);
  3672. }
  3673. shift @{$ss};
  3674. RemoveInternalTimer($hash) if(!ZWave_isWakeUp($hash));
  3675. }
  3676. if(@{$ss} == 0) {
  3677. delete $hash->{SendStack};
  3678. return;
  3679. }
  3680. $ss->[0] =~ m/^([^:]*?):(.*)$/;
  3681. my ($type, $msg) = ($1, $2);
  3682. IOWrite($hash,
  3683. $hash->{homeId}.($hash->{route}?",".$hash->{route}:""),
  3684. "00$msg");
  3685. $ss->[0] = "sent$type:$msg";
  3686. $hash->{lastMsgSent} = $now;
  3687. $zwave_lastHashSent = $hash;
  3688. if(!ZWave_isWakeUp($hash)) {
  3689. InternalTimer($hash->{lastMsgSent}+5, sub { # zme generates NO_ACK after 4s
  3690. Log 2, "ZWave: No ACK from $hash->{NAME} after 5s for $ss->[0]";
  3691. ZWave_processSendStack($hash, "next");
  3692. }, $hash, 0);
  3693. }
  3694. }
  3695. # packs multiple gets into a MULTI_CMD-get, may reorder
  3696. sub
  3697. ZWave_packSendStack($)
  3698. {
  3699. my ($hash) = @_;
  3700. my (@ns, @ms, $sfx, $cmd, $id);
  3701. my $ncmd = 0;
  3702. for my $se (@{$hash->{SendStack}}) {
  3703. if($se =~ m/^get:13(..)(...*)(....)$/) {
  3704. ($id, $cmd, $sfx) = ($1, $2, $3);
  3705. if($cmd =~ m/^..8f01(..)(.*)/i) { # already Multi-cmd
  3706. $ncmd += $1; $cmd = $2;
  3707. } else {
  3708. $ncmd++;
  3709. }
  3710. push(@ms, $cmd);
  3711. } else {
  3712. push(@ns, $se);
  3713. }
  3714. }
  3715. return if($ncmd < 2 || @ms < 2);
  3716. $cmd = join("", @ms);
  3717. push @ns, sprintf("get:13$id%02x8f01%02x%s%s",
  3718. length($cmd)/2+3, $ncmd, $cmd, $sfx);
  3719. $hash->{SendStack} = \@ns;
  3720. }
  3721. sub
  3722. ZWave_addToSendStack($$$)
  3723. {
  3724. my ($hash, $type, $cmd) = @_;
  3725. if(!$hash->{SendStack}) {
  3726. my @empty;
  3727. $hash->{SendStack} = \@empty;
  3728. }
  3729. my $ss = $hash->{SendStack};
  3730. push @{$ss}, "$type:$cmd";
  3731. #Log 1, "aTSS: $hash->{NAME}, $type, $cmd / L:".int(@{$ss});
  3732. if(ZWave_isWakeUp($hash)) {
  3733. # SECURITY XXX
  3734. if($cmd =~ m/^......988[01].*/) {
  3735. Log3 $hash->{NAME}, 5, "$hash->{NAME}: Sendstack bypassed for $cmd";
  3736. } else {
  3737. if($hash->{useMultiCmd}) {
  3738. ZWave_packSendStack($hash);
  3739. if($hash->{INTRIGGER}) { # Allow repacking of multiple gets on WUN
  3740. if(!$hash->{delayedProcessing}) {
  3741. $hash->{delayedProcessing} = 1;
  3742. InternalTimer(1, sub(){ZWave_processSendStack($hash, "next");}, 0);
  3743. }
  3744. return;
  3745. }
  3746. }
  3747. return "Scheduled for sending after WAKEUP" if(!$hash->{wakeupAlive});
  3748. }
  3749. } else { # clear commands without 0113 and 0013
  3750. my $now = gettimeofday();
  3751. if(@{$ss} > 1 && $now-$hash->{lastMsgSent} > 5) {
  3752. Log3 $hash, 2,
  3753. "ERROR: $hash->{NAME}: cleaning commands without ack after 5s";
  3754. delete $hash->{SendStack};
  3755. return ZWave_addToSendStack($hash, $type, $cmd);
  3756. }
  3757. }
  3758. ZWave_processSendStack($hash, "next") if(@{$ss} == 1);
  3759. return undef;
  3760. }
  3761. ###################################
  3762. # 0004000a03250300 (sensor binary off for id 11)
  3763. # { ZWave_Parse($defs{zd}, "0004000c028407", "") }
  3764. sub
  3765. ZWave_Parse($$@)
  3766. {
  3767. my ($iodev, $msg, $srcCmd) = @_;
  3768. my $homeId = $iodev->{homeId};
  3769. my $ioName = $iodev->{NAME};
  3770. if(!$homeId) {
  3771. Log3 $ioName, 1, "ERROR: $ioName homeId is not set!"
  3772. if(!$iodev->{errReported});
  3773. $iodev->{errReported} = 1;
  3774. return "";
  3775. }
  3776. if($msg =~ m/^01(..)(..*)/) { # 01==ANSWER from the ZWDongle
  3777. my ($cmd, $arg) = ($1, $2);
  3778. $cmd = $zw_func_id{$cmd} if($zw_func_id{$cmd});
  3779. if($cmd eq "ZW_SEND_DATA") { # 011301: data was sent.
  3780. if($arg != 1) {
  3781. if($zwave_lastHashSent) {
  3782. my $hash = $zwave_lastHashSent;
  3783. readingsSingleUpdate($hash, "SEND_DATA", "failed:$arg", 1);
  3784. $arg = "transmit queue overflow" if($arg == 0);
  3785. Log3 $ioName, 2, "ERROR: cannot SEND_DATA to $hash->{NAME}: $arg";
  3786. ZWave_processSendStack($hash, "retry");
  3787. } else {
  3788. Log3 $ioName, 2, "ERROR: cannot SEND_DATA: $arg (unknown device)";
  3789. }
  3790. }
  3791. return "";
  3792. }
  3793. if($cmd eq "SERIAL_API_SET_TIMEOUTS" && $arg =~ m/(..)(..)/) {
  3794. Log3 $ioName, 2, "SERIAL_API_SET_TIMEOUTS: ACK:$1 BYTES:$2";
  3795. return "";
  3796. }
  3797. if($cmd eq "ZW_REMOVE_FAILED_NODE_ID" ||
  3798. $cmd eq "ZW_REPLACE_FAILED_NODE") {
  3799. my $retval;
  3800. if($arg eq "00") { $retval = 'failedNodeRemoveStarted';
  3801. } elsif($arg eq "02") { $retval = 'notPrimaryController';
  3802. } elsif($arg eq "04") { $retval = 'noCallbackFunction';
  3803. } elsif($arg eq "08") { $retval = 'failedNodeNotFound';
  3804. } elsif($arg eq "10") { $retval = 'failedNodeRemoveProcessBusy';
  3805. } elsif($arg eq "20") { $retval = 'failedNodeRemoveFail';
  3806. } else { $retval = 'unknown_'.$arg; # should never happen
  3807. }
  3808. DoTrigger($ioName, "$cmd $retval");
  3809. return "";
  3810. }
  3811. if($cmd eq "ZW_REQUEST_NETWORK_UPDATE") {
  3812. my $retval;
  3813. if($arg eq "00") { $retval = 'selfOrNoSUC';
  3814. } elsif($arg eq "01") { $retval = 'started';
  3815. } else { $retval = 'unknown_'.$arg; # should never happen
  3816. }
  3817. DoTrigger($ioName, "$cmd $retval");
  3818. return "";
  3819. }
  3820. if($cmd eq "ZW_ASSIGN_SUC_RETURN_ROUTE" ||
  3821. $cmd eq "ZW_DELETE_SUC_RETURN_ROUTE" ||
  3822. $cmd eq "ZW_ASSIGN_RETURN_ROUTE" ||
  3823. $cmd eq "ZW_DELETE_RETURN_ROUTE" ||
  3824. $cmd eq "ZW_SEND_SUC_ID") {
  3825. my $retval;
  3826. if($arg eq "00") { $retval = 'alreadyActive';
  3827. } elsif($arg eq "01") { $retval = 'started';
  3828. } else { $retval = 'unknown_'.$arg; # should never happen
  3829. }
  3830. DoTrigger($ioName, "$cmd $retval");
  3831. return "";
  3832. }
  3833. if($cmd eq "ZW_SET_SUC_NODE_ID") {
  3834. my $retval;
  3835. if($arg eq "00") { $retval = 'failed';
  3836. } elsif($arg eq "01") { $retval = 'ok';
  3837. } else { $retval = 'unknown_'.$arg; # should never happen
  3838. }
  3839. DoTrigger($ioName, "$cmd $retval");
  3840. return "";
  3841. }
  3842. Log3 $ioName, 4, "$ioName unhandled ANSWER: $cmd $arg";
  3843. return "";
  3844. }
  3845. if($msg =~ m/^00(..)(..*)/) { # 00==REQUEST from the ZWDongle
  3846. my ($cmd, $arg) = ($1, $2);
  3847. $cmd = $zw_func_id{$cmd} if($zw_func_id{$cmd});
  3848. if($cmd eq "ZW_SET_DEFAULT") {
  3849. my $retval;
  3850. if($arg eq "01") { $retval = 'done';
  3851. } else { $retval = 'unknown_'.$arg; # should never happen
  3852. }
  3853. DoTrigger($ioName, "$cmd $retval");
  3854. return "";
  3855. }
  3856. }
  3857. if($msg !~ m/^00(..)(..)(..)(.*)/) { # 00=REQUEST
  3858. Log3 $ioName, 4, "$ioName: UNKNOWN msg $msg";
  3859. return "";
  3860. }
  3861. my ($cmd, $callbackid, $id, $arg) = ($1, $2, $3, $4);
  3862. $cmd = $zw_func_id{$cmd} if($zw_func_id{$cmd});
  3863. #####################################
  3864. # Controller commands
  3865. my $evt;
  3866. my $rawMsg = "CMD:$cmd ID:$id ARG:$arg"; # No fmt change, Forum #49165
  3867. Log3 $ioName, 4, $rawMsg ." CB:$callbackid";
  3868. my $hash = ZWave_callbackId($callbackid);
  3869. if($cmd eq 'ZW_ADD_NODE_TO_NETWORK' ||
  3870. $cmd eq 'ZW_REMOVE_NODE_FROM_NETWORK') {
  3871. my @vals = ("learnReady", "nodeFound", "slave",
  3872. "controller", "protocolDone", "done", "failed");
  3873. $evt = ($id eq "00" || hex($id)>@vals+1) ? "unknownArg" : $vals[hex($id)-1];
  3874. if(($evt eq "slave" || $evt eq "controller") &&
  3875. $arg =~ m/(..)....(..)..(.*)$/) {
  3876. my ($id,$type6,$classes) = ($1, $2, $3);
  3877. return ZWave_SetClasses($homeId, $id, $type6, $classes)
  3878. if($cmd eq 'ZW_ADD_NODE_TO_NETWORK');
  3879. }
  3880. if($evt eq "protocolDone" && $arg =~ m/(..)../) {
  3881. my $dh = $modules{ZWave}{defptr}{"$homeId $1"};
  3882. return "" if(!$dh);
  3883. my $addSecure = $iodev->{addSecure}; # addNode off deletes it
  3884. AnalyzeCommand(undef, "set $ioName addNode off")
  3885. if($cmd eq 'ZW_ADD_NODE_TO_NETWORK');
  3886. ZWave_wakeupTimer($dh, 1) if(ZWave_isWakeUp($dh));
  3887. return "" if($addSecure && ZWave_secIncludeStart($dh, $iodev) == 1);
  3888. return ZWave_execInits($dh, 0);
  3889. }
  3890. # addNode off generates ZW_ADD_NODE_TO_NETWORK:done sometimes (#51411)
  3891. if($evt eq "failed" && $cmd eq 'ZW_ADD_NODE_TO_NETWORK') {
  3892. asyncOutput($iodev->{addCL}, "addNode failed");
  3893. AnalyzeCommand(undef, "set $ioName addNode off")
  3894. }
  3895. } elsif($cmd eq "ZW_APPLICATION_UPDATE") {
  3896. if($arg =~ m/....(..)..(.*)$/) {
  3897. my ($type6,$classes) = ($1, $2);
  3898. my $ret = ZWave_SetClasses($homeId, $id, $type6, $classes);
  3899. $hash = $modules{ZWave}{defptr}{"$homeId $id"};
  3900. if($hash) {
  3901. if(!AttrVal($hash->{NAME}, "noWakeupForApplicationUpdate", 0)) { # 50090
  3902. if(ZWave_isWakeUp($hash)) {
  3903. ZWave_wakeupTimer($hash, 1);
  3904. ZWave_processSendStack($hash, "next");
  3905. }
  3906. }
  3907. if(!$ret) {
  3908. readingsSingleUpdate($hash, "CMD", $cmd, 1); # forum:20884
  3909. return $hash->{NAME};
  3910. }
  3911. } else {
  3912. InternalTimer(1, sub(){ # execInits for createNode
  3913. $hash = $modules{ZWave}{defptr}{"$homeId $id"};
  3914. ZWave_execInits($hash, 0) if($hash);
  3915. }, 0);
  3916. }
  3917. return $ret;
  3918. } elsif($callbackid eq "10") {
  3919. $evt = 'sucId '.hex($id);
  3920. DoTrigger($ioName, "$cmd $evt");
  3921. Log3 $ioName, 4, "$ioName $cmd $evt";
  3922. return "";
  3923. } elsif($callbackid eq "20") {
  3924. $evt = 'deleteDone '.hex($id);
  3925. DoTrigger($ioName, "$cmd $evt");
  3926. Log3 $ioName, 4, "$ioName $cmd $evt";
  3927. return "";
  3928. } elsif($callbackid eq "40") {
  3929. $evt = 'addDone '.hex($id);
  3930. DoTrigger($ioName, "$cmd $evt");
  3931. Log3 $ioName, 4, "$ioName $cmd $evt";
  3932. return "";
  3933. } elsif($callbackid eq "81") {
  3934. Log3 $ioName, 2, "ZW_REQUEST_NODE_INFO failed ".hex($id);
  3935. return "";
  3936. } else {
  3937. Log3 $ioName, 2, "ZW_APPLICATION_UPDATE unknown $callbackid";
  3938. return "";
  3939. }
  3940. } elsif($cmd eq "ZW_SEND_DATA") { # 0013cb00....
  3941. my %msg = ('00'=>'OK', '01'=>'NO_ACK', '02'=>'FAIL',
  3942. '03'=>'NOT_IDLE', '04'=>'NOROUTE' );
  3943. my $lmsg = ($msg{$id} ? $msg{$id} : "UNKNOWN_ERROR");
  3944. Log3 $ioName, ($id eq "00" ? 4 : 2),
  3945. "$ioName transmit $lmsg for CB $callbackid, target ".
  3946. ($hash ? $hash->{NAME} : "unknown");
  3947. if($id eq "00") {
  3948. if($hash) {
  3949. readingsSingleUpdate($hash, "transmit", $lmsg, 0);
  3950. ZWave_processSendStack($hash, "ack", $callbackid);
  3951. }
  3952. return "";
  3953. } else { # Wait for the retry timer to remove this cmd from the stack.
  3954. return "" if(!$hash);
  3955. #readingsSingleUpdate($hash, "state", "TRANSMIT_$lmsg", 1); #Forum #57781
  3956. readingsSingleUpdate($hash, "transmit", $lmsg, 1);
  3957. return $hash->{NAME};
  3958. }
  3959. } elsif($cmd eq "ZW_SET_LEARN_MODE") {
  3960. if($id eq "01") { $evt = 'started';
  3961. } elsif($id eq "06") { $evt = 'done'; # $arg = new NodeId
  3962. } elsif($id eq "07") { $evt = 'failed';
  3963. } elsif($id eq "80") { $evt = 'deleted';
  3964. } else { $evt = 'unknown'; # should never happen
  3965. }
  3966. } elsif($cmd eq "ZW_REQUEST_NODE_NEIGHBOR_UPDATE") {
  3967. if($id eq "21") { $evt = 'started';
  3968. } elsif($id eq "22") { $evt = 'done';
  3969. } elsif($id eq "23") { $evt = 'failed';
  3970. } else { $evt = 'unknown'; # should never happen
  3971. }
  3972. if($hash) {
  3973. readingsSingleUpdate($hash, "neighborUpdate", $evt, 1);
  3974. return $hash->{NAME};
  3975. }
  3976. } elsif($cmd eq "ZW_REMOVE_FAILED_NODE_ID") {
  3977. if($id eq "00") { $evt = 'nodeOk';
  3978. } elsif($id eq "01") { $evt = 'failedNodeRemoved';
  3979. } elsif($id eq "02") { $evt = 'failedNodeNotRemoved';
  3980. } else { $evt = 'unknown_'.$id; # should never happen
  3981. }
  3982. } elsif($cmd eq "ZW_REPLACE_FAILED_NODE") {
  3983. if($id eq "00") { $evt = 'nodeOk';
  3984. } elsif($id eq "03") { $evt = 'failedNodeReplace';
  3985. } elsif($id eq "04") { $evt = 'failedNodeReplaceDone';
  3986. } elsif($id eq "05") { $evt = 'failedNodeRemoveFailed';
  3987. } else { $evt = 'unknown_'.$id; # should never happen
  3988. }
  3989. } elsif($cmd eq "ZW_ASSIGN_SUC_RETURN_ROUTE" ||
  3990. $cmd eq "ZW_DELETE_SUC_RETURN_ROUTE" ||
  3991. $cmd eq "ZW_ASSIGN_RETURN_ROUTE" ||
  3992. $cmd eq "ZW_DELETE_RETURN_ROUTE" ||
  3993. $cmd eq "ZW_SEND_SUC_ID") {
  3994. if($id eq "00") { $evt = 'transmitOk';
  3995. } elsif($id eq "01") { $evt = 'transmitNoAck';
  3996. } elsif($id eq "02") { $evt = 'transmitFail';
  3997. } elsif($id eq "03") { $evt = 'transmitFailNotIdle';
  3998. } elsif($id eq "04") { $evt = 'transmitNoRoute';
  3999. } else { $evt = 'unknown_'.$id; # should never happen
  4000. }
  4001. } elsif($cmd eq "ZW_REQUEST_NETWORK_UPDATE") {
  4002. if($id eq "00") { $evt = 'done';
  4003. } elsif($id eq "01") { $evt = 'abort';
  4004. } elsif($id eq "02") { $evt = 'wait';
  4005. } elsif($id eq "03") { $evt = 'disabled';
  4006. } elsif($id eq "04") { $evt = 'overflow';
  4007. } else { $evt = 'unknown_'.$id; # should never happen
  4008. }
  4009. } elsif($cmd eq "ZW_SET_SUC_NODE_ID") {
  4010. if($id eq "05") { $evt = 'callbackSucceeded';
  4011. } elsif($id eq "06") { $evt = 'callbackFailed';
  4012. } else { $evt = 'unknown_'.$id; # do not know
  4013. }
  4014. } elsif($cmd eq "ZW_CONTROLLER_CHANGE" ||
  4015. $cmd eq "ZW_CREATE_NEW_PRIMARY") {
  4016. my @vals = ("learnReady", "nodeFound", "slave","controller", "protocolDone",
  4017. "done", "failed"); # slave should never happen
  4018. $evt = ($id eq "00" || hex($id)>@vals+1) ? "unknownArg" : $vals[hex($id)-1];
  4019. if($cmd eq "ZW_CREATE_NEW_PRIMARY" && $evt eq "protocolDone") {
  4020. AnalyzeCommand(undef, "set $ioName createNewPrimary stop");
  4021. }
  4022. if($cmd eq "ZW_CONTROLLER_CHANGE" && $evt eq "protocolDone") {
  4023. AnalyzeCommand(undef, "set $ioName addNode off");
  4024. }
  4025. }
  4026. if($evt) {
  4027. return "$cmd $evt" if($srcCmd);
  4028. DoTrigger($ioName, "$cmd $evt");
  4029. Log3 $ioName, 4, "$ioName $cmd $evt";
  4030. return "";
  4031. }
  4032. ######################################
  4033. # device messages
  4034. if($cmd ne "APPLICATION_COMMAND_HANDLER") {
  4035. Log3 $ioName, 4, "$ioName unhandled command $cmd";
  4036. return ""
  4037. }
  4038. if($arg =~ m/^(..)(..)(.*)/ && $2 eq "c6") { # Danfoss Living Strangeness
  4039. Log3 $ioName, 4, "Class mod for Danfoss ($2)";
  4040. $arg = sprintf("%s%02x%s", $1, hex($2) & 0x7f, $3);
  4041. }
  4042. if($arg =~ /^..5601(.*)(....)/) { # CRC_16_ENCAP: Unwrap encapsulated command
  4043. #Log3 $ioName, 4, "CRC FIX, MSG: ($1)"; # see Forum #23494
  4044. my $crc16 = ZWave_CRC16("5601".$1);
  4045. if ($2 eq $crc16) {
  4046. $arg = sprintf("%02x$1", length($1)/2);
  4047. } else {
  4048. Log3 $ioName, 4, "$ioName CRC_16 checksum mismatch, received $2," .
  4049. " calculated $crc16";
  4050. return "";
  4051. }
  4052. }
  4053. my ($baseHash, $baseId, $ep) = ("",$id,"");
  4054. if($arg =~ /^..6006(..)(.*)/) { # MULTI_CHANNEL CMD_ENCAP, V1, Forum #36126
  4055. $ep = $1;
  4056. $baseHash = $modules{ZWave}{defptr}{"$homeId $id"};
  4057. $id = "$id$ep";
  4058. $arg = sprintf("%02x$2", length($2)/2);
  4059. }
  4060. if($arg =~ /^..600d(..)(..)(.*)/) { # MULTI_CHANNEL CMD_ENCAP, V2
  4061. $ep = sprintf("%02x", hex($1 ne "00" ? $1 : $2) & 0x7f); # Forum #50176
  4062. if($ep ne "00") {
  4063. $baseHash = $modules{ZWave}{defptr}{"$homeId $id"};
  4064. $id = "$id$ep";
  4065. }
  4066. $arg = sprintf("%02x$3", length($3)/2);
  4067. }
  4068. $hash = $modules{ZWave}{defptr}{"$homeId $id"};
  4069. $baseHash = $hash if(!$baseHash);
  4070. if(!$hash) {
  4071. if(!$baseHash) {
  4072. Log3 $ioName, 4, "ZWave: unknown message $msg for ID $id";
  4073. return "";
  4074. }
  4075. # autocreate the device when pressing the remote button (Forum #43261)
  4076. $id=hex($id); $baseId=hex($baseId); $ep=hex($ep);
  4077. my $nn = "ZWave_Node_$baseId".($ep eq "0" ? "" : ".$ep");
  4078. my $ret = "UNDEFINED $nn ZWave $homeId $id";
  4079. Log3 $ioName, 3, "$ret, please define it. Triggered by $msg.";
  4080. DoTrigger("global", $ret);
  4081. return "";
  4082. }
  4083. my $name = $hash->{NAME};
  4084. my @event;
  4085. my @args = ($arg); # MULTI_CMD handling
  4086. while(@args) {
  4087. $arg = shift(@args);
  4088. return if($arg !~ m/^..(..)/);
  4089. my $class = $1;
  4090. my $className = $zwave_id2class{lc($class)} ?
  4091. $zwave_id2class{lc($class)} : "UNKNOWN_".uc($class);
  4092. if($className eq "MULTI_CMD") {
  4093. my ($ncmd, $off) = (0, 4);
  4094. while(length($arg) > $off*2) {
  4095. my $l = hex(substr($arg, $off*2, 2))+1;
  4096. push @args, substr($arg, $off*2, $l*2);
  4097. $off += $l;
  4098. }
  4099. next;
  4100. }
  4101. my $ptr = ZWave_getHash($hash, $className, "parse");
  4102. if(!$ptr) {
  4103. push @event, "UNPARSED:$className $arg";
  4104. next;
  4105. }
  4106. my $hookVeto = 0;
  4107. foreach my $h (keys %zwave_parseHook) {
  4108. if("$id:$arg" =~ m/$h/) {
  4109. my $fn = $zwave_parseHook{$h};
  4110. delete $zwave_parseHook{$h};
  4111. $hookVeto++ if($fn->($hash, $arg));
  4112. }
  4113. }
  4114. if(!$hookVeto) {
  4115. my $matched = 0;
  4116. foreach my $k (keys %{$ptr}) {
  4117. if($arg =~ m/^$k/) {
  4118. my $val = $ptr->{$k};
  4119. my @val = ($val);
  4120. @val = eval $val if(index($val, '$') >= 0);
  4121. push @event, @val if(defined($val[0]));
  4122. $matched++;
  4123. }
  4124. }
  4125. push @event, "UNPARSED:$className $arg" if(!$matched);
  4126. }
  4127. }
  4128. if($arg =~ m/^028407/) { # wakeup:notification (WUN)
  4129. if($hash->{ignoreDupMsg} && $hash->{wakeupAlive}) { # Ignore 2nd WUN
  4130. Log3 $name, 3, "$name: ignore duplicate WUN";
  4131. return ""
  4132. }
  4133. ZWave_wakeupTimer($baseHash, 1);
  4134. ZWave_processSendStack($baseHash, "next");
  4135. } else {
  4136. if($hash->{ignoreDupMsg} && $callbackid ne "00") {
  4137. my $hp = hex($callbackid);
  4138. if($zwave_cbid2dev{$hp}) {
  4139. delete $zwave_cbid2dev{$hp};
  4140. } else {
  4141. Log3 $name, 3, "$name: ignore duplicate answer $event[0]";
  4142. return "";
  4143. }
  4144. }
  4145. ZWave_processSendStack($baseHash, "msg", $arg)
  4146. if(!ZWave_isWakeUp($hash) || $hash->{wakeupAlive});
  4147. }
  4148. return "" if(!@event);
  4149. readingsBeginUpdate($hash);
  4150. for(my $i = 0; $i < int(@event); $i++) {
  4151. next if($event[$i] eq "");
  4152. my ($vn, $vv) = split(":", $event[$i], 2);
  4153. readingsBulkUpdate($hash, $vn, $vv);
  4154. readingsBulkUpdate($hash, "reportedState", $vv)
  4155. if($vn eq "state"); # different from set
  4156. }
  4157. readingsBulkUpdate($hash, "rawMsg", $rawMsg)
  4158. if(AttrVal($name, "eventForRaw", undef));
  4159. readingsEndUpdate($hash, 1);
  4160. if($hash->{asyncGet} && $msg =~ m/$hash->{asyncGet}{re}/) {
  4161. RemoveInternalTimer($hash->{asyncGet});
  4162. asyncOutput($hash->{asyncGet}{CL}, join("\n", @event));
  4163. delete($hash->{asyncGet});
  4164. }
  4165. return join("\n", @event) if($srcCmd);
  4166. return $name;
  4167. }
  4168. #####################################
  4169. sub
  4170. ZWave_Undef($$)
  4171. {
  4172. my ($hash, $arg) = @_;
  4173. my $homeId = $hash->{homeId};
  4174. my $id = $hash->{nodeIdHex};
  4175. delete $modules{ZWave}{defptr}{"$homeId $id"};
  4176. return undef;
  4177. }
  4178. #####################################
  4179. sub
  4180. ZWave_computeRoute($;$)
  4181. {
  4182. my ($spec,$attrVal) = @_;
  4183. for my $dev (devspec2array($spec)) {
  4184. my $av = AttrVal($dev, "zwaveRoute", $attrVal);
  4185. next if(!$av);
  4186. my @h;
  4187. for my $r (split(" ", $av)) {
  4188. if(!$defs{$r} || $defs{$r}{TYPE} ne "ZWave") {
  4189. my $msg = "zwaveRoute: $r is not a ZWave device";
  4190. Log 1, $msg;
  4191. return $msg;
  4192. }
  4193. push(@h, $defs{$r}{nodeIdHex});
  4194. }
  4195. $defs{$dev}{route} = join("",@h);
  4196. }
  4197. return undef;
  4198. }
  4199. sub
  4200. ZWave_Attr(@)
  4201. {
  4202. my ($type, $devName, $attrName, $param) = @_;
  4203. my $hash = $defs{$devName};
  4204. if($attrName eq "zwaveRoute") {
  4205. if($type eq "del") {
  4206. delete $hash->{route};
  4207. return undef;
  4208. }
  4209. return ZWave_computeRoute($devName, $param) if($init_done);
  4210. InternalTimer(1, "ZWave_computeRoute", "TYPE=ZWave", 0);
  4211. return undef;
  4212. } elsif($attrName eq "ignoreDupMsg") {
  4213. if($type eq "del") {
  4214. delete $hash->{ignoreDupMsg};
  4215. } else {
  4216. $hash->{ignoreDupMsg} = (defined($param) ? $param : 1);
  4217. }
  4218. return undef;
  4219. } elsif($attrName eq "vclasses") {
  4220. if($type eq "del") {
  4221. $hash->{".vclasses"} = {};
  4222. return undef;
  4223. }
  4224. my %h = map { split(":", $_) } split(" ", $param);
  4225. $hash->{".vclasses"} = \%h;
  4226. return undef;
  4227. } elsif($attrName eq "useMultiCmd") {
  4228. if($type eq "del") {
  4229. $hash->{".vclasses"} = {};
  4230. return undef;
  4231. }
  4232. my $a = ($attr{$devName} ? $attr{$devName}{classes} : "");
  4233. return "useMultiCmd: unsupported device, see help ZWave for details"
  4234. if(!$a || !($a =~ m/MULTI_CMD/ && $a =~ m/WAKE_UP/));
  4235. $hash->{useMultiCmd} = 1;
  4236. return undef;
  4237. }
  4238. return undef;
  4239. }
  4240. sub
  4241. ZWave_duration($)
  4242. {
  4243. my ($duration) = @_;
  4244. my $time = hex($duration);
  4245. $time = ($time - 0x7f) * 60 if($time>0x7f && $time<=0xfd);
  4246. return (lc($duration) eq "fe" ? "unknown" : "$time seconds");
  4247. }
  4248. #####################################
  4249. # Show the help from the device.xml, if the correct entry is selected
  4250. sub
  4251. ZWave_helpFn($$)
  4252. {
  4253. my ($d,$cmd) = @_;
  4254. my $mc = ZWave_configGetHash($defs{$d});
  4255. return "" if(!$mc);
  4256. my $h = $mc->{config}{$cmd};
  4257. return "" if(!$h || !$h->{Help});
  4258. $cmd .= " (numeric code $h->{index})" if(defined($h->{index}));
  4259. my $ret = "Help for $cmd:<br>".$h->{Help};
  4260. my $hi = $h->{Item};
  4261. $ret .= "Possible values: ".
  4262. join(", ", map {"$_ ($hi->{$_})"} sort keys %{$hi})."<br>"
  4263. if($hi);
  4264. return $ret;
  4265. }
  4266. sub
  4267. ZWave_getPic($$)
  4268. {
  4269. my ($iodev, $model) = @_;
  4270. my $hs = AttrVal($iodev, "helpSites", $zwave_helpSites);
  4271. for my $n (split(",", $hs)) {
  4272. my $img = $zwave_img{$n}{$model};
  4273. next if(!$img);
  4274. my $fn = $attr{global}{modpath}."/www/deviceimages/zwave/$img";
  4275. if(!-f $fn) { # Cache the picture
  4276. my $url = $n eq "alliance" ?
  4277. "http://products.z-wavealliance.org/ProductImages/Index?productName=":
  4278. "http://fhem.de/deviceimages/zwave/";
  4279. Log 3, "ZWave: downloading $url/$img for $model";
  4280. my $data = GetFileFromURL("$url/$img");
  4281. if($data && open(FH,">$fn")) {
  4282. print FH $data;
  4283. close(FH)
  4284. }
  4285. }
  4286. return "$FW_ME/deviceimages/zwave/$img";
  4287. }
  4288. return "";
  4289. }
  4290. sub
  4291. ZWave_fhemwebFn($$$$)
  4292. {
  4293. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  4294. my $pl = ""; # Pepper link and image
  4295. my $model = ReadingsVal($d, "modelId", "");
  4296. return '' if (!$model);
  4297. my $iodev = $defs{$d}{IODev}{NAME};
  4298. my $hs = AttrVal($iodev, "helpSites", $zwave_helpSites);
  4299. for my $n (split(",", $hs)) {
  4300. my $link = $zwave_link{$n}{$model};
  4301. next if(!$link);
  4302. $pl .= "<div class='detLink ZWPepper'>";
  4303. my $url = ($n eq "alliance" ?
  4304. "http://products.z-wavealliance.org/products/" :
  4305. "http://www.pepper1.net/zwavedb/device/");
  4306. $pl .= "<a target='_blank' href='$url/$link'>Details in $n DB</a>";
  4307. $pl .= "</div>";
  4308. }
  4309. my $img = ZWave_getPic($iodev, $model);
  4310. if($img && !$FW_ss) {
  4311. $pl .= "<div class='img'".($FW_tp?"":" style='float:right'").">";
  4312. $pl .= "<img style='max-width:96;max-height:96px;' src='$img'>";
  4313. $pl .= "</div>";
  4314. }
  4315. return
  4316. "<div id='ZWHelp' class='makeTable help'></div>$pl".
  4317. '<script type="text/javascript">'.
  4318. "var d='$d', FW_tp='$FW_tp';" . <<'JSEND'
  4319. $(document).ready(function() {
  4320. $("div#ZWHelp").insertBefore("div.makeTable.internals"); // Move
  4321. $("div.detLink.ZWPepper").insertAfter("div.detLink.devSpecHelp");
  4322. if(FW_tp) $("div.img.ZWPepper").appendTo("div#menu");
  4323. $("select.set,select.get").each(function(){
  4324. $(this).get(0).setValueFn = function(val) {
  4325. $("div#ZWHelp").html(val);
  4326. }
  4327. $(this).change(function(){
  4328. FW_queryValue('{ZWave_helpFn("'+d+'","'+$(this).val()+'")}',
  4329. $(this).get(0));
  4330. });
  4331. });
  4332. });
  4333. </script>
  4334. JSEND
  4335. }
  4336. #####################################
  4337. # 2-byte signed hex
  4338. sub
  4339. s2Hex($)
  4340. {
  4341. my ($p) = @_;
  4342. $p = hex($p);
  4343. return ($p > 32767 ? -(65536-$p) : $p);
  4344. }
  4345. 1;
  4346. =pod
  4347. =item summary devices communicating via the ZWave protocol
  4348. =item summary_DE Anbindung von ZWave Ger&auml;ten
  4349. =begin html
  4350. <a name="ZWave"></a>
  4351. <h3>ZWave</h3>
  4352. <ul>
  4353. This module is used to control ZWave devices via FHEM, see <a
  4354. href="http://www.z-wave.com">www.z-wave.com</a> on details for this device
  4355. family. This module is a client of the <a href="#ZWDongle">ZWDongle</a>
  4356. module, which is directly attached to the controller via USB or TCP/IP. To
  4357. use the SECURITY features, the Crypt-Rijndael perl module is needed.
  4358. <br><br>
  4359. <a name="ZWavedefine"></a>
  4360. <b>Define</b>
  4361. <ul>
  4362. <code>define &lt;name&gt; ZWave &lt;homeId&gt; &lt;id&gt; [classes]</code>
  4363. <br>
  4364. <br>
  4365. &lt;homeId&gt; is the homeId of the controller node, and id is the id of the
  4366. slave node in the network of this controller.<br>
  4367. classes is a hex-list of ZWave device classes. This argument is usually
  4368. specified by autocreate when creating a device. If you wish to manually
  4369. create a device, use the classes attribute instead, see below for details.
  4370. Defining a ZWave device the first time is usually done by autocreate.
  4371. <br>
  4372. Example:
  4373. <ul>
  4374. <code>define lamp ZWave 00ce2074 9</code><br>
  4375. <code>attr lamp classes SWITCH_BINARY BASIC MANUFACTURER_SPECIFIC VERSION
  4376. SWITCH_ALL ASSOCIATION METER CONFIGURATION ALARM</code><br>
  4377. </ul>
  4378. </ul>
  4379. <br>
  4380. Note: the sets/gets/generated events of a given node depend on the classes
  4381. supported by this node. If a node supports 3 classes, then the union of
  4382. these sets/gets/events will be available for this node.<br>
  4383. Commands for battery operated nodes will be queues internally, and sent when
  4384. the node sends a message. Answer to get commands appear then as events, the
  4385. corresponding readings will be updated.
  4386. <br><br>
  4387. <a name="ZWaveset"></a>
  4388. <b>Set</b>
  4389. <ul>
  4390. <br>
  4391. <b>Note</b>: devices with on/off functionality support the <a
  4392. href="#setExtensions"> set extensions</a>.
  4393. <br><br><b>All</b>
  4394. <li>neighborUpdate<br>
  4395. Requests controller to update his routing table which is based on
  4396. slave's neighbor list. The update may take significant time to complete.
  4397. With the event "done" or "failed" ZWDongle will notify the end of the
  4398. update process. To read node's neighbor list see neighborList get
  4399. below.</li>
  4400. <li>returnRouteAdd &lt;decimal nodeId&gt;<br>
  4401. Assign up to 4 static return routes to the routing/enhanced slave to
  4402. allow direct communication to &lt;decimal nodeId&gt;. (experts only)</li>
  4403. <li>returnRouteDel<br>
  4404. Delete all static return routes. (experts only)</li>
  4405. <li>sucRouteAdd<br>
  4406. Inform the routing/enhanced slave of the presence of a SUC/SIS. Assign
  4407. up to 4 static return routes to SUC/SIS.</li>
  4408. <li>sucRouteDel<br>
  4409. Delete static return routes to SUC/SIS node.</li>
  4410. <br><br><b>Class ALARM</b>
  4411. <li>alarmnotification &lt;alarmType&gt; (on|off)<br>
  4412. Enable (on) or disable (off) the sending of unsolicited reports for
  4413. the alarm type &lt;alarmType&gt;. A list of supported alarm types of the
  4414. device can be obtained with the alarmTypeSupported command. The
  4415. name of the alarm type is case insensitive. Sending of an unsolicted
  4416. notification only works to associated nodes, broadcasting is not
  4417. allowed, so associations have to be set up. This command is
  4418. specified in version 2.</li>
  4419. <li> Note:<br>
  4420. The name of the class ALARM was renamed to NOTIFICATION in
  4421. version 3 of the Zwave specification. Due to backward compatibility
  4422. reasons the class will be always referenced as ALARM in FHEM,
  4423. regardless of the version.</li>
  4424. <br><br><b>Class ASSOCIATION</b>
  4425. <li>associationAdd groupId nodeId ...<br>
  4426. Add the specified list of nodeIds to the association group groupId.<br> Note:
  4427. upon creating a fhem-device for the first time fhem will automatically add
  4428. the controller to the first association group of the node corresponding to
  4429. the fhem device, i.e it issues a "set name associationAdd 1
  4430. controllerNodeId"</li>
  4431. <li>associationDel groupId nodeId ...<br>
  4432. Remove the specified list of nodeIds from the association group groupId.</li>
  4433. <br><br><b>Class BASIC</b>
  4434. <li>basicValue value<br>
  4435. Send value (0-255) to this device. The interpretation is device dependent,
  4436. e.g. for a SWITCH_BINARY device 0 is off and anything else is on.</li>
  4437. <li>basicValue value<br>
  4438. Alias for basicValue, to make mapping from the incoming events easier.
  4439. </li>
  4440. <br><br><b>Class BASIC_WINDOW_COVERING</b>
  4441. <li>coveringClose<br>
  4442. Starts closing the window cover. Moving stops if blinds are fully closed or
  4443. a coveringStop command was issued.
  4444. </li>
  4445. <li>coveringOpen<br>
  4446. Starts opening the window cover. Moving stops if blinds are fully open or
  4447. a coveringStop command was issued.
  4448. </li>
  4449. <li>coveringStop<br>
  4450. Stop moving the window cover. Blinds are partially open (closed).
  4451. </li>
  4452. <br><br><b>Class CLIMATE_CONTROL_SCHEDULE</b>
  4453. <li>ccs [mon|tue|wed|thu|fri|sat|sun] HH:MM tempDiff HH:MM tempDiff ...<br>
  4454. set the climate control schedule for the given day.<br>
  4455. Up to 9 pairs of HH:MM tempDiff may be specified.<br>
  4456. HH:MM must occur in increasing order.
  4457. tempDiff is relative to the setpoint temperature, and may be between -12
  4458. and 12, with one decimal point, measured in Kelvin (or Centigrade).<br>
  4459. If only a weekday is specified without any time and tempDiff, then the
  4460. complete schedule for the specified day is removed and marked as unused.
  4461. </li>
  4462. <li>cssSetOverride (no|temporary|permanent) (frost|energy|$tempOffset) <br>
  4463. set the override state<br>
  4464. no: switch the override off<br>
  4465. temporary: override the current schedule only<br>
  4466. permanent: override all schedules<br>
  4467. frost/energy: set override mode to frost protection or engergy saving<br>
  4468. $tempOffset: the temperature setback (offset to setpoint) in 1/10 degrees<br>
  4469. range from -12.8 to 12.0, values will be limited to this range.
  4470. </li>
  4471. <br><br><b>Class CLOCK</b>
  4472. <li>clock<br>
  4473. set the clock to the current date/time (no argument required)
  4474. </li>
  4475. <br><br><b>Class COLOR_CONTROL</b>
  4476. <li>rgb<br>
  4477. Set the color of the device as a 6 digit RGB Value (RRGGBB), each color is
  4478. specified with a value from 00 to ff.</li>
  4479. <li>wcrgb<br>
  4480. Used for sending warm white, cold white, red, green and blue values
  4481. to device. Values must be decimal (0 - 255) and separated by blanks.
  4482. <ul>
  4483. set &lt;name&gt; wcrgb 0 255 0 0 0 (setting full cold white)<br>
  4484. </ul>
  4485. </li>
  4486. <br><br><b>Class CONFIGURATION</b>
  4487. <li>configByte cfgAddress 8bitValue<br>
  4488. configWord cfgAddress 16bitValue<br>
  4489. configLong cfgAddress 32bitValue<br>
  4490. Send a configuration value for the parameter cfgAddress. cfgAddress and
  4491. value is node specific.<br>
  4492. Note: if the model is set (see MANUFACTURER_SPECIFIC get), then more
  4493. specific config commands are available.</li>
  4494. <li>configDefault cfgAddress<br>
  4495. Reset the configuration parameter for the cfgAddress parameter to its
  4496. default value. See the device documentation to determine this value.</li>
  4497. <br><br><b>Class DOOR_LOCK, V2</b>
  4498. <li>doorLockOperation DOOR_LOCK_MODE<br>
  4499. Set the operation mode of the door lock.<br>
  4500. DOOR_LOCK_MODE:<br>
  4501. open = Door unsecured<br>
  4502. close = Door secured<br>
  4503. 00 = Door unsecured<br>
  4504. 01 = Door unsecured with timeout<br>
  4505. 10 = Door unsecured for inside door handles<br>
  4506. 11 = Door unsecured for inside door handles with timeout<br>
  4507. 20 = Door unsecured for outside door handles<br>
  4508. 21 = Door unsecured for outside door handles with timeout<br>
  4509. FF = Door secured<br>
  4510. Note: open/close can be used as an alias for 00/FF.
  4511. </li>
  4512. <li>doorLockConfiguration operationType outsidehandles
  4513. insidehandles timeoutSeconds<br>
  4514. Set the configuration for the door lock.<br>
  4515. operationType: [constant|timed]<br>
  4516. outsidehandle/insidehandle: 4-bit binary field for handle 1-4,
  4517. bit=0:handle disabled, bit=1:handle enabled, highest bit is for
  4518. handle 4, lowest bit for handle 1. Example 0110 0001
  4519. = outside handles 3 and 2 are active, inside handle 1 is active<br>
  4520. timeoutSeconds: time out for timed operation (in seconds) [1-15239].
  4521. </li>
  4522. <br><br><b>Class INDICATOR</b>
  4523. <li>indicatorOn<br>
  4524. switch the indicator on</li>
  4525. <li>indicatorOff<br>
  4526. switch the indicator off</li>
  4527. <li>indicatorDim value<br>
  4528. takes values from 1 to 99.
  4529. If the indicator does not support dimming. It is interpreted as on.</li>
  4530. <br><br><b>Class MANUFACTURER_PROPRIETARY</b>
  4531. <br>Fibaro FGR(M)-222 only:
  4532. <li>positionBlinds<br>
  4533. drive blinds to position %</li>
  4534. <li>positionSlat<br>
  4535. drive slat to position %</li>
  4536. <br>D-Link DCH-Z510, Philio PSE02, Zipato Indoor Siren only:<br>
  4537. switch alarm on with selected sound (to stop use: set &lt;device&gt; off)
  4538. <li>alarmEmergencyOn</li>
  4539. <li>alarmFireOn</li>
  4540. <li>alarmAmbulanceOn</li>
  4541. <li>alarmPoliceOn</li>
  4542. <li>alarmDoorchimeOn</li>
  4543. <li>alarmBeepOn</li>
  4544. <br><br><b>Class METER</b>
  4545. <li>meterReset<br>
  4546. Reset all accumulated meter values.<br>
  4547. Note: see meterSupported command and its output to detect if resetting the
  4548. value is supported by the device.<br>
  4549. The command will reset ALL accumulated values, it is not possible to
  4550. choose a single value.</li>
  4551. <br><br><b>Class MULTI_CHANNEL</b>
  4552. <li>mcCreateAll<br>
  4553. Create a FHEM device for all channels. This command is executed after
  4554. inclusion of a new device.
  4555. </li>
  4556. <br><br><b>Class MULTI_CHANNEL_ASSOCIATION</b>
  4557. <li>mcaAdd groupId node1 node2 ... 0 node1 endPoint1 node2 endPoint2 ...<br>
  4558. Add a list of node or node:endpoint associations. The latter can be used to
  4559. create channels on remotes. E.g. to configure the button 1,2,... on the
  4560. zwave.me remote, use:
  4561. <ul>
  4562. set remote mcaAdd 2 0 1 2<br>
  4563. set remote mcaAdd 3 0 1 3<br>
  4564. ....
  4565. </ul>
  4566. For each button a separate FHEM device will be generated.
  4567. </li>
  4568. <li>mcaDel groupId node1 node2 ... 0 node1 endPoint1 node2 endPoint2 ...<br>
  4569. delete node or node:endpoint associations.
  4570. Special cases: just specifying the groupId will delete everything for this
  4571. groupId. Specifying 0 for groupid will delete all associations.
  4572. </li>
  4573. <br><br><b>Class NETWORK_SCHEDULE (SCHEDULE), V1</b>
  4574. <li>schedule ID USER_ID YEAR-MONTH-DAY WDAY ACTIVE_ID DURATION_TYPE
  4575. HOUR:MINUTE DURATION NUM_REPORTS CMD ... CMD<br>
  4576. Set a schedule for a user. Due to lack of documentation,
  4577. details for some parameters are not available. Command Class is
  4578. used together with class USER_CODE.<br>
  4579. <ul>
  4580. ID: id of schedule, refer to maximum number of supported schedules
  4581. reported by the scheduleSupported command.<br>
  4582. USER_ID: id of user, starting from 1 up to the number of supported
  4583. users, refer also to the USER_CODE class description.<br>
  4584. YEAR-MONTH-DAY: start of schedule in the format yyyy-mm-dd.<br>
  4585. WDAY: weekday, 1=Monday, 7=Sunday.<br>
  4586. ACTIVE_ID: unknown parameter.<br>
  4587. DURATION_TYPE: unknown parameter.<br>
  4588. HOUR:MINUTE: start of schedule in the format hh:mm.<br>
  4589. DURATION: unknown parameter.<br>
  4590. NUM_REPORTS: number of reports to follow, must be 0.<br>
  4591. CMD: command(s) (as hexcode sequence) that the schedule executes,
  4592. see report of scheduleSupported command for supported command
  4593. class and mask. A list of space separated command can be
  4594. specified.<br>
  4595. </ul>
  4596. </li>
  4597. <li>scheduleRemove ID<br>
  4598. Remove the schedule with the id ID</li>
  4599. <li>scheduleState ID STATE<br>
  4600. Set the STATE of the schedule with the id ID. Description for
  4601. parameter STATE is not available.</li>
  4602. <br><br><b>Class NODE_NAMING</b>
  4603. <li>name NAME<br>
  4604. Store NAME in the EEPROM. Note: only ASCII is supported.</li>
  4605. <li>location LOCATION<br>
  4606. Store LOCATION in the EEPROM. Note: only ASCII is supported.</li>
  4607. <br><br><b>Class POWERLEVEL</b>
  4608. <li>Class is only used in an installation or test situation</li>
  4609. <li>powerlevel level timeout/s<br>
  4610. set powerlevel to level [0-9] for timeout/s [1-255].<br>
  4611. level 0=normal, level 1=-1dBm, .., level 9=-9dBm.</li>
  4612. <li>powerlevelTest nodeId level frames <br>
  4613. send number of frames [1-65535] to nodeId with level [0-9].</li>
  4614. <br><br><b>Class PROTECTION</b>
  4615. <li>protectionOff<br>
  4616. device is unprotected</li>
  4617. <li>protectionOn<br>
  4618. device is protected</li>
  4619. <li>protectionSeq<br>
  4620. device can be operated, if a certain sequence is keyed.</li>
  4621. <li>protectionBytes LocalProtectionByte RFProtectionByte<br>
  4622. for commandclass PROTECTION V2 - see devicemanual for supported
  4623. protectionmodes</li>
  4624. <br><br><b>Class SCENE_ACTIVATION</b>
  4625. <li>sceneConfig<br>
  4626. activate settings for a specific scene.
  4627. Parameters are: sceneId, dimmingDuration (0..255)
  4628. </li>
  4629. <br><br><b>Class SCENE_ACTUATOR_CONF</b>
  4630. <li>sceneConfig<br>
  4631. set configuration for a specific scene.
  4632. Parameters are: sceneId, dimmingDuration, finalValue (0..255)
  4633. </li>
  4634. <br><br><b>Class SCENE_CONTROLLER_CONF</b>
  4635. <li>groupConfig<br>
  4636. set configuration for a specific scene.
  4637. Parameters are: groupId, sceneId, dimmingDuration.
  4638. </li>
  4639. <br><br><b>Class SCHEDULE_ENTRY_LOCK, V1, V2, V3</b>
  4640. <li>scheduleEntryLockSet USER_ID ENABLED<br>
  4641. enables or disables schedules for a specified user ID (V1)<br>
  4642. <ul>
  4643. USER_ID: id of user, starting from 1 up to the number of supported
  4644. users, refer also to the USER_CODE class description.<br>
  4645. ENABLED: 0=disabled, 1=enabled<br>
  4646. </ul>
  4647. </li>
  4648. <li>scheduleEntryLockAllSet ENABLED<br>
  4649. enables or disables schedules for all users (V1)<br>
  4650. <ul>
  4651. ENABLED: 0=disabled, 1=enabled<br>
  4652. </ul>
  4653. </li>
  4654. <li>scheduleEntryLockWeekDaySet ACTION USER_ID SCHEDULE_ID WEEKDAY
  4655. STARTTIME ENDTIME<br>
  4656. erase or set a week day schedule for a specified user ID (V1)<br>
  4657. <ul>
  4658. ACTION: 0=erase schedule slot, 1=modify the schedule slot for the
  4659. user<br>
  4660. USER_ID: id of user, starting from 1 up to the number of supported
  4661. users, refer also to the USER_CODE class description.<br>
  4662. SCHEDULE_ID: schedule slot id (from 1 up to number of supported
  4663. schedule slots)<br>
  4664. WEEKDAY: day of week, choose one of:
  4665. "sun","mon","tue","wed","thu","fri","sat"<br>
  4666. STARTTIME: time of schedule start, in the format HH:MM
  4667. (leading 0 is mandatory)<br>
  4668. ENDTIME: time of schedule end in the format HH:MM
  4669. (leading 0 is mandatory)<br>
  4670. </ul>
  4671. </li>
  4672. <li>scheduleEntryLockYearDaySet ACTION USER_ID SCHEDULE_ID
  4673. STARTDATE STARTTIME ENDDATE ENDTIME<br>
  4674. erase or set a year day schedule for a specified user ID (V1)<br>
  4675. <ul>
  4676. ACTION: 0=erase schedule slot, 1=modify the schedule slot for the
  4677. user<br>
  4678. USER_ID: id of user, starting from 1 up to the number of supported
  4679. users, refer also to the USER_CODE class description.<br>
  4680. SCHEDULE_ID: schedule slot id (from 1 up to number of supported
  4681. schedule slots)<br>
  4682. STARTDATE: date of schedule start in the format YYYY-MM-DD<br>
  4683. STARTTIME: time of schedule start in the format HH:MM
  4684. (leading 0 is mandatory)<br>
  4685. ENDDATE: date of schedule end in the format YYYY-MM-DD<br>
  4686. ENDTIME: time of schedule end in the format HH:MM
  4687. (leading 0 is mandatory)<br>
  4688. </ul>
  4689. </li>
  4690. <li>scheduleEntryLockTimeOffsetSet TZO DST<br>
  4691. set the TZO and DST (V2)<br>
  4692. <ul>
  4693. TZO: current local time zone offset in the format (+|-)HH:MM
  4694. (sign and leading 0 is mandatory)<br>
  4695. DST: daylight saving time offset in the format (+|-)[[m]m]m
  4696. (sign is mandatory, minutes: 0 to 127, 1-3 digits)<br>
  4697. </ul>
  4698. </li>
  4699. <li>scheduleEntryLockDailyRepeatingSet ACTION USER_ID SCHEDULE_ID
  4700. WEEKDAYS STARTTIME DURATION<br>
  4701. set a daily repeating schedule for the specified user (V3)<br>
  4702. <ul>
  4703. ACTION: 0=erase schedule slot, 1=modify the schedule slot for the
  4704. user<br>
  4705. USER_ID: id of user, starting from 1 up to the number of supported
  4706. users, refer also to the USER_CODE class description.<br>
  4707. SCHEDULE_ID: schedule slot id (from 1 up to number of supported
  4708. schedule slots)<br>
  4709. WEEKDAYS: concatenated string of weekdays (choose from:
  4710. "sun","mon","tue","wed","thu","fri","sat");
  4711. e.g. "montuewedfri" or "satsun", unused days can be
  4712. specified as "..."<br>
  4713. STARTTIME: time of schedule start in the format HH:MM
  4714. (leading 0 is mandatory)<br>
  4715. DURATION: duration of schedule in the format HH:MM
  4716. (leading 0 is mandatory)<br>
  4717. </ul>
  4718. </li>
  4719. <br><br><b>Class SWITCH_ALL</b>
  4720. <li>swaIncludeNone<br>
  4721. the device does not react to swaOn and swaOff commands</li>
  4722. <li>swaIncludeOff<br>
  4723. the device reacts to the swaOff command
  4724. but does not react to the swaOn command</li>
  4725. <li>swaIncludeOn<br>
  4726. the device reacts to the swaOn command
  4727. but does not react to the swaOff command</li>
  4728. <li>swaIncludeOnOff<br>
  4729. the device reacts to the swaOn and swaOff commands</li>
  4730. <li>swaOn<br>
  4731. sends the all on command to the device</li>
  4732. <li>swaOff<br>
  4733. sends the all off command to the device.</li>
  4734. <br><br><b>Class SWITCH_BINARY</b>
  4735. <li>on<br>
  4736. switch the device on</li>
  4737. <li>off<br>
  4738. switch the device off</li>
  4739. <br><br><b>Class SWITCH_MULTILEVEL</b>
  4740. <li>on, off<br>
  4741. the same as for SWITCH_BINARY.</li>
  4742. <li>dim value<br>
  4743. dim/jump to the requested value (0..100)</li>
  4744. <li>dimWithDuration value duration<br>
  4745. dim to the requested value (0..100) in duration time. If duration is
  4746. less than 128, then it is interpreted as seconds, if it is between 128 and
  4747. 254, then as duration-128 minutes. Note: this command works only with
  4748. devices supporting version 2 of the SWITCH_MULTILEVEL class, which you can
  4749. verify with get versionClassAll</li>
  4750. <li>stop<br>
  4751. stop dimming/operation</li>
  4752. <br><br><b>Class THERMOSTAT_MODE</b>
  4753. <li>tmOff</li>
  4754. <li>tmEnergySaveHeating</li>
  4755. <li>tmHeating</li>
  4756. <li>tmManual<br>
  4757. set the thermostat mode to off, heating but saving energy, heating or
  4758. manual.
  4759. </li>
  4760. <br><br><b>Class THERMOSTAT_SETPOINT</b>
  4761. <li>setpointHeating value<br>
  4762. set the thermostat to heat to the given value.
  4763. The value is a whole number and read as celsius.<br>
  4764. See thermostatSetpointSet for a more enhanced method.
  4765. </li>
  4766. <li>setpointCooling value<br>
  4767. set the thermostat to heat to the given value.
  4768. The value is a whole number and read as celsius.<br>
  4769. See thermostatSetpointSet for a more enhanced method.
  4770. </li>
  4771. <li>thermostatSetpointSet TEMP [SCALE [TYPE [PREC [SIZE]]]]<br>
  4772. set the setpoint of the thermostat to the given value.<br>
  4773. <ul>
  4774. TEMP: setpoint temperature value, by default the value is used
  4775. with 1 decimal, see PREC<br>
  4776. SCALE: (optional) scale of temperature; [cC]=celsius,
  4777. [fF]=fahrenheit, defaults to celsius<br>
  4778. TYPE: (optional) setpoint type; [1, 15], defaults to 1=heating<br>
  4779. <ul>
  4780. 1=heating,
  4781. 2=cooling,
  4782. 7=furnance,
  4783. 8=dryAir,
  4784. 9=moistAir,
  4785. 10=autoChangeover,
  4786. 11=energySaveHeating,
  4787. 12=energySaveCooling,
  4788. 13=awayHeating,
  4789. 14=awayCooling,
  4790. 15=fullPower
  4791. </ul>
  4792. PREC: (optional) number of decimals to be used, [1-7], defaults
  4793. to 1<br>
  4794. SIZE: (optional) number of bytes used, [1, 2, 4], defaults to 2<br>
  4795. Note: optinal parameters can be ommitted and are used with there
  4796. default values. If you need or want to specify an optional
  4797. parameter, ALL parameters in front of this parameter need
  4798. to be also specified!<br>
  4799. Note: the number of decimals (defined by PREC) and the number of
  4800. bytes (defined by SIZE) used for the setpoint influence the usable
  4801. range for the temperature. Some device do not support all possible
  4802. values/combinations for PREC/SIZE.<br>
  4803. <ul>
  4804. 1 byte: 0 decimals [-128, 127], 1 decimal [-12.8, 12.7], ...<br>
  4805. 2 byte: 0 decimals [-32768, 32767], 1 decimal [-3276.8, 3276.7],
  4806. ...<br>
  4807. 4 byte: 0 decimals [-2147483648, 2147483647], ...<br>
  4808. </ul>
  4809. </ul>
  4810. </li>
  4811. <li>desired-temp value<br>
  4812. same as thermostatSetpoint, used to make life easier for helper-modules
  4813. like
  4814. </li>
  4815. <br><br><b>Class TIME, V2</b>
  4816. <li>timeOffset TZO DST_Offset DST_START DST_END<br>
  4817. Set the time offset for the internal clock of the device.<br>
  4818. TZO: Offset of time zone to UTC in format [+|-]hh:mm.<br>
  4819. DST_OFFSET: Offset for daylight saving time (DST) in minutes
  4820. in the format [+|-]mm.<br>
  4821. DST_START / DST_END: Start and end of daylight saving time in the
  4822. format MM-DD_HH:00.<br>
  4823. Note: Sign for both offsets must be specified!<br>
  4824. Note: Minutes for DST_START and DST_END must be specified as "00"!
  4825. </li>
  4826. <br><br><b>Class TIME_PARAMETERS, V1</b>
  4827. <li>timeParametersGet<br>
  4828. The device request time parameters. Right now the user should define a
  4829. notify with a "set timeParameters" command.
  4830. </li>
  4831. <li>timeParameters DATE TIME<br>
  4832. Set the time (UTC) to the internal clock of the device.<br>
  4833. DATE: Date in format YYYY-MM-DD.<br>
  4834. TIME: Time (UTC) in the format hh:mm:ss.<br>
  4835. Note: Time zone offset to UTC must be set with command class TIME.
  4836. </li>
  4837. <br><br><b>Class USER_CODE</b>
  4838. <li>userCode id status code</br>
  4839. set code and status for the id n. n ist starting at 1, status is 0 for
  4840. available (deleted) and 1 for set (occupied). code is a hexadecimal string.
  4841. </li>
  4842. <br><br><b>Class WAKE_UP</b>
  4843. <li>wakeupInterval value nodeId<br>
  4844. Set the wakeup interval of battery operated devices to the given value in
  4845. seconds. Upon wakeup the device sends a wakeup notification to nodeId.</li>
  4846. <li>wakeupNoMoreInformation<br>
  4847. put a battery driven device into sleep mode. </li>
  4848. </ul>
  4849. <br>
  4850. <a name="ZWaveget"></a>
  4851. <b>Get</b>
  4852. <ul>
  4853. <br><br><b>All</b>
  4854. <li>neighborList<br>
  4855. returns the list of neighbors. Provides insights to actual network
  4856. topology. List includes dead links and non-routing neighbors.
  4857. Since this information is stored in the dongle, the information will be
  4858. returned directly even for WAKE_UP devices.</li>
  4859. <br><br><b>Class ALARM</b>
  4860. <li>alarm &lt;alarmId&gt;<br>
  4861. return the value for the (decimal) alarmId. The value is device
  4862. specific. This command is specified in version 1 and should only
  4863. be used with old devices that only support version 1.</li>
  4864. <li>alarmWithType &lt;alarmType&gt;<br>
  4865. return the event for the specified alarm type. This command is
  4866. specified in version 2.
  4867. </li>
  4868. <li>alarmWithTypeEvent &lt;alarmType&gt; &lt;eventnumber&gt;<br>
  4869. return the event details for the specified alarm type and
  4870. eventnumber. This command is specified in version 3. The eventnumber
  4871. is specific for each alarm type, a list of the supported
  4872. eventnumbers can be obtained by the "alarmEventSupported" command,
  4873. refer also to the documentation of the device.
  4874. </li>
  4875. <li>alarmTypeSupported<br>
  4876. Returns a list of the supported alarm types of the device which are
  4877. used as parameters in the "alarmWithType" and "alarmWithTypeEvent"
  4878. commands. This command is specified in version 2.</li>
  4879. <li>alarmEventSupported &lt;alarmType&gt;<br>
  4880. Returns a list of the supported events for the specified alarm type.
  4881. The number of the events can be used as parameter in the
  4882. "alarmWithTypeEvent" command. This command is specified in
  4883. version 3.</li>
  4884. <br><br><b>Class ASSOCIATION</b>
  4885. <li>association groupId<br>
  4886. return the list of nodeIds in the association group groupId in the form:<br>
  4887. assocGroup_X:Max Y, Nodes id,id...
  4888. </li>
  4889. <li>associationGroups<br>
  4890. return the number of association groups<br>
  4891. </li>
  4892. <li>associationAll<br>
  4893. request association info for all possible groups.</li>
  4894. <br><br><b>Class ASSOCIATION_GRP_INFO</b>
  4895. <li>associationGroupName groupId<br>
  4896. return the name of association groups
  4897. </li>
  4898. <li>associationGroupCmdList groupId<br>
  4899. return Command Classes and Commands that will be sent to associated
  4900. devices in this group<br>
  4901. </li>
  4902. <br><br><b>Class BASIC</b>
  4903. <li>basicStatus<br>
  4904. return the status of the node as basicReport:XY. The value (XY) depends on
  4905. the node, e.g a SWITCH_BINARY device report 00 for off and FF (255) for on.
  4906. Devices with version 2 (or greater) can return two additional values, the
  4907. 'target value' and 'duration'. The 'duration' is reported in seconds,
  4908. as "unknown duration" (value 0xFE = 253) or as "255 (reserved value)"
  4909. (value 0xFF = 255).
  4910. </li>
  4911. <br><br><b>Class BATTERY</b>
  4912. <li>battery<br>
  4913. return the charge of the battery in %, as battery:value % or battery:low
  4914. </li>
  4915. <br><br><b>Class CLIMATE_CONTROL_SCHEDULE</b>
  4916. <li>ccsOverride<br>
  4917. request the climate control schedule override report
  4918. </li>
  4919. <li>ccs [mon|tue|wed|thu|fri|sat|sun]<br>
  4920. request the climate control schedule for the given day.
  4921. </li>
  4922. <li>ccsAll<br>
  4923. request the climate control schedule for all days. (runs in background)
  4924. </li>
  4925. <br><br><b>Class CLOCK</b>
  4926. <li>clock<br>
  4927. request the clock data
  4928. </li>
  4929. <br><br><b>Class COLOR_CONTROL</b>
  4930. <li>ccCapability<br>
  4931. return capabilities.</li>
  4932. <li>ccStatus channelId<br>
  4933. return status of channel ChannelId.
  4934. </li>
  4935. <br><br><b>Class CONFIGURATION</b>
  4936. <li>config cfgAddress<br>
  4937. return the value of the configuration parameter cfgAddress. The value is
  4938. device specific.<br>
  4939. Note: if the model is set (see MANUFACTURER_SPECIFIC get), then more
  4940. specific config commands are available.
  4941. </li>
  4942. <li>configAll<br>
  4943. If the model of a device is set, and configuration descriptions are
  4944. available from the database for this device, then request the value of all
  4945. known configuration parameters.</li>
  4946. <br><br><b>Class DOOR_LOCK, V2</b>
  4947. <li>doorLockConfiguration<br>
  4948. Request the configuration report from the door lock.
  4949. </li>
  4950. <li>doorLockOperation<br>
  4951. Request the operconfiguration report from the door lock.
  4952. </li>
  4953. <br><br><b>Class HRV_STATUS</b>
  4954. <li>hrvStatus<br>
  4955. report the current status (temperature, etc)
  4956. </li>
  4957. <li>hrvStatusSupported<br>
  4958. report the supported status fields as a bitfield.
  4959. </li>
  4960. <br><br><b>Class INDICATOR</b>
  4961. <li>indicatorStatus<br>
  4962. return the indicator status of the node, as indState:on, indState:off or
  4963. indState:dim value.
  4964. </li>
  4965. <br><br><b>Class MANUFACTURER_PROPRIETARY</b>
  4966. <li>position<br>
  4967. Fibaro FGRM-222 only: return the blinds position and slat angle.
  4968. </li>
  4969. <br><br><b>Class MANUFACTURER_SPECIFIC</b>
  4970. <li>model<br>
  4971. return the manufacturer specific id (16bit),
  4972. the product type (16bit)
  4973. and the product specific id (16bit).<br>
  4974. Note: if the openzwave xml files are installed, then return the name of the
  4975. manufacturer and of the product. This call is also necessary to decode more
  4976. model specific configuration commands and parameters.
  4977. </li>
  4978. <br><br><b>Class METER</b>
  4979. <li>meter scale<br>
  4980. return the meter report for the requested scale.<br>
  4981. Note: protocol V1 does not support the scale parameter, the parameter
  4982. will be ignored and the default scale will be returned.<br>
  4983. For protocol V2 and higher, scale is supported and depends on the
  4984. type of the meter (energy, gas or water).<br>
  4985. The device may not support all scales, see the meterSupported
  4986. command and its output. If the scale parameter is omitted, the
  4987. default unit will be reported.<br>
  4988. Example: For an electric meter, meter 0 will report energy in kWh,
  4989. meter 2 will report power in W and meter 6 will report current in A
  4990. (if these scales are supported).<br>
  4991. </li>
  4992. <li>meterSupported<br>
  4993. request the type of the meter, the supported scales and the
  4994. capability to reset the accumulated value.<br>
  4995. Note: The output contains the decimal numbers of the supported
  4996. scales that can be used as parameter for the meter command.
  4997. </li>
  4998. <br><br><b>Class MULTI_CHANNEL</b>
  4999. <li>mcEndpoints<br>
  5000. return the list of endpoints available, e.g.:<br>
  5001. mcEndpoints: total 2, identical
  5002. </li>
  5003. <li>mcCapability chid<br>
  5004. return the classes supported by the endpoint/channel chid. If the channel
  5005. does not exists, create a FHEM node for it. Example:<br>
  5006. mcCapability_02:SWITCH_BINARY<br>
  5007. <b>Note:</b> This is the best way to create the secondary nodes of a
  5008. MULTI_CHANNEL device. The device is only created for channel 2 or greater.
  5009. </li>
  5010. <br><br><b>Class MULTI_CHANNEL_ASSOCIATION</b>
  5011. <li>mca groupid<br>
  5012. return the associations for the groupid. for the syntax of the returned
  5013. data see the mcaAdd command above.</li>
  5014. <li>mcaAll<br>
  5015. request association info for all possible groupids.
  5016. </li>
  5017. <br><br><b>Class NETWORK_SCHEDULE (SCHEDULE), V1</b>
  5018. <li>scheduleSupported<br>
  5019. Request the supported features, e.g. number of supported schedules.
  5020. Due to the lack of documentation, details for some fields in the
  5021. report are not available.</li>
  5022. <li>schedule ID<br>
  5023. Request the details for the schedule with the id ID. Due to the
  5024. lack of documentation, details for some fields in the report are
  5025. not available.</li>
  5026. <li>scheduleState<br>
  5027. Request the details for the schedule state. Due to the lack of
  5028. documentation, details for some fields in the report are not
  5029. available.</li>
  5030. <br><br><b>Class NODE_NAMING</b>
  5031. <li>name<br>
  5032. Get the name from the EEPROM. Note: only ASCII is supported.</li>
  5033. <li>location<br>
  5034. Get the location from the EEPROM. Note: only ASCII is supported.</li>
  5035. <br><br><b>Class POWERLEVEL</b>
  5036. <li>powerlevel<br>
  5037. Get the current powerlevel and remaining time in this level.</li>
  5038. <li>powerlevelTest<br>
  5039. Get the result of last powerlevelTest.</li>
  5040. <br><br><b>Class PROTECTION</b>
  5041. <li>protection<br>
  5042. returns the protection state. It can be on, off or seq.</li>
  5043. <br><br><b>Class SCENE_ACTUATOR_CONF</b>
  5044. <li>sceneConfig<br>
  5045. returns the settings for a given scene. Parameter is sceneId
  5046. </li>
  5047. <br><br><b>Class SCENE_CONTROLLER_CONF</b>
  5048. <li>groupConfig<br>
  5049. returns the settings for a given group. Parameter is groupId
  5050. </li>
  5051. <br><br><b>Class SCHEDULE_ENTRY_LOCK, V1, V2, V3</b>
  5052. <li>scheduleEntryLockTypeSupported<br>
  5053. returns the number of available slots for week day and year day
  5054. schedules (V1), in V3 the number of available slots for the daily
  5055. repeating schedule is reported additionally
  5056. </li>
  5057. <li>scheduleEntryLockWeekDay USER_ID SCHEDULE_ID<br>
  5058. returns the specified week day schedule for the specified user
  5059. (day of week, start time, end time) (V1)<br>
  5060. <ul>
  5061. USER_ID: id of user, starting from 1 up to the number of supported
  5062. users, refer also to the USER_CODE class description.<br>
  5063. SCHEDULE_ID: schedule slot id (from 1 up to number of supported
  5064. schedule slots)<br>
  5065. </ul>
  5066. </li>
  5067. <li>scheduleEntryLockYearDay USER_ID SCHEDULE_ID<br>
  5068. returns the specified year day schedule for the specified user
  5069. (start date, start time, end date, end time) (V1)<br>
  5070. <ul>
  5071. USER_ID: id of user, starting from 1 up to the number of supported
  5072. users, refer also to the USER_CODE class description.<br>
  5073. SCHEDULE_ID: schedule slot id (from 1 up to number of supported
  5074. schedule slots)<br>
  5075. </ul>
  5076. </li>
  5077. <li>scheduleEntryLockDailyRepeating USER_ID SCHEDULE_ID<br>
  5078. returns the specified daily schedule for the specified user
  5079. (weekdays, start date, duration) (V3)<br>
  5080. <ul>
  5081. USER_ID: id of user, starting from 1 up to the number of supported
  5082. users, refer also to the USER_CODE class description.<br>
  5083. SCHEDULE_ID: schedule slot id (from 1 up to number of supported
  5084. schedule slots)<br>
  5085. </ul>
  5086. </li>
  5087. <li>scheduleEntryLockTimeOffset<br>
  5088. returns the time zone offset TZO and the daylight saving time
  5089. offset (V2)
  5090. </li>
  5091. <br><br><b>Class SECURITY</b>
  5092. <li>secSupportedReport<br>
  5093. (internaly used to) request the command classes that are supported
  5094. with SECURITY
  5095. </li>
  5096. <li>Notes:<br>
  5097. This class needs the installation of the perl module Crypt::Rijndael and
  5098. a defined networkkey in the attributes of the ZWDongle device<br>
  5099. Currently a secure inclusion can only be started from the command input
  5100. with "set &lt;ZWDongle_device_name&gt; addNode [onSec|onNwSec]"<br>
  5101. These commands are only described here for completeness of the
  5102. documentation, but are not intended for manual usage. These commands
  5103. will be removed from the interface in future version.</li>
  5104. <br><br><b>Class SENSOR_ALARM</b>
  5105. <li>alarm alarmType<br>
  5106. return the nodes alarm status of the requested alarmType. 00 = GENERIC,
  5107. 01 = SMOKE, 02 = CO, 03 = CO2, 04 = HEAT, 05 = WATER, 255 = returns the
  5108. nodes first supported alarm type.
  5109. </li>
  5110. <br><br><b>Class SENSOR_BINARY</b>
  5111. <li>sbStatus<br>
  5112. return the status of the node.
  5113. </li>
  5114. <br><br><b>Class SENSOR_MULTILEVEL</b>
  5115. <li>smStatus<br>
  5116. request data from the node (temperature/humidity/etc)
  5117. </li>
  5118. <br><br><b>Class SWITCH_ALL</b>
  5119. <li>swaInclude<br>
  5120. return the switch-all mode of the node.
  5121. </li>
  5122. <br><br><b>Class SWITCH_BINARY</b>
  5123. <li>swbStatus<br>
  5124. return the status of the node, as state:on or state:off.
  5125. </li>
  5126. <br><br><b>Class SWITCH_MULTILEVEL</b>
  5127. <li>swmStatus<br>
  5128. return the status of the node, as state:on, state:off or state:dim value.
  5129. </li>
  5130. <br><br><b>Class THERMOSTAT_MODE</b>
  5131. <li>thermostatMode<br>
  5132. request the mode
  5133. </li>
  5134. <br><br><b>Class THERMOSTAT_SETPOINT</b>
  5135. <li>setpoint [TYPE]<br>
  5136. request the setpoint<br>
  5137. TYPE: (optional) setpoint type; [1, 15], defaults to 1=heating<br>
  5138. <ul>
  5139. 1=heating,
  5140. 2=cooling,
  5141. 7=furnance,
  5142. 8=dryAir,
  5143. 9=moistAir,
  5144. 10=autoChangeover,
  5145. 11=energySaveHeating,
  5146. 12=energySaveCooling,
  5147. 13=awayHeating,
  5148. 14=awayCooling,
  5149. 15=fullPower
  5150. </ul>
  5151. </li>
  5152. <li>thermostatSetpointSupported<br>
  5153. requests the list of supported setpoint types
  5154. </li>
  5155. <br><br><b>Class TIME, V2</b>
  5156. <li>time<br>
  5157. Request the (local) time from the internal clock of the device.
  5158. </li>
  5159. <li>date<br>
  5160. Request the (local) date from the internal clock of the device.
  5161. </li>
  5162. <li>timeOffset<br>
  5163. Request the report for the time offset and DST settings from the
  5164. internal clock of the device.
  5165. </li>
  5166. <br><br><b>Class TIME_PARAMETERS, V1</b>
  5167. <li>time<br>
  5168. Request the date and time (UTC) from the internal clock of the device.
  5169. </li>
  5170. <br><br><b>Class USER_CODE</b>
  5171. <li>userCode n</br>
  5172. request status and code for the id n
  5173. </li>
  5174. <br><br><b>Class VERSION</b>
  5175. <li>version<br>
  5176. return the version information of this node in the form:<br>
  5177. Lib A Prot x.y App a.b
  5178. </li>
  5179. <li>versionClass classId or className<br>
  5180. return the supported command version for the requested class
  5181. </li>
  5182. <li>versionClassAll<br>
  5183. executes "get devicename versionClass class" for each class from the
  5184. classes attribute in the background without generating events, and sets the
  5185. vclasses attribute at the end.
  5186. </li>
  5187. <br><br><b>Class WAKE_UP</b>
  5188. <li>wakeupInterval<br>
  5189. return the wakeup interval in seconds, in the form<br>
  5190. wakeupReport:interval seconds target id
  5191. </li>
  5192. <li>wakeupIntervalCapabilities (V2 only)<br>
  5193. return the wake up interval capabilities in seconds, in the form<br>
  5194. wakeupIntervalCapabilitiesReport:min seconds max seconds default seconds
  5195. step seconds
  5196. </li>
  5197. <br><br><b>Class ZWAVEPLUS_INFO</b>
  5198. <li>zwavePlusInfo<br>
  5199. request the zwavePlusInfo
  5200. </li>
  5201. </ul>
  5202. <br>
  5203. <a name="ZWaveattr"></a>
  5204. <b>Attributes</b>
  5205. <ul>
  5206. <li><a href="#IODev">IODev</a></li>
  5207. <li><a name="WNMI_delay">WNMI_delay</a><br>
  5208. This attribute set the time delay between the last message sent to an
  5209. WakeUp device and the sending of the WNMI Message
  5210. (WakeUpNoMoreInformation) that will set the device to sleep mode. Value
  5211. is in seconds, subseconds my be specified. Values outside of 0.2-5.0 are
  5212. probably harmful.
  5213. </li>
  5214. <li><a name="classes">classes</a><br>
  5215. This attribute is needed by the ZWave module, as the list of the possible
  5216. set/get commands depends on it. It contains a space separated list of
  5217. class names (capital letters).
  5218. </li>
  5219. <li><a href="#do_not_notify">do_not_notify</a></li>
  5220. <li><a href="#dummy">dummy</a></li>
  5221. <li><a name="eventForRaw">eventForRaw</a><br>
  5222. Generate an an additional event for the RAW message. Can be used if
  5223. someone fears that critical notifies wont work, if FHEM changes the event
  5224. text after an update. </li>
  5225. <li><a name="extendedAlarmReadings">extendedAlarmReadings</a><br>
  5226. Some devices support more than one alarm type, this attribute
  5227. selects which type of reading is used for the reports of the ALARM
  5228. (or NOTIFICATION) class:<br>
  5229. A value of "0" selects a combined, single reading ("alarm") for
  5230. all alarm types of the device. Subsequent reports of different
  5231. alarm types will overwrite each other. This is the default setting
  5232. and the former behavior.<br>
  5233. A value of "1" selects separate alarm readings for each alarm type
  5234. of the device. The readings are named "alarm_&lt;alarmtype&gt;.
  5235. This can also be selected if only one alarmtype is supported by
  5236. the device. This reading also contains the status of the
  5237. alarm notification. For compatibility reasons this is currently
  5238. not supported with the combined reading.<br>
  5239. A value of "2" selects both of the above and creates the combined and
  5240. the seperate readings at the same time, this should only be used
  5241. if really needed as duplicate events are generated.
  5242. </li>
  5243. <li><a href="#ignore">ignore</a></li>
  5244. <li><a name="ignoreDupMsg">ignoreDupMsg</a><br>
  5245. Experimental: if set (to 1), ignore duplicate wakeup messages, or
  5246. multiple responses to a single get due to missing lowlevel ACK.
  5247. </li>
  5248. <li><a href="#neighborListPos">neighborListPos</a></li>
  5249. <li><a name="noExplorerFrames">noExplorerFrames</a><br>
  5250. turn off the use of Explorer Frames
  5251. </li>
  5252. <li><a name="noWakeupForApplicationUpdate">noWakeupForApplicationUpdate</a>
  5253. <br>
  5254. some devices (notable the Aeotec Multisensor 6) are only awake after an
  5255. APPLICATION UPDATE telegram for a very short time. If this attribute is
  5256. set (recommended for the Aeotec Multisensor 6), the WakeUp-Stack is not
  5257. processed after receiving such a message.
  5258. </li>
  5259. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  5260. <li><a name="secure_classes">secure_classes</a><br>
  5261. This attribute is the result of the "set DEVICE secSupportedReport"
  5262. command. It contains a space seperated list of the the command classes
  5263. that are supported with SECURITY.
  5264. </li>
  5265. <li><a href="#showtime">showtime</a></li>
  5266. <li><a name="vclasses">vclasses</a><br>
  5267. This is the result of the "get DEVICE versionClassAll" command, and
  5268. contains the version information for each of the supported classes.
  5269. </li>
  5270. <li><a name="useMultiCmd">useMultiCmd</a><br>
  5271. Experimental: if a device supports MULTI_CMD and WAKE_UP, then pack
  5272. multiple get messages on the SendStack into a single MULTI_CMD to save
  5273. radio transmissions.
  5274. </li>
  5275. <li><a name="zwaveRoute">zwaveRoute</a><br>
  5276. space separated list of (ZWave) device names. They will be used in the
  5277. given order to route messages from the controller to this device. Specify
  5278. them in the order from the controller to the device. Do not specify the
  5279. controller and the device itself, only the routers inbetween. Used only
  5280. if the IODev is a ZWCUL device. </li>
  5281. </ul>
  5282. <br>
  5283. <a name="ZWaveevents"></a>
  5284. <b>Generated events:</b>
  5285. <ul>
  5286. <br><b>neighborUpdate</b>
  5287. <li>ZW_REQUEST_NODE_NEIGHBOR_UPDATE [started|done|failed]</li>
  5288. <br><b>returnRouteAdd</b>
  5289. <li>ZW_ASSIGN_RETURN_ROUTE [started|alreadyActive|transmitOk|
  5290. transmitNoAck|transmitFail|transmitNotIdle|
  5291. transmitNoRoute]</li>
  5292. <br><b>returnRouteDel</b>
  5293. <li>ZW_DELETE_RETURN_ROUTE [started|alreadyActive|transmitOk|
  5294. transmitNoAck|transmitFail|transmitNotIdle|
  5295. transmitNoRoute]</li>
  5296. <br><b>sucRouteAdd</b>
  5297. <li>ZW_ASSIGN_SUC_RETURN_ROUTE [started|alreadyActive|transmitOk|
  5298. transmitNoAck|transmitFail|transmitNotIdle|
  5299. transmitNoRoute]</li>
  5300. <br><b>sucRouteDel</b>
  5301. <li>ZW_DELETE_SUC_RETURN_ROUTE [started|alreadyActive|transmitOk|
  5302. transmitNoAck|transmitFail|transmitNotIdle|
  5303. transmitNoRoute]</li>
  5304. <br><b>Class ALARM</b>
  5305. <li>Note:<br>
  5306. Depending on the setting of the attribute "extendedAlarmReadings"
  5307. the generated events differ slightly. With a value of "0" or "2" a
  5308. combined reading for all alarm types of the device with the name
  5309. "alarm" will be used. With a value of "1" or "2" separate readings
  5310. for each supported alarm type will be generated with names
  5311. "alarm_&lt;alarmType&gt;.</li>
  5312. <li>Devices with class version 1 support: alarm_type_X:level Y</li>
  5313. <li>For higher class versions more detailed events with 100+ different
  5314. strings in the form alarm:&lt;string&gt;
  5315. (or alarm_&lt;alarmType&gt;:&lt;string&gt;) are generated.<br>
  5316. For the combined reading, the name of the alarm type is part of
  5317. the reading event, for separate readings it is part of the
  5318. reading name.<br>
  5319. If a cleared event can be identified, the string "Event cleared:"
  5320. is reported before the event details.<br>
  5321. The seperate readings also contain the status of the
  5322. alarm / notification. For compatibility reasons this is currently
  5323. not supported with the combined reading. </li>
  5324. <br><b>Class APPLICATION_STATUS</b>
  5325. <li>applicationStatus: [cmdRejected]</li>
  5326. <li>applicationBusy: [tryAgainLater|tryAgainInWaitTimeSeconds|
  5327. RequestQueued|unknownStatusCode] $waitTime</li>
  5328. <br><br><b>Class ASSOCIATION</b>
  5329. <li>assocGroup_X:Max Y Nodes A,B,...</li>
  5330. <li>assocGroups:X</li>
  5331. <br><br><b>Class ASSOCIATION_GRP_INFO</b>
  5332. <li>assocGroupName_X:name</li>
  5333. <li>assocGroupCmdList_X:AABBCCDD...</li>
  5334. <br><br><b>Class BASIC</b>
  5335. <li>basicReport:X (for version 1), basicReport:X target y duration z
  5336. (for version 2 or greater)</li>
  5337. <li>basicGet:request</li>
  5338. <li>basicSet:X</li>
  5339. <br><br><b>Class BASIC_WINDOW_COVERING</b>
  5340. <li>covering:[open|close|stop]</li>
  5341. <br><br><b>Class BATTERY</b>
  5342. <li>battery:chargelevel %</li>
  5343. <br><br><b>Class CENTRAL_SCENE</b>
  5344. <li>cSceneSet:X</li>
  5345. <li>cSceneDim:X</li>
  5346. <li>cSceneDimEnd:X</li>
  5347. <li>cSceneDouble:X</li>
  5348. <li>cSceneMultiple_N:X<br>where N is 3, 4 or 5 (multiple presses)</li>
  5349. <br><br><b>Class CLIMATE_CONTROL_SCHEDULE</b>
  5350. <li>ccsOverride:[no|temporary|permanent],
  5351. [frost protection|energy saving|unused]</li>
  5352. <li>ccsChanged:&lt;number&gt;</li>
  5353. <li>ccs_[mon|tue|wed|thu|fri|sat|sun]:HH:MM temp HH:MM temp...</li>
  5354. <br><br><b>Class CLOCK</b>
  5355. <li>clock:get</li>
  5356. <li>clock:[mon|tue|wed|thu|fri|sat|sun] HH:MM</li>
  5357. <br><br><b>Class COLOR_CONTROL</b>
  5358. <li>ccCapability:XY</li>
  5359. <li>ccStatus_X:Y</li>
  5360. <br><br><b>Class CONFIGURATION</b>
  5361. <li>config_X:Y<br>
  5362. Note: if the model is set (see MANUFACTURER_SPECIFIC get), then more
  5363. specific config messages are available.</li>
  5364. <br><br><b>Class DEVICE_RESET_LOCALLY</b>
  5365. <li>deviceResetLocally:yes<br></li>
  5366. <br><br><b>Class DOOR_LOCK, V2</b>
  5367. <li>doorLockConfiguration: mode: [constant|timed] outsideHandles:
  5368. $outside_mode(4 bit field) insideHandles: $inside_mode(4 bit field)
  5369. timeoutSeconds: [not_supported|$seconds]</li>
  5370. <li>doorLockOperation: mode: $mode outsideHandles:
  5371. $outside_mode(4 bit field) insideHandles: $inside_mode(4 bit field)
  5372. door: [open|closed] bolt: [locked|unlocked] latch: [open|closed]
  5373. timeoutSeconds: [not_supported|$time]<br>
  5374. $mode = [unsecured|unsecured_withTimeout|unsecured_inside|
  5375. unsecured_inside_withTimeout|unsecured_outside|
  5376. unsecured_outside_withTimeout|secured</li>
  5377. <br><br><b>Class HAIL</b>
  5378. <li>hail:01<br></li>
  5379. <br><br><b>Class HRV_STATUS</b>
  5380. <li>outdoorTemperature: %0.1f C</li>
  5381. <li>supplyAirTemperature: %0.1f C</li>
  5382. <li>exhaustAirTemperature: %0.1f C</li>
  5383. <li>dischargeAirTemperature: %0.1f C</li>
  5384. <li>indoorTemperature: %0.1f C</li>
  5385. <li>indoorHumidity: %s %</li>
  5386. <li>remainingFilterLife: %s %</li>
  5387. <li>supportedStatus: &lt;list of supported stati&gt;</li>
  5388. <br><br><b>Class INDICATOR</b>
  5389. <li>indState:[on|off|dim value]</li>
  5390. <br><br><b>Class MANUFACTURER_PROPRIETARY</b>
  5391. <li>Fibaro FGRM-222 with ReportsType Fibar CC only:</li>
  5392. <li>position:Blind [%] Slat [%]<br>
  5393. (VenetianBlindMode)</li>
  5394. <li>position:[%]<br>
  5395. (RollerBlindMode)</li>
  5396. <br><br><b>Class MANUFACTURER_SPECIFIC</b>
  5397. <li>modelId:hexValue hexValue hexValue</li>
  5398. <li>model:manufacturerName productName</li>
  5399. <li>modelConfig:configLocation</li>
  5400. <br><br><b>Class METER</b>
  5401. <li>energy:val [kWh|kVAh|pulseCount|powerFactor]</li>
  5402. <li>gas:val [m3|feet3|pulseCount]</li>
  5403. <li>water:val [m3|feet3|USgallons|pulseCount]</li>
  5404. <li>power:val W</li>
  5405. <li>voltage:val V</li>
  5406. <li>current:val A</li>
  5407. <li>meterSupported:type:[meter_type] scales:[list of supported scales]
  5408. resetable:[yes|no]</li>
  5409. <br><br><b>Class MULTI_CHANNEL</b>
  5410. <li>endpoints:total X $dynamic $identical</li>
  5411. <li>mcCapability_X:class1 class2 ...</li>
  5412. <br><br><b>Class NETWORK_SCHEDULE (SCHEDULE), V1</b>
  5413. <li>schedule_&lt;id&gt;: ID: $schedule_id userID: $user_id sYear:
  5414. $starting_year sMonth: $starting_month activeID: $active_id
  5415. sDay: $starting_day sWeekDay: $starting_weekday sHour:
  5416. $starting_hour durationType: $duration_type sMinute:
  5417. $starting_minute duration: $duration numReportsToFollow:
  5418. $number_of_reports_to_follow numCmds: $number_of_commands
  5419. cmdLen: $length_of_command cmd: $commandsequence(hex)</li>
  5420. <li>scheduleSupported: num: $number_of_supported_schedules
  5421. startTimeSupport: $start_time_support(6 bit field) fallbackSupport:
  5422. $fallback_support enableDisableSupport: $ena_dis_support
  5423. numCCs: $number_of_supported_command_classes
  5424. overrideTypes: $override_types(7 bit field) overrideSupport:
  5425. $override_support</li>
  5426. <li>scheduleSupportedCC: CC_&lt;x&gt;: $number_of_command_class
  5427. CCname_&lt;x&gt;: $name_of_command_class]CCmask_&lt;x&gt;:
  5428. $mask_for_command(2 bit)</li>
  5429. <br><br><b>Class NODE_NAMING</b>
  5430. <li>name:NAME</li>
  5431. <li>location:LOCATION</li>
  5432. <br><br><b>Class POWERLEVEL</b>
  5433. <li>powerlvl:current x remain y<br>
  5434. NOTE: "current 0 remain 0" means normal mode without timeout</li>
  5435. <li>powerlvlTest:node x status y frameAck z<br>
  5436. NOTE: status 0=failed, 1=success (at least one ACK), 2=in progress</li>
  5437. <br><br><b>Class PROTECTION</b>
  5438. <li>protection:[on|off|seq]</li>
  5439. <br><br><b>Class SCENE_ACTIVATION</b>
  5440. <li>scene_Id:level finalValue</li>
  5441. <br><br><b>Class SCENE_ACTUATOR_CONF</b>
  5442. <li>scene_Id:level dimmingDuration finalValue</li>
  5443. <br><br><b>Class SCENE_CONTROLLER_CONF</b>
  5444. <li>group_Id:scene dimmingDuration</li>
  5445. <br><br><b>Class SCHEDULE_ENTRY_LOCK</b>
  5446. <li>scheduleEntryLockEntryTypeSupported:WeekDaySlots: $value
  5447. YearDaySlots: $value</li>
  5448. <li>weekDaySchedule_$userId:userID: $value slotID: $value $weekday
  5449. $starthour:$startminute $endhour:$endminute</li>
  5450. <li>yearDaySchedule_$userId:userID: $value slotID: $value
  5451. start: $year-$month-$day $hour:$minute
  5452. end: $year-$month-$day $hour:$minute</li>
  5453. <li>scheduleEntryLockDailyRepeating_$userId:userID: $value $weekdays
  5454. $hour:$minute $durationhour:$durationminute<br>
  5455. Note: $weekdays is a concatenated string with weekdaynames
  5456. ("sun","mon","tue","wed","thu","fri","sat") where inactive
  5457. weekdays are represented by "...", e.g. montue...wedfri</li>
  5458. <li>scheduleEntryLockTimeOffset:TZO: $sign$hour:$minute DST:
  5459. $sign$minutes</li>
  5460. <br><br><b>Class SECURITY</b>
  5461. <li>none<br>
  5462. Note: the class security should work transparent to the sytem and is not
  5463. intended to generate events</li>
  5464. <br><br><b>Class SENSOR_ALARM</b>
  5465. <li>alarm_type_X:level Y node $nodeID seconds $seconds</li>
  5466. <br><br><b>Class SENSOR_BINARY</b>
  5467. <li>SENSORY_BINARY V1:</li>
  5468. <li>state:open</li>
  5469. <li>state:closed</li>
  5470. <li>SENSORY_BINARY V2:</li>
  5471. <li>unknown:[off|on]</li>
  5472. <li>generalPurpose:[off|on]</li>
  5473. <li>smoke:[off|on]</li>
  5474. <li>CO:[off|on]</li>
  5475. <li>CO2:[off|on]</li>
  5476. <li>heat:[off|on]</li>
  5477. <li>water:[off|on]</li>
  5478. <li>freeze:[off|on]</li>
  5479. <li>tamper:[off|on]</li>
  5480. <li>aux:[off|on]</li>
  5481. <li>doorWindow:[off|on]</li>
  5482. <li>tilt:[off|on]</li>
  5483. <li>motion:[off|on]</li>
  5484. <li>glassBreak:[off|on]</li>
  5485. <br><br><b>Class SENSOR_MULTILEVEL</b>
  5486. <li>temperature $val [C|F]</li>
  5487. <li>generalPurpose $val %</li>
  5488. <li>luminance $val [%|Lux]</li>
  5489. <li>power $val [W|Btu/h]</li>
  5490. <li>humidity $val %</li>
  5491. <li>velocity $val [m/s|mph]</li>
  5492. <li>direction $val</li>
  5493. <li>atmosphericPressure $val [kPa|inchHg]</li>
  5494. <li>barometricPressure $val [kPa|inchHg]</li>
  5495. <li>solarRadiation $val W/m2</li>
  5496. <li>dewpoint $val [C|F]</li>
  5497. <li>rain $val [mm/h|in/h]</li>
  5498. <li>tideLevel $val [m|feet]</li>
  5499. <li>weight $val [kg|pound]</li>
  5500. <li>voltage $val [V|mV]</li>
  5501. <li>current $val [A|mA]</li>
  5502. <li>CO2-level $val ppm</li>
  5503. <li>airFlow $val [m3/h|cfm]</li>
  5504. <li>tankCapacity $val [l|cbm|usgal]</li>
  5505. <li>distance $val [m|cm|feet]</li>
  5506. <li>anglePosition $val [%|relN|relS]</li>
  5507. <li>rotation $val [rpm|Hz]</li>
  5508. <li>waterTemperature $val [C|F]</li>
  5509. <li>soilTemperature $val [C|F]</li>
  5510. <li>seismicIntensity $val [mercalli|EU macroseismic|liedu|shindo]</li>
  5511. <li>seismicMagnitude $val [local|moment|surface wave|body wave]</li>
  5512. <li>ultraviolet $val [UV]</li>
  5513. <li>electricalResistivity $val [ohm]</li>
  5514. <li>electricalConductivity $val [siemens/m]</li>
  5515. <li>loudness $val [dB|dBA]</li>
  5516. <li>moisture $val [%|content|k ohms|water activity]</li>
  5517. <li>frequency $val [Hz|kHz]</li>
  5518. <li>time $val [seconds]</li>
  5519. <li>targetTemperature $val [C|F]</li>
  5520. <li>particulateMatter $val [mol/m3|micro-g/m3]</li>
  5521. <li>formaldehydeLevel $val [mol/m3]</li>
  5522. <li>radonConcentration $val [bq/m3|pCi/L]</li>
  5523. <li>methaneDensity $val [mol/m3]</li>
  5524. <li>volatileOrganicCompound $val [mol/m3]</li>
  5525. <li>carbonMonoxide $val [mol/m3]</li>
  5526. <li>soilHumidity $val [%]</li>
  5527. <li>soilReactivity $val [pH]</li>
  5528. <li>soilSalinity $val [mol/m3]</li>
  5529. <li>heartRate $val [Bpm]</li>
  5530. <li>bloodPressure $val [Systolic mmHg|Diastolic mmHg]</li>
  5531. <li>muscleMass $val [Kg]</li>
  5532. <li>fatMass $val [Kg]</li>
  5533. <li>boneMass $val [Kg]</li>
  5534. <li>totalBodyWater $val [Kg]</li>
  5535. <li>basicMetabolicRate $val [J]</li>
  5536. <li>bodyMassIndex $val [BMI]</li>
  5537. <br><br><b>Class SWITCH_ALL</b>
  5538. <li>swa:[none|on|off|on off]</li>
  5539. <br><br><b>Class SWITCH_BINARY</b>
  5540. <li>state:on</li>
  5541. <li>state:off</li>
  5542. <li>state:setOn</li>
  5543. <li>state:setOff</li>
  5544. <br><br><b>Class SWITCH_MULTILEVEL</b>
  5545. <li>state:on</li>
  5546. <li>state:off</li>
  5547. <li>state:setOn</li>
  5548. <li>state:setOff</li>
  5549. <li>state:dim value</li>
  5550. <li>state:swmBeginUp</li>
  5551. <li>state:swmBeginDown</li>
  5552. <li>state:swm [Decrement|Increment] [Up|Down]
  5553. Start: $sl Duration: $dur Step: $step</li>
  5554. <li>state:swmEnd</li>
  5555. <br><br><b>Class THERMOSTAT_MODE</b>
  5556. <li>off</li>
  5557. <li>cooling</li>
  5558. <li>heating</li>
  5559. <li>manual</li>
  5560. <li>setTmOff</li>
  5561. <li>setTmHeating</li>
  5562. <li>setTmCooling</li>
  5563. <li>setTmManual</li>
  5564. <br><br><b>Class THERMOSTAT_SETPOINT</b>
  5565. <li>setpointTemp:$temp $scale $type<br>
  5566. <ul>
  5567. $temp: setpoint temperature with number of decimals as reported
  5568. by the device<br>
  5569. $scale: [C|F]; C=Celsius scale, F=Fahrenheit scale<br>
  5570. $type: setpoint type, one of:<br>
  5571. <ul>
  5572. heating,
  5573. cooling,
  5574. furnance,
  5575. dryAir,
  5576. moistAir,
  5577. autoChangeover,
  5578. energySaveHeating,
  5579. energySaveCooling,
  5580. awayHeating,
  5581. awayCooling,
  5582. fullPower
  5583. </ul>
  5584. </ul>
  5585. </li>
  5586. <br><br><b>Class TIME, V2</b>
  5587. <li>time:$time RTC: [failed|working]</li>
  5588. <li>date:$date</li>
  5589. <li>timeOffset: UTC-Offset: $utco DST-Offset(minutes): $dsto DST-Start:
  5590. $start DST-End: $end</li>
  5591. <br><br><b>Class TIME_PARAMETERS, V1</b>
  5592. <li>timeParameters: date: $date time(UTC): $time</li>
  5593. <br><br><b>Class USER_CODE</b>
  5594. <li>userCode:id x status y code z</li>
  5595. <br><br><b>Class VERSION</b>
  5596. <li>V1:</li>
  5597. <li>version:Lib A Prot x.y App a.b</li>
  5598. <li>V2:</li>
  5599. <li>version:Lib A Prot x.y App a.b HW B FWCounter C FW c.d</li>
  5600. <li>V1 and V2:</li>
  5601. <li>versionClass_$classId:$version</li>
  5602. <br><br><b>Class WAKE_UP</b>
  5603. <li>wakeup:notification</li>
  5604. <li>wakeupReport:interval:X target:Y</li>
  5605. <li>wakeupIntervalCapabilitiesReport:min W max X default Y step Z</li>
  5606. <br><br><b>Class ZWAVEPLUS_INFO</b>
  5607. <li>zwavePlusInfo:version: V role: W node: X installerIcon: Y userIcon: Z</li>
  5608. </ul>
  5609. </ul>
  5610. =end html
  5611. =cut