10_ZWave.pm 221 KB

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