10_CUL_HM.pm 549 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284
  1. ##############################################
  2. ##############################################
  3. # CUL HomeMatic handler
  4. # $Id: 10_CUL_HM.pm 15457 2017-11-19 18:18:18Z martinp876 $
  5. package main;
  6. use strict;
  7. use warnings;
  8. use HMConfig;
  9. use Color;
  10. use Digest::MD5 qw(md5);
  11. eval "use Crypt::Rijndael";
  12. my $cryptFunc = ($@)?0:1;
  13. # ========================import constants=====================================
  14. my $culHmModel =\%HMConfig::culHmModel;
  15. my $culHmRegDefShLg =\%HMConfig::culHmRegDefShLg;
  16. my $culHmRegDefine =\%HMConfig::culHmRegDefine;
  17. my $culHmRegGeneral =\%HMConfig::culHmRegGeneral;
  18. my $culHmRegType =\%HMConfig::culHmRegType;
  19. my $culHmRegModel =\%HMConfig::culHmRegModel;
  20. my $culHmRegChan =\%HMConfig::culHmRegChan;
  21. my $culHmGlobalGets =\%HMConfig::culHmGlobalGets;
  22. my $culHmVrtGets =\%HMConfig::culHmVrtGets;
  23. my $culHmSubTypeGets =\%HMConfig::culHmSubTypeGets;
  24. my $culHmModelGets =\%HMConfig::culHmModelGets;
  25. my $culHmGlobalSetsDevice =\%HMConfig::culHmGlobalSetsDevice;
  26. my $culHmSubTypeDevSets =\%HMConfig::culHmSubTypeDevSets;
  27. my $culHmGlobalSetsChn =\%HMConfig::culHmGlobalSetsChn;
  28. my $culHmGlobalSets =\%HMConfig::culHmGlobalSets;
  29. my $culHmGlobalSetsVrtDev =\%HMConfig::culHmGlobalSetsVrtDev;
  30. my $culHmSubTypeSets =\%HMConfig::culHmSubTypeSets;
  31. my $culHmModelSets =\%HMConfig::culHmModelSets;
  32. my $culHmChanSets =\%HMConfig::culHmChanSets;
  33. my $culHmFunctSets =\%HMConfig::culHmFunctSets;
  34. my $culHmBits =\%HMConfig::culHmBits;
  35. my $culHmCmdFlags =\@HMConfig::culHmCmdFlags;
  36. my $K_actDetID ="000000";
  37. my %activeCmds = ( "valvePos" => 1,"up" => 1,"unlock" => 1,"toggleDir" => 1
  38. ,"toggle" => 1
  39. ,"tempListWed" => 1,"tempListTue" => 1,"tempListThu" => 1,"tempListSun" => 1
  40. ,"tempListSat" => 1,"tempListMon" => 1,"tempListFri" => 1
  41. ,"stop" => 1,"setRepeat" => 1
  42. ,"reset" => 1,"regSet" => 1,"regBulk" => 1
  43. ,"press" => 1,"postEvent" => 1,"playTone" => 1
  44. ,"peerIODev" => 1,"peerChan" => 1,"peerBulk" => 1
  45. ,"pctSlat" => 1,"pctLvlSlat" => 1,"pct" => 1,"pair" => 1
  46. ,"open" => 1,"on" => 1,"old" => 1,"off" => 1
  47. ,"lock" => 1,"level" => 1,"led" => 1
  48. ,"keydef" => 1,"fwUpdate" => 1,"down" => 1
  49. ,"controlParty" => 1,"controlManu" => 1
  50. ,"color" => 1,"colProgram" => 1,"brightCol" => 1,"brightAuto" => 1
  51. ,"on-till" => 1,"on-for-timer" => 1,"desired-temp" => 1
  52. );
  53. ############################################################
  54. sub CUL_HM_Initialize($);
  55. sub CUL_HM_reqStatus($);
  56. sub CUL_HM_autoReadConfig();
  57. sub CUL_HM_updateConfig($);
  58. sub CUL_HM_Define($$);
  59. sub CUL_HM_Undef($$);
  60. sub CUL_HM_Rename($$$);
  61. sub CUL_HM_Attr(@);
  62. sub CUL_HM_Parse($$);
  63. sub CUL_HM_parseCommon(@);
  64. sub CUL_HM_qAutoRead($$);
  65. sub CUL_HM_Get($@);
  66. sub CUL_HM_Set($@);
  67. sub CUL_HM_valvePosUpdt(@);
  68. sub CUL_HM_infoUpdtDevData($$$);
  69. sub CUL_HM_infoUpdtChanData(@);
  70. sub CUL_HM_getConfig($);
  71. sub CUL_HM_SndCmd($$);
  72. sub CUL_HM_responseSetup($$);
  73. sub CUL_HM_eventP($$);
  74. sub CUL_HM_protState($$);
  75. sub CUL_HM_respPendRm($);
  76. sub CUL_HM_respPendTout($);
  77. sub CUL_HM_respPendToutProlong($);
  78. sub CUL_HM_PushCmdStack($$);
  79. sub CUL_HM_ProcessCmdStack($);
  80. sub CUL_HM_pushConfig($$$$$$$$@);
  81. sub CUL_HM_ID2PeerList ($$$);
  82. sub CUL_HM_peerChId($$);
  83. sub CUL_HM_peerChName($$);
  84. sub CUL_HM_getMId($);
  85. sub CUL_HM_getRxType($);
  86. sub CUL_HM_getAssChnIds($);
  87. sub CUL_HM_h2IoId($);
  88. sub CUL_HM_IoId($);
  89. sub CUL_HM_hash2Id($);
  90. sub CUL_HM_hash2Name($);
  91. sub CUL_HM_name2Hash($);
  92. sub CUL_HM_name2Id(@);
  93. sub CUL_HM_id2Name($);
  94. sub CUL_HM_id2Hash($);
  95. sub CUL_HM_getDeviceHash($);
  96. sub CUL_HM_getDeviceName($);
  97. sub CUL_HM_DumpProtocol($$@);
  98. sub CUL_HM_getRegFromStore($$$$@);
  99. sub CUL_HM_updtRegDisp($$$);
  100. sub CUL_HM_encodeTime8($);
  101. sub CUL_HM_decodeTime8($);
  102. sub CUL_HM_encodeTime16($);
  103. sub CUL_HM_convTemp($);
  104. sub CUL_HM_decodeTime16($);
  105. sub CUL_HM_secSince2000();
  106. sub CUL_HM_getChnLvl($);
  107. sub CUL_HM_initRegHash();
  108. sub CUL_HM_fltCvT($);
  109. sub CUL_HM_CvTflt($);
  110. sub CUL_HM_getRegN($$@);
  111. sub CUL_HM_4DisText($);
  112. sub CUL_HM_TCtempReadings($);
  113. sub CUL_HM_repReadings($);
  114. sub CUL_HM_dimLog($);
  115. sub CUL_HM_ActGetCreateHash();
  116. sub CUL_HM_time2sec($);
  117. sub CUL_HM_ActAdd($$);
  118. sub CUL_HM_ActDel($);
  119. sub CUL_HM_ActCheck($);
  120. sub CUL_HM_UpdtReadBulk(@);
  121. sub CUL_HM_UpdtReadSingle(@);
  122. sub CUL_HM_setAttrIfCh($$$$);
  123. sub CUL_HM_noDup(@); #return list with no duplicates
  124. sub CUL_HM_noDupInString($);#return string with no duplicates, comma separated
  125. sub CUL_HM_storeRssi(@);
  126. sub CUL_HM_qStateUpdatIfEnab($@);
  127. sub CUL_HM_getAttrInt($@);
  128. sub CUL_HM_appFromQ($$);
  129. sub CUL_HM_autoReadReady($);
  130. sub CUL_HM_calcDisWm($$$);
  131. # ----------------modul globals-----------------------
  132. my $respRemoved; # used to control trigger of stack processing
  133. my $IOpoll = 0.2;# poll speed to scan IO device out of order
  134. my $maxPendCmds = 10; #number of parallel requests
  135. my @evtEt = (); #readings for entities. Format hash:trigger:reading:value
  136. my $evtDly = 0; # ugly switch to delay set readings if in parser - actually not our job, but fhem.pl refuses
  137. # need to take care that ACK is first
  138. #+++++++++++++++++ startup, init, definition+++++++++++++++++++++++++++++++++++
  139. sub CUL_HM_Initialize($) {
  140. my ($hash) = @_;
  141. $hash->{Match} = "^A....................";
  142. $hash->{DefFn} = "CUL_HM_Define";
  143. $hash->{UndefFn} = "CUL_HM_Undef";
  144. $hash->{ParseFn} = "CUL_HM_Parse";
  145. $hash->{SetFn} = "CUL_HM_Set";
  146. $hash->{GetFn} = "CUL_HM_Get";
  147. $hash->{RenameFn} = "CUL_HM_Rename";
  148. $hash->{AttrFn} = "CUL_HM_Attr";
  149. $hash->{NotifyFn} = "CUL_HM_Notify";
  150. $hash->{Attr}{dev} = "ignore:1,0 dummy:1,0 " # -- device only attributes
  151. ."IODev IOList IOgrp "
  152. ."rssiLog:1,0 " # enable writing RSSI to Readings (device only)
  153. ."actCycle " # also for action detector
  154. ."hmKey hmKey2 hmKey3 "
  155. ;
  156. $hash->{Attr}{devPhy} = # -- physical device only attributes
  157. "serialNr firmware .stc .devInfo "
  158. ."actStatus "
  159. ."autoReadReg:0_off,1_restart,2_pon-restart,3_onChange,4_reqStatus,5_readMissing,8_stateOnly "
  160. ."burstAccess:0_off,1_auto "
  161. ."msgRepeat "
  162. ."hmProtocolEvents:0_off,1_dump,2_dumpFull,3_dumpTrigger "
  163. ."aesKey:5,4,3,2,1,0 "
  164. ;
  165. $hash->{Attr}{chn} = "repPeers " # -- channel only attributes
  166. ."peerIDs "
  167. ."tempListTmpl "
  168. ."levelRange levelMap "
  169. ."cyclicMsgOffset "
  170. ;
  171. $hash->{Attr}{glb} = "do_not_notify:1,0 showtime:1,0 "
  172. ."rawToReadable unit "#"KFM-Sensor" only
  173. ."expert:0_defReg,1_allReg,2_defReg+raw,3_allReg+raw,4_off,8_templ+default,12_templOnly,251_anything "
  174. ."param "
  175. ."readOnly:0,1 "
  176. ."actAutoTry:0_off,1_on "
  177. ."aesCommReq:1,0 " # IO will request AES if
  178. ;
  179. $hash->{AttrList} = $hash->{Attr}{glb}
  180. .$hash->{Attr}{dev}
  181. .$hash->{Attr}{devPhy}
  182. .$hash->{Attr}{chn}
  183. .$readingFnAttributes
  184. ;
  185. CUL_HM_initRegHash();
  186. my @modellist;
  187. foreach my $model (keys %{$culHmModel}){
  188. push @modellist,$culHmModel->{$model}{name};
  189. }
  190. $hash->{AttrList} .= " model:" .join(",", sort @modellist);
  191. $hash->{AttrList} .= " subType:".join(",",
  192. CUL_HM_noDup(map { $culHmModel->{$_}{st} } keys %{$culHmModel}));
  193. $hash->{prot}{rspPend} = 0;#count Pending responses
  194. my @statQArr = ();
  195. my @statQWuArr = ();
  196. my @confQArr = ();
  197. my @confQWuArr = ();
  198. my @confCheckArr = ();
  199. my @confUpdt = ();
  200. $hash->{helper}{qReqStat} = \@statQArr;
  201. $hash->{helper}{qReqStatWu} = \@statQWuArr;
  202. $hash->{helper}{qReqConf} = \@confQArr;
  203. $hash->{helper}{qReqConfWu} = \@confQWuArr;
  204. $hash->{helper}{confCheckArr} = \@confCheckArr;
  205. $hash->{helper}{confUpdt} = \@confUpdt;
  206. $hash->{helper}{cfgCmpl}{init}= 1;# mark entities with complete config
  207. #statistics
  208. $hash->{stat}{s}{dummy}=0;
  209. $hash->{stat}{r}{dummy}=0;
  210. RemoveInternalTimer("StatCntRfresh");
  211. InternalTimer(gettimeofday()+3600*20,"CUL_HM_statCntRfresh","StatCntRfresh", 0);
  212. $hash->{hmIoMaxDly} = 60;# poll timeout - stop poll and discard
  213. $hash->{hmAutoReadScan} = 4; # delay autoConf readings
  214. $hash->{helper}{hmManualOper} = 0;# default automode
  215. }
  216. sub CUL_HM_updateConfig($){
  217. # this routine is called 5 sec after the last define of a restart
  218. # this gives FHEM sufficient time to fill in attributes
  219. # it will also be called after each manual definition
  220. # Purpose is to parse attributes and read config
  221. RemoveInternalTimer("updateConfig");
  222. if (!$init_done){
  223. InternalTimer(1,"CUL_HM_updateConfig", "updateConfig", 0);#start asap once FHEM is operational
  224. return;
  225. }
  226. foreach my $name (@{$modules{CUL_HM}{helper}{updtCfgLst}}){
  227. my $hash = $defs{$name};
  228. next if (!$hash->{DEF}); # likely renamed
  229. foreach my $read (grep/(RegL_0.:|_chn:\d\d)/,keys%{$hash->{READINGS}}){
  230. my $readN = $read;
  231. $readN =~ s/(RegL_0.):/$1\./;
  232. $readN =~ s/_chn:(\d\d)/_chn-$1/;
  233. $hash->{READINGS}{$readN} = $hash->{READINGS}{$read};
  234. delete $hash->{READINGS}{$read};
  235. }
  236. my $id = $hash->{DEF};
  237. my $nAttr = $modules{CUL_HM}{helper}{hmManualOper};# no update for attr
  238. if ($id eq $K_actDetID){# if action detector
  239. $attr{$name}{"event-on-change-reading"} =
  240. AttrVal($name, "event-on-change-reading", ".*")
  241. if(!$nAttr);
  242. $attr{$name}{model} = "ActionDetector";
  243. delete $hash->{helper}{role};
  244. delete $attr{$name}{$_}
  245. foreach ( "autoReadReg","actCycle","actStatus","burstAccess","serialNr"
  246. ,"IODev","IOList","IOgrp","hmProtocolEvents","rssiLog");
  247. #$hash->{helper}{role}{vrt} = 1;
  248. #$hash->{helper}{role}{dev} = 1;
  249. next;
  250. }
  251. CUL_HM_ID2PeerList($name,"",1); # update peerList out of peerIDs
  252. my $chn = substr($id."00",6,2);
  253. my $st = CUL_HM_Get($hash,$name,"param","subType");
  254. my $md = CUL_HM_Get($hash,$name,"param","model");
  255. my $dHash = CUL_HM_getDeviceHash($hash);
  256. $dHash->{helper}{role}{prs} = 1 if(CUL_HM_Set($hash,$name,"?") =~ m/press/ && $st ne "virtual");
  257. foreach my $rName ("D-firmware","D-serialNr",".D-devInfo",".D-stc"){
  258. # move certain attributes to readings for future handling
  259. my $aName = $rName;
  260. $aName =~ s/D-//;
  261. my $aVal = AttrVal($name,$aName,undef);
  262. CUL_HM_UpdtReadSingle($hash,$rName,$aVal,0)
  263. if (!defined ReadingsVal($name,$rName,undef));
  264. }
  265. if ($md =~ /(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/){
  266. $hash->{helper}{role}{chn} = 1 if (length($id) == 6); #tc special
  267. }
  268. elsif ($md =~ m/^HM-CC-RT-DN/){
  269. $hash->{helper}{shRegR}{"07"} = "00" if ($chn eq "04");# shadowReg List 7 read from CH 0
  270. $hash->{helper}{shRegW}{"07"} = "04" if ($chn eq "00");# shadowReg List 7 write to CH 4
  271. }
  272. elsif ($md =~ m/^HM-TC-IT-WM-W-EU/){
  273. $hash->{helper}{shRegR}{"07"} = "00" if ($chn eq "02");# shadowReg List 7 read from CH 0
  274. $hash->{helper}{shRegW}{"07"} = "02" if ($chn eq "00");# shadowReg List 7 write to CH 4
  275. }
  276. elsif ($md =~ m/^(HM-CC-VD|ROTO_ZEL-STG-RM-FSA)/){
  277. $hash->{helper}{oldDes} = "0";
  278. }
  279. elsif ($md =~ m/^(HM-Dis-WM55)/){
  280. foreach my $t ("s","l"){
  281. if(!defined $hash->{helper}{dispi}{$t}{"l1"}{d}){# setup if one is missing
  282. $hash->{helper}{dispi}{$t}{"l$_"}{d}=1 foreach (1,2,3,4,5,6);
  283. }
  284. }
  285. }
  286. elsif ($md =~ m/^(HM-Dis-EP-WM55)/){
  287. CUL_HM_UpdtReadSingle($hash,"state","-",0) if(InternalVal($name,"chanNo",0)>3);
  288. }
  289. elsif ($md =~ m/^(CCU-FHEM)/){
  290. $hash->{helper}{role}{vrt} = 1;
  291. if($hash->{helper}{role}{dev}){
  292. CUL_HM_UpdtCentral($name); # first update, then keys
  293. foreach my $io (split ",",AttrVal($name,"IOList","")) {
  294. next if(!$defs{$io});
  295. if($defs{$io}->{TYPE} eq "HMLAN" && eval "defined(&HMLAN_writeAesKey)"){
  296. HMLAN_writeAesKey($io);
  297. }
  298. elsif ($defs{$io}->{TYPE} eq "HMUARTLGW") {
  299. CallFn($io,"WriteFn",$defs{$io},undef,"writeAesKey:${io}");
  300. }
  301. elsif ($defs{$io}->{TYPE} =~ m/^(TSCUL|TSSTACKED)$/
  302. && eval "defined(&TSCUL_WriteAesKeyHM)"){
  303. TSCUL_WriteAesKeyHM($io); # noansi: for TSCUL
  304. }
  305. }
  306. }
  307. }
  308. elsif ($st =~ m/^(motionDetector|motionAndBtn)$/ ){
  309. CUL_HM_UpdtReadSingle($hash,"state","-",0);
  310. CUL_HM_UpdtReadSingle($hash,"motion","-",0);
  311. RemoveInternalTimer($name.":motionCheck");
  312. InternalTimer(gettimeofday()+30+2,"CUL_HM_motionCheck", $name.":motionCheck", 0);
  313. }
  314. elsif ($st eq "dimmer" ) {#setup virtual dimmer channels
  315. my $mId = CUL_HM_getMId($hash);
  316. #configure Dimmer virtual channel assotiation
  317. if ($hash->{helper}{role}{chn}){
  318. my $chn = (length($id) == 8)?substr($id,6,2):"01";
  319. my $devId = substr($id,0,6);
  320. if ($culHmModel->{$mId} && $culHmModel->{$mId}{chn} =~ m/Dim_V/){#virtual?
  321. my @chnPh = (grep{$_ =~ m/Sw:/ } split ',',$culHmModel->{$mId}{chn});
  322. @chnPh = split ':',$chnPh[0] if (@chnPh);
  323. my $chnPhyMax = $chnPh[2]?$chnPh[2]:1; # max Phys channels
  324. my $chnPhy = ($chnPhyMax == 2 && $chn > 4)?2:1; # assotiated phy chan( either 1 or 2)
  325. my $idPhy = $devId.sprintf("%02X",$chnPhy);# ID assot phy chan
  326. my $pHash = CUL_HM_id2Hash($idPhy); # hash assot phy chan
  327. $idPhy = $pHash->{DEF}; # could be device!!!
  328. if ($pHash){
  329. $pHash->{helper}{vDim}{idPhy} = $idPhy;
  330. my $vHash = CUL_HM_id2Hash($devId.sprintf("%02X",$chnPhyMax+2*$chnPhy-1));
  331. if ($vHash){
  332. $pHash->{helper}{vDim}{idV2} = $vHash->{DEF};
  333. $vHash->{helper}{vDim}{idPhy} = $idPhy;
  334. }
  335. else{
  336. delete $pHash->{helper}{vDim}{idV2};
  337. }
  338. $vHash = CUL_HM_id2Hash($devId.sprintf("%02X",$chnPhyMax+2*$chnPhy));
  339. if ($vHash){
  340. $pHash->{helper}{vDim}{idV3} = $vHash->{DEF};
  341. $vHash->{helper}{vDim}{idPhy} = $idPhy;
  342. }
  343. else{
  344. delete $pHash->{helper}{vDim}{idV3};
  345. }
  346. }
  347. }
  348. }
  349. }
  350. elsif ($st eq "virtual" ) {#setup virtuals
  351. $hash->{helper}{role}{vrt} = 1;
  352. if ( $hash->{helper}{fkt}
  353. && $hash->{helper}{fkt} =~ m/^(vdCtrl|virtThSens)$/){
  354. my $vId = substr($id."01",0,8);
  355. $hash->{helper}{virtTC} = "00";
  356. $hash->{helper}{vd}{msgRed}= 0 if(!defined $hash->{helper}{vd}{msgRed});
  357. if(!defined $hash->{helper}{vd}{next}){
  358. ($hash->{helper}{vd}{msgCnt},$hash->{helper}{vd}{next}) =
  359. split(";",ReadingsVal($name,".next","0;".gettimeofday()));
  360. $hash->{helper}{vd}{idl} = 0;
  361. $hash->{helper}{vd}{idh} = 0;
  362. }
  363. my $d =ReadingsVal($name,"valvePosTC","");
  364. $d =~ s/ %//;
  365. CUL_HM_Set($hash,$name,"valvePos",$d);
  366. CUL_HM_Set($hash,$name,"virtTemp",ReadingsVal($name,"temperature",""));
  367. CUL_HM_Set($hash,$name,"virtHum" ,ReadingsVal($name,"humidity",""));
  368. CUL_HM_UpdtReadSingle($hash,"valveCtrl","restart",1) if (ReadingsVal($name,"valvePosTC",""));
  369. RemoveInternalTimer("valvePos:$vId");
  370. RemoveInternalTimer("valveTmr:$vId");
  371. InternalTimer($hash->{helper}{vd}{next}
  372. ,"CUL_HM_valvePosUpdt","valvePos:$vId",0);
  373. # delete - virtuals dont have regs
  374. delete $attr{$name}{$_}
  375. foreach ("autoReadReg","actCycle","actStatus","burstAccess","serialNr");
  376. }
  377. }
  378. elsif ($st eq "sensRain") {
  379. $hash->{helper}{lastRain} = ReadingsTimestamp($name,"state","")
  380. if (ReadingsVal($name,"state","") eq "rain");
  381. }
  382. next if ($nAttr);# stop if default setting if attributes is not desired
  383. my $actCycle = AttrVal($name,"actCycle",undef);
  384. CUL_HM_ActAdd($id,$actCycle) if ($actCycle );#add 2 ActionDetect?
  385. # --- set default attributes if missing ---
  386. if ($hash->{helper}{role}{dev}){
  387. if( $st ne "virtual"){
  388. $attr{$name}{expert} = AttrVal($name,"expert" ,"2_raw");
  389. $attr{$name}{autoReadReg}= AttrVal($name,"autoReadReg","4_reqStatus");
  390. CUL_HM_hmInitMsg($hash);
  391. }
  392. if (CUL_HM_getRxType($hash)&0x02){#burst dev must restrict retries!
  393. $attr{$name}{msgRepeat} = 1 if (!$attr{$name}{msgRepeat});
  394. }
  395. }
  396. CUL_HM_Attr("attr",$name,"expert",$attr{$name}{expert})
  397. if ($attr{$name}{expert});#need update after readings are available
  398. if ($chn eq "03" &&
  399. $md =~ /(-TC|ROTO_ZEL-STG-RM-FWT|HM-CC-RT-DN)/){
  400. $attr{$name}{stateFormat} = "last:trigLast";
  401. }
  402. foreach(keys %{$attr{$name}}){
  403. delete $attr{$name}{$_} if(CUL_HM_AttrCheck($name,$_));
  404. }
  405. CUL_HM_chgExpLvl($hash);# need to update expert visib as of device
  406. # -+-+-+-+-+ add default web-commands
  407. my $webCmd;
  408. $webCmd = AttrVal($name,"webCmd",undef);
  409. if(!defined $webCmd){
  410. if ($st eq "virtual" ){
  411. if ($hash->{helper}{fkt} && $hash->{helper}{fkt} eq "sdLead1") {$webCmd="teamCall:alarmOn:alarmOff";}
  412. elsif($hash->{helper}{fkt} && $hash->{helper}{fkt} eq "vdCtrl") {$webCmd="valvePos";}
  413. elsif($hash->{helper}{fkt} && $hash->{helper}{fkt} eq "virtThSens"){$webCmd="virtTemp:virtHum";}
  414. elsif(!$hash->{helper}{role}{dev}) {$webCmd="press short:press long";}
  415. elsif($md =~ m/^virtual_/) {$webCmd="virtual";}
  416. elsif($md eq "CCU-FHEM") {$webCmd="virtual:update";}
  417. }
  418. elsif((!$hash->{helper}{role}{chn} &&
  419. $md !~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/)
  420. ||$st eq "repeater"
  421. ||$md =~ m/^(HM-CC-VD|ROTO_ZEL-STG-RM-FSA)/ ){$webCmd="getConfig:clear msgEvents";
  422. if ($md =~ m/^HM-CC-RT-DN/) {$webCmd.=":burstXmit";}
  423. }
  424. elsif($st eq "blindActuator"){
  425. if ($hash->{helper}{role}{chn}){$webCmd="statusRequest:toggleDir:on:off:up:down:stop";}
  426. else{ $webCmd="statusRequest:getConfig:clear msgEvents";}
  427. }
  428. elsif($st eq "dimmer" ){
  429. if ($hash->{helper}{role}{chn}){$webCmd="statusRequest:toggle:on:off:up:down";}
  430. else{ $webCmd="statusRequest:getConfig:clear msgEvents";}
  431. }
  432. elsif($st eq "switch" ){
  433. if ($hash->{helper}{role}{chn}){$webCmd="statusRequest:toggle:on:off";}
  434. else{ $webCmd="statusRequest:getConfig:clear msgEvents";}
  435. }
  436. elsif($st eq "smokeDetector"){ $webCmd="statusRequest";
  437. if (defined $hash->{helper}{fkt} && $hash->{helper}{fkt} eq "sdLead1"){
  438. $webCmd.=":teamCall:alarmOn:alarmOff";}
  439. }
  440. elsif($st eq "keyMatic" ){ $webCmd="lock:inhibit on:inhibit off";
  441. }
  442. elsif( $md eq "HM-OU-CFM-PL"
  443. ||$md eq "HM-OU-CFM-TW" ){ $webCmd="press short:press long"
  444. .($chn eq "02"?":playTone replay":"");
  445. }
  446. if ($webCmd){
  447. my $eventMap = AttrVal($name,"eventMap",undef);
  448. my @wc;
  449. push @wc,ReplaceEventMap($name, $_, 1) foreach (split ":",$webCmd);
  450. $webCmd = join ":",@wc;
  451. }
  452. }
  453. $attr{$name}{webCmd} = $webCmd if ($webCmd);
  454. CUL_HM_qStateUpdatIfEnab($name);
  455. next if (0 == (0x07 & CUL_HM_getAttrInt($name,"autoReadReg")));
  456. if(CUL_HM_peerUsed($name) == 2){
  457. CUL_HM_qAutoRead($name,1);
  458. }
  459. else{
  460. foreach(CUL_HM_reglUsed($name)){
  461. next if (!$_);
  462. if(ReadingsVal($name,$_,"x") !~ m/00:00/){
  463. CUL_HM_qAutoRead($name,1);
  464. last;
  465. }
  466. }
  467. }
  468. #remove invalid attributes
  469. if (!$hash->{helper}{role}{dev}){
  470. my @l = split(" ",$modules{CUL_HM}{Attr}{dev});
  471. map {$_ =~ s/\:.*//} @l;
  472. foreach (@l){
  473. delete $attr{$name}{$_} if (defined $attr{$name}{$_});
  474. }
  475. }
  476. if (!$hash->{helper}{role}{chn}){
  477. my @l = split(" ",$modules{CUL_HM}{Attr}{chn});
  478. map {$_ =~ s/\:.*//} @l;
  479. foreach (@l){
  480. delete $attr{$name}{$_} if (defined $attr{$name}{$_});
  481. }
  482. }
  483. CUL_HM_complConfig($name);
  484. }
  485. delete $modules{CUL_HM}{helper}{updtCfgLst};
  486. }
  487. sub CUL_HM_Define($$) {##############################
  488. my ($hash, $def) = @_;
  489. my @a = split("[ \t][ \t]*", $def);
  490. my $HMid = uc($a[2]);
  491. return "wrong syntax: define <name> CUL_HM 6-digit-hex-code [Raw-Message]"
  492. if(!(int(@a)==3 || int(@a)==4) || $HMid !~ m/^[A-F0-9]{6}([A-F0-9]{2})?$/i );
  493. return "HMid DEF already used by " . CUL_HM_id2Name($HMid)
  494. if ($modules{CUL_HM}{defptr}{$HMid});
  495. my $name = $hash->{NAME};
  496. if(length($HMid) == 8) {# define a channel
  497. my $devHmId = substr($HMid, 0, 6);
  498. my $chn = substr($HMid, 6, 2);
  499. my $devHash = $modules{CUL_HM}{defptr}{$devHmId};
  500. return "please define a device with hmId:".$devHmId." first" if(!$devHash);
  501. my $devName = $devHash->{NAME};
  502. $hash->{device} = $devName; #readable ref to device name
  503. $hash->{chanNo} = $chn; #readable ref to Channel
  504. $devHash->{"channel_$chn"} = $name; #reference in device as well
  505. $attr{$name}{model} = AttrVal($devName, "model", undef);
  506. $hash->{helper}{role}{chn}=1;
  507. if($chn eq "01"){
  508. $attr{$name}{peerIDs} = AttrVal($devName, "peerIDs", "");
  509. $hash->{READINGS}{peerList}{VAL} = ReadingsVal($devName,"peerList","");
  510. $hash->{peerList} = $devHash->{peerList} if($devHash->{peerList});
  511. delete $devHash->{helper}{role}{chn};#device no longer
  512. delete $devHash->{peerList};
  513. delete $devHash->{READINGS}{peerList};
  514. delete $attr{$devName}{peerIDs};
  515. }
  516. }
  517. else{# define a device
  518. $hash->{helper}{role}{dev} = 1;
  519. $hash->{helper}{role}{chn} = 1;# take role of chn 01 until it is defined
  520. $hash->{helper}{q}{qReqConf} = ""; # queue autoConfig requests
  521. $hash->{helper}{q}{qReqStat} = ""; # queue statusRequest for this device
  522. $hash->{helper}{mRssi}{mNo} = "";
  523. $hash->{helper}{HM_CMDNR} = int(rand(250));# should be different from previous
  524. CUL_HM_prtInit ($hash);
  525. $hash->{helper}{io}{vccu} = "";
  526. $hash->{helper}{io}{prefIO} = "";
  527. CUL_HM_assignIO($hash)if (!$init_done && $HMid ne "000000");
  528. }
  529. $modules{CUL_HM}{defptr}{$HMid} = $hash;
  530. $hash->{NOTIFYDEV} = "global";
  531. #- - - - create auto-update - - - - - -
  532. CUL_HM_ActGetCreateHash() if($HMid eq '000000');#startTimer
  533. $hash->{DEF} = $HMid;
  534. CUL_HM_Parse($hash, $a[3]) if(int(@a) == 4);
  535. CUL_HM_queueUpdtCfg($name);
  536. return undef;
  537. }
  538. sub CUL_HM_Undef($$) {###############################
  539. my ($hash, $name) = @_;
  540. my $devName = $hash->{device};
  541. my $HMid = $hash->{DEF};
  542. CUL_HM_unQEntity($name,"qReqConf");
  543. CUL_HM_unQEntity($name,"qReqStat");
  544. CUL_HM_complConfigTestRm($name);
  545. my $chn = substr($HMid,6,2);
  546. if ($chn){# delete a channel
  547. my $devHash = $defs{$devName};
  548. delete $devHash->{"channel_$chn"} if ($devName);
  549. $devHash->{helper}{role}{chn}=1 if($chn eq "01");# return chan 01 role
  550. }
  551. else{# delete a device
  552. CommandDelete(undef,$hash->{$_}) foreach (grep(/^channel_/,keys %{$hash}));
  553. }
  554. delete($modules{CUL_HM}{defptr}{$HMid});
  555. return undef;
  556. }
  557. sub CUL_HM_Rename($$$) {#############################
  558. my ($name, $oldName) = @_;
  559. my $hash = $defs{$name};
  560. return if($hash->{TYPE} ne "CUL_HM");
  561. my $HMid = CUL_HM_name2Id($name);
  562. if (!$hash->{helper}{role}{dev}){# we are channel, inform the device
  563. $hash->{chanNo} = substr($HMid,6,2);
  564. my $devHash = CUL_HM_id2Hash(substr($HMid,0,6));
  565. $hash->{device} = $devHash->{NAME};
  566. $devHash->{"channel_".$hash->{chanNo}} = $name;
  567. }
  568. else{# we are a device - inform channels if exist
  569. foreach (grep (/^channel_/, keys%{$hash})){
  570. next if(!$_);
  571. my $chnHash = $defs{$hash->{$_}};
  572. $chnHash->{device} = $name;
  573. }
  574. CUL_HM_UpdtCentral($name) if (AttrVal($name, "model", "") eq "CCU-FHEM");
  575. }
  576. if ($hash->{helper}{role}{chn}){
  577. my $HMidCh = substr($HMid."01",0,8);
  578. foreach my $pId (keys %{$modules{CUL_HM}{defptr}}){#all devices for peer
  579. my $pH = $modules{CUL_HM}{defptr}{$pId};
  580. my $pN = $pH->{NAME};
  581. my $pPeers = AttrVal($pN, "peerIDs", "");
  582. if ($pPeers =~ m/$HMidCh/){
  583. CUL_HM_ID2PeerList ($pN,"x",0);
  584. foreach my $pR (grep /-$oldName-/,keys%{$pH->{READINGS}}){#update reading of the peer
  585. my $pRn = $pR;
  586. $pRn =~ s/$oldName/$name/;
  587. $pH->{READINGS}{$pRn}{VAL} = $pH->{READINGS}{$pR}{VAL};
  588. $pH->{READINGS}{$pRn}{TIME} = $pH->{READINGS}{$pR}{TIME};
  589. delete $pH->{READINGS}{$pR};
  590. }
  591. if (eval "defined(&HMinfo_templateMark)"){
  592. foreach my $pT (grep /$oldName:/,keys%{$pH->{helper}{tmpl}}){#update reading of the peer
  593. my $param = $pH->{helper}{tmpl}{$pT};
  594. my ($px,$tmpl) = split(">",$pT);
  595. HMinfo_templateDel($pN,$tmpl,$px);
  596. $px =~ s/$oldName/$name/;
  597. HMinfo_templateMark($pH,"$px>$tmpl",split(" ",$param));
  598. }
  599. }
  600. }
  601. }
  602. }
  603. return;
  604. }
  605. sub CUL_HM_Attr(@) {#################################
  606. my ($cmd,$name, $attrName,$attrVal) = @_;
  607. my $chk = ($cmd eq "set")?CUL_HM_AttrCheck($name, $attrName):"";
  608. my $hash = CUL_HM_name2Hash($name);
  609. return $chk if ($chk);
  610. my $updtReq = 0;
  611. if ($attrName eq "expert"){#[0,1,2]
  612. $attr{$name}{$attrName} = $attrVal;
  613. CUL_HM_chgExpLvl($_) foreach ((map{CUL_HM_id2Hash($_)} CUL_HM_getAssChnIds($name)),$defs{$name});
  614. }
  615. elsif($attrName eq "readOnly"){#[0,1]
  616. if ($cmd eq "set"){
  617. return "$attrName: $attrVal not allowed. Should be one of 0,1" if (int($attrVal) > 1);
  618. }
  619. }
  620. elsif($attrName eq "actCycle"){#"000:00" or 'off'
  621. if ($cmd eq "set"){
  622. if (CUL_HM_name2Id($name) eq $K_actDetID){
  623. return "$attrName must be higher then 30, $attrVal not allowed"
  624. if ($attrVal < 30);
  625. }
  626. else{
  627. return "attribut not allowed for channels"
  628. if (!$hash->{helper}{role}{dev});
  629. }
  630. }
  631. $updtReq = 1;
  632. }
  633. elsif($attrName eq "param"){
  634. my $md = CUL_HM_Get($hash,$name,"param","model");
  635. my $st = CUL_HM_Get($hash,$name,"param","subType");
  636. my $chn = substr(CUL_HM_hash2Id($hash),6,2);
  637. if ($md eq "HM-Sen-RD-O" && $chn eq "02"){
  638. delete $hash->{helper}{param};
  639. my @param = split ",",$attrVal;
  640. foreach (@param){
  641. if ($_ eq "offAtPon"){$hash->{helper}{param}{offAtPon} = 1}
  642. elsif ($_ eq "onAtRain"){$hash->{helper}{param}{onAtRain} = 1}
  643. else {return "param $_ unknown, use offAtPon or onAtRain";}
  644. }
  645. }
  646. elsif ($md eq "HM-Dis-EP-WM55" && $chn eq "03"){#reWriteDisplay
  647. if ($cmd eq "set"){
  648. if ($attrVal =~ m/^reWriteDisplay([0-9][0-9])$/){# no action, just set
  649. my $delay = $1;
  650. if($delay < 1 || $delay >99){
  651. return "invalid $delay- select between reWriteDisplay01 and reWriteDisplay99";
  652. }
  653. }
  654. else{
  655. return "attribut param $attrVal not valid for $name. Only reWriteDisplayxx allowed";
  656. }
  657. }
  658. else{
  659. delete $hash->{helper}{vd}{msgRed};
  660. }
  661. }
  662. elsif ($st eq "virtual"){
  663. if ($cmd eq "set"){
  664. if ($attrVal eq "noOnOff"){# no action
  665. }
  666. elsif ($attrVal =~ m/msgReduce/){# send only each other message
  667. my (undef,$rCnt) = split(":",$attrVal,2);
  668. $rCnt=(defined $rCnt && $rCnt =~ m/^\d$/)?$rCnt:1;
  669. $hash->{helper}{vd}{msgRed}=$rCnt;
  670. }
  671. else{
  672. return "attribut param $attrVal not valid for $name";
  673. }
  674. }
  675. else{
  676. delete $hash->{helper}{vd}{msgRed};
  677. }
  678. }
  679. else{
  680. if ($cmd eq "set"){
  681. if ($attrVal =~ m/(levelInverse|ponRestore)/){# no action
  682. }
  683. elsif ($attrVal =~ m/(showTimed)/){# no action
  684. #we could check for those subtypes
  685. #sensRain
  686. #siren
  687. #powerMeter
  688. #switch
  689. #dimmer
  690. #rgb
  691. }
  692. else{
  693. return "attribut param $attrVal not valid for $name";
  694. }
  695. }
  696. else{
  697. delete $hash->{helper}{vd}{msgRed};
  698. }
  699. }
  700. }
  701. elsif($attrName eq "peerIDs"){
  702. if ($cmd eq "set"){
  703. return "$attrName not usable for devices" if(!$hash->{helper}{role}{chn});
  704. my $id = $hash->{DEF};
  705. if ($id ne $K_actDetID && $attrVal){# if not action detector
  706. my @ids = grep /......../,split(",",$attrVal);
  707. $attr{$name}{peerIDs} = join",",@ids if (@ids);
  708. CUL_HM_ID2PeerList($name,"",1); # update peerList out of peerIDs
  709. }
  710. }
  711. else{# delete
  712. delete $hash->{peerList};
  713. delete $hash->{READINGS}{peerList};
  714. }
  715. }
  716. elsif($attrName eq "msgRepeat"){
  717. if ($cmd eq "set"){
  718. return "$attrName not usable for channels" if(!$hash->{helper}{role}{dev});#only for device
  719. return "value $attrVal ignored, must be an integer" if ($attrVal !~ m/^(\d+)$/);
  720. }
  721. return;
  722. }
  723. elsif($attrName eq "model" && $hash->{helper}{role}{dev}){
  724. delete $hash->{helper}{rxType}; # needs new calculation
  725. delete $hash->{helper}{mId};
  726. if ($attrVal eq "CCU-FHEM"){
  727. $attr{$name}{subType} = "virtual";
  728. $updtReq = 1;
  729. CUL_HM_UpdtCentral($name);
  730. }
  731. else{
  732. CUL_HM_hmInitMsg($hash);
  733. }
  734. $attr{$name}{$attrName} = $attrVal if ($cmd eq "set");
  735. }
  736. elsif($attrName eq "subType"){
  737. $updtReq = 1;
  738. }
  739. elsif($attrName eq "aesCommReq" ){
  740. if ($cmd eq "set"){
  741. return "$attrName support 0 or 1 only" if ($attrVal !~ m/[01]/);
  742. return "$attrName invalid for virtal devices" if ($hash->{role}{vrt});
  743. $attr{$name}{$attrName} = $attrVal;
  744. # if ( $attrVal eq "1"
  745. # && $hash->{device}) { # is a channel
  746. # $attr{$hash->{device}}{$attrName} = $attrVal; # automatically enable on device, too - does not make sense
  747. # }
  748. }
  749. else{
  750. delete $attr{$name}{$attrName};
  751. }
  752. CUL_HM_hmInitMsg(CUL_HM_getDeviceHash($hash));
  753. }
  754. elsif($attrName eq "aesKey" ){
  755. if ($cmd eq "set"){
  756. return "$attrName support 0 to 5 only" if ($attrVal < 0 || $attrVal > 5);
  757. $attr{$name}{$attrName} = $attrVal;
  758. }
  759. else{
  760. delete $attr{$name}{$attrName};
  761. }
  762. CUL_HM_hmInitMsg(CUL_HM_getDeviceHash($hash));
  763. }
  764. elsif($attrName eq "burstAccess"){
  765. if ($cmd eq "set"){
  766. return "use burstAccess only for device" if (!$hash->{helper}{role}{dev});
  767. return $name." not a conditional burst model" if (!CUL_HM_getRxType($hash) & 0x80);
  768. return "$attrVal not a valid option for burstAccess" if ($attrVal !~ m/^[01]/);
  769. if ($attrVal =~ m/^0/){$hash->{protCondBurst} = "forced_off";}
  770. else {$hash->{protCondBurst} = "unknown";}
  771. }
  772. else{ $hash->{protCondBurst} = "forced_off";}
  773. delete $hash->{helper}{rxType}; # needs new calculation
  774. }
  775. elsif($attrName eq "IOList"){
  776. return "use $attrName only for vccu device"
  777. if (!$hash->{helper}{role}{dev}
  778. || AttrVal($name,"model","CCU-FHEM") !~ "CCU-FHEM");
  779. if($cmd eq "set"){$attr{$name}{$attrName} = $attrVal;}
  780. else {delete $attr{$name}{$attrName};}
  781. CUL_HM_UpdtCentral($name);
  782. }
  783. elsif($attrName eq "IOgrp" ){
  784. if ($cmd eq "set"){
  785. return "use $attrName only for devices" if (!$hash->{helper}{role}{dev});
  786. my ($ioCCU,$prefIO) = split(":",$attrVal,2);
  787. $hash->{helper}{io}{vccu} = $ioCCU;
  788. delete $hash->{helper}{io}{prefIO};
  789. if ($prefIO){
  790. my @prefIOA;
  791. if ($init_done){@prefIOA = grep /.+/,map{$defs{$_} ? $_ : ""} split(",",$prefIO);}
  792. else {@prefIOA = split(",",$prefIO);}#checkis possible after init. Assume correct if not finished
  793. $hash->{helper}{io}{prefIO} = \@prefIOA if (int(@prefIOA));
  794. my $attrValAssamble = "$ioCCU:".join(",",@prefIOA);
  795. if ($attrVal ne $attrValAssamble){# original setting not possible
  796. $attr{$name}{$attrName} = $attrValAssamble;
  797. return "value corrected $attrName:$attrValAssamble";
  798. }
  799. }
  800. }
  801. else{
  802. $hash->{helper}{io}{vccu} = "";
  803. $hash->{helper}{io}{prefIO} = "";
  804. }
  805. }
  806. elsif($attrName eq "autoReadReg"){
  807. if ($cmd eq "set"){
  808. CUL_HM_complConfigTest($name)
  809. if (!CUL_HM_getAttrInt($name,"ignore"));;
  810. }
  811. }
  812. elsif($attrName eq "rssiLog" ){
  813. if ($cmd eq "set"){
  814. return "use $attrName only for device" if (!$hash->{helper}{role}{dev});
  815. }
  816. }
  817. elsif($attrName eq "levelRange" ){
  818. if ($cmd eq "set"){
  819. return "use $attrName only for dimmer" if ((CUL_HM_Get($defs{$name},$name,"param","subType") ne "dimmer")
  820. && $init_done );
  821. my ($min,$max) = split (",",$attrVal);
  822. return "use format min,max" if (!defined $max);
  823. return "min:$min must be between 0 and 100" if ($min<0 || $min >100);
  824. return "max:$max must be between 0 and 100" if ($max<0 || $max >100);
  825. return "min:$min mit be lower then max:$max" if ($min >= $max);
  826. }
  827. }
  828. elsif($attrName eq "levelMap" ){
  829. if ($cmd eq "set"){
  830. return "use $attrName only for channels" if (!$hash->{helper}{role}{chn});
  831. delete $hash->{helper}{lm};
  832. foreach (split":",$attrVal){
  833. my ($val,$vNm) = split"=",$_;
  834. if ($val !~ m/^\d*$/){
  835. delete $hash->{helper}{lm};
  836. return "$val is not numeric";
  837. }
  838. $hash->{helper}{lm}{$val} = $vNm;
  839. }
  840. }
  841. else{
  842. delete $hash->{helper}{lm};
  843. }
  844. }
  845. elsif($attrName eq "actAutoTry" ){
  846. if ($cmd eq "set"){
  847. return "$attrName only usable for ActionDetector" if(CUL_HM_hash2Id($hash) ne "000000");#only for device
  848. }
  849. }
  850. elsif($attrName eq "tempListTmpl" ){
  851. if ($cmd eq "set"){
  852. CUL_HM_UpdtReadSingle($hash,"tempTmplSet",$attrVal,0)
  853. }
  854. else{
  855. delete $hash->{READINGS}{"tempTmplSet"};
  856. }
  857. }
  858. elsif($attrName =~ m/^hmKey/){
  859. my $retVal= "";
  860. return "use $attrName only for vccu device"
  861. if (!$hash->{helper}{role}{dev}
  862. || AttrVal($name,"model","CCU-FHEM") !~ "CCU-FHEM");
  863. if ($cmd eq "set"){
  864. # eQ3 default key A4E375C6B09FD185F27C4E96FC273AE4
  865. my $kno = ($attrName eq "hmKey")?1:substr($attrName,5,1);
  866. my ($no,$val) = (sprintf("%02X",$kno),$attrVal);
  867. if ($attrVal =~ m/:/){#number given
  868. ($no,$val) = split ":",$attrVal;
  869. return "illegal number:$no" if (hex($no) < 1 || hex($no) > 255 || length($no) != 2);
  870. }
  871. $attr{$name}{$attrName} = "$no:".
  872. (($val =~ m/^[0-9A-Fa-f]{32}$/ )
  873. ? $val
  874. : unpack('H*', md5($val)));
  875. $retVal = "$attrName set to $attr{$name}{$attrName}"
  876. if($attrVal ne $attr{$name}{$attrName});
  877. }
  878. else{
  879. delete $attr{$name}{$attrName};
  880. }
  881. if ($init_done){
  882. foreach my $io (split ",",AttrVal($name,"IOList","")) {
  883. next if(!$defs{$io});
  884. if ($defs{$io}->{TYPE} eq "HMLAN" && eval "defined(&HMLAN_writeAesKey)"){
  885. HMLAN_writeAesKey($io);
  886. }
  887. elsif ($defs{$io}->{TYPE} eq "HMUARTLGW") {
  888. CallFn($io,"WriteFn",$defs{$io},undef,"writeAesKey:${io}");
  889. }
  890. elsif ( $defs{$io}->{TYPE} =~ m/^(TSCUL|TSSTACKED)$/
  891. && eval "defined(&TSCUL_WriteAesKeyHM)"){
  892. TSCUL_WriteAesKeyHM($io); # noansi: for TSCUL
  893. }
  894. }
  895. }
  896. return $retVal;
  897. }
  898. CUL_HM_queueUpdtCfg($name) if ($updtReq);
  899. return;
  900. }
  901. sub CUL_HM_AttrCheck(@) {############################
  902. #verify if attr is applicable
  903. my ($name, $attrName) = @_;
  904. return undef if (!$init_done); # we cannot determine if attributes are missing
  905. if ($defs{$name}{helper}{role}{vrt}){
  906. return " $attrName illegal for virtual devices"
  907. if ($modules{CUL_HM}{Attr}{devPhy} =~ m/\b$attrName\b/);
  908. }
  909. if (!$defs{$name}{helper}{role}{chn}){
  910. return " $attrName only valid for channels"
  911. if ($modules{CUL_HM}{Attr}{chn} =~ m/\b$attrName\b/);
  912. }
  913. if (!$defs{$name}{helper}{role}{dev}){
  914. return " $attrName only valid for devices"
  915. if (($modules{CUL_HM}{Attr}{dev}.$modules{CUL_HM}{Attr}{devPhy}) =~ m/\b$attrName\b/);
  916. }
  917. return undef;
  918. }
  919. sub CUL_HM_prtInit($){ #setup protocol variables after define
  920. my ($hash)=@_;
  921. $hash->{helper}{prt}{sProc} = 0; # stack not being processed by now
  922. $hash->{helper}{prt}{bErr} = 0;
  923. }
  924. sub CUL_HM_hmInitMsg($){ #define device init msg for HMLAN
  925. #message to be send to HMLAN/USB to define device communication defails
  926. #bit-usage is widely unknown.
  927. #p[1]: 00000001 = request AES
  928. #p[1]: 00000010 = data pending - autosend wakeup and lazyConfig
  929. # if device send data
  930. #p[2]: is this the number of the AES key to be used?
  931. return if (!$init_done);
  932. my ($hash)=@_;
  933. my $rxt = CUL_HM_getRxType($hash);
  934. my $id = CUL_HM_hash2Id($hash);
  935. my @p;
  936. my $name = $hash->{NAME};
  937. my $mask = ($hash->{helper}{role}{chn} && AttrVal($name,"aesCommReq",0))?2:0;
  938. foreach (grep /channel/,keys %{$hash}){
  939. $mask |= (2 ** hex(substr($_,8,2))) if(AttrVal($hash->{$_},"aesCommReq",0));
  940. }
  941. if ($mask<256) {$mask = join("",reverse unpack "(A2)*",sprintf("%02X",$mask));}
  942. elsif ($mask<65536) {$mask = join("",reverse unpack "(A2)*",sprintf("%04X",$mask));}
  943. else {$mask = join("",reverse unpack "(A2)*",sprintf("%08X",$mask));}
  944. my ($highestKey, undef) = CUL_HM_getKeys($hash);
  945. my $key = sprintf("%02X",AttrVal($name,"aesKey",$highestKey));
  946. @p = ("$id","00",$key,$mask) if (!$hash->{helper}{role}{vrt});
  947. if (AttrVal($name,"aesCommReq",0)){
  948. $p[1] = sprintf("%02X",(hex($p[1]) + 1));
  949. $p[3] = ($p[3]eq "")?"1E":$p[3];
  950. }
  951. $hash->{helper}{io}{newChn} = "";
  952. $hash->{helper}{io}{rxt} = (($rxt & 0x18) #wakeup || #lazyConfig
  953. && AttrVal($name,"model",0) ne "HM-WDS100-C6-O") #Todo - not completely clear how it works
  954. ?2:0;
  955. $hash->{helper}{io}{p} = \@p;
  956. CUL_HM_hmInitMsgUpdt($hash);
  957. }
  958. sub CUL_HM_hmInitMsgUpdt($){ #update device init msg for HMLAN
  959. my ($hash)=@_;
  960. return if ( $hash->{helper}{role}{vrt}
  961. ||!defined $hash->{helper}{io}{p});
  962. my $oldChn = $hash->{helper}{io}{newChn};
  963. my @p = @{$hash->{helper}{io}{p}};
  964. # General todo
  965. # $p[1] |= 2; need to be set if data is pending for a wakeup device.
  966. # it will force HMLAN to send A112 (have data). HMLAN will return
  967. # status "81" ACK if the device answers the A112 - FHEM should start sending Data by then
  968. #
  969. if($hash->{helper}{prt}{sProc} && $hash->{cmdStack}){
  970. $p[1] = sprintf("%02X",hex($p[1]) | $hash->{helper}{io}{rxt});
  971. }
  972. # else{
  973. # $p[1] = sprintf("%02X",hex($p[1]) & 0xFD);# remove this Bit if no more data to send
  974. # # otherwise could cause continous send (e.g. from SC)
  975. # }
  976. $hash->{helper}{io}{newChn} = '+'.join(",",@p);
  977. if (( $hash->{helper}{io}{newChn} ne $oldChn)
  978. && $hash->{IODev}
  979. && $hash->{IODev}->{TYPE}
  980. && ( $hash->{IODev}->{helper}{VTS_AES} # for TSCUL VTS0.14 up
  981. || $hash->{IODev}->{TYPE} =~ m/^(HMLAN|HMUARTLGW)$/ )) {
  982. IOWrite($hash, "", "init:$p[0]");
  983. }
  984. }
  985. sub CUL_HM_Notify(@){#################################
  986. my ($ntfy, $dev) = @_;
  987. return "" if ($dev->{NAME} ne "global");
  988. my $events = deviceEvents($dev, AttrVal($ntfy->{NAME}, "addStateEvent", 0));
  989. return undef if(!$events); # Some previous notify deleted the array.
  990. return undef if (grep !/INITIALIZED/,@{$events});
  991. delete $modules{CUL_HM}{NotifyFn};
  992. # execute some cleanup after init
  993. CUL_HM_updateConfig("startUp");
  994. InternalTimer(1,"CUL_HM_setupHMLAN", "initHMLAN", 0);#start asap once FHEM is operational
  995. return undef;
  996. }
  997. sub CUL_HM_setupHMLAN(@){#################################
  998. foreach (devspec2array("TYPE=CUL_HM:FILTER=DEF=......:FILTER=subType!=virtual")){
  999. $defs{$_}{helper}{io}{newChn} = 0;
  1000. CUL_HM_hmInitMsg($defs{$_}); #update device init msg for HMLAN
  1001. }
  1002. }
  1003. #+++++++++++++++++ msg receive, parsing++++++++++++++++++++++++++++++++++++++++
  1004. # translate level to readable
  1005. my %lvlStr = ( md =>{ "HM-SEC-WDS" =>{"00"=>"dry" ,"64"=>"damp" ,"C8"=>"wet" }
  1006. ,"HM-SEC-WDS-2" =>{"00"=>"dry" ,"64"=>"damp" ,"C8"=>"wet" }
  1007. ,"HM-CC-SCD" =>{"00"=>"normal" ,"64"=>"added" ,"C8"=>"addedStrong"}
  1008. ,"HM-Sen-RD-O" =>{"00"=>"dry" ,"C8"=>"rain"}
  1009. ,"HM-MOD-Em-8" =>{"00"=>"closed" ,"C8"=>"open"}
  1010. ,"HM-WDS100-C6-O" =>{"00"=>"quiet" ,"C8"=>"storm"}
  1011. }
  1012. ,mdCh=>{ "HM-Sen-RD-O01" =>{"00"=>"dry" ,"C8"=>"rain"}
  1013. ,"HM-Sen-RD-O02" =>{"00"=>"off" ,"C8"=>"on"}
  1014. }
  1015. ,st =>{ "smokeDetector" =>{"01"=>"no alarm","C7"=>"tone off","C8"=>"Smoke Alarm"}
  1016. ,"threeStateSensor"=>{"00"=>"closed" ,"64"=>"tilted" ,"C8"=>"open"}
  1017. }
  1018. );
  1019. my %disColor=(white=>0,red=>1,orange=>2,yellow=>3,green=>4,blue=>5);
  1020. my %disIcon=( off =>0, on=>1, open=>2, closed=>3, error=>4, ok=>5
  1021. ,info=>6, newMsg=>7, serviceMsg=>8
  1022. ,sigGreen=>9, sigYellow=>10, sigRed=>11
  1023. ,ic12=>12, ic13=>13
  1024. ,noIcon=>99
  1025. );
  1026. my %disBtn=( txt01_1=>0, txt01_2=>1, txt02_1=>2, txt02_2=>3, txt03_1=>4
  1027. , txt03_2=>5, txt04_1=>6, txt04_2=>7, txt05_1=>8, txt05_2=>9
  1028. , txt06_1=>10,txt06_2=>11,txt07_1=>12,txt07_2=>13,txt08_1=>14
  1029. , txt08_2=>15,txt09_1=>16,txt09_2=>17,txt10_1=>18,txt10_2=>19
  1030. );
  1031. sub CUL_HM_Parse($$) {#########################################################
  1032. my ($iohash, $msgIn) = @_;
  1033. my %mh; # hash for data of this message
  1034. ($mh{msg},$mh{msgStat},$mh{myRSSI},$mh{msgIO},$mh{auth}) = split(":",$msgIn,5);
  1035. ($mh{t},$mh{len},$mh{mNo},$mh{mFlg},$mh{mTp},$mh{src},$mh{dst},$mh{p}) = unpack 'A1A2A2A2A2A6A6A*',$mh{msg};
  1036. $mh{mFlgH} = hex($mh{mFlg});
  1037. # Msg format: Allnnffttssssssddddddpp...
  1038. return if (!$iohash ||
  1039. ref($iohash) ne 'HASH' ||
  1040. $mh{t} ne 'A' ||
  1041. length($mh{msg})<20);
  1042. if ($modules{CUL_HM}{helper}{updating}){
  1043. if ("done" eq CUL_HM_FWupdateSteps($mh{msg})){
  1044. my $sH = CUL_HM_id2Hash($mh{t});
  1045. my @e = CUL_HM_pushEvnts();
  1046. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$sH->{NAME}$/,@e);
  1047. return (@e,$sH->{NAME}); #return something to please dispatcher
  1048. }
  1049. else{
  1050. return "";
  1051. }
  1052. }
  1053. return "" if($mh{msgStat} && $mh{msgStat} eq 'NACK');# lowlevel error
  1054. $mh{p} = "" if(!defined($mh{p})); # generate some abreviations
  1055. my @mI = unpack '(A2)*',$mh{p}; # split message info to bytes
  1056. $mh{mStp} = $mI[0] ? $mI[0] : ""; #message subtype
  1057. $mh{mTyp} = $mh{mTp}.$mh{mStp}; #message type/subtype
  1058. # $shash will be replaced for multichannel commands
  1059. $mh{devH} = CUL_HM_id2Hash($mh{src}); #sourcehash - will be modified to channel entity
  1060. $mh{dstH} = CUL_HM_id2Hash($mh{dst}); # destination device hash
  1061. $mh{id} = CUL_HM_h2IoId($iohash);
  1062. $mh{ioName} = $iohash->{NAME};
  1063. $evtDly = 1;# switch delay trigger on
  1064. CUL_HM_statCnt($mh{ioName},"r");
  1065. $mh{dstN} = ($mh{dst} eq "000000") ? "broadcast" :
  1066. ($mh{dstH} ? $mh{dstH}->{NAME} :
  1067. ($mh{dst} eq $mh{id} ? $mh{ioName} :
  1068. $mh{dst}));
  1069. if(!$mh{devH} && $mh{mTp} eq "00") { # generate device
  1070. my $sname = "HM_$mh{src}";
  1071. Log3 undef, 2, "CUL_HM Unknown device $sname is now defined";
  1072. DoTrigger("global","UNDEFINED $sname CUL_HM $mh{src}");
  1073. $mh{devH} = CUL_HM_id2Hash($mh{src}); #sourcehash - changed to channel entity
  1074. $mh{devH}->{IODev} = $iohash;
  1075. $mh{devH}->{helper}{io}{nextSend} = gettimeofday()+0.09 if(!defined($mh{devH}->{helper}{io}{nextSend}));# io couldn't set
  1076. }
  1077. my @entities = ("global"); #additional entities with events to be notifies
  1078. #################### attack alarm detection#####################
  1079. if ( $mh{dstH} && $mh{dst} ne "000000"
  1080. && !CUL_HM_getAttrInt($mh{dstN},"ignore")
  1081. && ($mh{mTp} eq '01' || $mh{mTp} eq '11'
  1082. )){
  1083. my $ioId = AttrVal($mh{dstH}->{IODev}{NAME},"hmId","-");
  1084. if($ioId ne $mh{src}){
  1085. if ( !defined $mh{dstH}->{"prot"."ErrIoId_$mh{src}"}
  1086. && ReadingsVal($mh{dstN},"sabotageAttackId_ErrIoId_$mh{src}:",undef)){
  1087. (undef,$mh{dstH}->{"prot"."ErrIoId_$mh{src}"}) =
  1088. split(":",ReadingsVal($mh{dstN},"sabotageAttackId_ErrIoId_$mh{src}:",undef));
  1089. }
  1090. CUL_HM_eventP($mh{dstH},"ErrIoId_$mh{src}");
  1091. my ($evntCnt,undef) = split(' last_at:',$mh{dstH}->{"prot"."ErrIoId_$mh{src}"},2);
  1092. push @evtEt,[$mh{dstH},1,"sabotageAttackId_ErrIoId_$mh{src}: cnt:$evntCnt"];
  1093. }
  1094. my $tm = substr($mh{msg},8);
  1095. if( defined $mh{dstH}->{helper}{cSnd} &&
  1096. $mh{dstH}->{helper}{cSnd} !~ m/$tm/){
  1097. if ( !defined $mh{dstH}->{"prot"."ErrIoAttack"}
  1098. && ReadingsVal($mh{dstN},"sabotageAttack_ErrIoAttack cnt:",undef)){
  1099. $mh{dstH}->{"prot"."ErrIoAttack"} =
  1100. ReadingsVal($mh{dstN},"sabotageAttack_ErrIoAttack cnt:",undef);
  1101. }
  1102. Log3 $mh{dstN},2,"CUL_HM $mh{dstN} attack:$mh{dstH}->{helper}{cSnd}:".$tm;
  1103. CUL_HM_eventP($mh{dstH},"ErrIoAttack");
  1104. my ($evntCnt,undef) = split(' last_at:',$mh{dstH}->{"prot"."ErrIoAttack"},2);
  1105. push @evtEt,[$mh{dstH},1,"sabotageAttack_ErrIoAttack cnt:$evntCnt"];
  1106. }
  1107. }
  1108. ###########
  1109. # return "" if($mh{src} eq $mh{id});# mirrored messages - covered by !$shash
  1110. if(!$mh{devH}){ # Unknown source
  1111. $evtDly = 0;# switch delay trigger off
  1112. return "" if ($mh{msg} =~ m/998112......000001/);# HMLAN internal message, consum
  1113. my $ccu =InternalVal($mh{ioName},"owner_CCU","");
  1114. CUL_HM_DumpProtocol("RCV",$iohash,$mh{len},$mh{mNo},$mh{mFlg},$mh{mTp},$mh{src},$mh{dst},$mh{p});
  1115. if ($defs{$ccu}){#
  1116. push @evtEt,[$defs{$ccu},0,"unknown_$mh{src}:received"];# do not trigger
  1117. return CUL_HM_pushEvnts();
  1118. }
  1119. return;
  1120. }
  1121. CUL_HM_assignIO($mh{devH}); #this way the init and remove work even on startup for TSCUL
  1122. if ( !defined $mh{devH}->{IODev}
  1123. || !defined $mh{devH}->{IODev}{NAME}){
  1124. Log3 $mh{devH},1,"CUL_HM $mh{devN} error: no IO deviced!!! correkt it";
  1125. $mh{devH}->{IODev} = $iohash;
  1126. }
  1127. $respRemoved = 0; #set to 'no response in this message' at start
  1128. $mh{devN} = $mh{devH}->{NAME}; #sourcehash - will be modified to channel entity
  1129. $mh{shash} = $mh{devH}; # source hash - will be redirected to channel if applicable
  1130. my $ioId = CUL_HM_h2IoId($mh{devH}->{IODev});
  1131. $ioId = $mh{id} if(!$ioId);
  1132. if (CUL_HM_getAttrInt($mh{devN},"ignore")){
  1133. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devN}$/,@entities);
  1134. return (CUL_HM_pushEvnts(),$mh{devN},@entities);
  1135. }
  1136. #----------CUL aesCommReq handling---------
  1137. if ( AttrVal($mh{devN},"aesCommReq",0) #aesCommReq enabled for device
  1138. && $mh{devH}{IODev}{NAME} ne $mh{ioName} #message not received on assigned IO
  1139. && $mh{msgStat} !~ m/AES/) { #IO did not already do AES processing for us
  1140. my $oldIo = $mh{devH}{IODev}{NAME};
  1141. CUL_HM_assignIO($mh{devH}); #update IO in case of roaming
  1142. if ( $mh{devH}{IODev}{NAME} ne $mh{ioName} #current IO not selected as new IO
  1143. || AttrVal($mh{devH}{IODev}{NAME},"rfmode","") ne "HomeMatic" #new IO is not CUL
  1144. || AttrVal($oldIo,"rfmode","") ne "HomeMatic") { #old IO is not CUL
  1145. Log3 $mh{devH},5,"CUL_HM ignoring message for ${oldIo} received on $mh{ioName}";
  1146. #Do not process message further, the assigned IO has to handle it
  1147. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devN}$/,@entities);
  1148. return (CUL_HM_pushEvnts(),$mh{devN});
  1149. }
  1150. }
  1151. #----------CUL aesCommReq handling---------
  1152. my $aComReq = AttrVal($mh{devN},"aesCommReq",0);
  1153. my $dRfMode = AttrVal($mh{devH}{IODev}{NAME},"rfmode","");
  1154. my $dIoOk = ($mh{devH}{IODev}{NAME} eq $mh{ioName}) ? 1 : 0;
  1155. if ( $aComReq #aesCommReq enabled for device
  1156. && !$dIoOk #message not received on assigned IO
  1157. && $mh{msgStat} !~ m/AES/) { #IO did not already do AES processing for us
  1158. my $oldIo = $mh{devH}{IODev}{NAME};
  1159. CUL_HM_assignIO($mh{devH}); #update IO in case of roaming
  1160. if ( !$dIoOk #current IO not selected as new IO
  1161. || $dRfMode ne "HomeMatic" #new IO is not CUL
  1162. || AttrVal($oldIo,"rfmode","") ne "HomeMatic") { #old IO is not CUL
  1163. Log3 $mh{devH},5,"CUL_HM ignoring message for ${oldIo} received on $mh{ioName}";
  1164. #Do not process message further, the assigned IO has to handle it
  1165. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devN}$/,@entities);
  1166. return (CUL_HM_pushEvnts(),$mh{devN});
  1167. }
  1168. }
  1169. if ( $dRfMode eq "HomeMatic" # $mh{devH}->{IODev}->{TYPE} eq "CUL"
  1170. && $dIoOk #message received on assigned IO
  1171. && $cryptFunc == 1
  1172. && $ioId eq $mh{dst}
  1173. && $aComReq) { #aesCommReq enabled for device
  1174. if ($mh{devH}->{helper}{aesCommRq}{msgStat}) {
  1175. #----------Message was already handled, pass on result---------
  1176. $mh{msgStat} = $mh{devH}->{helper}{aesCommRq}{msgStat};
  1177. delete($mh{devH}->{helper}{aesCommRq});
  1178. }
  1179. elsif ( $mh{devH}->{helper}{aesCommRq}{msg}
  1180. && $mh{mTp} eq "03") {
  1181. #----------Check AES response from device (CUL)---------
  1182. my $aesM = $mh{devH}->{helper}{aesCommRq}{msg};
  1183. my (undef, %keys) = CUL_HM_getKeys($mh{devH});
  1184. my $key = $keys{$mh{devH}->{helper}{aesCommRq}{kNo}};
  1185. $key = $key ^ pack("H12", $mh{devH}->{helper}{aesCommRq}{challenge});
  1186. my $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_ECB());
  1187. my $iv = pack("H*", substr($aesM, 23));
  1188. my $response = $cipher->decrypt(pack("H32", $mh{p})) ^ $iv;
  1189. my $authbytes = unpack("H8", $response);
  1190. $response = $cipher->decrypt(substr($response, 0, 16));
  1191. my $cmd = uc unpack("H20",substr($response, 6, 1) .
  1192. chr(ord(substr($response, 7, 1)) & 0xbf) . #~RPTED
  1193. substr($response, 8, 8));
  1194. my $origcmd = uc substr($aesM, 3, 2) .
  1195. sprintf("%02X", (hex(substr($aesM, 5, 2)) & 0xbf)) . #~RPTED
  1196. substr($aesM, 7, 16);
  1197. Log3 $mh{devH},5,"CUL_HM $mh{dstN} iv: ".unpack("H*", $iv)
  1198. ."\n decrypted cmd: $cmd"
  1199. ."\n original cmd: $origcmd";
  1200. if ($cmd eq $origcmd) {
  1201. Log3 $mh{devH},4,"CUL_HM $mh{dstN} signature: good, authbytes: ${authbytes}";
  1202. $mh{devH}->{helper}{aesAuthBytes} = $authbytes;
  1203. $mh{devH}->{helper}{aesCommRq}{msgStat} = "AESCom-ok";
  1204. }
  1205. else {
  1206. Log3 $mh{devH},4,"CUL_HM $mh{dstN} signature: bad";
  1207. $mh{devH}->{helper}{aesCommRq}{msgStat} = "AESCom-fail";
  1208. }
  1209. #continue with old message
  1210. return CUL_HM_Parse($iohash, $mh{devH}->{helper}{aesCommRq}{msgIn});
  1211. }
  1212. else {
  1213. my $doAES = 1;
  1214. my $chn ;
  1215. if($mh{mTp} =~ m/^4[01]/){ #someone is triggered##########
  1216. CUL_HM_m_setCh(\%mh,$mI[0]);
  1217. $chn = $mI[0];
  1218. }
  1219. elsif ($mh{mTp} eq "10") {
  1220. if ($mh{mStp} =~ m/^0[46]/) {
  1221. CUL_HM_m_setCh(\%mh,$mI[1]);
  1222. }
  1223. elsif ($mh{mStp} eq "01") {
  1224. $doAES = 0;
  1225. }
  1226. elsif (!($mh{mFlgH} & 0x20)) { #response required Flag
  1227. $doAES = 0;
  1228. }
  1229. }
  1230. elsif ($mh{mTp} =~ m/^0[23]/) {
  1231. $doAES = 0;
  1232. }
  1233. if ($doAES && $chn && defined(CUL_HM_id2Hash($mh{src}.sprintf("%02X",$chn)))) {
  1234. CUL_HM_m_setCh(\%mh,$mI[0]);
  1235. }
  1236. if ( $doAES
  1237. && AttrVal($mh{cName},"aesCommReq",0)) { #aesCommReq enabled for channel
  1238. #----------Generate AES challenge for device (CUL)---------
  1239. my ($kNo, %keys) = CUL_HM_getKeys($mh{devH});
  1240. $kNo = AttrVal($mh{devN},"aesKey",$kNo);
  1241. if (defined($keys{$kNo})) {
  1242. my $challenge = (defined($mh{devH}->{helper}{aesCommRq}{challenge}))
  1243. ? $mh{devH}->{helper}{aesCommRq}{challenge}
  1244. : sprintf("%08X%04X",rand(0xffffffff), rand(0xffff));
  1245. Log3 $mh{cHash},5,"CUL_HM $mh{devN} requesting signature with challenge $challenge for key $kNo";
  1246. $mh{devH}->{helper}{aesCommRq}{msg} = $mh{msg};
  1247. $mh{devH}->{helper}{aesCommRq}{msgIn} = $msgIn;
  1248. $mh{devH}->{helper}{aesCommRq}{challenge} = $challenge;
  1249. $mh{devH}->{helper}{aesCommRq}{kNo} = $kNo;
  1250. my $cmd = "$mh{mNo}A002$mh{dst}$mh{src}04${challenge}".sprintf("%02X", $kNo*2);
  1251. $cmd = sprintf("As%02X%s", length($cmd)/2, $cmd);
  1252. IOWrite($mh{devH}, "", $cmd);
  1253. $mh{msgStat}="AESpending";
  1254. }
  1255. else {
  1256. $mh{devH}->{helper}{aesCommRq}{msg} = "";
  1257. Log3 $mh{cHash},1,"CUL_HM $mh{devN} required key $mh{kNo} not defined in VCCU!";
  1258. }
  1259. }
  1260. else {
  1261. delete($mh{devH}->{helper}{aesCommRq});
  1262. }
  1263. }
  1264. }
  1265. if ($mh{msgStat}){
  1266. if ($mh{msgStat} =~ m/AESKey/){
  1267. push @evtEt,[$mh{devH},1,"aesKeyNbr:".substr($mh{msgStat},7)];
  1268. $mh{msgStat} = ""; # already processed
  1269. }
  1270. elsif($mh{msgStat} =~ m/AESpending/){# AES communication pending
  1271. push @evtEt,[$mh{devH},1,"aesCommToDev:pending"];
  1272. if ($mh{mTyp} eq "0204") {
  1273. my (undef,undef,$aesKeyNbr) = unpack'A2A12A2',$mh{p};
  1274. push @evtEt,[$mh{devH},1,"aesKeyNbr:".$aesKeyNbr] if (defined $aesKeyNbr);
  1275. }
  1276. #Do not process message further, as it may be faked
  1277. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devN}$/,@entities);
  1278. return (CUL_HM_pushEvnts(),$mh{devN});
  1279. }
  1280. elsif($mh{msgStat} =~ m/AESCom/){# AES communication to central
  1281. my $aesStat = substr($mh{msgStat},7);
  1282. push @evtEt,[$mh{devH},1,"aesCommToDev:".$aesStat];
  1283. ### General may need substential rework
  1284. # activate AES only for dedicated channels?
  1285. if($mh{mTp} =~ m/^4[01]/){ #someone is triggered##########
  1286. my $chn = hex($mI[0])& 0x3f;
  1287. my $cName = CUL_HM_id2Name($mh{src}.sprintf("%02X",$chn));
  1288. $cName = CUL_HM_id2Name($mh{src}) if (!defined($defs{$cName}));
  1289. my $bCnt = hex($mI[1]);
  1290. push @evtEt,[$defs{$cName},1,"trig_aes_$mh{dstN}:$aesStat:$bCnt"]
  1291. if (defined $defs{$cName});
  1292. if($aesStat eq "ok" #aes ok
  1293. && defined $mh{devH}->{cmdStacAESPend} #commands waiting
  1294. && $ioId eq $mh{dst}){ #aes from IO device
  1295. foreach (@{$mh{devH}->{cmdStacAESPend}}) {
  1296. my ($h,$c) = split(";",$_);
  1297. CUL_HM_PushCmdStack(CUL_HM_id2Hash($h),$c);
  1298. }
  1299. CUL_HM_ProcessCmdStack($mh{devH});
  1300. }
  1301. delete $mh{devH}->{cmdStacAESPend};
  1302. my @peers = grep !/00000000/,split(",",AttrVal($cName,"peerIDs",""));
  1303. foreach my $peer (grep /$mh{dst}/,@peers){
  1304. my $pName = CUL_HM_id2Name($peer);
  1305. $pName = CUL_HM_id2Name(substr($peer,0,6)) if (!$defs{$pName});
  1306. next if (!$defs{$pName});#||substr($peer,0,6) ne $mh{dst}
  1307. push @evtEt,[$defs{$pName},1,"trig_aes_$cName:$aesStat:$bCnt"];
  1308. }
  1309. }
  1310. if ($aesStat ne "ok") { #unauthenticated message, abort
  1311. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devH}->{NAME}$/,@entities);
  1312. return (CUL_HM_pushEvnts(),$mh{devN});
  1313. }
  1314. }
  1315. }
  1316. CUL_HM_eventP($mh{devH},"Evt_$mh{msgStat}")if ($mh{msgStat});#log io-events
  1317. CUL_HM_eventP($mh{devH},"Rcv");
  1318. my $target = " (to $mh{dstN})";
  1319. $mh{st} = AttrVal($mh{devN}, "subType", "");
  1320. $mh{md} = AttrVal($mh{devN}, "model" , "");
  1321. my $tn = TimeNow();
  1322. CUL_HM_storeRssi($mh{devN}
  1323. ,"at_".(($mh{mFlgH}&0x40)?"rpt_":"").$mh{ioName} # repeater?
  1324. ,$mh{myRSSI}
  1325. ,$mh{mNo});
  1326. # +++++ check for duplicate or repeat ++++
  1327. my $msgX = "No:$mh{mNo} - t:$mh{mTp} s:$mh{src} d:$mh{dst} ".($mh{p}?$mh{p}:"");
  1328. if($mh{devH}->{lastMsg} && $mh{devH}->{lastMsg} eq $msgX) { #duplicate -lost 'ack'?
  1329. if( $mh{devH}->{helper}{rpt} #was responded
  1330. && $mh{devH}->{helper}{rpt}{IO} eq $mh{ioName} #from same IO
  1331. && $mh{devH}->{helper}{rpt}{flg} eq substr($mh{msg},5,1) #not from repeater
  1332. && $mh{devH}->{helper}{rpt}{ts} < gettimeofday()-0.24 # again if older then 240ms (typ repeat time)
  1333. #todo: hack since HMLAN sends duplicate status messages
  1334. ){
  1335. my $ack = $mh{devH}->{helper}{rpt}{ack};#shorthand
  1336. my $i=0;
  1337. $mh{devH}->{helper}{rpt}{ts} = gettimeofday();
  1338. CUL_HM_SndCmd(${$ack}[$i++],${$ack}[$i++]
  1339. .($mh{devH}->{helper}{aesAuthBytes}
  1340. ?$mh{devH}->{helper}{aesAuthBytes}
  1341. :"")
  1342. ) while ($i<@{$ack});
  1343. delete($mh{devH}->{helper}{aesAuthBytes});
  1344. Log3 $mh{devN},4,"CUL_HM $mh{devN} dupe: repeat ".scalar(@{$ack})." ack, dont process";
  1345. }
  1346. else{
  1347. Log3 $mh{devN},4,"CUL_HM $mh{devN} dupe: dont process";
  1348. }
  1349. CUL_HM_pushEvnts();
  1350. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devH}->{NAME}$/,@entities);
  1351. CUL_HM_sndIfOpen("x:$mh{ioName}");
  1352. return (CUL_HM_pushEvnts(),$mh{devN},@entities); #return something to please dispatcher
  1353. }
  1354. delete $mh{devH}->{helper}{rpt};# new message, rm recent ack
  1355. my @ack; # ack and responses, might be repeated
  1356. CUL_HM_DumpProtocol("RCV",$iohash,$mh{len},$mh{mNo},$mh{mFlg},$mh{mTp},$mh{src},$mh{dst},$mh{p});
  1357. #----------start valid messages parsing ---------
  1358. my $parse = CUL_HM_parseCommon($iohash,\%mh);
  1359. $mh{devH}->{lastMsg} = $msgX;# is used in parseCommon and need previous setting. so set it here
  1360. push @evtEt,[$mh{devH},1,"powerOn:$tn"] if($parse eq "powerOn");
  1361. push @evtEt,[$mh{devH},1,""] if($parse eq "parsed"); # msg is parsed but may
  1362. # be processed further
  1363. if ($parse eq "ACK" ||
  1364. $parse eq "done" ){# remember - ACKinfo will be passed on
  1365. push @evtEt,[$mh{devH},1,""];
  1366. }
  1367. elsif($parse eq "NACK"){
  1368. push @evtEt,[$mh{shash},1,"state:NACK"];
  1369. }
  1370. elsif($parse eq "AES"){
  1371. return CUL_HM_pushEvnts();# exit now, don't send ACK
  1372. }
  1373. elsif($mh{mTp} eq "12") {#$lcm eq "09A112" Another fhem request (HAVE_DATA)
  1374. ;
  1375. }
  1376. elsif($mh{md} =~ m/^(KS550|KS888|HM-WDS100-C6-O)/) { ########################
  1377. if($mh{mTp} eq "70") {
  1378. my ($t,$h,$r,$w,$wd,$s,$b) = map{hex($_)} unpack 'A4A2A4A4(A2)*',$mh{p};
  1379. push @evtEt,[$mh{devH},1,"battery:". (($t & 0x8000)?"low" :"ok" )] if ($mh{md} eq "HM-WDS100-C6-O-2"); #has no battery
  1380. my $tsgn = ($t & 0x4000);
  1381. $t = ($t & 0x3fff)/10;
  1382. $t = sprintf("%0.1f", $t-1638.4) if($tsgn);
  1383. my $ir = ($r & 0x8000)?1:0;
  1384. $r = ($r & 0x7fff) * 0.295;
  1385. my $wdr = ($w>>14)*22.5;
  1386. $w = ($w & 0x3fff)/10;
  1387. $wd = $wd * 5;
  1388. my $sM = "state:";
  1389. if(defined $t) {$sM .= "T: $t " ;push @evtEt,[$mh{shash},1,"temperature:$t" ];}
  1390. if(defined $h) {$sM .= "H: $h " ;push @evtEt,[$mh{shash},1,"humidity:$h" ];}
  1391. if(defined $w) {$sM .= "W: $w " ;push @evtEt,[$mh{shash},1,"windSpeed:$w" ];}
  1392. if(defined $r) {$sM .= "R: $r " ;push @evtEt,[$mh{shash},1,"rain:$r" ];}
  1393. if(defined $ir) {$sM .= "IR: $ir " ;push @evtEt,[$mh{shash},1,"isRaining:$ir" ];}
  1394. if(defined $wd) {$sM .= "WD: $wd " ;push @evtEt,[$mh{shash},1,"windDirection:$wd" ];}
  1395. if(defined $wdr){$sM .= "WDR: $wdr ";push @evtEt,[$mh{shash},1,"windDirRange:$wdr" ];}
  1396. if(defined $s) {$sM .= "S: $s " ;push @evtEt,[$mh{shash},1,"sunshine:$s" ];}
  1397. if(defined $b) {$sM .= "B: $b " ;push @evtEt,[$mh{shash},1,"brightness:$b" ];}
  1398. push @evtEt,[$mh{shash},1,$sM];
  1399. }
  1400. elsif ($mh{mTp} eq "41"){
  1401. my ($chn,$state)=(hex($mI[0]),$mI[2]);
  1402. #my $cnt = hex($mI[1]);
  1403. my $txt;
  1404. if ($mh{cHash}->{helper}{lm} && $mh{cHash}->{helper}{lm}{hex($state)}){$txt = $mh{cHash}->{helper}{lm}{hex($state)}}
  1405. elsif ($lvlStr{md}{$mh{md}}) {$txt = $lvlStr{md}{$mh{md}}{$state}}
  1406. elsif ($lvlStr{st}{$mh{st}}) {$txt = $lvlStr{st}{$mh{st}}{$state}}
  1407. else {$txt = "unknown:$state"}
  1408. push @evtEt,[$mh{cHash},1,"storm:$txt"];
  1409. push @evtEt,[$mh{devH} ,1,"trig_$mh{chnHx}:$mh{dstN}"];
  1410. my $err = $chn & 0x80;
  1411. push @evtEt,[$mh{devH},1,"battery:". ($err?"low" :"ok" )] if ($mh{md} eq "HM-WDS100-C6-O-2"); #has no battery
  1412. }
  1413. else {
  1414. push @evtEt,[$mh{shash},1,"unknown:$mh{p}"];
  1415. }
  1416. }
  1417. elsif($mh{md} =~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/) { ######################
  1418. my $chn = $mI[1];
  1419. if( $mh{mTp} eq "70") { # weather event
  1420. $chn = '01'; # fix definition
  1421. my ($t,$h) = (hex($mI[0].$mI[1]), hex($mI[2]));# temp is 15 bit signed
  1422. $t &= 0x7fff;
  1423. $t = -1 - ($t ^ 0x7FFF) if ($t & 0x4000);
  1424. $t /= 10;
  1425. my $chnHash = $modules{CUL_HM}{defptr}{$mh{src}.$chn};
  1426. if ($chnHash){
  1427. push @evtEt,[$chnHash,1,"state:T: $t H: $h"];
  1428. push @evtEt,[$chnHash,1,"measured-temp:$t"];
  1429. push @evtEt,[$chnHash,1,"humidity:$h"];
  1430. }
  1431. push @evtEt,[$mh{shash},1,"state:T: $t H: $h"];
  1432. push @evtEt,[$mh{shash},1,"measured-temp:$t"];
  1433. push @evtEt,[$mh{shash},1,"humidity:$h"];
  1434. }
  1435. elsif( $mh{mTp} eq "58") {# climate event
  1436. $chn = '02'; # fix definition
  1437. my ( $d1, $vp) = # adjust_command[0..4] adj_data[0..250]
  1438. ( $mI[0], hex($mI[1]));
  1439. $vp = int($vp/2.56+0.5); # valve position in %
  1440. my $chnHash = $modules{CUL_HM}{defptr}{$mh{src}.$chn};
  1441. if($chnHash){
  1442. push @evtEt,[$chnHash,1,"state:$vp"];
  1443. if ($chnHash->{helper}{needUpdate}){
  1444. if ($chnHash->{helper}{needUpdate} == 1){
  1445. $chnHash->{helper}{needUpdate}++;
  1446. }
  1447. else{
  1448. CUL_HM_qStateUpdatIfEnab(":".$chnHash->{NAME});
  1449. delete $chnHash->{helper}{needUpdate};
  1450. }
  1451. }
  1452. }
  1453. push @evtEt,[$mh{devH},1,"actuator:$vp"];
  1454. # Set the valve state too, without an extra trigger
  1455. if($mh{dstH}){
  1456. push @evtEt,[$mh{dstH},1,"state:set_$vp" ];
  1457. push @evtEt,[$mh{dstH},1,"ValveDesired:$vp"];
  1458. }
  1459. }
  1460. elsif(($mh{mTyp} eq '0201')|| # ackStatus
  1461. ($mh{mTyp} eq '1006')){ # infoStatus
  1462. my $dTemp = hex($mI[2])/2;
  1463. $dTemp = ($dTemp < 6 )?'off':
  1464. ($dTemp >30 )?'on' :sprintf("%0.1f", $dTemp);
  1465. my $err = hex($mI[3]);
  1466. my $chnHash = $modules{CUL_HM}{defptr}{$mh{src}.$chn};
  1467. if($chnHash){
  1468. my $chnName = $chnHash->{NAME};
  1469. my $mode = ReadingsVal($chnName,"R-controlMode","");
  1470. push @evtEt,[$chnHash,1,"desired-temp:$dTemp"];
  1471. push @evtEt,[$chnHash,1,"desired-temp-manu:$dTemp"] if($mode =~ m/manual/ && $mh{mTp} eq '10');
  1472. $chnHash->{helper}{needUpdate} = 1 if($mode =~ m/central/ && $mh{mTp} eq '10');
  1473. }
  1474. push @evtEt,[$mh{shash},1,"desired-temp:$dTemp"];
  1475. push @evtEt,[$mh{devH},1,"battery:".($err&0x80?"low":"ok")];
  1476. }
  1477. elsif( $mh{mTp} eq "10" && # Config change report
  1478. ($mh{p} =~ m/^0402000000000501/)) { # paramchanged L5
  1479. my $chnHash = $modules{CUL_HM}{defptr}{$mh{src}.$chn};
  1480. my $dTemp;
  1481. if($chnHash){
  1482. my $chnName = $chnHash->{NAME};
  1483. my $mode = ReadingsVal($chnName,"R-controlMode","");
  1484. $dTemp = ReadingsVal($chnName,"desired-temp","21.0");
  1485. if (!$chnHash->{helper}{oldMode} || $chnHash->{helper}{oldMode} ne $mode){
  1486. $dTemp = ReadingsVal($chnName,"desired-temp-manu",$dTemp)if ($mode =~ m/manual/);
  1487. $dTemp = ReadingsVal($chnName,"desired-temp-cent",$dTemp)if ($mode =~ m/central/);
  1488. $chnHash->{helper}{oldMode} = $mode;
  1489. }
  1490. push @evtEt,[$chnHash,1,"desired-temp:$dTemp"];
  1491. }
  1492. push @evtEt,[$mh{shash},1,"desired-temp:$dTemp"]
  1493. }
  1494. elsif( $mh{mTp} eq "01"){ # status reports
  1495. if($mh{p} =~ m/^010809(..)0A(..)/) { # TC set valve for VD => post events to VD
  1496. my ( $of, $vep) = (hex($1), hex($2));
  1497. push @evtEt,[$mh{devH},1,"ValveErrorPosition_for_$mh{dstN}: $vep"];
  1498. push @evtEt,[$mh{devH},1,"ValveOffset_for_$mh{dstN}: $of"];
  1499. push @evtEt,[$mh{dstH},1,"ValveErrorPosition:set_$vep"];
  1500. push @evtEt,[$mh{dstH},1,"ValveOffset:set_$of"];
  1501. }
  1502. elsif($mh{p} =~ m/^010[56]/){ # 'prepare to set' or 'end set'
  1503. push @evtEt,[$mh{shash},1,""]; #
  1504. }
  1505. }
  1506. elsif( $mh{mTp} eq "3F" && $ioId eq $mh{dst}) { # Timestamp request
  1507. my $s2000 = sprintf("%02X", CUL_HM_secSince2000());
  1508. push @ack,$mh{shash},"$mh{mNo}803F$ioId$mh{src}0204$s2000";
  1509. push @evtEt,[$mh{shash},1,"time-request"];
  1510. }
  1511. }
  1512. elsif($mh{md} =~ m/^(HM-CC-VD|ROTO_ZEL-STG-RM-FSA)/) { ######################
  1513. if($mh{mTp} eq "02" && @mI > 2) {#subtype+chn+value+err
  1514. my ($chn,$vp, $err) = map{hex($_)} @mI[1..3];
  1515. $chn = sprintf("%02X",$chn&0x3f);
  1516. $vp = int($vp)/2; # valve position in %
  1517. push @evtEt,[$mh{shash},1,"ValvePosition:$vp"];
  1518. push @evtEt,[$mh{shash},1,"state:$vp"];
  1519. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  1520. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  1521. my $stErr = ($err >>1) & 0x7; # Status-Byte Evaluation
  1522. push @evtEt,[$mh{devH},1,"battery:".(($stErr == 4)?"critical":($err&0x80?"low":"ok"))];
  1523. if (!$stErr){#remove both conditions
  1524. push @evtEt,[$mh{devH},1,"motorErr:ok"];
  1525. }
  1526. else{
  1527. push @evtEt,[$mh{devH},1,"motorErr:blocked" ]if($stErr == 1);
  1528. push @evtEt,[$mh{devH},1,"motorErr:loose" ]if($stErr == 2);
  1529. push @evtEt,[$mh{devH},1,"motorErr:adjusting range too small"]if($stErr == 3);
  1530. # push @evtEt,[$mh{shash},1,"battery:critical" ]if($stErr == 4);
  1531. }
  1532. push @evtEt,[$mh{devH},1,"motor:opening"] if(($err&0x30) == 0x10);
  1533. push @evtEt,[$mh{devH},1,"motor:closing"] if(($err&0x30) == 0x20);
  1534. push @evtEt,[$mh{devH},1,"motor:stop" ] if(($err&0x30) == 0x00);
  1535. #VD hang detection
  1536. my $des = ReadingsVal($mh{devN}, "ValveDesired", $vp);
  1537. $des =~ s/ .*//; # remove unit
  1538. if (($des < $vp-1 || $des > $vp+1) && ($err&0x30) == 0x00){
  1539. if ($mh{shash}->{helper}{oldDes} eq $des){#desired valve position stable
  1540. push @evtEt,[$mh{shash},1,"operState:errorTargetNotMet"];
  1541. push @evtEt,[$mh{shash},1,"operStateErrCnt:".(ReadingsVal($mh{devN},"operStateErrCnt","0")+1)];
  1542. }
  1543. else{
  1544. push @evtEt,[$mh{shash},1,"operState:changed"];
  1545. }
  1546. }
  1547. else{
  1548. push @evtEt,[$mh{shash},1,"operState:".((($err&0x30) == 0x00)?"onTarget":"adjusting")];
  1549. }
  1550. $mh{shash}->{helper}{oldDes} = $des;
  1551. }
  1552. }
  1553. elsif($mh{md} =~ m/^HM-CC-RT-DN/) { #########################################
  1554. my %ctlTbl=( 0=>"auto", 1=>"manual", 2=>"party",3=>"boost");
  1555. if(($mh{mTyp} eq "100A") || #info-level/
  1556. ($mh{mTyp} eq "0201")) {#ackInfo
  1557. my %errTbl=( 0=>"ok", 1=>"ValveTight", 2=>"adjustRangeTooLarge"
  1558. ,3=>"adjustRangeTooSmall" , 4=>"communicationERR"
  1559. ,5=>"unknown", 6=>"lowBat", 7=>"ValveErrorPosition" );
  1560. my ($err ,$ctrlMode ,$setTemp ,$bTime,$pTemp,$pStart,$pEnd,$chn,$uk0,$lBat,$actTemp,$vp) =
  1561. (hex($mI[3]),hex($mI[5]),hex($mI[1].$mI[2]),"-" ,"-" ,"-" ,"-" );
  1562. if($mh{mTp} eq "10"){
  1563. $chn = "04";#fixed
  1564. my $bat =(($err ) & 0x1f)/10+1.5;
  1565. $actTemp =sprintf("%2.1f",((($setTemp ) & 0x3ff)/10));
  1566. $vp = (hex($mI[4]) ) & 0x7f ;
  1567. $setTemp = ($setTemp >>10);
  1568. $err = ($err >> 5);
  1569. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"} if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  1570. push @evtEt,[$mh{shash},1,"measured-temp:$actTemp" ];
  1571. push @evtEt,[$mh{shash},1,"ValvePosition:$vp" ];
  1572. #device---
  1573. push @evtEt,[$mh{devH},1,"measured-temp:$actTemp"];
  1574. push @evtEt,[$mh{devH},1,"batteryLevel:$bat"];
  1575. push @evtEt,[$mh{devH},1,"actuator:$vp"];
  1576. if ($err == 6){ $lBat = "low";}
  1577. elsif($err == 0){ $lBat = "ok";}# we cannot determin bat if any other state!
  1578. #weather Chan
  1579. my $wHash = $modules{CUL_HM}{defptr}{$mh{src}."01"};
  1580. if ($wHash){
  1581. push @evtEt,[$wHash,1,"measured-temp:$actTemp"];
  1582. push @evtEt,[$wHash,1,"state:$actTemp"];
  1583. }
  1584. }
  1585. else{
  1586. $chn = $mI[1];
  1587. $setTemp = ($setTemp );
  1588. $lBat = $err&0x80?"low":"ok"; # prior to changes of $err!
  1589. $err = ($err >> 1);
  1590. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"} if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  1591. $actTemp = ReadingsVal($mh{devN},"measured-temp","");
  1592. $vp = ReadingsVal($mh{devN},"actuator","");
  1593. }
  1594. delete $mh{devH}->{helper}{getBatState};
  1595. $setTemp =(($setTemp ) & 0x3f )/2;
  1596. $err = ($err ) & 0x7 ;
  1597. $uk0 = ($ctrlMode ) & 0x3f ;#unknown
  1598. $ctrlMode = ($ctrlMode >> 6) & 0x3 ;
  1599. $setTemp = ($setTemp < 5 )?'off':
  1600. ($setTemp >30 )?'on' :sprintf("%.1f",$setTemp);
  1601. if (defined $mI[12]){# message with party mode
  1602. my @pt = map{hex($_)} @mI[5..$#mI];
  1603. $pTemp =(($pt[7] )& 0x3f)/2 if (defined $pt[7]) ;
  1604. my $sta = ( ($pt[0] )& 0x3f)/2;
  1605. $pStart = (($pt[2] )& 0x7f) # year
  1606. ."-".(($pt[6] >> 4)& 0x0f) # month
  1607. ."-".(($pt[1] )& 0x1f) # day
  1608. ." ".int($sta) # Time h
  1609. .":".(int($sta)!=$sta?"30":"00")# Time min
  1610. ;
  1611. my $et = ( ($pt[3] )& 0x3f)/2;
  1612. $pEnd = (($pt[5] )& 0x7f) # year
  1613. ."-".(($pt[6] )& 0x0f) # month
  1614. ."-".(($pt[4] )& 0x1f) # day
  1615. ." ".int($et) # Time h
  1616. .":".(int($et)!=$et?"30":"00")# Time min
  1617. ;
  1618. }
  1619. elsif(defined $mI[5] && $ctrlMode == 3 ){#message with boost
  1620. $bTime = ((hex($mI[5]) ) & 0x3f)." min";
  1621. }
  1622. my $climaHash = CUL_HM_id2Hash($mh{src}."04");# always to Clima channel
  1623. push @evtEt,[$climaHash,1,"desired-temp:$setTemp" ];
  1624. push @evtEt,[$climaHash,1,"controlMode:$ctlTbl{$ctrlMode}"];
  1625. push @evtEt,[$climaHash,1,"state:T: $actTemp desired: $setTemp valve: $vp"];
  1626. push @evtEt,[$climaHash,1,"boostTime:$bTime"];
  1627. push @evtEt,[$climaHash,1,"partyStart:$pStart"];
  1628. push @evtEt,[$climaHash,1,"partyEnd:$pEnd"];
  1629. push @evtEt,[$climaHash,1,"partyTemp:$pTemp"];
  1630. #push @evtEt,[$mh{shash},1,"unknown0:$uk0"];
  1631. #push @evtEt,[$mh{shash},1,"unknown1:".$2 if ($p =~ m/^0A(.10)(.*)/)];
  1632. push @evtEt,[$mh{devH},1,"motorErr:$errTbl{$err}" ] if($mh{mTp} eq "10");
  1633. push @evtEt,[$mh{devH},1,"battery:$lBat"] if ($lBat);
  1634. push @evtEt,[$mh{devH},1,"desired-temp:$setTemp"];
  1635. }
  1636. elsif($mh{mTp} eq "59" && defined $mI[0]) {#inform team about new value
  1637. my $setTemp = sprintf("%.1f",int(hex($mI[0])/4)/2);
  1638. my $ctrlMode = hex($mI[0])&0x3;
  1639. push @evtEt,[$mh{shash},1,"desired-temp:$setTemp"];
  1640. push @evtEt,[$mh{shash},1,"controlMode:$ctlTbl{$ctrlMode}"];
  1641. my $tHash = $modules{CUL_HM}{defptr}{$mh{dst}."04"};
  1642. if ($tHash){
  1643. push @evtEt,[$tHash,1,"desired-temp:$setTemp"];
  1644. push @evtEt,[$tHash,1,"controlMode:$ctlTbl{$ctrlMode}"];
  1645. }
  1646. }
  1647. elsif($mh{mTp} eq "3F" && $ioId eq $mh{dst}) { # Timestamp request
  1648. my $s2000 = sprintf("%02X", CUL_HM_secSince2000());
  1649. push @ack,$mh{shash},"$mh{mNo}803F$ioId$mh{src}0204$s2000";
  1650. push @evtEt,[$mh{shash},1,"time-request"];
  1651. # schedule desired-temp just to get an AckInfo for battery state
  1652. $mh{shash}->{helper}{getBatState} = 1;
  1653. }
  1654. }
  1655. elsif($mh{md} eq "HM-TC-IT-WM-W-EU") { ######################################
  1656. my %ctlTbl=( 0=>"auto", 1=>"manual", 2=>"party",3=>"boost");
  1657. if( ( $mh{mTp} eq "10" && $mI[0] eq '0B') #info-level
  1658. ||( $mh{mTp} eq "02" && $mI[0] eq '01')) {#ack-status
  1659. my @d = map{hex($_)} unpack 'A2A4(A2)*',$mh{p};
  1660. my ($setTemp,$actTemp, $cRep,$wRep,$bat ,$lbat,$ctrlMode,$bTime,$pTemp,$pStart,$pEnd) =
  1661. ($d[1],$d[1], $d[2],$d[2],$d[2],$d[2],"" ,"-" ,"-" ,"-" ,"-");
  1662. CUL_HM_m_setCh(\%mh,"02");
  1663. $lbat = ($lbat ) & 0x80;
  1664. if ($mh{mTp} eq "10"){
  1665. $ctrlMode = $d[3];
  1666. $bat =(($bat ) & 0x1f)/10+1.5;
  1667. $setTemp =(($setTemp >>10) & 0x3f )/2;
  1668. $actTemp =(($actTemp ) & 0x3ff)/10;
  1669. $actTemp = -1 * $actTemp if ($d[1] & 0x200 );# obey signed
  1670. $actTemp = sprintf("%2.1f",$actTemp);
  1671. push @evtEt,[$mh{cHash},1,"measured-temp:$actTemp"];
  1672. push @evtEt,[$mh{devH},1,"measured-temp:$actTemp"];
  1673. push @evtEt,[$mh{devH},1,"batteryLevel:$bat"];
  1674. $cRep = (($cRep >>6) & 0x01 )?"on":"off";
  1675. $wRep = (($wRep >>5) & 0x01 )?"on":"off";
  1676. }
  1677. else{#actTemp is not provided in ack message - use old value
  1678. $ctrlMode = $d[4];
  1679. $actTemp = ReadingsVal($mh{devN},"measured-temp",0);
  1680. $setTemp =(hex($mI[2]) & 0x3f )/2;
  1681. $cRep = (($cRep >>2) & 0x01 )?"on":"off";
  1682. $wRep = (($wRep >>1) & 0x01 )?"on":"off";
  1683. }
  1684. $ctrlMode = ($ctrlMode >> 6) & 0x3 ;
  1685. $setTemp = ($setTemp < 5 )?'off':
  1686. ($setTemp >30 )?'on' :sprintf("%.1f",$setTemp);
  1687. if (defined $d[11]){# message with party mode
  1688. $pTemp =(($d[11] )& 0x3f)/2 if (defined $d[11]) ;
  1689. my @p;
  1690. if ($mh{mTp} eq "10") {@p = @d[3..9]}
  1691. else {@p = @d[4..10]}
  1692. my $sta = (($p[0] )& 0x3f)/2;
  1693. $pStart = (($p[2] )& 0x7f) # year
  1694. ."-".(($p[6] >> 4)& 0x0f) # month
  1695. ."-".(($p[1] )& 0x1f) # day
  1696. ." ".int($sta) # Time h
  1697. .":".(int($sta)!=$sta?"30":"00")# Time min
  1698. ;
  1699. my $et = (($p[3] )& 0x3f)/2;
  1700. $pEnd = (($p[5] )& 0x7f) # year
  1701. ."-".(($p[6] )& 0x0f) # month
  1702. ."-".(($p[4] )& 0x1f) # day
  1703. ." ".int($et) # Time h
  1704. .":".(int($et)!=$et?"30":"00")# Time min
  1705. ;
  1706. push @evtEt,[$mh{cHash},1,"partyStart:$pStart"];
  1707. push @evtEt,[$mh{cHash},1,"partyEnd:$pEnd"];
  1708. push @evtEt,[$mh{cHash},1,"partyTemp:$pTemp"];
  1709. }
  1710. elsif(defined $d[3] && $ctrlMode == 3 ){#message with boost
  1711. $bTime = (($d[3] ) & 0x3f)." min";
  1712. }
  1713. push @evtEt,[$mh{cHash},1,"desired-temp:$setTemp"];
  1714. push @evtEt,[$mh{cHash},1,"controlMode:$ctlTbl{$ctrlMode}"];
  1715. push @evtEt,[$mh{cHash},1,"state:T: $actTemp desired: $setTemp"];
  1716. push @evtEt,[$mh{cHash},1,"commReporting:$cRep"];
  1717. push @evtEt,[$mh{cHash},1,"winOpenReporting:$wRep"];
  1718. push @evtEt,[$mh{cHash},1,"boostTime:$bTime"];
  1719. push @evtEt,[$mh{devH},1,"battery:".($lbat?"low":"ok")];
  1720. push @evtEt,[$mh{devH},1,"desired-temp:$setTemp"];
  1721. }
  1722. elsif($mh{mTp} eq "70"){
  1723. my $chn = "01";
  1724. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  1725. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  1726. my ($t,$h) = map{hex($_)} unpack 'A4A2',$mh{p};
  1727. $t &= 0x7fff;
  1728. $t -= 0x8000 if($t & 0x4000);
  1729. $t = sprintf("%0.1f", $t/10);
  1730. push @evtEt,[$mh{shash},1,"temperature:$t"];
  1731. push @evtEt,[$mh{shash},1,"humidity:$h"];
  1732. push @evtEt,[$mh{shash},1,"state:T: $t H: $h"];
  1733. }
  1734. elsif($mh{mTp} eq "5A"){# thermal control - might work with broadcast
  1735. my $chn = "02";
  1736. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  1737. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  1738. my ($t,$h) = map{hex($_)} unpack 'A4A2',$mh{p};
  1739. my $setTemp =(($t >>10) & 0x3f )/2;
  1740. my $actTemp =(($t ) & 0x3ff)/10;
  1741. $actTemp = sprintf("%2.1f",$actTemp);
  1742. $setTemp = ($setTemp < 5 )?'off':
  1743. ($setTemp >30 )?'on' :sprintf("%.1f",$setTemp);
  1744. push @evtEt,[$mh{shash},1,"measured-temp:$actTemp"];
  1745. push @evtEt,[$mh{shash},1,"desired-temp:$setTemp"];
  1746. push @evtEt,[$mh{shash},1,"humidity:$h"];
  1747. push @evtEt,[$mh{shash},1,"state:T: $actTemp desired: $setTemp"];
  1748. }
  1749. elsif($mh{mTp} =~ m/^4./) {
  1750. my ($chn,$lvl) = ($mI[0],hex($mI[2])/2);
  1751. my $chnHash = $modules{CUL_HM}{defptr}{$mh{src}.$chn};
  1752. if ($chnHash){
  1753. push @evtEt,[$chnHash,1,"level:$lvl"];
  1754. }
  1755. }
  1756. elsif($mh{mTp} eq "3F" && $ioId eq $mh{dst}) { # Timestamp request
  1757. my $s2000 = sprintf("%02X", CUL_HM_secSince2000());
  1758. push @ack,$mh{shash},"$mh{mNo}803F$ioId$mh{src}0204$s2000";
  1759. push @evtEt,[$mh{shash},1,"time-request"];
  1760. }
  1761. }
  1762. elsif($mh{md} =~ m/^(HM-Sen-Wa-Od|HM-CC-SCD)$/){ ############################
  1763. if (($mh{mTyp} eq "0201") || # handle Ack_Status
  1764. ($mh{mTyp} eq "1006") || #or Info_Status message here
  1765. ($mh{mTp} eq "41")) {
  1766. my $lvl = $mI[2];
  1767. my $err = ($mh{mTp} eq "41") ? hex($mI[0]) : ($mI[3] ? hex($mI[3]) : "");
  1768. if ($lvlStr{md}{$mh{md}}){$lvl = $lvlStr{md}{$mh{md}}{$lvl}}
  1769. elsif ($lvlStr{st}{$mh{st}}){$lvl = $lvlStr{st}{$mh{st}}{$lvl} }
  1770. else {$lvl = hex($lvl)/2}
  1771. push @evtEt,[$mh{shash},1,"level:$lvl"] if($mh{md} eq "HM-Sen-Wa-Od");
  1772. push @evtEt,[$mh{shash},1,"state:$lvl"];
  1773. push @evtEt,[$mh{devH} ,1,"battery:".($err&0x80?"low":"ok")] if ($err ne "");
  1774. }
  1775. }
  1776. elsif($mh{md} eq "KFM-Sensor") { ############################################
  1777. if ($mh{mTp} eq "53"){
  1778. if($mh{p} =~ m/^(..)4(.)0200(..)(..)(..)/) {
  1779. my ($chn,$seq, $k_v1, $k_v2, $k_v3) = (hex($1),hex($2),$3,hex($4),hex($5));
  1780. push @evtEt,[$mh{devH},1,"battery:".($chn & 0x80?"low":"ok")];
  1781. my $v = 1408 - ((($k_v3 & 0x07)<<8) + $k_v2);
  1782. push @evtEt,[$mh{shash},1,"rawValue:$v"];
  1783. my $nextSeq = ReadingsVal($mh{devN},"Sequence","");
  1784. $nextSeq =~ s/_.*//;
  1785. $nextSeq = ($nextSeq %15)+1;
  1786. push @evtEt,[$mh{shash},1,"Sequence:$seq".($nextSeq ne $seq?"_seqMiss":"")];
  1787. my $r2r = AttrVal($mh{devN}, "rawToReadable", undef);
  1788. if($r2r) {
  1789. my @r2r = split("[ :]", $r2r);
  1790. foreach(my $idx = 0; $idx < @r2r-2; $idx+=2) {
  1791. if($v >= $r2r[$idx] && $v <= $r2r[$idx+2]) {
  1792. my $f = (($v-$r2r[$idx])/($r2r[$idx+2]-$r2r[$idx]));
  1793. my $cv = ($r2r[$idx+3]-$r2r[$idx+1])*$f + $r2r[$idx+1];
  1794. my $unit = AttrVal($mh{devN}, "unit", "");
  1795. push @evtEt,[$mh{shash},1,sprintf("state:%.1f %s",$cv,$unit)];
  1796. push @evtEt,[$mh{shash},1,sprintf("content:%.1f %s",$cv,$unit)];
  1797. last;
  1798. }
  1799. }
  1800. }
  1801. else {
  1802. push @evtEt,[$mh{shash},1,"state:$v"];
  1803. }
  1804. }
  1805. }
  1806. }
  1807. elsif($mh{st} eq "THSensor") { ##############################################
  1808. if ($mh{mTp} eq "70"){
  1809. my $chn;
  1810. my ($d1,$h,$ap) = map{hex($_)} unpack 'A4A2A4',$mh{p};
  1811. if ($mh{md} =~ m/^(WS550|WS888|HM-WDC7000)/){$chn = "10"}
  1812. elsif ($mh{md} =~ m/^HM-WDS30-OT2-SM/) {$chn = "05";$h=""}
  1813. elsif ($mh{md} =~ m/^(S550IA|HM-WDS30-T-O)/) {$chn = "01";$h=""}
  1814. else {$chn = "01"}
  1815. my $t = $d1 & 0x7fff;
  1816. $t -= 0x8000 if($t &0x4000);
  1817. $t = sprintf("%0.1f", $t/10);
  1818. my $statemsg = "state:T: $t";
  1819. push @evtEt,[$mh{shash},1,"temperature:$t"];#temp is always there
  1820. push @evtEt,[$mh{devH},1,"battery:".($d1 & 0x8000?"low":"ok")];
  1821. if($modules{CUL_HM}{defptr}{$mh{src}.$chn}){
  1822. my $ch = $modules{CUL_HM}{defptr}{$mh{src}.$chn};
  1823. push @evtEt,[$ch,1,$statemsg];
  1824. push @evtEt,[$ch,1,"temperature:$t"];
  1825. }
  1826. if ($h) {$statemsg .= " H: $h" ; push @evtEt,[$mh{shash},1,"humidity:$h"]; }
  1827. if ($ap){$statemsg .= " AP: $ap"; push @evtEt,[$mh{shash},1,"airpress:$ap"];}
  1828. push @evtEt,[$mh{shash},1,$statemsg];
  1829. }
  1830. elsif ($mh{mTp} eq "53"){
  1831. my ($chn,@dat) = unpack 'A2(A6)*',$mh{p};
  1832. push @evtEt,[$mh{devH},1,"battery:".(hex($chn)&0x80?"low":"ok")];
  1833. foreach (@dat){
  1834. my ($a,$d) = unpack 'A2A4',$_;
  1835. $d = hex($d);
  1836. $d -= 0x10000 if($d & 0xC000);
  1837. $d = sprintf("%0.1f",$d/10);
  1838. my $chId = sprintf("%02X",hex($a) & 0x3f);
  1839. my $chnHash = $modules{CUL_HM}{defptr}{$mh{src}.$chId};
  1840. if ($chnHash){
  1841. push @evtEt,[$chnHash,1,"state:T: $d"];
  1842. push @evtEt,[$chnHash,1,"temperature:$d"];
  1843. }
  1844. else{
  1845. push @evtEt,[$mh{shash},1,"Chan_$chId:T: $d"];
  1846. }
  1847. }
  1848. }
  1849. }
  1850. elsif($mh{st} eq "sensRain") {###############################################
  1851. my $hHash = CUL_HM_id2Hash($mh{src}."02");# hash for heating
  1852. my $pon = 0;# power on if mNo == 0 and heating status plus second msg
  1853. # status or trigger from rain channel
  1854. if (($mh{mTyp} eq "0201") || #Ack_Status
  1855. ($mh{mTyp} eq "1006")) { #Info_Status
  1856. my ($subType,$chn,$val,$err) = ($mI[0],hex($mI[1]),$mI[2],hex($mI[3]));
  1857. $chn = sprintf("%02X",$chn&0x3f);
  1858. my $chId = $mh{src}.$chn;
  1859. $mh{shash} = $modules{CUL_HM}{defptr}{$chId}
  1860. if($modules{CUL_HM}{defptr}{$chId});
  1861. my ($timedOn,$stateExt)=("off","");
  1862. if($err&0x40 && $chn eq "02"){
  1863. $timedOn = "running";
  1864. $stateExt = "-till" if(AttrVal($mh{cName},"param","") =~ m/showTimed/ );
  1865. }
  1866. push @evtEt,[$mh{cHash},1,"timedOn:$timedOn"];
  1867. my $mdCh = $mh{md}.$chn;
  1868. if($lvlStr{mdCh}{$mdCh} && $lvlStr{mdCh}{$mdCh}{$val}){
  1869. $val = $lvlStr{mdCh}{$mdCh}{$val};
  1870. }
  1871. else{
  1872. $val = hex($val)/2;
  1873. }
  1874. push @evtEt,[$mh{shash},1,"state:$val$stateExt"];
  1875. if ($val eq "rain"){#--- handle lastRain---
  1876. $mh{shash}->{helper}{lastRain} = $tn;
  1877. }
  1878. elsif ($val eq "dry" && $mh{shash}->{helper}{lastRain}){
  1879. push @evtEt,[$mh{shash},0,"lastRain:$mh{shash}->{helper}{lastRain}"];
  1880. delete $mh{shash}->{helper}{lastRain};
  1881. }
  1882. push @evtEt,[$mh{shash},0,'.level:'.($val eq "off"?"0":"100")];
  1883. if ($mh{mNo} eq "00" && $chn eq "02" && $val eq "on"){
  1884. $hHash->{helper}{pOn} = 1;
  1885. }
  1886. elsif ($mh{mNo} eq "01" && $chn eq "01" &&
  1887. $hHash->{helper}{pOn} && $hHash->{helper}{pOn} == 1){
  1888. $pon = 1;
  1889. }
  1890. else{
  1891. delete $hHash->{helper}{pOn};
  1892. my $hHash = CUL_HM_id2Hash($mh{src}."02");# hash for heating
  1893. if ($chn eq "01" &&
  1894. $hHash->{helper}{param} && $hHash->{helper}{param}{onAtRain}){
  1895. CUL_HM_Set($hHash,$hHash->{NAME},$val eq "rain"?"on":"off");
  1896. }
  1897. }
  1898. }
  1899. elsif ($mh{mTp} eq "41") { #eventonAtRain
  1900. my ($chn,$bno,$val) = @mI;
  1901. $chn = sprintf("%02X",hex($chn)&0x3f);
  1902. $mh{shash} = $modules{CUL_HM}{defptr}{$mh{src}.$chn}
  1903. if($modules{CUL_HM}{defptr}{$mh{src}.$chn});
  1904. push @evtEt,[$mh{shash},1,"trigger:".hex($bno).":".$lvlStr{mdCh}{$mh{md}.$chn}{$val}.$target];
  1905. if ($mh{mNo} eq "01" && $bno eq "01" &&
  1906. $hHash->{helper}{pOn} && $hHash->{helper}{pOn} == 1){
  1907. $pon = 1;
  1908. }
  1909. delete $mh{shash}->{helper}{pOn};
  1910. }
  1911. if ($pon){# we have power ON, perform action
  1912. if($mh{devH}->{helper}{PONtest}){
  1913. push @evtEt,[$mh{devH},1,"powerOn:$tn",];
  1914. $mh{devH}->{helper}{PONtest} = 0;
  1915. }
  1916. CUL_HM_Set($hHash,$hHash->{NAME},"off")
  1917. if ($hHash && $hHash->{helper}{param}{offAtPon});
  1918. }
  1919. }
  1920. elsif($mh{st} =~ m/^(switch|dimmer|blindActuator|rgb)$/) {###################
  1921. if (($mh{mTyp} eq "0201") || # handle Ack_Status
  1922. ($mh{mTyp} eq "1006")) { # or Info_Status message here
  1923. my $rSUpdt = 0;# require status update
  1924. my ($val,$err) = (hex($mI[2]),hex($mI[3]));
  1925. $val /= 2 if ($mh{st} ne "rgb" || $mh{chn} != 3);
  1926. CUL_HM_m_setCh(\%mh,$mI[1]);
  1927. my($lvlMin,$lvlMax)=split",",AttrVal($mh{cName}, "levelRange", "0,100");
  1928. my $physLvl; #store phys level if available
  1929. if( defined $mI[5] #message with physical level?
  1930. && $mh{st} eq "dimmer"){
  1931. my $pl = hex($mI[5])/2;
  1932. my $vDim = $mh{cHash}->{helper}{vDim}; #shortcut
  1933. if ($vDim->{idPhy} &&
  1934. CUL_HM_id2Hash($vDim->{idPhy})){ #has virt chan
  1935. RemoveInternalTimer("sUpdt:".$mh{src}.$mh{chnM});
  1936. if ($mh{mTp} eq "10"){ #valid PhysLevel
  1937. foreach my $tmpKey ("idPhy","idV2","idV3",){#update all virtuals
  1938. my $vh = ($vDim->{$tmpKey} ? CUL_HM_id2Hash($vDim->{$tmpKey}) : "");
  1939. next if (!$vh || $vDim->{$tmpKey} eq $mh{src}.$mh{chnM});
  1940. my $vl = ReadingsVal($vh->{NAME},"level","???");
  1941. my $vs = ($vl eq "100"?"on":($vl eq "0"?"off":"$vl"));
  1942. my($clvlMin,$clvlMax)=split",",AttrVal($vh->{NAME}, "levelRange", "0,100");
  1943. my $plc = int((($pl-$clvlMin)*200)/($clvlMax - $clvlMin))/2;
  1944. $plc = 1 if ($pl && $plc <= 0);
  1945. $vs = ($plc ne $vl)?"chn:$vs phys:$plc":$vs;
  1946. push @evtEt,[$vh,1,"state:$vs"];
  1947. push @evtEt,[$vh,1,"phyLevel:$pl"];
  1948. }
  1949. push @evtEt,[$mh{cHash},1,"phyLevel:$pl"]; #phys level,don't use relative adjustment
  1950. $pl = (($pl-$lvlMin)<=0 && $pl)
  1951. ? ($pl?1:0)
  1952. : int((($pl-$lvlMin)*200)/($lvlMax - $lvlMin))/2;
  1953. $physLvl = $pl;
  1954. }
  1955. else{ #invalid PhysLevel
  1956. $rSUpdt = 1;
  1957. CUL_HM_stateUpdatDly($mh{cName},5) if ($mh{cHash}->{helper}{dlvl});# update to get level
  1958. }
  1959. }
  1960. }
  1961. my $pVal = $val;# necessary for oper 'off', not logical off
  1962. $val = (($val-$lvlMin)<=0)
  1963. ? ($val?1:0)
  1964. : int((($val-$lvlMin)*200)/($lvlMax - $lvlMin))/2;
  1965. # blind option: reverse Level Meaning 0 = open, 100 = closed
  1966. if (AttrVal($mh{cName}, "param", "") =~ m/levelInverse/){;
  1967. $pVal = $val = 100-$val;
  1968. }
  1969. if(!defined $physLvl){ #not updated? use old or ignore
  1970. $physLvl = ReadingsVal($mh{cName},"phyLevel",$val);
  1971. $physLvl = (($physLvl-$lvlMin)<=0 && $physLvl)
  1972. ? ($physLvl?1:0)
  1973. : int((($physLvl-$lvlMin)*200)/($lvlMax - $lvlMin))/2;
  1974. }
  1975. my $vs = ($mh{cHash}->{helper}{lm} && $mh{cHash}->{helper}{lm}{$val})
  1976. ?$mh{cHash}->{helper}{lm}{$val}
  1977. :($val==100 ? "on"
  1978. :($pVal==0 ? "off"
  1979. : "$val")); # user string...
  1980. #-- if timed on is set possibly show this in a state --
  1981. my ($timedOn,$stateExt)=("off","");
  1982. if($err&0x40){
  1983. $timedOn = "running";
  1984. $stateExt = "-till" if(AttrVal($mh{cName},"param","") =~ m/showTimed/ );
  1985. }
  1986. push @evtEt,[$mh{cHash},1,"level:$val"];
  1987. push @evtEt,[$mh{cHash},1,"pct:$val"]; # duplicate to level - necessary for "slider"
  1988. push @evtEt,[$mh{cHash},1,"deviceMsg:$vs$target"] if($mh{chnM} ne "00");
  1989. push @evtEt,[$mh{cHash},1,"state:".(($physLvl ne $val)?"chn:$vs phys:$physLvl":$vs.$stateExt)];
  1990. push @evtEt,[$mh{cHash},1,"timedOn:$timedOn"];
  1991. if ($mh{cHash}->{helper}{dlvl} && defined $err){#are we waiting?
  1992. if ($mI[2] ne $mh{cHash}->{helper}{dlvl} #level not met?
  1993. && !($err&0x70)){ #and already stopped not timedOn
  1994. #level not met, repeat
  1995. Log3 $mh{cName},3,"CUL_HM $mh{cName} repeat, level $mI[2] instead of $mh{cHash}->{helper}{dlvl}";
  1996. if ($mh{cHash}->{helper}{dlvlCmd}){# first try
  1997. CUL_HM_PushCmdStack($mh{cHash},$mh{cHash}->{helper}{dlvlCmd});
  1998. CUL_HM_ProcessCmdStack($mh{cHash});
  1999. delete $mh{cHash}->{helper}{dlvlCmd};# will prevent second try
  2000. }
  2001. else{# no second try - alarm and stop
  2002. push @evtEt,[$mh{cHash},1,"levelMissed:desired:".hex($mh{cHash}->{helper}{dlvl})/2];
  2003. delete $mh{cHash}->{helper}{dlvl};# we only make one attempt
  2004. }
  2005. }
  2006. else{# either level met, timed on or we are driving...
  2007. delete $mh{cHash}->{helper}{dlvl};
  2008. }
  2009. }
  2010. if ($mh{st} ne "switch"){
  2011. my $eventName = "unknown"; # different names for events
  2012. if ($mh{st} eq "blindActuator") {$eventName = "motor" ;}
  2013. elsif($mh{st} =~ m/^(dimmer|rgb)$/) {$eventName = "dim" ;}
  2014. my $dir = ($err >> 4) & 3;
  2015. my %dirName = ( 0=>"stop" ,1=>"up" ,2=>"down" ,3=>"err" );
  2016. push @evtEt,[$mh{cHash},1,"$eventName:$dirName{$dir}:$vs" ];
  2017. $mh{cHash}->{helper}{dir}{rct} = $mh{cHash}->{helper}{dir}{cur}
  2018. if($mh{cHash}->{helper}{dir}{cur} &&
  2019. $mh{cHash}->{helper}{dir}{cur} ne $dirName{$dir});
  2020. $mh{cHash}->{helper}{dir}{cur} = $dirName{$dir};
  2021. }
  2022. if (!$rSUpdt){#dont touch if necessary for dimmer
  2023. if(($err&0x70) == 0x10 || ($err&0x70) == 0x20){
  2024. my $wt = $mh{cHash}->{helper}{stateUpdatDly}
  2025. ?$mh{cHash}->{helper}{stateUpdatDly}
  2026. :120;
  2027. CUL_HM_stateUpdatDly($mh{cName},$wt);
  2028. }
  2029. else {
  2030. CUL_HM_unQEntity($mh{cName},"qReqStat");
  2031. }
  2032. delete $mh{cHash}->{helper}{stateUpdatDly};
  2033. }
  2034. if ($mh{st} eq "dimmer"){
  2035. if (lc($mh{md}) =~ m/^hm-lc-dim.l.*/){
  2036. push @evtEt,[$mh{cHash},1,"loadFail:".(($err == 6)?"on":"off")];#note: err is times 2!
  2037. }
  2038. else{
  2039. push @evtEt,[$mh{cHash},1,"overload:".(($err&0x02)?"on":"off")];
  2040. push @evtEt,[$mh{cHash},1,"overheat:".(($err&0x04)?"on":"off")];
  2041. push @evtEt,[$mh{cHash},1,"reduced:" .(($err&0x08)?"on":"off")];
  2042. }
  2043. #hack for blind - other then behaved devices blind does not send
  2044. # a status info for chan 0 at power on
  2045. # chn3 (virtual chan) and not used up to now
  2046. # info from it is likely a power on!
  2047. if($mh{devH}->{helper}{PONtest} && $mh{chn} == 3){
  2048. push @evtEt,[$mh{devH},1,"powerOn:$tn",] ;
  2049. $mh{devH}->{helper}{PONtest} = 0;
  2050. }
  2051. }
  2052. elsif ($mh{st} eq "rgb"){
  2053. if ($mh{chn} == 2){
  2054. push @evtEt,[$mh{cHash},1,"color:$val"]; # duplicate to color - necessary for "colorpicker"
  2055. push @evtEt,[$mh{cHash},1,"rgb:".(($val==100)?("FFFFFF"):(Color::hsv2hex($val/100,1,1)))];
  2056. }
  2057. push @evtEt,[$mh{cHash},1,"colProgram:$val"] if ($mh{chn} == 3); # duplicate to colProgram - necessary for "slider"
  2058. }
  2059. elsif ($mh{st} eq "blindActuator"){
  2060. my $param = AttrVal($mh{cName}, "param", "");
  2061. if ($param =~ m/ponRestoreSmart/){
  2062. if($parse eq "powerOn"){
  2063. my $level = ReadingsVal($mh{cName},"level",0);# still the old level
  2064. $mh{cHash}->{helper}{prePONlvl} = $level;
  2065. $level = ($level<50)?0:100;
  2066. CUL_HM_Set($mh{cHash},$mh{cName},"pct",$level);
  2067. }
  2068. elsif ( $mh{cHash}->{helper}{dir}{cur} eq "stop"
  2069. && defined $mh{cHash}->{helper}{prePONlvl} ){
  2070. if ($val != 0 && $val != 100){
  2071. CUL_HM_Set($mh{cHash},$mh{cName},"pct",$mh{cHash}->{helper}{prePONlvl});
  2072. }
  2073. delete $mh{cHash}->{helper}{prePONlvl};
  2074. }
  2075. }
  2076. elsif ($param =~ m/ponRestoreForce/){
  2077. if($parse eq "powerOn"){
  2078. my $level = ReadingsVal($mh{cName},"level",0);# still the old level
  2079. $mh{cHash}->{helper}{prePONlvl} = $level;
  2080. CUL_HM_Set($mh{cHash},$mh{cName},"pct","0");
  2081. }
  2082. elsif ( $mh{cHash}->{helper}{dir}{cur} eq "stop"
  2083. && defined $mh{cHash}->{helper}{prePONlvl}){
  2084. if ($val == 0){
  2085. CUL_HM_Set($mh{cHash},$mh{cName},"pct",100);
  2086. }
  2087. elsif($val == 100){
  2088. CUL_HM_Set($mh{cHash},$mh{cName},"pct",$mh{cHash}->{helper}{prePONlvl});
  2089. delete $mh{cHash}->{helper}{prePONlvl};
  2090. }
  2091. else{
  2092. delete $mh{cHash}->{helper}{prePONlvl};# some stop inbetween - maybe user action. stop processing
  2093. }
  2094. }
  2095. }
  2096. if ($mh{md} eq "HM-LC-Ja1PBU-FM" && defined $mI[6]){
  2097. my %dirName = ( 0=>"stop" ,1=>"up" ,2=>"down" ,3=>"err" );
  2098. push @evtEt,[$mh{cHash},1,"pctSlat:".hex($mI[5])/2];
  2099. push @evtEt,[$mh{cHash},1,"slatDir:".$dirName{hex($mI[6]) & 0x3}];
  2100. }
  2101. }
  2102. elsif ($mh{md} eq "HM-SEC-SFA-SM"){
  2103. push @evtEt,[$mh{devH},1,"powerError:" .(($err&0x02) ? "on":"off")];
  2104. push @evtEt,[$mh{devH},1,"sabotageError:".(($err&0x04) ? "on":"off")];
  2105. push @evtEt,[$mh{devH},1,"battery:".(($err&0x08)?"critical":($err&0x80?"low":"ok"))];
  2106. }
  2107. elsif ($mh{md} =~ m/^(HM-LC-SW.-BA-PCB|HM-Dis-TD-T)/){
  2108. push @evtEt,[$mh{devH},1,"battery:" . (($err&0x80) ? "low" : "ok" )];
  2109. }
  2110. }
  2111. }
  2112. elsif($mh{st} =~ m/^(remote|pushButton|swi|display)$/
  2113. ||$mh{md} eq "HM-SEN-EP") { #############################################
  2114. if($mh{mTp} eq "40") {
  2115. my $bat = ($mh{chnraw} & 0x80)?"low":"ok";
  2116. my $type = ($mh{chnraw} & 0x40)?"l":"s";
  2117. my $state = ($mh{chnraw} & 0x40)?"Long":"Short";
  2118. my $chId = $mh{src}.$mh{chnHx};
  2119. my $btnName = $mh{cHash}->{helper}{role}{chn}
  2120. ? $mh{cName}
  2121. : "Btn$mh{chn}";
  2122. if($type eq "l"){# long press
  2123. #$state .= ($mh{mFlgH} & 0x20 ? "Release" : "");# not sufficient
  2124. $state .= ((($mh{mFlgH} & 0x24) == 0x20) ? "Release" : "");
  2125. }
  2126. push @evtEt,[$mh{devH},1,"battery:$bat"];
  2127. push @evtEt,[$mh{devH},1,"state:$btnName $state"];
  2128. if($mh{md} eq "HM-Dis-WM55"){
  2129. if ($mh{devH}->{cmdStack}){# there are pending commands. we only send new ones
  2130. delete $mh{devH}->{cmdStack};
  2131. delete $mh{devH}->{cmdStacAESPend};
  2132. delete $mh{devH}->{helper}{prt}{rspWait};
  2133. delete $mh{devH}->{helper}{prt}{rspWaitSec};
  2134. delete $mh{devH}->{helper}{prt}{mmcA};
  2135. delete $mh{devH}->{helper}{prt}{mmcS};
  2136. delete $mh{devH}->{lastMsg};
  2137. }
  2138. CUL_HM_calcDisWm($mh{cHash},$mh{devN},$type);
  2139. if (AttrVal($btnName,"aesCommReq",0)){
  2140. my @arr = ();
  2141. $mh{devH}->{cmdStacAESPend} = \@arr;
  2142. push (@{$mh{devH}->{cmdStacAESPend} },"$mh{src};++A011$mh{id}$mh{src}$_")
  2143. foreach (@{$mh{cHash}->{helper}{disp}{$type}});
  2144. }
  2145. else{
  2146. CUL_HM_PushCmdStack($mh{devH},"++A011$mh{id}$mh{src}$_")
  2147. foreach (@{$mh{cHash}->{helper}{disp}{$type}});
  2148. }
  2149. }
  2150. }
  2151. if($mh{md} eq "HM-Dis-EP-WM55"){
  2152. my $disName = InternalVal($mh{devN},"channel_03",undef);
  2153. if (defined $disName ){
  2154. if (AttrVal($disName,"param","") =~ m/reWriteDisplay(..)/){
  2155. my $delay = $1;
  2156. RemoveInternalTimer($disName.":reWriteDisplay");
  2157. InternalTimer(gettimeofday()+$delay,"CUL_HM_reWriteDisplay", $disName.":reWriteDisplay", 0);
  2158. }
  2159. }
  2160. }
  2161. else{# could be an Em8
  2162. my($chn,$state,$err);
  2163. if($mh{mTp} eq "41"){
  2164. ($chn,$state)=(hex($mI[0]),$mI[2]);
  2165. #my $cnt = hex($mI[1]);
  2166. my $err = $chn & 0x80;
  2167. $chn = sprintf("%02X",$chn & 0x3f);
  2168. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  2169. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  2170. push @evtEt,[$mh{devH},1,"battery:". ($err?"low" :"ok" )];
  2171. }
  2172. elsif(($mh{mTp} eq "10" && $mI[0] eq "06") ||
  2173. ($mh{mTp} eq "02" && $mI[0] eq "01")) {
  2174. ($chn,$state,$err) = (hex($mI[1]), $mI[2], hex($mI[3]));
  2175. $chn = sprintf("%02X",$chn&0x3f);
  2176. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  2177. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  2178. push @evtEt,[$mh{devH},1,"alive:yes"];
  2179. push @evtEt,[$mh{devH},1,"battery:". (($err&0x80)?"low" :"ok" )];
  2180. }
  2181. if (defined($state) && $chn ne "00"){# if state was detected post events
  2182. my $txt;
  2183. if ($mh{shash}->{helper}{lm} && $mh{shash}->{helper}{lm}{hex($state)}){$txt = $mh{shash}->{helper}{lm}{hex($state)}}
  2184. elsif ($lvlStr{md}{$mh{md}}){$txt = $lvlStr{md}{$mh{md}}{$state}}
  2185. elsif ($lvlStr{st}{$mh{st}}){$txt = $lvlStr{st}{$mh{st}}{$state}}
  2186. else {$txt = "unknown:$state"}
  2187. push @evtEt,[$mh{shash},1,"state:$txt"];
  2188. push @evtEt,[$mh{shash},1,"contact:$txt$target"];
  2189. }
  2190. }
  2191. }
  2192. elsif($mh{st} =~ m/^(siren)$/) {#############################################
  2193. if (($mh{mTyp} eq "0201") || # handle Ack_Status
  2194. ($mh{mTyp} eq "1006")) { # or Info_Status message here
  2195. my ($chn,$val,$err) = (hex($mI[1]),hex($mI[2])/2,hex($mI[3]));
  2196. my $vs = $val == 0 ? "off" : "on";
  2197. #-- if timed on is set possibly show this in a state --
  2198. my ($timedOn,$stateExt)=("off","");
  2199. if($err&0x40){
  2200. $timedOn = "running";
  2201. $stateExt = "-till" if(AttrVal($mh{cName},"param","") =~ m/showTimed/ );
  2202. }
  2203. if ($chn == 4){
  2204. my %lvlSet = ("00"=>"disarmed","32"=>"armExtSens","C8"=>"armAll","FF"=>"armBlocked");
  2205. $vs = defined $lvlSet{$val}?$lvlSet{$val}:$val;
  2206. }
  2207. push @evtEt,[$mh{cHash},1,"level:$val"];
  2208. push @evtEt,[$mh{cHash},1,"pct:$val"]; # duplicate to level - necessary for "slider"
  2209. push @evtEt,[$mh{cHash},1,"deviceMsg:$vs$target"] if($mh{chnM} ne "00");
  2210. push @evtEt,[$mh{cHash},1,"state:$vs$stateExt"];
  2211. push @evtEt,[$mh{cHash},1,"timedOn:$timedOn"];
  2212. push @evtEt,[$mh{devH} ,1,"powerOn:$tn",] if ($chn == 0) ;
  2213. push @evtEt,[$mh{devH} ,1,"sabotageError:".(($err&0x04)?"on" :"off")];
  2214. push @evtEt,[$mh{devH} ,1,"battery:" .(($err&0x80)?"low":"ok" )];
  2215. }
  2216. }
  2217. elsif($mh{st} eq "senBright") { #############################################
  2218. if ($mh{mTp} =~ m/^5[34]/){
  2219. #Channel is fixed 1
  2220. my ($chn,$unkn,$dat) = unpack 'A2A2A8',$mh{p};# chn = 01
  2221. push @evtEt,[$mh{devH},1,"battery:".(hex($chn)&0x80?"low":"ok")];
  2222. $dat = sprintf("%0.2f",hex($dat))/100; #down to 0.01lux per docu
  2223. # verify whether we have a channel or will use the Device instead
  2224. my $cHash = ($modules{CUL_HM}{defptr}{$mh{src}."01"})
  2225. ?$modules{CUL_HM}{defptr}{$mh{src}."01"}
  2226. :$mh{devH};
  2227. push @evtEt,[$cHash,1,"state:B: $dat"];
  2228. push @evtEt,[$cHash,1,"brightness:$dat"];
  2229. #push @evtEt,[$cHash,1,"unknown: 0x".$unkn]; # read 0xC1, but what is it?
  2230. }
  2231. }
  2232. elsif($mh{st} eq "powerSensor") {############################################
  2233. if (($mh{mTyp} eq "0201") || # handle Ack_Status
  2234. ($mh{mTyp} eq "1006")) { # or Info_Status message here
  2235. my ($chn,$val,$err) = (hex($mI[1]),hex($mI[2])/2,hex($mI[3]));
  2236. $chn = sprintf("%02X",$chn&0x3f);
  2237. my $chId = $mh{src}.$chn;
  2238. $mh{shash} = $modules{CUL_HM}{defptr}{$chId}
  2239. if($modules{CUL_HM}{defptr}{$chId});
  2240. push @evtEt,[$mh{devH},1,"battery:".(($err&0x80)?"low" :"ok" )];
  2241. push @evtEt,[$mh{shash},1,"state:$val"];
  2242. }
  2243. elsif ($mh{mTp} eq "60" ||$mh{mTp} eq "61" ) { # IEC_POWER_EVENT_CYCLIC
  2244. my ($chn,$eUnit,$eCnt,$pUnit,$pIEC) = map{hex($_)} unpack 'A2A2A10A2A8',$mh{p};
  2245. push @evtEt,[$mh{devH},1,"battery:".(($chn&0x80)?"low" :"ok" )];
  2246. $chn = sprintf("%02X",$chn&0x3f);
  2247. my $chId = $mh{src}.$chn;
  2248. $mh{shash} = $modules{CUL_HM}{defptr}{$chId}
  2249. if($modules{CUL_HM}{defptr}{$chId});
  2250. # push @evtEt,[$mh{shash},1,"energyTariff:" .(( $eUnit & 0xfe)?(-1*($eUnit >> 4)):($eUnit >> 4))];
  2251. # push @evtEt,[$mh{shash},1,"powerTariff:" .((($pUnit >> 4) & 0xfe)?(-1*($pUnit >> 4)):($pUnit >> 4))];
  2252. push @evtEt,[$mh{shash},1,"energyTariff:" .( $eUnit >> 4 )];
  2253. push @evtEt,[$mh{shash},1,"energyUnit:" .( $eUnit & 0x01)];
  2254. push @evtEt,[$mh{shash},1,"powerTariff:" .( $pUnit >> 4 )];
  2255. push @evtEt,[$mh{shash},1,"powerUnit:" .( $pUnit & 0x01)];
  2256. push @evtEt,[$mh{shash},1,"powerSign:" .(( $pUnit >> 3) & 0x01)];
  2257. push @evtEt,[$mh{shash},1,"powerIEC:" .( $pIEC )];
  2258. push @evtEt,[$mh{shash},1,"energyIEC:" .( $eCnt )];
  2259. }
  2260. elsif ($mh{mTp} eq "53" ||$mh{mTp} eq "54" ) { # Gas_EVENT_CYCLIC
  2261. $mh{shash} = $modules{CUL_HM}{defptr}{$mh{src}."01"}
  2262. if($modules{CUL_HM}{defptr}{$mh{src}."01"});
  2263. my ($eCnt,$P) = map{hex($_)} unpack 'A8A6',$mh{p};
  2264. $eCnt = ($eCnt&0x7fffffff)/1000; #0.0 ..2147483.647 m3
  2265. $P = $P /1000; #0.0 ..16777.215 m3
  2266. push @evtEt,[$mh{shash},1,"gasCnt:" .$eCnt];
  2267. push @evtEt,[$mh{shash},1,"gasPower:" .$P];
  2268. my $sumState = "eState:E: $eCnt P: $P";
  2269. push @evtEt,[$mh{shash},1,$sumState];
  2270. push @evtEt,[$mh{shash},1,"boot:" .(($eCnt&0x800000)?"on":"off")];
  2271. my $eo = ReadingsVal($mh{shash}->{NAME},"gasCntOffset",0);
  2272. if($eCnt == 0 && hex($mh{mNo}) < 3 ){
  2273. if($mh{devH}->{helper}{PONtest}){
  2274. push @evtEt,[$mh{devH},1,"powerOn:$tn",] ;
  2275. $mh{devH}->{helper}{PONtest} = 0;
  2276. }
  2277. $eo += ReadingsVal($mh{shash}->{NAME},"gasCnt",0);
  2278. push @evtEt,[$mh{shash},1,"gasCntOffset:".$eo];
  2279. }
  2280. push @evtEt,[$mh{shash},1,"gasCntCalc:".($eo + $eCnt)];
  2281. }
  2282. elsif ($mh{mTp} eq "5E" ||$mh{mTp} eq "5F" ) { # POWER_EVENT_CYCLIC
  2283. $mh{shash} = $modules{CUL_HM}{defptr}{$mh{src}."01"}
  2284. if($modules{CUL_HM}{defptr}{$mh{src}."01"});
  2285. my ($eCnt,$P) = map{hex($_)} unpack 'A6A6',$mh{p};
  2286. $eCnt = ($eCnt&0x7fffff)/10; #0.0 ..838860.7 Wh
  2287. $P = $P /100; #0.0 ..167772.15 W
  2288. push @evtEt,[$mh{shash},1,"energy:" .$eCnt];
  2289. push @evtEt,[$mh{shash},1,"power:" .$P];
  2290. my $sumState = "eState:E: $eCnt P: $P";
  2291. push @evtEt,[$mh{shash},1,$sumState];
  2292. push @evtEt,[$mh{shash},1,"boot:" .(($eCnt&0x800000)?"on":"off")];
  2293. push @evtEt,[$defs{$mh{devH}->{channel_02}},1,"state:$eCnt"] if ($mh{devH}->{channel_02});
  2294. push @evtEt,[$defs{$mh{devH}->{channel_03}},1,"state:$P" ] if ($mh{devH}->{channel_03});
  2295. my $el = ReadingsVal($mh{shash}->{NAME},"energy",0);# get Energy last
  2296. my $eo = ReadingsVal($mh{shash}->{NAME},"energyOffset",0);
  2297. if($eCnt == 0 && hex($mh{mNo}) < 3 && !$mh{shash}->{helper}{pon}){
  2298. if($mh{devH}->{helper}{PONtest}){
  2299. push @evtEt,[$mh{devH},1,"powerOn:$tn",] ;
  2300. $mh{devH}->{helper}{PONtest} = 0;
  2301. }
  2302. $eo += $el;
  2303. push @evtEt,[$mh{shash},1,"energyOffset:".$eo];
  2304. $mh{shash}->{helper}{pon} = 1;# power on is detected - only send once
  2305. }
  2306. elsif($el > 800000 && $el > $eCnt ){# handle overflow
  2307. $eo += 838860.7;
  2308. push @evtEt,[$mh{shash},1,"energyOffset:".$eo];
  2309. }
  2310. else{
  2311. delete $mh{shash}->{helper}{pon};
  2312. }
  2313. push @evtEt,[$mh{shash},1,"energyCalc:".($eo + $eCnt)];
  2314. }
  2315. }
  2316. elsif($mh{st} eq "powerMeter") {#############################################
  2317. if (($mh{mTyp} eq "0201") || # handle Ack_Status
  2318. ($mh{mTyp} eq "1006")) { # or Info_Status message here
  2319. # powerOn
  2320. # m:01 A45F 36D06A 123ABC 8000000000000000090CFE
  2321. # m:02 A410 36D06A 123ABC 06010000
  2322. my ($val,$err) = (hex($mI[2])/2,hex($mI[3]));
  2323. my $chId = $mh{src}.$mh{chnHx};
  2324. $mh{shash} = $modules{CUL_HM}{defptr}{$chId}
  2325. if($modules{CUL_HM}{defptr}{$chId});
  2326. my $vs = ($val==100 ? "on":($val==0 ? "off":"$val %")); # user string...
  2327. #-- if timed on is set possibly show this in a state --
  2328. my ($timedOn,$stateExt)=("off","");
  2329. if($err&0x40){
  2330. $timedOn = "running";
  2331. $stateExt = "-till" if(AttrVal($mh{shash}->{NAME},"param","") =~ m/showTimed/ );
  2332. }
  2333. push @evtEt,[$mh{shash},1,"level:$val"];
  2334. push @evtEt,[$mh{shash},1,"pct:$val"]; # duplicate to level - necessary for "slider"
  2335. push @evtEt,[$mh{shash},1,"deviceMsg:$vs$target"] if($mh{chnHx} ne "00");
  2336. push @evtEt,[$mh{shash},1,"state:$vs$stateExt"];
  2337. push @evtEt,[$mh{shash},1,"timedOn:$timedOn"];
  2338. }
  2339. elsif ($mh{mTp} eq "5E" ||$mh{mTp} eq "5F" ) { # POWER_EVENT_CYCLIC
  2340. $mh{shash} = $modules{CUL_HM}{defptr}{$mh{src}."02"}
  2341. if($modules{CUL_HM}{defptr}{$mh{src}."02"});
  2342. my ($eCnt,$P,$I,$U,$F) = map{hex($_)} unpack 'A6A6A4A4A2',$mh{p};
  2343. $eCnt = ($eCnt&0x7fffff)/10; #0.0 ..838860.7 Wh
  2344. $P = $P /100; #0.0 ..167772.15 W
  2345. $I = $I /1; #0.0 ..65535.0 mA
  2346. $U = $U /10; #0.0 ..6553.5 mV
  2347. $F -= 256 if ($F > 127);
  2348. $F = $F/100+50; # 48.72..51.27 Hz
  2349. push @evtEt,[$mh{shash},1,"energy:" .$eCnt];
  2350. push @evtEt,[$mh{shash},1,"power:" .$P];
  2351. push @evtEt,[$mh{shash},1,"current:" .$I];
  2352. push @evtEt,[$mh{shash},1,"voltage:" .$U];
  2353. push @evtEt,[$mh{shash},1,"frequency:".$F];
  2354. push @evtEt,[$mh{shash},1,"eState:E: $eCnt P: $P I: $I U: $U f: $F"];
  2355. push @evtEt,[$mh{shash},1,"boot:" .(($eCnt&0x800000)?"on":"off")];
  2356. push @evtEt,[$defs{$mh{devH}->{channel_02}},1,"state:$eCnt"] if ($mh{devH}->{channel_02});
  2357. push @evtEt,[$defs{$mh{devH}->{channel_03}},1,"state:$P" ] if ($mh{devH}->{channel_03});
  2358. push @evtEt,[$defs{$mh{devH}->{channel_04}},1,"state:$I" ] if ($mh{devH}->{channel_04});
  2359. push @evtEt,[$defs{$mh{devH}->{channel_05}},1,"state:$U" ] if ($mh{devH}->{channel_05});
  2360. push @evtEt,[$defs{$mh{devH}->{channel_06}},1,"state:$F" ] if ($mh{devH}->{channel_06});
  2361. my $el = ReadingsVal($mh{shash}->{NAME},"energy",0);# get Energy last
  2362. my $eo = ReadingsVal($mh{shash}->{NAME},"energyOffset",0);
  2363. if($eCnt == 0 && hex($mh{mNo}) < 3 && !$mh{shash}->{helper}{pon}){
  2364. if($mh{devH}->{helper}{PONtest}){
  2365. push @evtEt,[$mh{devH},1,"powerOn:$tn",] if ($mh{md} !~ m/^HM-ES-PMSw1/);
  2366. $mh{devH}->{helper}{PONtest} = 0;
  2367. }
  2368. $eo += $el;
  2369. push @evtEt,[$mh{shash},1,"energyOffset:".$eo];
  2370. $mh{shash}->{helper}{pon} = 1;# power on is detected - only ssend once
  2371. }
  2372. elsif($el > 800000 && $el > $eCnt ){# handle overflow
  2373. $eo += 838860.7;
  2374. push @evtEt,[$mh{shash},1,"energyOffset:".$eo];
  2375. }
  2376. else{
  2377. delete $mh{shash}->{helper}{pon};
  2378. }
  2379. push @evtEt,[$mh{shash},1,"energyCalc:".($eo + $eCnt)];
  2380. CUL_HM_unQEntity($mh{shash}->{NAME},"qReqStat");
  2381. }
  2382. }
  2383. elsif($mh{st} eq "repeater"){ ###############################################
  2384. if (($mh{mTyp} eq "0201") || # handle Ack_Status
  2385. ($mh{mTyp} eq "1006")) { #or Info_Status message here
  2386. my ($state,$err);
  2387. ($state,$err) = ($1,hex($2)) if ($mh{p} =~ m/^....(..)(..)/);
  2388. # not sure what level are possible
  2389. push @evtEt,[$mh{cHash},1,"state:" .($state eq '00'?"ok":"level:".$state)];
  2390. push @evtEt,[$mh{devH} ,1,"battery:".(($err&0x80)?"low" :"ok" )];
  2391. my $flag = ($err>>4) &0x7;
  2392. push @evtEt,[$mh{cHash},1,"flags:" .(($flag)?"none" :$flag )];
  2393. }
  2394. }
  2395. elsif($mh{st} eq "virtual" && $mh{md} =~ m/^virtual_/){ #####################
  2396. # possibly add code to count all acks that are paired.
  2397. if($mh{mTp} eq "02") {# this must be a reflection from what we sent, ignore
  2398. push @evtEt,[$mh{shash},1,""];
  2399. }
  2400. elsif ($mh{mTp} =~ m/^4[01]/){# if channel is SD team we have to act
  2401. if ($mh{cHash}->{helper}{fkt} && $mh{cHash}->{helper}{fkt} eq "sdLead2"){
  2402. CUL_HM_parseSDteam_2($mh{mTp},$mh{src},$mh{dst},$mh{p});
  2403. }
  2404. else{
  2405. CUL_HM_parseSDteam($mh{mTp},$mh{src},$mh{dst},$mh{p});
  2406. }
  2407. }
  2408. }
  2409. elsif($mh{st} eq "outputUnit"){ #############################################
  2410. if($mh{mTp} eq "40" && @mI == 2){
  2411. my $bno = hex($mI[1]);
  2412. push @evtEt,[$mh{cHash},1,"state:Btn$mh{chn} on$target"];
  2413. }
  2414. elsif(($mh{mTyp} eq "0201") || # handle Ack_Status
  2415. ($mh{mTyp} eq "1006")){ # or Info_Status message
  2416. my $msgState = (@mI > 2 ? $mI[2] : "" );
  2417. if ($mh{md} eq "HM-OU-LED16") {
  2418. #special: all LEDs map to device state
  2419. my $devState = ReadingsVal($mh{devN},"color","00000000");
  2420. if($parse eq "powerOn"){# reset LEDs after power on
  2421. CUL_HM_PushCmdStack($mh{devH},'++A011'.$ioId.$mh{src}."8100".$devState);
  2422. CUL_HM_ProcessCmdStack($mh{devH});
  2423. # no event necessary, all the same as before
  2424. }
  2425. else {# just update datafields in storage
  2426. my %colTbl=("00"=>"off","01"=>"red","10"=>"green","11"=>"orange");
  2427. if (@mI > 8){#status for all channel included
  2428. # open to decode byte $mI[4] - related to backlight? seen 20 and 21
  2429. my $lStat = join("",@mI[5..8]); # all LED status in one long
  2430. my @leds = reverse(unpack('(A2)*',sprintf("%032b",hex($lStat))));
  2431. $_ = $colTbl{$_} foreach (@leds);
  2432. for(my $cCnt = 0;$cCnt<16;$cCnt++){# go for all channels
  2433. my $cH = $modules{CUL_HM}{defptr}{$mh{src}.sprintf("%02X",$cCnt+1)};
  2434. next if (!$cH);
  2435. if (ReadingsVal($cH->{NAME},"state","") ne $leds[$cCnt]) {
  2436. push @evtEt,[$cH,1,"color:$leds[$cCnt]"];
  2437. push @evtEt,[$cH,1,"state:$leds[$cCnt]"];
  2438. }
  2439. }
  2440. push @evtEt,[$mh{devH},1,"color:$lStat"];
  2441. push @evtEt,[$mh{devH},1,"state:$lStat"];
  2442. }
  2443. else{# branch can be removed if message is always that long
  2444. my $bitLoc = ($mh{chn}-1)*2;#calculate bit location
  2445. my $mask = 3<<$bitLoc;
  2446. my $value = sprintf("%08X",(hex($devState) &~$mask)|($msgState<<$bitLoc));
  2447. push @evtEt,[$mh{devH},1,"color:$value"];
  2448. push @evtEt,[$mh{devH},1,"state:$value"];
  2449. if (!$mh{cHash}{helper}{role}{dev}){
  2450. my $actColor = $colTbl{sprintf("%02b",hex($msgState))};
  2451. $actColor = "unknown" if(!$actColor);
  2452. push @evtEt,[$mh{cHash},1,"color:$actColor"];
  2453. push @evtEt,[$mh{cHash},1,"state:$actColor"];
  2454. }
  2455. }
  2456. }
  2457. }
  2458. # elsif ($mh{md} eq "HM-OU-CFM-PL"){
  2459. else{
  2460. my $val = hex($mI[2])/2;
  2461. $val = ($val == 100 ? "on" : ($val == 0 ? "off" : "$val %"));
  2462. push @evtEt,[$mh{cHash},1,"state:$val"];
  2463. push @evtEt,[$mh{devH} ,1,"battery:".(hex($mI[3]&0x80)?"low":"ok" )]if ($mh{md} eq "HM-OU-CFM-TW" && $mI[3]);
  2464. }
  2465. }
  2466. }
  2467. elsif($mh{st} =~ m/^(motionDetector|motionAndBtn)$/) { ######################
  2468. my $state = $mI[2];
  2469. if(($mh{mTyp} eq "0201") ||
  2470. ($mh{mTyp} eq "1006")) {
  2471. my ($chn,$err,$bright)=(hex($mI[1]),hex($mI[3]),hex($mI[2]));
  2472. my $chId = $mh{src}.sprintf("%02X",$chn&0x3f);
  2473. $mh{shash} = $modules{CUL_HM}{defptr}{$chId}
  2474. if($modules{CUL_HM}{defptr}{$chId});
  2475. push @evtEt,[$mh{shash},1,"brightness:".$bright];
  2476. if ($mh{md} eq "HM-Sec-MDIR"){
  2477. push @evtEt,[$mh{shash},1,"sabotageError:".(($err&0x0E)?"on":"off")];
  2478. }
  2479. else{
  2480. push @evtEt,[$mh{shash},1,"cover:". (($err&0x0E)?"open" :"closed")];
  2481. }
  2482. push @evtEt,[$mh{devH},1,"battery:". (($err&0x80)?"low" :"ok" )];
  2483. }
  2484. elsif($mh{mTp} eq "41") {#01 is channel
  2485. my($chn,$cnt,$bright,$nextTr) = map{hex($_)} (@mI,0);
  2486. push @evtEt,[$mh{devH},1,"battery:".($chn&0x80?"low":"ok")]; # observed with HM-SEN-MDIR-SM FW V1.6
  2487. if ($nextTr){
  2488. $nextTr = (15 << ($nextTr >> 4) - 4); # strange mapping of literals
  2489. RemoveInternalTimer($mh{cName}.":motionCheck");
  2490. InternalTimer(gettimeofday()+$nextTr+2,"CUL_HM_motionCheck", $mh{cName}.":motionCheck", 0);
  2491. $mh{cHash}->{helper}{moStart} = gettimeofday() if (!defined $mh{cHash}->{helper}{moStart});
  2492. }
  2493. else{
  2494. $nextTr = "none ";
  2495. }
  2496. my $chId = $mh{src}.sprintf("%02X",$chn & 0x3f);
  2497. $mh{shash} = $modules{CUL_HM}{defptr}{$chId}
  2498. if($modules{CUL_HM}{defptr}{$chId});
  2499. push @evtEt,[$mh{shash},1,"state:motion"];
  2500. push @evtEt,[$mh{shash},1,"motion:on$target"];
  2501. push @evtEt,[$mh{shash},1,"motionCount:$cnt"."_next:$nextTr"."s"];
  2502. push @evtEt,[$mh{shash},1,"brightness:$bright"];
  2503. }
  2504. elsif($mh{mTp} eq "70" && $mh{p} =~ m/^7F(..)(.*)/) {
  2505. my($d1, $d2) = ($1, $2);
  2506. push @evtEt,[$mh{shash},1,"devState_raw$d1:$d2"];
  2507. $state = 0;
  2508. }
  2509. if($ioId eq $mh{dst} && $mh{mFlgH}&0x20 && $state){
  2510. push @ack,$mh{shash},$mh{mNo}."8002".$ioId.$mh{src}."0101".$state."00";
  2511. $mh{AckDone} = 1; # mark allready done device specific
  2512. }
  2513. }
  2514. elsif($mh{st} eq "smokeDetector") { #########################################
  2515. #Info Level: mTp=0x10 p(..)(..)(..) subtype=06, channel, state (1 byte)
  2516. #Event: mTp=0x41 p(..)(..)(..) channel , unknown, state (1 byte)
  2517. if ($mh{mTp} eq "10" && $mh{p} =~ m/^06..(..)(..)/) {
  2518. # m:A0 A010 233FCE 1743BF 0601 01 00 31
  2519. my ($state,$err) = (hex($1),hex($2));
  2520. push @evtEt,[$mh{devH} ,1,"battery:" .(($err&0x80)?"low" :"ok")];
  2521. push @evtEt,[$mh{cHash},1,"level:" .hex($state)];
  2522. $state = (($state < 2)?"off":"smoke-Alarm");
  2523. push @evtEt,[$mh{cHash},1,"state:$state"];
  2524. if ($mh{md} eq "HM-SEC-SD-2"){
  2525. push @evtEt,[$mh{cHash},1,"alarmTest:" .(($err&0x02)?"failed" :"ok")];
  2526. push @evtEt,[$mh{cHash},1,"smokeChamber:".(($err&0x04)?"degraded":"ok")];
  2527. if(length($mh{p}) == 8 && $mh{mNo} eq "80"){
  2528. push @evtEt,[$mh{devH},1,"powerOn:$tn",] ;
  2529. }
  2530. CUL_HM_parseSDteam_2($mh{mTp},$mh{src},$mh{dst},$mh{p});
  2531. }
  2532. else{
  2533. if($mh{devH}->{helper}{PONtest} &&(length($mh{p}) == 8 && $mh{mNo} eq "00")){
  2534. push @evtEt,[$mh{devH},1,"powerOn:$tn",] ;
  2535. $mh{devH}->{helper}{PONtest} = 0;
  2536. }
  2537. }
  2538. my $tName = ReadingsVal($mh{cName},"peerList","");#inform team
  2539. $tName =~ s/,.*//;
  2540. CUL_HM_updtSDTeam($tName,$mh{cName},$state);
  2541. }
  2542. elsif ($mh{mTp} =~ m/^4[01]/){ #autonomous event
  2543. #01 1441 44E347 44E347 0101960000048BAF3B0E
  2544. #02 1441 44E347 44E347 01020000000445C4A14C
  2545. if ($mh{md} eq "HM-SEC-SD-2"){
  2546. CUL_HM_parseSDteam_2($mh{mTp},$mh{src},$mh{dst},$mh{p});
  2547. }
  2548. else{
  2549. CUL_HM_parseSDteam($mh{mTp},$mh{src},$mh{dst},$mh{p});
  2550. }
  2551. }
  2552. elsif ($mh{mTp} eq "01"){ #Configs
  2553. my $sType = substr($mh{p},0,2);
  2554. if ($sType eq "01"){# add peer to group
  2555. push @evtEt,[$mh{shash},1,"SDteam:add_$mh{dstN}"];
  2556. }
  2557. elsif($sType eq "02"){# remove from group
  2558. push @evtEt,[$mh{shash},1,"SDteam:remove_".$mh{dstN}];
  2559. }
  2560. elsif($sType eq "05"){# set param List 3 and 4
  2561. push @evtEt,[$mh{shash},1,""];
  2562. }
  2563. }
  2564. else{
  2565. push @evtEt,[$mh{shash},1,"SDunknownMsg:$mh{p}"] if(!@evtEt);
  2566. }
  2567. if($ioId eq $mh{dst} && ($mh{mFlgH}&0x20)){ # Send Ack/Nack
  2568. push @ack,$mh{shash},$mh{mNo}."8002".$ioId.$mh{src}.($mh{mFlg}.$mh{mTp} eq "A001" ? "80":"00");
  2569. }
  2570. }
  2571. elsif($mh{st} eq "threeStateSensor") { ######################################
  2572. #Event: mTp=0x41 p(..)(..)(..) channel , unknown, state
  2573. #Info Level: mTp=0x10 p(..)(..)(..)(..) subty=06, chn, state,err (3bit)
  2574. #AckStatus: mTp=0x02 p(..)(..)(..)(..) subty=01, chn, state,err (3bit)
  2575. my ($chn,$state,$err,$cnt); #define locals
  2576. if(($mh{mTyp} eq "0201") ||
  2577. ($mh{mTyp} eq "1006")) {
  2578. ($chn,$state,$err) = (hex($mI[1]), $mI[2], hex($mI[3]));
  2579. $chn = sprintf("%02X",$chn&0x3f);
  2580. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  2581. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  2582. push @evtEt,[$mh{devH},1,"alive:yes"];
  2583. push @evtEt,[$mh{devH},1,"battery:". (($err&0x80)?"low" :"ok" )];
  2584. if ( $mh{md} =~ m/^(HM-SEC-SC.*|HM-SEC-RHS|Roto_ZEL-STG-RM-F.K)$/){
  2585. push @evtEt,[$mh{devH},1,"sabotageError:".(($err&0x0E)?"on" :"off")];}
  2586. elsif($mh{md} ne "HM-SEC-WDS"){push @evtEt,[$mh{devH},1,"cover:" .(($err&0x0E)?"open" :"closed")];}
  2587. }
  2588. elsif($mh{mTp} eq "41"){
  2589. ($chn,$cnt,$state)=(hex($1),$2,$3) if($mh{p} =~ m/^(..)(..)(..)/);
  2590. my $err = $chn & 0x80;
  2591. $chn = sprintf("%02X",$chn & 0x3f);
  2592. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  2593. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  2594. push @evtEt,[$mh{devH},1,"battery:". ($err?"low" :"ok" )];
  2595. push @ack,$mh{shash},$mh{mNo}."8002".$mh{dst}.$mh{src}."00"
  2596. if ( $ioId eq $mh{dst}
  2597. && !$mh{devH}{IODev}->{helper}{VTS_ACK}
  2598. && $mh{devH}{IODev}->{TYPE} !~ m/^(HMLAN|HMUARTLGW)$/); #noansi: additional CUL ACK
  2599. }
  2600. if (defined($state)){# if state was detected post events
  2601. my $txt;
  2602. if ($mh{shash}->{helper}{lm} && $mh{shash}->{helper}{lm}{hex($state)}){$txt = $mh{shash}->{helper}{lm}{hex($state)}}
  2603. elsif ($lvlStr{md}{$mh{md}}){$txt = $lvlStr{md}{$mh{md}}{$state}}
  2604. elsif ($lvlStr{st}{$mh{st}}){$txt = $lvlStr{st}{$mh{st}}{$state}}
  2605. else {$txt = "unknown:$state"}
  2606. push @evtEt,[$mh{shash},1,"state:$txt"];
  2607. push @evtEt,[$mh{shash},1,"contact:$txt$target"];
  2608. }
  2609. elsif(!@evtEt){push @evtEt,[$mh{devH},1,"3SSunknownMsg:$mh{p}"];}
  2610. }
  2611. elsif($mh{st} eq "winMatic") { #############################################
  2612. my($sType,$chn,$lvl,$stat) = @mI;
  2613. if(($mh{mTyp} eq "0201") ||
  2614. ($mh{mTyp} eq "1006")){
  2615. $stat = hex($stat);
  2616. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  2617. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  2618. my $lvlS = $lvl eq "FF" ? 1:0;
  2619. $lvl = hex($lvl)/2;
  2620. my $dat4 = ($stat >> 4) & 0x03;
  2621. if ($chn eq "01"){
  2622. my %err = (0=>"ok",1=>"TurnError",2=>"TiltError");
  2623. my %dir = (0=>"no",1=>"up",2=>"down",3=>"undefined");
  2624. push @evtEt,[$mh{shash},1,"motorErr:" .$err{($stat >> 1) & 0x03}];
  2625. push @evtEt,[$mh{shash},1,"direction:" .$dir{$dat4}];
  2626. push @evtEt,[$mh{shash},1,"level:" .($lvlS ? "0" : $lvl) ] if($dat4 == 0);
  2627. push @evtEt,[$mh{shash},1,"lock:" .($lvlS ? "locked" : "unlocked")];
  2628. }
  2629. else{ #should be akku
  2630. my %statF = (0=>"trickleCharge",1=>"charge",2=>"discharge",3=>"unknown");
  2631. push @evtEt,[$mh{shash},1,"charge:" .$statF{$dat4}];
  2632. }
  2633. # stateflag meaning unknown
  2634. push @evtEt,[$mh{shash},1,"state:".($lvlS ? "locked" : $lvl) ];
  2635. }
  2636. }
  2637. elsif($mh{st} eq "keyMatic") { #############################################
  2638. #Info Level: mTp=0x10 p(..)(..)(..)(..) subty=06, chn, state,err (3bit)
  2639. #AckStatus: mTp=0x02 p(..)(..)(..)(..) subty=01, chn, state,err (3bit)
  2640. if(($mh{mTyp} eq "1006") ||
  2641. ($mh{mTyp} eq "0201")) {
  2642. my ($chn,$val, $err) = ($mI[1],hex($mI[2]), hex($mI[3]));
  2643. $mh{shash} = $modules{CUL_HM}{defptr}{"$mh{src}$chn"}
  2644. if($modules{CUL_HM}{defptr}{"$mh{src}$chn"});
  2645. my $stErr = ($err >>1) & 0x7;
  2646. my $error = 'unknown_'.$stErr;
  2647. $error = 'motor aborted' if ($stErr == 2);
  2648. $error = 'clutch failure' if ($stErr == 1);
  2649. $error = 'none' if ($stErr == 0);
  2650. my %dir = (0=>"none",1=>"up",2=>"down",3=>"undef");
  2651. my $state = "";
  2652. RemoveInternalTimer ($mh{devN}.":uncertain:permanent");
  2653. CUL_HM_unQEntity($mh{devN},"qReqStat");
  2654. if ($err & 0x30) { # uncertain - we have to check
  2655. CUL_HM_stateUpdatDly($mh{devN},13) if(ReadingsVal($mh{devN},"uncertain","no") eq "no");
  2656. InternalTimer(gettimeofday()+20,"CUL_HM_readValIfTO", $mh{devN}.":uncertain:permanent", 0);
  2657. $state = " (uncertain)";
  2658. }
  2659. push @evtEt,[$mh{shash},1,"unknown:40"] if($err&0x40);
  2660. push @evtEt,[$mh{devH} ,1,"battery:" .(($err&0x80) ? "low":"ok")];
  2661. push @evtEt,[$mh{shash},1,"uncertain:" .(($err&0x30) ? "yes":"no")];
  2662. push @evtEt,[$mh{shash},1,"direction:" .$dir{($err>>4)&3}];
  2663. push @evtEt,[$mh{shash},1,"error:" . ($error)];
  2664. push @evtEt,[$mh{shash},1,"lock:" . (($val == 1) ? "unlocked" : "locked")];
  2665. push @evtEt,[$mh{shash},1,"state:" . (($val == 1) ? "unlocked" : "locked") . $state];
  2666. }
  2667. }
  2668. elsif($mh{md} eq "CCU-FHEM") { #############################################
  2669. push @evtEt,[$mh{shash},1,""];
  2670. }
  2671. elsif (eval "defined(&CUL_HM_Parse$mh{st})"){################################
  2672. no strict "refs";
  2673. my @ret = &{"CUL_HM_Parse$mh{st}"}($mh{mFlg},$mh{mTp},$mh{src},$mh{dst},$mh{p},$target);
  2674. use strict "refs";
  2675. push @evtEt,@ret;
  2676. }
  2677. else{########################################################################
  2678. ; # no one wants the message
  2679. }
  2680. #------------ parse if FHEM or virtual actor is destination ---------------
  2681. if( AttrVal($mh{dstN}, "subType", "none") eq "virtual"
  2682. && AttrVal($mh{dstN}, "model", "none") =~ m/^virtual_/){# see if need for answer
  2683. my $sendAck = 0;
  2684. if($mh{mTp} =~ m/^4/ && @mI > 1) { #Push Button event
  2685. my ($recChn,$trigNo) = (hex($mI[0]),hex($mI[1]));# button number/event count
  2686. my $longPress = ($recChn & 0x40)?"long":"short";
  2687. my $recId = $mh{src}.sprintf("%02X",($recChn&0x3f));
  2688. foreach my $dChId (CUL_HM_getAssChnIds($mh{dstN})){# need to check all chan
  2689. next if (!$modules{CUL_HM}{defptr}{$dChId});
  2690. my $dChNo = substr($dChId,6,2);
  2691. my $dChName = CUL_HM_id2Name($dChId);
  2692. if(($attr{$dChName}{peerIDs}?$attr{$dChName}{peerIDs}:"") =~ m/$recId/){
  2693. my $dChHash = $defs{$dChName};
  2694. $sendAck = 1;
  2695. $dChHash->{helper}{trgLgRpt} = 0
  2696. if (!defined($dChHash->{helper}{trgLgRpt}));
  2697. $dChHash->{helper}{trgLgRpt} +=1;
  2698. my $trgLgRpt = $dChHash->{helper}{trgLgRpt};
  2699. my ($stT,$stAck) = ("ack","00");#state text and state Ack for Msg
  2700. if (AttrVal($dChName,"param","") !~ m/noOnOff/){
  2701. $stT = ReadingsVal($dChName,"virtActState","OFF");
  2702. $stT = ($stT eq "OFF")?"ON":"OFF"
  2703. if ($trigNo ne ReadingsVal($dChName,"virtActTrigNo","0"));
  2704. $stAck = '01'.$dChNo.(($stT eq "ON")?"C8":"00")."00"
  2705. }
  2706. if ((($mh{mFlgH} & 0x24) == 0x20)){
  2707. $longPress .= "_Release";
  2708. $dChHash->{helper}{trgLgRpt}=0;
  2709. push @ack,$mh{shash},$mh{mNo}."8002".$mh{dst}.$mh{src}.$stAck;
  2710. }
  2711. push @evtEt,[$dChHash,1,"state:$stT"];
  2712. push @evtEt,[$dChHash,1,"virtActState:$stT"];
  2713. push @evtEt,[$dChHash,1,"virtActTrigger:".CUL_HM_id2Name($recId)];
  2714. push @evtEt,[$dChHash,1,"virtActTrigType:$longPress"];
  2715. push @evtEt,[$dChHash,1,"virtActTrigRpt:$trgLgRpt"];
  2716. push @evtEt,[$dChHash,1,"virtActTrigNo:$trigNo"];
  2717. }
  2718. }
  2719. }
  2720. elsif($mh{mTp} eq "58" && $mh{p} =~ m/^(..)(..)/) {# climate event
  2721. my ($d1,$vp) =($1,hex($2)); # adjust_command[0..4] adj_data[0..250]
  2722. $vp = int($vp/2.56+0.5); # valve position in %
  2723. my $chnHash = $modules{CUL_HM}{defptr}{$mh{dst}."01"};
  2724. $chnHash = $mh{dstH} if (!$chnHash);
  2725. push @evtEt,[$chnHash,1,"ValvePosition:$vp %"];
  2726. push @evtEt,[$chnHash,1,"ValveAdjCmd:".$d1];
  2727. push @ack,$chnHash,$mh{mNo}."8002".$mh{dst}.$mh{src}.'0101'.
  2728. sprintf("%02X",$vp*2)."0000";
  2729. }
  2730. elsif($mh{mTp} eq "02"){
  2731. if ($mh{dstH}->{helper}{prt}{rspWait}{mNo} &&
  2732. $mh{dstH}->{helper}{prt}{rspWait}{mNo} eq $mh{mNo} ){
  2733. #ack we waited for - stop Waiting
  2734. CUL_HM_respPendRm($mh{dstH});
  2735. }
  2736. }
  2737. else{
  2738. $sendAck = 1;
  2739. }
  2740. push @ack,$mh{dstH},$mh{mNo}."8002".$mh{dst}.$mh{src}."00" if ($mh{mFlgH} & 0x20 && (!@ack) && $sendAck);
  2741. }
  2742. elsif($ioId eq $mh{dst}){# if fhem is destination check if we need to react
  2743. if( $mh{mTp} =~ m/^4./ #Push Button event
  2744. && !$mh{AckDone} #noansi: allready done device specific
  2745. && ($mh{mFlgH} & 0x20)){ #response required Flag
  2746. # fhem CUL shall ack a button press
  2747. if ($mh{md} =~ m/^(HM-SEC-SC.*|Roto_ZEL-STG-RM-FFK)$/){# SCs - depending on FW version - do not accept ACK only. Especially if peered
  2748. push @ack,$mh{shash},$mh{mNo}."8002".$mh{dst}.$mh{src}."0101".((hex($mI[0])&1)?"C8":"00")."00";
  2749. }
  2750. else{
  2751. push @ack,$mh{shash},$mh{mNo}."8002$mh{dst}$mh{src}"."00";
  2752. }
  2753. Log3 $mh{devN},5,"CUL_HM $mh{devN} prep ACK for $mI[0]";
  2754. }
  2755. }
  2756. #------------ send default ACK if not applicable------------------
  2757. # ack if we are destination, anyone did accept the message (@evtEt)
  2758. # parser did not supress
  2759. push @ack,$mh{shash}, $mh{mNo}."8002".$ioId.$mh{src}."00"
  2760. if( ($ioId eq $mh{dst}) #are we adressee
  2761. && ($mh{mFlgH} & 0x20) #response required Flag
  2762. && @evtEt #only ack if we identified it
  2763. && (!@ack) #sender requested ACK
  2764. );
  2765. if (@ack) {# send acks and store for repeat
  2766. $mh{devH}->{helper}{rpt}{IO} = $mh{ioName};
  2767. $mh{devH}->{helper}{rpt}{flg} = substr($mh{msg},5,1);
  2768. $mh{devH}->{helper}{rpt}{ack} = \@ack;
  2769. $mh{devH}->{helper}{rpt}{ts} = gettimeofday();
  2770. my $i=0;
  2771. my $rr = $respRemoved;
  2772. CUL_HM_SndCmd($ack[$i++],$ack[$i++]
  2773. .($mh{devH}->{helper}{aesAuthBytes}
  2774. ?$mh{devH}->{helper}{aesAuthBytes}
  2775. :"")
  2776. )while ($i<@ack);
  2777. $respRemoved = $rr;
  2778. Log3 $mh{devN},5,"CUL_HM $mh{devN} sent ACK:".(int(@ack));
  2779. delete($mh{devH}->{helper}{aesAuthBytes});
  2780. }
  2781. CUL_HM_ProcessCmdStack($mh{devH}) if ($respRemoved); # cont if complete
  2782. CUL_HM_sndIfOpen("x:".$mh{ioName});
  2783. #------------ process events ------------------
  2784. push @evtEt,[$mh{devH},1,"noReceiver:src:$mh{src} ".$mh{mFlg}.$mh{mTp}." $mh{p}"]
  2785. if(!@entities && !@evtEt);
  2786. push @entities,CUL_HM_pushEvnts();
  2787. @entities = CUL_HM_noDup(@entities,$mh{devN});
  2788. $defs{$_}{".noDispatchVars"} = 1 foreach (grep !/^$mh{devN}$/,@entities);
  2789. return @entities;
  2790. }
  2791. sub CUL_HM_parseCommon(@){#####################################################
  2792. # parsing commands that are device independent
  2793. my ($ioHash,$mhp) = @_;
  2794. return "" if(!$mhp->{devH}{DEF});# this should be from ourself
  2795. my ($p) = $mhp->{p};
  2796. my $devHlpr = $mhp->{devH}{helper};
  2797. my $ret = "";
  2798. my $rspWait = $devHlpr->{prt}{rspWait};
  2799. my $pendType = $rspWait->{Pending} ? $rspWait->{Pending} : "";
  2800. #------------ parse message flag for start processing command Stack
  2801. # TC wakes up with 8270, not with A258
  2802. # VD wakes up with 8202
  2803. # 9610
  2804. my $rxt = CUL_HM_getRxType($mhp->{shash});
  2805. $devHlpr->{PONtest} = 1 if($mhp->{mNo} =~ m/^0[012]/ &&
  2806. $devHlpr->{HM_CMDNR} < 250 &&
  2807. $devHlpr->{HM_CMDNR} > 5);# this is power on
  2808. $devHlpr->{HM_CMDNR} = hex($mhp->{mNo});# sync msgNo prior to any sending
  2809. if($rxt & 0x08){ #wakeup device
  2810. if(($mhp->{mFlgH} & 0xA2) == 0x82){ #wakeup signal
  2811. CUL_HM_appFromQ($mhp->{devN},"wu");# stack cmds if waiting
  2812. if ($mhp->{devH}{cmdStack}){
  2813. CUL_HM_SndCmd($mhp->{devH}, '++A112'.CUL_HM_IoId($mhp->{devH}).$mhp->{src});
  2814. CUL_HM_ProcessCmdStack($mhp->{devH});
  2815. }
  2816. }
  2817. elsif($devHlpr->{prt}{sProc} != 1){ # no wakeup signal,
  2818. # this is an autonom message send ACK but dont process further
  2819. $devHlpr->{prt}{sleeping} = 1 if($mhp->{mFlgH} & 0x20) ;
  2820. }
  2821. }
  2822. if($rxt & 0x10 && $devHlpr->{prt}{sleeping}){ # lazy config
  2823. if($mhp->{mFlgH} & 0x02 #wakeup device
  2824. && $defs{$mhp->{devH}{IODev}{NAME}}{TYPE} =~ m/^(HMLAN|HMUARTLGW)$/){
  2825. $devHlpr->{io}{newCh} = 1 if ($devHlpr->{prt}{sProc} == 2);
  2826. CUL_HM_appFromQ($mhp->{devN},"cf");# stack cmds if waiting
  2827. $devHlpr->{prt}{sleeping} = 0;
  2828. CUL_HM_ProcessCmdStack($mhp->{devH});
  2829. }
  2830. else{
  2831. $devHlpr->{prt}{sleeping} = 1;
  2832. }
  2833. }
  2834. my $repeat;
  2835. $devHlpr->{supp_Pair_Rep} = 0 if ($mhp->{mTp} ne "00"); # noansi: reset pairing suppress flag as we got something different from device
  2836. if ($mhp->{mTp} eq "02"){# Ack/Nack/aesReq ####################
  2837. my $reply;
  2838. my $success;
  2839. if ($devHlpr->{prt}{rspWait}{brstWu}){
  2840. if ($devHlpr->{prt}{rspWait}{mNo} eq $mhp->{mNo} &&
  2841. $mhp->{mStp} eq "00"){
  2842. if ($devHlpr->{prt}{awake} && $devHlpr->{prt}{awake}==4){#re-burstWakeup
  2843. delete $devHlpr->{prt}{rspWait};#clear burst-wakeup values
  2844. $devHlpr->{prt}{rspWait}{$_} = $devHlpr->{prt}{rspWaitSec}{$_}
  2845. foreach (keys%{$devHlpr->{prt}{rspWaitSec}}); #back to original message
  2846. delete $devHlpr->{prt}{rspWaitSec};
  2847. IOWrite($mhp->{devH}, "", $devHlpr->{prt}{rspWait}{cmd}); # and send
  2848. CUL_HM_statCnt($mhp->{devH}{IODev}{NAME},"s");
  2849. return "done";
  2850. }
  2851. $mhp->{devH}{protCondBurst} = "on" if ( $mhp->{devH}{protCondBurst}
  2852. && $mhp->{devH}{protCondBurst} !~ m/forced/);
  2853. $devHlpr->{prt}{awake}=2;#awake
  2854. }
  2855. else{
  2856. $mhp->{devH}{protCondBurst} = "off" if ( !$mhp->{devH}{protCondBurst}
  2857. || $mhp->{devH}{protCondBurst} !~ m/forced/);
  2858. $devHlpr->{prt}{awake}=3;#reject
  2859. return "done";
  2860. }
  2861. }
  2862. if (defined($devHlpr->{AESreqAck})) {
  2863. if ($devHlpr->{AESreqAck} eq substr($mhp->{p}, -1 * length($devHlpr->{AESreqAck}))) {
  2864. push @evtEt,[$mhp->{devH},1,"aesCommToDev:ok"];
  2865. }
  2866. else {
  2867. push @evtEt,[$mhp->{devH},1,"aesCommToDev:fail"];
  2868. }
  2869. delete $devHlpr->{AESreqAck};
  2870. }
  2871. if ($mhp->{mStp} =~ m/^8/){#NACK
  2872. #82 : peer not accepted - list full (VD)
  2873. #84 : request undefined register
  2874. #85 : peer not accepted - why? unknown
  2875. $success = "no";
  2876. CUL_HM_eventP($mhp->{devH},"Nack");
  2877. $reply = "NACK";
  2878. }
  2879. elsif($mhp->{mStp} eq "01"){ #ACKinfo#################
  2880. $success = "yes";
  2881. CUL_HM_m_setCh($mhp,substr($mhp->{p},2,2));
  2882. push @evtEt,[$mhp->{cHash},0,"recentStateType:ack"];
  2883. if (length($mhp->{p})>9){
  2884. my $rssi = substr($mhp->{p},8,2);
  2885. CUL_HM_storeRssi( $mhp->{devN}
  2886. ,$mhp->{dstN}
  2887. ,(-1)*(hex($rssi))
  2888. ,$mhp->{mNo})
  2889. if ($rssi && $rssi ne '00' && $rssi ne'80');
  2890. }
  2891. $reply = "ACKStatus";
  2892. if ($devHlpr->{tmdOn}){
  2893. if ((not hex(substr($mhp->{p},6,2))&0x40) && # not timedOn, we have to repeat
  2894. $devHlpr->{tmdOn} eq substr($mhp->{p},2,2) ){# virtual channels for dimmer may be incorrect
  2895. my ($pre,$nbr,$msg) = unpack 'A4A2A*',$devHlpr->{prt}{rspWait}{cmd};
  2896. $devHlpr->{prt}{rspWait}{cmd} = sprintf("%s%02X%s",
  2897. $pre,hex($nbr)+1,$msg);
  2898. CUL_HM_eventP($mhp->{devH},"TimedOn");
  2899. $success = "no";
  2900. $repeat = 1;
  2901. $reply = "NACK";
  2902. }
  2903. }
  2904. }
  2905. elsif($mhp->{mStp} eq "04"){ #ACK-AES, ###############
  2906. my (undef,$challenge,$aesKeyNbr) = unpack'A2A12A2',$mhp->{p};
  2907. push @evtEt,[$mhp->{devH},1,"aesKeyNbr:".$aesKeyNbr] if (defined $aesKeyNbr);# if ($mh{msgStat} =~ m/AESKey/)
  2908. if (AttrVal($mhp->{devH}{IODev}{NAME},"rfmode","") eq "HomeMatic" &&
  2909. defined($aesKeyNbr)) {
  2910. if ($mhp->{devH}{IODev}{TYPE} =~ m/^(TSCUL|TSSTACKED)$/) { #nonsi: for TSCUL
  2911. return "AES"; # noansi: TSCUL did it, now the normal ACK is expected
  2912. }
  2913. if ($cryptFunc == 1 && #AES is available
  2914. $devHlpr->{prt}{rspWait}{cmd}){ #There is a previously executed command
  2915. my (undef, %keys) = CUL_HM_getKeys($mhp->{devH});
  2916. my $kNo = hex($aesKeyNbr) / 2;
  2917. Log3 $mhp->{devH},5,"CUL_HM $mhp->{devN} signing request for $devHlpr->{prt}{rspWait}{cmd} challenge: "
  2918. .$challenge." kNo: ".$kNo;
  2919. if (!defined($keys{$kNo})) {
  2920. Log3 $mhp->{devH},1,"CUL_HM $mhp->{devN} unknown key for index $kNo, define it in the VCCU!";
  2921. $reply = "done";
  2922. }
  2923. else {
  2924. my $key = $keys{$kNo} ^ pack("H12", $challenge);
  2925. my $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_ECB());
  2926. my($s,$us) = gettimeofday();
  2927. my $respRaw = pack("NnH20", $s, $us, substr($devHlpr->{prt}{rspWait}{cmd}, 4, 20));
  2928. my $response = $cipher->encrypt($respRaw);
  2929. $devHlpr->{AESreqAck} = uc(unpack("H*", substr($response,0,4)));
  2930. Log3 $mhp->{devH},5,"CUL_HM $mhp->{devN} signing response: ".unpack("H*", $respRaw)
  2931. ." should send $devHlpr->{AESreqAck} to authenticate";
  2932. $response = $response ^ pack("H*", substr($devHlpr->{prt}{rspWait}{cmd}, 24));
  2933. $response = $cipher->encrypt(substr($response, 0, 16));
  2934. CUL_HM_SndCmd($mhp->{devH}, $mhp->{mNo}.$mhp->{mFlg}.'03'.CUL_HM_IoId($mhp->{devH}).$mhp->{src}.unpack("H*", $response));
  2935. $reply = "AES";
  2936. $repeat = 1;#prevent stop for messagenumber match
  2937. }
  2938. }
  2939. elsif ($cryptFunc != 1){ #AES is not available
  2940. Log3 $mhp->{devH},1,"CUL_HM $mhp->{devN} need Crypt::Rijndael to answer signing request with CUL";
  2941. $reply = "done";
  2942. }
  2943. }
  2944. else {
  2945. return "done";
  2946. }
  2947. }
  2948. else{ #ACK
  2949. $success = "yes";
  2950. $reply = "ACK";
  2951. }
  2952. if (defined $success && $success eq "yes"){# search if a trigger was accepted
  2953. if($mhp->{dstH}{helper}{ack}{$mhp->{devN}}){
  2954. my ($dChN,$mNo) = split(":",$mhp->{dstH}{helper}{ack}{$mhp->{devN}});
  2955. my $rv = ReadingsVal($dChN,"triggerTo_$mhp->{devN}",undef);
  2956. if ($mNo eq $mhp->{mNo} && $rv){
  2957. push @evtEt,[$defs{$dChN},1,"triggerTo_$mhp->{devN}:${rv}_ack"];
  2958. }
  2959. delete $mhp->{dstH}{helper}{ack}{$mhp->{devN}};
  2960. }
  2961. }
  2962. if ( $devHlpr->{prt}{mmcS}
  2963. && $devHlpr->{prt}{mmcS} == 3){
  2964. # after write device might need a break
  2965. # allow for wake types only - and if commands are pending
  2966. $devHlpr->{prt}{try} = 1 if(CUL_HM_getRxType($mhp->{devH}) & 0x08 #wakeup
  2967. && $mhp->{devH}{cmdStack});
  2968. if ($success eq 'yes'){
  2969. delete $devHlpr->{prt}{mmcA};
  2970. delete $devHlpr->{prt}{mmcS};
  2971. }
  2972. };
  2973. if($success){#do we have a final ack?
  2974. #mark timing on the channel, not the device
  2975. my $chn = sprintf("%02X",hex(substr($mhp->{p},2,2))&0x3f);
  2976. my $chnhash = $modules{CUL_HM}{defptr}{$chn?$mhp->{src}.$chn:$mhp->{src}};
  2977. $chnhash = $mhp->{devH} if(!$chnhash);
  2978. push @evtEt,[$chnhash,0,"CommandAccepted:$success"];
  2979. CUL_HM_ProcessCmdStack($mhp->{devH}) if(CUL_HM_IoId($mhp->{devH}) eq $mhp->{dst});
  2980. delete $devHlpr->{prt}{wuReSent}
  2981. if (!$devHlpr->{prt}{mmcS});
  2982. }
  2983. $ret = $reply;
  2984. }
  2985. elsif($mhp->{mTp} eq "03"){# AESack #############################
  2986. #Reply to AESreq - only visible with CUL or in monitoring mode
  2987. #not with HMLAN/USB
  2988. #my $aesKey = $p;
  2989. push @evtEt,[$mhp->{devH},1,"aesReqTo:".$mhp->{dstH}{NAME}] if (defined $mhp->{dstH});
  2990. $ret = "done";
  2991. }
  2992. elsif($mhp->{mTp} eq "00"){######################################
  2993. if ($devHlpr->{supp_Pair_Rep}){# repeated # Change noansi, don`t let the user press pair button forever if first pair try failed
  2994. $devHlpr->{supp_Pair_Rep} = 0; # noansi: reset flag, suppress only once not to lockup if device answer is not received
  2995. return "done"; # suppress handling of a repeated pair request
  2996. }
  2997. $devHlpr->{supp_Pair_Rep} = 1; # noansi: suppress next handling of a repeated pair request (if nothing else arrives in between from device)
  2998. my $paired = 0; #internal flag
  2999. CUL_HM_infoUpdtDevData($mhp->{devN}, $mhp->{devH},$mhp->{p})
  3000. if (!$modules{CUL_HM}{helper}{hmManualOper});
  3001. my $ioN = $ioHash->{NAME};
  3002. # hmPair set in IOdev or eventually in ccu!
  3003. my $ioOwn = InternalVal($ioN,"owner_CCU","");
  3004. my $hmPair = InternalVal($ioN,"hmPair" ,InternalVal($ioOwn,"hmPair" ,0 ));
  3005. my $hmPser = InternalVal($ioN,"hmPairSerial",InternalVal($ioOwn,"hmPairSerial",""));
  3006. if ( $hmPair ){# pairing is active
  3007. if (!$hmPser || $hmPser eq ReadingsVal($mhp->{devN},"D-serialNr","")){
  3008. # pairing requested - shall we?
  3009. my $ioId = CUL_HM_h2IoId($ioHash);
  3010. # pair now
  3011. Log3 $mhp->{devH},3, "CUL_HM pair: $mhp->{devN} "
  3012. ."$attr{$mhp->{devN}}{subType}, "
  3013. ."model $attr{$mhp->{devN}}{model} "
  3014. ."serialNr ".ReadingsVal($mhp->{devN},"D-serialNr","");
  3015. CUL_HM_RemoveHMPair("hmPairForSec:$ioOwn");# just in case...
  3016. delete $ioHash->{hmPair};
  3017. delete $ioHash->{hmPairSerial};
  3018. CUL_HM_respPendRm($mhp->{devH}); # remove all pending messages
  3019. delete $mhp->{devH}{cmdStack};
  3020. delete $devHlpr->{prt}{rspWait};
  3021. delete $devHlpr->{prt}{rspWaitSec};
  3022. delete $mhp->{devH}{READINGS}{"RegL_00."};
  3023. delete $mhp->{devH}{READINGS}{".RegL_00."};
  3024. if (!$modules{CUL_HM}{helper}{hmManualOper}){
  3025. $attr{$mhp->{devN}}{IODev} = $ioN;
  3026. $attr{$mhp->{devN}}{IOgrp} = "$ioOwn:$ioHash->{NAME}" if($ioOwn);
  3027. CUL_HM_assignIO($mhp->{devH}) ;
  3028. }
  3029. my ($idstr, $s) = ($ioId, 0xA);
  3030. $idstr =~ s/(..)/sprintf("%02X%s",$s++,$1)/ge;
  3031. CUL_HM_pushConfig($mhp->{devH}, $ioId, $mhp->{src},0,0,0,0, "0201$idstr");
  3032. $attr{$mhp->{devN}}{autoReadReg}=
  3033. AttrVal($mhp->{devN},"autoReadReg","4_reqStatus");
  3034. CUL_HM_qAutoRead($mhp->{devN},0);
  3035. # stack cmds if waiting. Do noch start if we have a burst device
  3036. # it may not paire
  3037. CUL_HM_appFromQ($mhp->{devN},"cf") if ($rxt == 0x04);
  3038. $respRemoved = 1;#force command stack processing
  3039. $paired = 1;
  3040. }
  3041. }
  3042. if($paired == 0 && CUL_HM_getRxType($mhp->{devH}) & 0x14){#no pair -send config?
  3043. CUL_HM_appFromQ($mhp->{devN},"cf"); # stack cmds if waiting
  3044. my $ioId = CUL_HM_h2IoId($mhp->{devH}{IODev});
  3045. $respRemoved = 1;#force command stack processing
  3046. }
  3047. $devHlpr->{HM_CMDNR} += 0x27; # force new setting. Send will take care of module 255
  3048. $ret = "done";
  3049. }
  3050. elsif($mhp->{mTp} eq "10"){######################################
  3051. CUL_HM_m_setCh($mhp,substr($mhp->{p},2,2));
  3052. if ($mhp->{mStp} eq "00"){ #SerialRead====================================
  3053. my $sn = pack("H*",substr($mhp->{p},2,20));
  3054. push @evtEt,[$mhp->{devH},0,"D-serialNr:$sn"];
  3055. $attr{$mhp->{devN}}{serialNr} = $sn;
  3056. CUL_HM_respPendRm($mhp->{devH}) if ($pendType eq "SerialRead");
  3057. $ret = "done";
  3058. }
  3059. elsif($mhp->{mStp} eq "01"){ #storePeerList=================================
  3060. my $mNoInt = hex($mhp->{mNo});
  3061. if ($pendType eq "PeerList" &&
  3062. ($rspWait->{mNo} == $mNoInt || $rspWait->{mNo} == $mNoInt-1)){
  3063. $rspWait->{mNo} = $mNoInt;
  3064. my $chn = $devHlpr->{prt}{rspWait}{forChn};
  3065. my $chnhash = $modules{CUL_HM}{defptr}{$mhp->{src}.$chn};
  3066. $chnhash = $mhp->{devH} if (!$chnhash);
  3067. my $chnName = $chnhash->{NAME};
  3068. my @peers;
  3069. if($mhp->{md} eq "HM-Dis-WM55"){
  3070. #how ugly - this device adds one byte at begin - remove it.
  3071. (undef,@peers) = unpack 'A4(A8)*',$mhp->{p};
  3072. }
  3073. else{
  3074. (undef,@peers) = unpack 'A2(A8)*',$mhp->{p};
  3075. }
  3076. $_ = '00000000' foreach (grep /^000000/,@peers);#correct bad term(6 chars) from rain sens)
  3077. $_ .= '0x' foreach (grep /^......$/,@peers); #if channel is unknown we assume at least a device
  3078. $chnhash->{helper}{peerIDsRaw}.= ",".join",",@peers;
  3079. CUL_HM_ID2PeerList ($chnName,$_,1) foreach (@peers);
  3080. if (grep /00000000/,@peers) {# last entry, peerList is complete
  3081. # check for request to get List3 data
  3082. my $reqPeer = $chnhash->{helper}{getCfgList};
  3083. if ($reqPeer){
  3084. my $flag = 'A0';
  3085. my $ioId = CUL_HM_IoId($mhp->{devH});
  3086. my @peerID = split(",",(AttrVal($chnName,"peerIDs","")));
  3087. foreach my $l (split ",",$chnhash->{helper}{getCfgListNo}){
  3088. next if (!$l);
  3089. my $listNo = "0".$l;
  3090. foreach my $peer (grep (!/00000000/,@peerID)){
  3091. next if ($peer =~ m/0x$/);
  3092. $peer .="01" if (length($peer) == 6); # add the default
  3093. if ($peer &&($peer eq $reqPeer || $reqPeer eq "all")){
  3094. CUL_HM_PushCmdStack($mhp->{devH},sprintf("++%s01%s%s%s04%s%s",
  3095. $flag,$ioId,$mhp->{src},$chn,$peer,$listNo));# List3 or 4
  3096. }
  3097. }
  3098. }
  3099. }
  3100. CUL_HM_respPendRm($mhp->{devH});
  3101. delete $chnhash->{helper}{getCfgList};
  3102. delete $chnhash->{helper}{getCfgListNo};
  3103. CUL_HM_rmOldRegs($chnName);
  3104. $chnhash->{READINGS}{".peerListRDate"}{VAL} = $chnhash->{READINGS}{".peerListRDate"}{TIME} = TimeNow();
  3105. }
  3106. else{
  3107. CUL_HM_respPendToutProlong($mhp->{devH});#wasn't last - reschedule timer
  3108. }
  3109. }
  3110. $ret = "done";
  3111. }
  3112. elsif($mhp->{mStp} eq "02" ||$mhp->{mStp} eq "03"){ #ParamResp==============
  3113. my $mNoInt = hex($mhp->{mNo});
  3114. if ( $pendType eq "RegisterRead" &&
  3115. ($rspWait->{mNo} == $mNoInt || $rspWait->{mNo} == $mNoInt-1)){
  3116. $repeat = 1;#prevent stop for messagenumber match
  3117. $rspWait->{mNo} = $mNoInt; # next message will be numbered same or one plus.
  3118. CUL_HM_m_setCh($mhp,$rspWait->{forChn});
  3119. my ($format,$data);
  3120. ($format,$data) = ($1,$2) if ($mhp->{p} =~ m/^(..)(.*)/);
  3121. my $list = $rspWait->{forList};
  3122. $list = "00" if (!$list); #use the default
  3123. if ($format eq "02"){ # list 2: format aa:dd aa:dd ...
  3124. $data =~ s/(..)(..)/ $1:$2/g;
  3125. }
  3126. elsif ($format eq "03"){ # list 3: format aa:dddd
  3127. my $addr;
  3128. my @dataList;
  3129. ($addr,$data) = (hex($1),$2) if ($data =~ m/(..)(.*)/);
  3130. if ($addr == 0){
  3131. $data = "00:00";
  3132. push @dataList,"00:00";
  3133. }
  3134. else{
  3135. $data =~ s/(..)/$1:/g;
  3136. foreach my $d1 (split(":",$data)){
  3137. push (@dataList,sprintf("%02X:%s",$addr++,$d1));
  3138. }
  3139. $data = join(" ",@dataList);
  3140. }
  3141. }
  3142. my $lastAddr;
  3143. $lastAddr = hex($1) if ($data =~ m/.*(..):..$/);
  3144. my $peer = $rspWait->{forPeer};
  3145. my $regLNp = "RegL_".$list.".".$peer;# pure, no expert
  3146. my $regLN = ($mhp->{cHash}{helper}{expert}{raw}?"":".").$regLNp;
  3147. if ( defined $lastAddr
  3148. && ( $lastAddr > $rspWait->{nAddr}
  3149. || $lastAddr == 0)){
  3150. CUL_HM_UpdtReadSingle($mhp->{cHash},$regLN,ReadingsVal($mhp->{cName},$regLN,"")." $data",0);
  3151. $rspWait->{nAddr} = $lastAddr;
  3152. }
  3153. if ($data =~ m/00:00$/){ # this was the last message in the block
  3154. if($list eq "00"){
  3155. push @evtEt,[$mhp->{devH},0,"PairedTo:".CUL_HM_getRegFromStore($mhp->{devN},"pairCentral",0,"")];
  3156. }
  3157. CUL_HM_respPendRm($mhp->{devH});
  3158. delete $mhp->{cHash}{helper}{shadowReg}{$regLNp}; #rm shadow
  3159. # peerChannel name from/for user entry. <IDorName> <deviceID> <ioID>
  3160. CUL_HM_updtRegDisp($mhp->{cHash},$list,$peer);
  3161. }
  3162. else{
  3163. CUL_HM_respPendToutProlong($mhp->{devH});#wasn't last - reschedule timer
  3164. }
  3165. }
  3166. $ret = "done";
  3167. }
  3168. elsif($mhp->{mStp} eq "04" ||$mhp->{mStp} eq "05"){ #ParamChange============
  3169. #m:1E A010 4CF663 1743BF 0500(00000000)(07)(00) # finish
  3170. #m:1E A010 4CF663 1743BF 0500(00000000)(07)(62)(2120212020EA36F643)
  3171. my($mCh,$peerID,$list,$data) = ($1,$2,$3,$4) if($mhp->{p} =~ m/^0.(..)(........)(..)(.*)/);
  3172. CUL_HM_m_setCh($mhp,$mCh);
  3173. my $fch = CUL_HM_shC($mhp->{cHash},$list,$mhp->{chnHx});
  3174. my $fHash = $modules{CUL_HM}{defptr}{$mhp->{src}.$fch};
  3175. $fHash = $mhp->{devH} if (!$fHash);
  3176. my $fName = $fHash->{NAME};
  3177. my $peer = ($peerID ne "00000000") ? CUL_HM_peerChName($peerID,"000000") : "";
  3178. if($data eq "00"){#update finished for mStp 05. Now update display
  3179. CUL_HM_updtRegDisp($fHash,$list,$peer);
  3180. }
  3181. else{
  3182. my $regLNp = "RegL_".$list.".".$peer;
  3183. $regLNp =~ s/broadcast//;
  3184. $regLNp =~ s/ /_/g; #remove blanks
  3185. my $regLN = ($mhp->{cHash}{helper}{expert}{raw}?"":".").$regLNp;
  3186. my $rCur = ReadingsVal($fName,$regLN,"");
  3187. if ($rCur){# if list not present we cannot update
  3188. if ($mhp->{mStp} eq "05"){ # generate $data identical for 04 and 05
  3189. $data = "";
  3190. my ($addr,$data1);
  3191. ($addr,$data1) = (hex($3),$4) if($mhp->{p} =~ m/^05..(........)(..)(..)(.*)/);
  3192. foreach my $d1 ($data1 =~ m/.{2}/g){
  3193. $data .= sprintf(" %02X:%s",$addr++,$d1);
  3194. }
  3195. }
  3196. else{
  3197. $data =~ s/(..)(..)/ $1:$2/g;
  3198. }
  3199. my $sdH = CUL_HM_shH($mhp->{cHash},$list,$mhp->{dst});
  3200. my $shdwReg = $sdH->{helper}{shadowReg}{$regLNp};
  3201. foreach my $entry (split(" ",$data)){
  3202. my ($a,$d) = split(":",$entry);
  3203. last if ($a eq "00");
  3204. if ($rCur =~ m/$a:/){ $rCur =~ s/$a:../$a:$d/;}
  3205. else { $rCur .= " ".$entry;}
  3206. $shdwReg =~ s/ $a:..// if ($shdwReg);# confirmed: remove from shadow
  3207. }
  3208. CUL_HM_UpdtReadSingle($fHash,$regLN,$rCur,0);
  3209. CUL_HM_updtRegDisp($fHash,$list,$peer) if ($mhp->{mStp} eq "04");
  3210. }
  3211. }
  3212. $ret= "parsed"; # send ACK
  3213. }
  3214. elsif($mhp->{mStp} eq "06"){ #reply to status request=======================
  3215. my $rssi = substr($mhp->{p},8,2);
  3216. push @evtEt,[$mhp->{cHash},0,"recentStateType:info"];
  3217. CUL_HM_storeRssi( $mhp->{devN}
  3218. ,$mhp->{dstN}
  3219. ,(-1)*(hex($rssi))
  3220. ,$mhp->{mNo})
  3221. if ($rssi && $rssi ne '00' && $rssi ne'80');
  3222. CUL_HM_unQEntity($mhp->{cName},"qReqStat");
  3223. if ($pendType eq "StatusReq"){#it is the answer to our request
  3224. CUL_HM_respPendRm($mhp->{devH});
  3225. $ret = "STATresp";
  3226. }
  3227. else{
  3228. if ($mhp->{chn} == 0
  3229. || ( $mhp->{chn} == 1
  3230. && $devHlpr->{PONtest})){# this is power on
  3231. CUL_HM_qStateUpdatIfEnab($mhp->{devN});
  3232. CUL_HM_qAutoRead($mhp->{devN},2);
  3233. $ret = "powerOn" ;# check dst eq "000000" as well?
  3234. $devHlpr->{PONtest} = 0;
  3235. }
  3236. }
  3237. }
  3238. }
  3239. elsif($mhp->{mTp} eq "12"){ #wakeup received - ignore############
  3240. $ret = "done";
  3241. }
  3242. elsif($mhp->{mTp} =~ m/^4[01]/){ #someone is triggered##########
  3243. CUL_HM_m_setCh($mhp,substr($mhp->{p},0,2));
  3244. my $cnt = hex(substr($mhp->{p},2,2));
  3245. my $long = ($mhp->{chnraw} & 0x40)?"long":"short";
  3246. my $level = "-";
  3247. if (length($mhp->{p})>5){
  3248. my $l = substr($mhp->{p},4,2);
  3249. if ($mhp->{cHash}{helper}{lm} && $mhp->{cHash}{helper}{lm}{hex($l)}){$level = $mhp->{cHash}{helper}{lm}{hex($l)}}
  3250. elsif ($lvlStr{md}{$mhp->{md}} && $lvlStr{md}{$mhp->{md}}{$l} ){$level = $lvlStr{md}{$mhp->{md}}{$l}}
  3251. elsif ($lvlStr{st}{$mhp->{st}} && $lvlStr{st}{$mhp->{st}}{$l} ){$level = $lvlStr{st}{$mhp->{st}}{$l}}
  3252. else {$level = hex($l)};
  3253. }
  3254. elsif($mhp->{mTp} eq "40"){
  3255. $level = $long;
  3256. my $state = ucfirst($long);
  3257. if(!defined $mhp->{cHash}{helper}{BNO} || $mhp->{cHash}{helper}{BNO} ne $cnt){#cnt = event counter
  3258. $mhp->{cHash}{helper}{BNO} = $cnt;
  3259. $mhp->{cHash}{helper}{BNOCNT} = 0; # message counter reset
  3260. }
  3261. if (($mhp->{mFlgH} & 0x24) == 0x20 && ($long eq "long")){ # release long press
  3262. $state .= "Release";
  3263. }
  3264. else{ # continue long press
  3265. $mhp->{cHash}{helper}{BNOCNT} += 1;
  3266. }
  3267. $state .= " $mhp->{cHash}{helper}{BNOCNT}_$cnt";
  3268. push @evtEt,[$mhp->{cHash},1,"trigger:".(ucfirst($long))."_$cnt"];
  3269. push @evtEt,[$mhp->{cHash},1,"state:".$state." (to $mhp->{dstN})"] if ($mhp->{devH} ne $mhp->{cHash});
  3270. if( $mhp->{mFlgH} & 0x20
  3271. && $mhp->{dst} ne "000000"
  3272. && $mhp->{dst} ne $mhp->{id}){
  3273. push @evtEt,[$mhp->{cHash},1,"triggerTo_$mhp->{dstN}:".(ucfirst($long))."_$cnt"];
  3274. $devHlpr->{ack}{$mhp->{dstN}} = "$mhp->{cName}:$mhp->{mNo}";
  3275. }
  3276. }
  3277. push @evtEt,[$mhp->{cHash},1,"trigger_cnt:$cnt"];
  3278. my $peerIDs = AttrVal($mhp->{cName},"peerIDs","");
  3279. if ($peerIDs =~ m/$mhp->{dst}/){# dst is available in the ID list
  3280. foreach my $peer (grep /^$mhp->{dst}/,split(",",$peerIDs)){
  3281. my $pName = CUL_HM_id2Name($peer);
  3282. $pName = CUL_HM_id2Name($mhp->{dst}) if (!$pName || !$defs{$pName}); #$dst - device-id of $peer
  3283. next if (!$pName || !$defs{$pName});
  3284. push @evtEt,[$defs{$pName},1,"trig_$mhp->{cName}:".(ucfirst($level))."_$cnt"];
  3285. push @evtEt,[$defs{$pName},1,"trigLast:$mhp->{cName}".(($level ne "-")?":$level":"")];
  3286. CUL_HM_stateUpdatDly($pName,10) if ($mhp->{mTp} eq "40");#conditional request may not deliver state-req
  3287. }
  3288. }
  3289. elsif($mhp->{mFlgH} & 2 # dst can be garbage - but not if answer request
  3290. && ( !$mhp->{dstH}
  3291. || $mhp->{dst} ne CUL_HM_IoId($mhp->{dstH}))
  3292. ){
  3293. my $pName = CUL_HM_id2Name($mhp->{dst});
  3294. push @evtEt,[$mhp->{cHash},1,"trigDst_$pName:noConfig"];
  3295. }
  3296. return "";
  3297. }
  3298. elsif($mhp->{mTp} eq "70"){ #Time to trigger TC##################
  3299. #send wakeup and process command stack
  3300. }
  3301. if ($rspWait->{mNo} &&
  3302. $rspWait->{mNo} eq $mhp->{mNo} &&
  3303. !$repeat){
  3304. #response we waited for - stop Waiting
  3305. CUL_HM_respPendRm($mhp->{devH});
  3306. }
  3307. return $ret;
  3308. }
  3309. sub CUL_HM_m_setCh($$){### add channel identification to Message Hash
  3310. my ($mhp,$chn) = @_;
  3311. $mhp->{chnM} = $chn;
  3312. $mhp->{chnraw}= hex($mhp->{chnM});
  3313. $mhp->{chn} = $mhp->{chnraw} & 0x3f;
  3314. $mhp->{chnHx} = sprintf("%02X",$mhp->{chn});
  3315. $mhp->{cHash} = CUL_HM_id2Hash($mhp->{src}.$mhp->{chnHx});
  3316. $mhp->{cHash} = $mhp->{shash} if (!$mhp->{cHash});
  3317. $mhp->{cName} = $mhp->{cHash}{NAME};
  3318. }
  3319. sub CUL_HM_queueUpdtCfg($){
  3320. my $name = shift;
  3321. if ($modules{CUL_HM}{helper}{hmManualOper}){ # no update when manual operation
  3322. delete $modules{CUL_HM}{helper}{updtCfgLst};
  3323. }
  3324. else{
  3325. my @arr;
  3326. if ($modules{CUL_HM}{helper}{updtCfgLst}){
  3327. @arr = CUL_HM_noDup((@{$modules{CUL_HM}{helper}{updtCfgLst}}, $name));
  3328. }
  3329. else{
  3330. push @arr,$name;
  3331. }
  3332. $modules{CUL_HM}{helper}{updtCfgLst} = \@arr;
  3333. }
  3334. RemoveInternalTimer("updateConfig");
  3335. InternalTimer(gettimeofday()+5,"CUL_HM_updateConfig", "updateConfig", 0);
  3336. }
  3337. sub CUL_HM_parseSDteam(@){#handle SD team events
  3338. my ($mTp,$sId,$dId,$p) = @_;
  3339. my @entities;
  3340. my $dHash = CUL_HM_id2Hash($dId);
  3341. my $dName = CUL_HM_id2Name($dId);
  3342. my $sHash = CUL_HM_id2Hash($sId);
  3343. my $sName = CUL_HM_hash2Name($sHash);
  3344. if (AttrVal($sName,"subType","") eq "virtual"){
  3345. foreach my $cId (CUL_HM_getAssChnIds($sName)){
  3346. my $cHash = CUL_HM_id2Hash($cId);
  3347. next if (!$cHash->{sdTeam} || $cHash->{sdTeam} ne "sdLead");
  3348. my $cName = CUL_HM_id2Name($cId);
  3349. $sHash = $cHash;
  3350. $sName = CUL_HM_id2Name($cId);
  3351. last;
  3352. }
  3353. }
  3354. return () if (!$sHash->{sdTeam} || $sHash->{sdTeam} ne "sdLead");
  3355. if ($mTp eq "40"){ #test
  3356. my $trgCnt = hex(substr($p,2,2));
  3357. my $err = hex(substr($p,0,2));
  3358. push @evtEt,[$sHash,1,"teamCall:from $dName:$trgCnt"];
  3359. push @evtEt,[$dHash,1,"battery:" .(($err&0x80) ? "low":"ok")];
  3360. foreach (split ",",$attr{$sName}{peerIDs}){
  3361. my $tHash = CUL_HM_id2Hash($_);
  3362. push @evtEt,[$tHash,1,"teamCall:from $dName:$trgCnt"];
  3363. }
  3364. }
  3365. elsif ($mTp eq "41"){ #Alarm detected
  3366. #C8: Smoke Alarm
  3367. #C7: tone off
  3368. #01: no alarm
  3369. my (undef,$No,$state) = unpack 'A2A2A2',$p;
  3370. if(($dHash) && # update source(ID reported in $dst)
  3371. (!$dHash->{helper}{alarmNo} || $dHash->{helper}{alarmNo} ne $No)){
  3372. $dHash->{helper}{alarmNo} = $No;
  3373. }
  3374. my ($sVal,$sProsa,$smokeSrc) = (hex($state),"off","none");
  3375. if ($sVal > 1){
  3376. $sProsa = "smoke-Alarm_".$No;
  3377. $smokeSrc = $dName;
  3378. }
  3379. return if($sProsa eq ReadingsVal($sHash->{NAME},"state",""));
  3380. push @evtEt,[$sHash,1,"recentAlarm:$smokeSrc"] if($sVal == 200);
  3381. push @evtEt,[$sHash,1,"state:$sProsa"];
  3382. push @evtEt,[$sHash,1,'level:'.$sVal];
  3383. push @evtEt,[$sHash,1,"eventNo:".$No];
  3384. push @evtEt,[$sHash,1,"smoke_detect:".$smokeSrc];
  3385. foreach (split ",",$attr{$sName}{peerIDs}){
  3386. my $tHash = CUL_HM_id2Hash($_);
  3387. push @evtEt,[$tHash,1,"state:$sProsa"];
  3388. push @evtEt,[$tHash,1,"smoke_detect:$smokeSrc"];
  3389. }
  3390. }
  3391. return @entities;
  3392. }
  3393. sub CUL_HM_parseSDteam_2(@){#handle SD team events
  3394. my ($mTp,$sId,$dId,$p) = @_;
  3395. my $dHash = CUL_HM_id2Hash($dId);
  3396. my $dName = CUL_HM_id2Name($dId);
  3397. my $sHash = CUL_HM_id2Hash($sId);
  3398. my $sName = CUL_HM_hash2Name($sHash);
  3399. if (AttrVal($sName,"subType","") eq "virtual"){#search for the team lead channel
  3400. foreach my $cId (CUL_HM_getAssChnIds($sName)){
  3401. my $cHash = CUL_HM_id2Hash($cId);
  3402. next if (!$cHash->{sdTeam} || $cHash->{sdTeam} ne "sdLead");
  3403. $sHash = $cHash;
  3404. $sName = CUL_HM_hash2Name($sHash);
  3405. last;
  3406. }
  3407. }
  3408. return () if (!$sHash->{sdTeam} || $sHash->{sdTeam} ne "sdLead"
  3409. ||!$dHash);
  3410. my ($chn,$No,$state,$null,$aesKNo,$aesStr) = unpack 'A2A2A2A4A2A8',$p;
  3411. if(!$dHash->{helper}{alarmNo} || $dHash->{helper}{alarmNo} ne $No){
  3412. $dHash->{helper}{alarmNo} = $No;
  3413. }
  3414. else{
  3415. return ();# duplicate alarm
  3416. }
  3417. my ($sVal,$sProsa,$smokeSrc) = (hex($state),"off","none");
  3418. my @tHash = ((map{CUL_HM_id2Hash($_)} grep !/00000000/, split ",",$attr{$sName}{peerIDs})
  3419. ,$sHash);
  3420. if ($sVal > 179 ||$sVal <51 ){# need to raise alarm
  3421. if ($sVal > 179){# need to raise alarm
  3422. #"SHORT_COND_VALUE_LO" value="50"/>
  3423. #"SHORT_COND_VALUE_HI" value="180"/>
  3424. $sProsa = "smoke-Alarm_".$No;
  3425. $smokeSrc = $dName;
  3426. push @evtEt,[$sHash,1,"recentAlarm:$smokeSrc"] if($sVal == 200);
  3427. }
  3428. elsif($sVal <51){#alarm inactive
  3429. #$sProsa = "off_".$No;
  3430. #$smokeSrc = $dName;
  3431. }
  3432. push @evtEt,[$sHash,1,'level:'.$sVal];
  3433. }
  3434. elsif($sVal == 150){#alarm teamcall
  3435. push @evtEt,[$_,1,"teamCall:from $dName:$No"] foreach (@tHash);
  3436. }
  3437. elsif($sVal == 151){#alarm teamcall repeat
  3438. push @evtEt,[$dHash,1,"MsgRepeated $No"];#unclear. first repeater send 97 instead of 96. What about 2nd ans third repeater?
  3439. }
  3440. foreach (@tHash){
  3441. push @evtEt,[$_,1,"state:$sProsa"];
  3442. push @evtEt,[$_,1,"smoke_detect:$smokeSrc"];
  3443. }
  3444. push @evtEt,[$dHash,1,"battery:" .((hex($chn)&0x80) ? "low":"ok")];
  3445. push @evtEt,[$sHash,1,"eventNo:".$No];
  3446. Log3 $sHash,5,"CUL_HM $sName sdTeam: no:$No state:$state aesNo:$aesKNo aesStr:$aesStr";
  3447. return;
  3448. }
  3449. sub CUL_HM_updtSDTeam(@){#in: TeamName, optional caller name and its new state
  3450. # update team status if virtual team lead
  3451. # check all member state
  3452. # prio: 1:alarm, 2: unknown, 3: off
  3453. # sState given in input may not yet be visible in readings
  3454. my ($name,$sName,$sState) = @_;
  3455. return undef if (!$defs{$name} || AttrVal($name,"model","") !~ m "virtual");
  3456. ($sName,$sState) = ("","") if (!$sName || !$sState);
  3457. return undef if (ReadingsVal($name,"state","off") =~ m/smoke-Alarm/);
  3458. my $dStat = "off";
  3459. foreach my $pId(split(',',AttrVal($name,"peerIDs",""))){#screen teamIDs for Alarm
  3460. my $pNam = (($pId && $pId ne "00000000") ? CUL_HM_id2Name(substr($pId,0,6)) : "");
  3461. next if (!$pNam ||!$defs{$pNam});
  3462. my $pStat = ($pNam eq $sName)
  3463. ?$sState
  3464. :ReadingsVal($pNam,"state",undef);
  3465. if (!$pStat) {$dStat = "unknown";}
  3466. elsif ($pStat ne "off") {$dStat = $pStat;last;}
  3467. }
  3468. return CUL_HM_UpdtReadSingle($defs{$name},"state",$dStat,1);
  3469. }
  3470. sub CUL_HM_pushEvnts(){########################################################
  3471. #write events to Readings and collect touched devices
  3472. my @ent = ();
  3473. $evtDly = 0;# switch delay trigger off
  3474. if (scalar(@evtEt) > 0){
  3475. @evtEt = sort {($a->[0] cmp $b->[0])|| ($a->[1] cmp $b->[1])} @evtEt;
  3476. my ($h,$x) = ("","");
  3477. my @evts = ();
  3478. foreach my $e(@evtEt){
  3479. if(scalar(@{$e} != 3)){
  3480. Log 2,"CUL_HM set reading invalid:".join(",",@{$e});
  3481. next;
  3482. }
  3483. if ($h ne ${$e}[0] || $x ne ${$e}[1]){
  3484. push @ent,CUL_HM_UpdtReadBulk($h,$x,@evts);
  3485. @evts = ();
  3486. ($h,$x) = (${$e}[0],${$e}[1]);
  3487. }
  3488. push @evts,${$e}[2] if (${$e}[2]);
  3489. }
  3490. @evtEt = ();
  3491. push @ent,CUL_HM_UpdtReadBulk($h,$x,@evts);
  3492. }
  3493. return @ent;
  3494. }
  3495. sub CUL_HM_Get($@) {#+++++++++++++++++ get command+++++++++++++++++++++++++++++
  3496. my ($hash, @a) = @_;
  3497. return "no value specified" if(@a < 2);
  3498. return "" if(!$hash->{NAME});
  3499. my $name = $hash->{NAME};
  3500. my $devName = InternalVal($name,"device",$name);
  3501. my $st = AttrVal($devName, "subType", "");
  3502. my $md = AttrVal($devName, "model", "");
  3503. my $cmd = $a[1];
  3504. my $roleC = $hash->{helper}{role}{chn}?1:0; #entity may act in multiple roles
  3505. my $roleD = $hash->{helper}{role}{dev}?1:0;
  3506. my $roleV = $hash->{helper}{role}{vrt}?1:0;
  3507. my $fkt = $hash->{helper}{fkt}?$hash->{helper}{fkt}:"";
  3508. my ($dst,$chn) = unpack 'A6A2',$hash->{DEF}.($roleC?'01':'00');
  3509. my $h = undef;
  3510. $h = $culHmGlobalGets->{$cmd} if(!$roleV &&($roleD || $roleC));
  3511. $h = $culHmVrtGets->{$cmd} if(!defined($h) && $roleV);
  3512. $h = $culHmSubTypeGets->{$st}{$cmd} if(!defined($h) && $culHmSubTypeGets->{$st});
  3513. $h = $culHmModelGets->{$md}{$cmd} if(!defined($h) && $culHmModelGets->{$md});
  3514. $h = "" if(!defined($h) && (eval "defined(&HMinfo_GetFn)" && $cmd eq "regTable"));
  3515. my @h;
  3516. @h = split(" ", $h) if($h);
  3517. if(!defined($h)) {
  3518. my @arr = ();
  3519. if(!$roleV &&($roleD || $roleC)){foreach(keys %{$culHmGlobalGets} ){push @arr,"$_:".$culHmGlobalGets->{$_} }};
  3520. if($roleV) {foreach(keys %{$culHmVrtGets} ){push @arr,"$_:".$culHmVrtGets->{$_} }};
  3521. if($culHmSubTypeGets->{$st}) {foreach(keys %{$culHmSubTypeGets->{$st}}){push @arr,"$_:".${$culHmSubTypeGets->{$st}}{$_} }};
  3522. if($culHmModelGets->{$md}) {foreach(keys %{$culHmModelGets->{$md}} ){push @arr,"$_:".${$culHmModelGets->{$md}}{$_} }};
  3523. if($culHmModelGets->{$md}) {foreach(keys %{$culHmModelGets->{$md}} ){push @arr,"$_:".${$culHmModelGets->{$md}}{$_} }};
  3524. if(eval"defined(&HMinfo_GetFn)"){ {push @arr,"regTable:" }};
  3525. foreach(@arr){
  3526. my ($cmd,$val) = split(":",$_,2);
  3527. if (!$val ||
  3528. $val !~ m/^\[.*\]$/ ||
  3529. $val =~ m/\[.*\[/ ||
  3530. $val =~ m/(\<|\>)]/
  3531. ){
  3532. $_ = $cmd;
  3533. }
  3534. else{
  3535. $val =~ s/(\[|\])//g;
  3536. my @vArr = split('\|',$val);
  3537. foreach (@vArr){
  3538. if ($_ =~ m/(.*)\.\.(.*)/ ){
  3539. my @list = map { ($_.".0", $_+0.5) } (($1+0)..($2+0));
  3540. pop @list;
  3541. $_ = join(",",@list);
  3542. }
  3543. }
  3544. $_ = "$cmd:".join(",",@vArr);
  3545. }
  3546. }
  3547. my $usg = "Unknown argument $cmd, choose one of ".join(" ",sort @arr);
  3548. return $usg;
  3549. }
  3550. elsif($h eq "" && @a != 2) {
  3551. return "$cmd requires no parameters";
  3552. }
  3553. elsif($h !~ m/\.\.\./ && @h != @a-2) {
  3554. return "$cmd requires parameter: $h";
  3555. }
  3556. my $devHash = CUL_HM_getDeviceHash($hash);
  3557. #----------- now start processing --------------
  3558. if ($cmd eq "param") { ###################################################
  3559. my $p = $a[2];
  3560. return $attr{$name}{$p} if ($attr{$name}{$p});
  3561. return $hash->{READINGS}{$p}{VAL} if ($hash->{READINGS}{$p});
  3562. return $hash->{READINGS}{".$p"}{VAL} if ($hash->{READINGS}{".$p"});
  3563. return $hash->{$p} if ($hash->{$p});
  3564. return $hash->{helper}{$p} if ($hash->{helper}{$p} && ref($hash->{helper}{$p}) ne "HASH");
  3565. return $attr{$devName}{$p} if ($attr{$devName}{$p});
  3566. return "undefined";
  3567. }
  3568. elsif($cmd =~ m/^(reg|regVal)$/) { #########################################
  3569. my (undef,undef,$regReq,$list,$peerId) = @a;
  3570. return if(!defined $regReq);
  3571. if ($regReq eq 'all'){
  3572. my @regArr = CUL_HM_getRegN($st,$md,($roleD?"00":""),($roleC?$chn:""));
  3573. my @peers; # get all peers we have a reglist
  3574. my @listWp; # list that require peers
  3575. foreach my $readEntry (keys %{$hash->{READINGS}}){
  3576. if ($readEntry =~ m/^[\.]?RegL_(.*)/){ #reg Reading "RegL_<list>:peerN
  3577. my $peer = substr($1,3);
  3578. next if (!$peer);
  3579. push(@peers,$peer);
  3580. push(@listWp,substr($1,1,1));
  3581. }
  3582. }
  3583. my @regValList; #storage of results
  3584. my $regHeader = "list:peer\tregister :value\n";
  3585. foreach my $regName (@regArr){
  3586. my $regL = $culHmRegDefine->{$regName}->{l};
  3587. my @peerExe = (grep (/$regL/,@listWp)) ? @peers : ("00000000");
  3588. foreach my $peer(@peerExe){
  3589. next if($peer eq "");
  3590. my $regVal= CUL_HM_getRegFromStore($name,$regName,0,$peer);#determine
  3591. my $peerN = CUL_HM_id2Name($peer);
  3592. $peerN = " " if ($peer eq "00000000");
  3593. push @regValList,sprintf(" %d:%s\t%-16s :%s\n",
  3594. $regL,$peerN,$regName,$regVal)
  3595. if ($regVal !~ m/invalid/);
  3596. }
  3597. }
  3598. my $addInfo = "";
  3599. if ($md =~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/ && $chn eq "02"){$addInfo = CUL_HM_TCtempReadings($hash)}
  3600. elsif ($md =~ m/^HM-CC-RT-DN/ && $chn eq "04"){$addInfo = CUL_HM_TCITRTtempReadings($hash,$md,7)}
  3601. elsif ($md =~ m/^HM-TC-IT/ && $chn eq "02"){$addInfo = CUL_HM_TCITRTtempReadings($hash,$md,7,8,9)}
  3602. elsif ($md =~ m/^(^HM-PB-4DIS-WM|HM-Dis-WM55|HM-RC-Dis-H-x-EU|ROTO_ZEL-STG-RM-DWT-10)/)
  3603. {$addInfo = CUL_HM_4DisText($hash)}
  3604. elsif ($md eq "HM-Sys-sRP-Pl") {$addInfo = CUL_HM_repReadings($hash)}
  3605. return $name." type:".$st." - \n".
  3606. $regHeader.join("",sort(@regValList)).
  3607. $addInfo;
  3608. }
  3609. else{
  3610. my $regVal = CUL_HM_getRegFromStore($name,$regReq,$list,$peerId);
  3611. $regVal =~ s/ .*// if ($cmd eq "regVal");
  3612. return ($regVal =~ m/^invalid/)? "Value not captured:$name - $regReq"
  3613. : $regVal;
  3614. }
  3615. }
  3616. elsif($cmd eq "regTable") { ########################################
  3617. return HMinfo_GetFn($hash,$name,"register","-f","\^".$name."\$");
  3618. }
  3619. elsif($cmd eq "regList") { #################################################
  3620. my @regArr = CUL_HM_getRegN($st,$md,$chn);
  3621. return CUL_HM_getRegInfo(\@regArr,$roleD,$roleC) ;
  3622. my @rI;
  3623. foreach my $regName (@regArr){
  3624. my $reg = $culHmRegDefine->{$regName};
  3625. my $help = $reg->{t};
  3626. my ($min,$max) = ($reg->{min},"to ".$reg->{max});
  3627. if ($reg->{c} eq "lit"){
  3628. $help .= " options:".join(",",keys%{$reg->{lit}});
  3629. $min = "";
  3630. $max = "literal";
  3631. }
  3632. elsif (defined($reg->{lit})){
  3633. $help .= " special:".join(",",keys%{$reg->{lit}});
  3634. }
  3635. push @rI,sprintf("%4d: %-16s | %3s %-14s | %8s | %s\n",
  3636. $reg->{l},$regName,$min,$max.$reg->{u},
  3637. ((($reg->{l} == 3)||($reg->{l} == 4))?"required":""),
  3638. $help)
  3639. if (($roleD && $reg->{l} == 0)||
  3640. ($roleC && $reg->{l} != 0));
  3641. }
  3642. my $info = sprintf("list: %16s | %-18s | %-8s | %s\n",
  3643. "register","range","peer","description");
  3644. foreach(sort(@rI)){$info .= $_;}
  3645. return $info;
  3646. }
  3647. elsif($cmd eq "cmdList") { #################################################
  3648. my @arr;
  3649. if(!$roleV) {push @arr,"$_ $culHmGlobalGets->{$_}" foreach (keys %{$culHmGlobalGets})};
  3650. if($roleV) {push @arr,"$_ $culHmVrtGets->{$_}" foreach (keys %{$culHmVrtGets})};
  3651. push @arr,"$_ $culHmSubTypeGets->{$st}{$_}" foreach (keys %{$culHmSubTypeGets->{$st}});
  3652. push @arr,"$_ $culHmModelGets->{$md}{$_}" foreach (keys %{$culHmModelGets->{$md}});
  3653. my @arr1;
  3654. if( !$roleV) {foreach(keys %{$culHmGlobalSets} ){push @arr1,"$_ ".$culHmGlobalSets->{$_} }};
  3655. if(($st eq "virtual"||!$st) && $roleD){foreach(keys %{$culHmGlobalSetsVrtDev} ){push @arr1,"$_ ".$culHmGlobalSetsVrtDev->{$_} }};
  3656. if( !$roleV && $roleD){foreach(keys %{$culHmGlobalSetsDevice} ){push @arr1,"$_ ".$culHmGlobalSetsDevice->{$_} }};
  3657. if( !$roleV && $roleD){foreach(keys %{$culHmSubTypeDevSets->{$st}}){push @arr1,"$_ ".${$culHmSubTypeDevSets->{$st}}{$_}}};
  3658. if( !$roleV && $roleC){foreach(keys %{$culHmGlobalSetsChn} ){push @arr1,"$_ ".$culHmGlobalSetsChn->{$_} }};
  3659. if( $culHmSubTypeSets->{$st} && $roleC){foreach(keys %{$culHmSubTypeSets->{$st}} ){push @arr1,"$_ ".${$culHmSubTypeSets->{$st}}{$_} }};
  3660. if( $culHmModelSets->{$md}) {foreach(keys %{$culHmModelSets->{$md}} ){push @arr1,"$_ ".${$culHmModelSets->{$md}}{$_} }};
  3661. if( $culHmChanSets->{$md."00"} && $roleD){foreach(keys %{$culHmChanSets->{$md."00"}} ){push @arr1,"$_ ".${$culHmChanSets->{$md."00"}}{$_} }};
  3662. if( $culHmChanSets->{$md.$chn} && $roleC){foreach(keys %{$culHmChanSets->{$md.$chn}} ){push @arr1,"$_ ".${$culHmChanSets->{$md.$chn}}{$_} }};
  3663. if( $culHmFunctSets->{$fkt} && $roleC){foreach(keys %{$culHmFunctSets->{$fkt}} ){push @arr1,"$_ ".${$culHmFunctSets->{$fkt}}{$_} }};
  3664. my $info .= " Gets ------\n";
  3665. $info .= join("\n",sort @arr);
  3666. $info .= "\n\n Sets ------\n";
  3667. $info .= join("\n",sort @arr1);
  3668. return $info;
  3669. }
  3670. elsif($cmd eq "saveConfig"){ ###############################################
  3671. return "no filename given" if (!$a[2]);
  3672. my $fName = $a[2];
  3673. open(aSave, ">>$fName") || return("Can't open $fName: $!");
  3674. my $sName;
  3675. my @eNames;
  3676. if ($a[3] && $a[3] eq "strict"){
  3677. @eNames = ($name);
  3678. $sName = $name;
  3679. }
  3680. else{
  3681. $sName = $devName;
  3682. @eNames = CUL_HM_getAssChnNames($sName);
  3683. }
  3684. print aSave "\n\n#======== store device data:".$sName." === from: ".TimeNow();
  3685. foreach my $eName (@eNames){
  3686. print aSave "\n#--- entity:".$eName;
  3687. foreach my $rName ("D-firmware","D-serialNr",".D-devInfo",".D-stc"){
  3688. my $rVal = ReadingsVal($eName,$rName,undef);
  3689. print aSave "\nsetreading $eName $rName $rVal" if (defined $rVal);
  3690. }
  3691. my $pIds = AttrVal($eName, "peerIDs", "");
  3692. my $timestamps = "\n# timestamp of the readings for reference";
  3693. if ($pIds){
  3694. print aSave "\n# Peer Names:"
  3695. .InternalVal($eName,"peerList","");
  3696. $timestamps .= "\n# "
  3697. .InternalVal($eName,"peerList","")
  3698. ." :peerList";
  3699. print aSave "\nset $eName peerBulk $pIds#"
  3700. .ReadingsTimestamp($eName,"peerList","1900-01-01 00:00:01");
  3701. }
  3702. my $ehash = $defs{$eName};
  3703. foreach my $read (sort grep(/^[\.]?RegL_/,keys %{$ehash->{READINGS}})){
  3704. my $ts = ReadingsTimestamp($eName,$read,"1900-01-01 00:00:01");
  3705. print aSave "\nset $eName regBulk $read"
  3706. ." ".ReadingsVal($eName,$read,"")
  3707. ." #$ts";
  3708. $timestamps .= "\n# $ts :$read";
  3709. }
  3710. print aSave $timestamps;
  3711. }
  3712. print aSave "\n======= finished ===\n";
  3713. close(aSave);
  3714. }
  3715. elsif($cmd eq "listDevice"){ ###############################################
  3716. if ($md eq "CCU-FHEM"){
  3717. my @dl = grep !/^$/,
  3718. map{AttrVal($_,"IOgrp","") =~ m/^$name/ ? $_ : ""}
  3719. keys %defs;
  3720. my @rl;
  3721. foreach (@dl){
  3722. my(undef,$pref) = split":",$attr{$_}{IOgrp},2;
  3723. $pref = "---" if (!$pref);
  3724. my $IODev = $defs{$_}{IODev}->{NAME}?$defs{$_}{IODev}->{NAME}:"---";
  3725. push @rl, "$IODev / $pref $_ ";
  3726. }
  3727. return "devices using $name\ncurrent IO / preferred\n ".join "\n ", sort @rl;
  3728. }
  3729. elsif ($md eq "ActionDetector"){
  3730. my $re = $a[2]?$a[2]:"all";
  3731. if($re && $re =~ m/^(all|alive|unknown|dead|notAlive)$/){
  3732. my @fnd = map {$_.":".$defs{$name}{READINGS}{$_}{VAL}}
  3733. grep /^status_/,
  3734. keys %{$defs{ActionDetector}{READINGS}};
  3735. if ($re eq "notAlive"){ @fnd = grep !/:alive$/,@fnd; }
  3736. elsif ($re eq "all") {; }
  3737. else { @fnd = grep /:$a[2]$/,@fnd;}
  3738. $_ =~ s/status_(.*):.*/$1/ foreach(@fnd);
  3739. push @fnd,"empty" if (!scalar(@fnd));
  3740. return join",",sort(@fnd);
  3741. } else{
  3742. return "please enter parameter [alive|unknown|dead|notAlive]";
  3743. }
  3744. }
  3745. }
  3746. elsif($cmd eq "info"){ ###############################################
  3747. return CUL_HM_ActInfo();
  3748. }
  3749. Log3 $name,3,"CUL_HM get $name " . join(" ", @a[1..$#a]);
  3750. my $rxType = CUL_HM_getRxType($hash);
  3751. CUL_HM_ProcessCmdStack($devHash) if ($rxType & 0x03);#burst/all
  3752. return "";
  3753. }
  3754. sub CUL_HM_Set($@) {#+++++++++++++++++ set command+++++++++++++++++++++++++++++
  3755. my ($hash, @a) = @_;
  3756. return "no value specified" if(@a < 2);
  3757. return "FW update in progress - please wait"
  3758. if ($modules{CUL_HM}{helper}{updating});
  3759. my $act = join(" ", @a[1..$#a]);
  3760. my $name = $hash->{NAME};
  3761. return "device ignored due to attr 'ignore'"
  3762. if (CUL_HM_getAttrInt($name,"ignore"));
  3763. my $devName = InternalVal($name,"device",$name);
  3764. my $st = AttrVal($devName, "subType", "");
  3765. my $md = AttrVal($devName, "model" , "");
  3766. my $flag = 'A0'; #set flag
  3767. my $cmd = $a[1];
  3768. my ($dst,$chn) = unpack 'A6A2',$hash->{DEF}.'01';#default to chn 01 for dev
  3769. return "" if (!defined $chn);
  3770. my $roleC = $hash->{helper}{role}{chn}?1:0; #entity may act in multiple roles
  3771. my $roleD = $hash->{helper}{role}{dev}?1:0;
  3772. my $roleV = $hash->{helper}{role}{vrt}?1:0;
  3773. my $fkt = $hash->{helper}{fkt}?$hash->{helper}{fkt}:"";
  3774. my $oCmd = $cmd;# we extend press to press/L/S if press is defined
  3775. if ( $cmd =~ m/^press/){
  3776. $cmd = (InternalVal($name,"peerList",""))?"press":"?";
  3777. }
  3778. my $h = undef;
  3779. $h = $culHmGlobalSets->{$cmd} if( !$roleV &&($roleD || $roleC));
  3780. $h = $culHmGlobalSetsVrtDev->{$cmd} if(!defined($h) &&( $roleV || !$st) && $roleD);
  3781. $h = $culHmGlobalSetsDevice->{$cmd} if(!defined($h) && !$roleV && $roleD);
  3782. $h = $culHmSubTypeDevSets->{$st}{$cmd}if(!defined($h) && !$roleV && $roleD);
  3783. $h = $culHmGlobalSetsChn->{$cmd} if(!defined($h) && !$roleV && $roleC);
  3784. $h = $culHmSubTypeSets->{$st}{$cmd} if(!defined($h) && $culHmSubTypeSets->{$st} && $roleC);
  3785. $h = $culHmModelSets->{$md}{$cmd} if(!defined($h) && $culHmModelSets->{$md} );
  3786. $h = $culHmChanSets->{$md."00"}{$cmd} if(!defined($h) && $culHmChanSets->{$md."00"} && $roleD);
  3787. $h = $culHmChanSets->{$md.$chn}{$cmd} if(!defined($h) && $culHmChanSets->{$md.$chn} && $roleC);
  3788. $h = $culHmFunctSets->{$fkt}{$cmd} if(!defined($h) && $culHmFunctSets->{$fkt});
  3789. $cmd = $oCmd;# necessary for press/S/L - check better implementation
  3790. my @h;
  3791. @h = split(" ", $h) if($h);
  3792. my @postCmds=(); #Commands to be appended after regSet (ugly...)
  3793. if(!defined($h) && defined($culHmSubTypeSets->{$st}{pct}) && $cmd =~ m/^\d+/) {
  3794. splice @a, 1, 0,"pct";#insert the actual command
  3795. }
  3796. elsif(!defined($h)) { ### unknown - return the commandlist
  3797. my @arr1 = ();
  3798. if( !$roleV &&($roleD || $roleC) ){foreach(keys %{$culHmGlobalSets} ){push @arr1,"$_:".$culHmGlobalSets->{$_} }};
  3799. if(( $roleV||!$st) && $roleD){foreach(keys %{$culHmGlobalSetsVrtDev} ){push @arr1,"$_:".$culHmGlobalSetsVrtDev->{$_} }};
  3800. if( !$roleV && $roleD){foreach(keys %{$culHmGlobalSetsDevice} ){push @arr1,"$_:".$culHmGlobalSetsDevice->{$_} }};
  3801. if( !$roleV && $roleD){foreach(keys %{$culHmSubTypeDevSets->{$st}}){push @arr1,"$_:".${$culHmSubTypeDevSets->{$st}}{$_}}};
  3802. if( !$roleV && $roleC){foreach(keys %{$culHmGlobalSetsChn} ){push @arr1,"$_:".$culHmGlobalSetsChn->{$_} }};
  3803. if( $culHmSubTypeSets->{$st} && $roleC){foreach(keys %{$culHmSubTypeSets->{$st}} ){push @arr1,"$_:".${$culHmSubTypeSets->{$st}}{$_} }};
  3804. if( $culHmModelSets->{$md}) {foreach(keys %{$culHmModelSets->{$md}} ){push @arr1,"$_:".${$culHmModelSets->{$md}}{$_} }};
  3805. if( $culHmChanSets->{$md."00"} && $roleD){foreach(keys %{$culHmChanSets->{$md."00"}} ){push @arr1,"$_:".${$culHmChanSets->{$md."00"}}{$_} }};
  3806. if( $culHmChanSets->{$md.$chn} && $roleC){foreach(keys %{$culHmChanSets->{$md.$chn}} ){push @arr1,"$_:".${$culHmChanSets->{$md.$chn}}{$_} }};
  3807. if( $culHmFunctSets->{$fkt} && $roleC){foreach(keys %{$culHmFunctSets->{$fkt}} ){push @arr1,"$_:".${$culHmFunctSets->{$fkt}}{$_} }};
  3808. @arr1 = CUL_HM_noDup(@arr1);
  3809. foreach(@arr1){
  3810. my ($cmd,$val) = split(":",$_,2);
  3811. if (!$val){ # no agruments possible
  3812. $_ = "$cmd:noArg";
  3813. }
  3814. elsif($val !~ m/^\[.*\]$/ ||
  3815. $val =~ m/\[.*\[/ ||
  3816. $val =~ m/(\<|\>)]/
  3817. ){
  3818. $_ = $cmd;
  3819. }
  3820. else{
  3821. $val =~ s/(\[|\])//g;
  3822. my @vArr = split('\|',$val);
  3823. foreach (@vArr){
  3824. if ($_ =~ m/(.*)\.\.(.*)/ ){
  3825. my @list = map { ($_.".0", $_+0.5) } (($1+0)..($2+0));
  3826. pop @list;
  3827. $_ = join(",",@list);
  3828. }
  3829. }
  3830. $_ = "$cmd:".join(",",@vArr);
  3831. }
  3832. }
  3833. @arr1 = ("--") if (!scalar @arr1);
  3834. my $usg = "Unknown argument $cmd, choose one of ".join(" ",sort @arr1);
  3835. $usg =~ s/ pct/ pct:slider,0,1,100/;
  3836. $usg =~ s/ pctSlat/ pctSlat:slider,0,1,100/;
  3837. $usg =~ s/ virtual/ virtual:slider,1,1,50/;
  3838. $usg =~ s/ color/ color:colorpicker,HUE,0,0.5,100/;
  3839. if ($usg =~ m/ tempTmplSet/){
  3840. my $tl = $modules{CUL_HM}{AttrList};
  3841. my $ok = ($tl =~ s/.* (tempListTmpl)(\:.*? ).*/$2/);
  3842. $tl = $ok?$tl:"";
  3843. $usg =~ s/ tempTmplSet/ tempTmplSet$tl/;
  3844. }
  3845. if ( $usg =~ m/ templateDel/
  3846. && eval "defined(&HMinfo_templateDel)"
  3847. && keys %{$hash->{helper}{tmpl}}){
  3848. my $tl = join(",",(sort keys %{$hash->{helper}{tmpl}}));
  3849. # $tl =~ s/:/>/;
  3850. $usg =~ s/ templateDel/ templateDel:$tl/;
  3851. }
  3852. else{
  3853. $usg =~ s/ templateDel//;#not an option
  3854. }
  3855. if ( $usg =~ m/ press/){
  3856. my $peers = join",",grep/./,split",",InternalVal($name,"peerList","");
  3857. if ($peers){
  3858. $usg =~ s/ press/ press pressS:$peers pressL:$peers/g;
  3859. }
  3860. else{#remove command
  3861. $usg =~ s/ press[SL]//g;
  3862. }
  3863. }
  3864. return $usg;
  3865. }
  3866. elsif($h eq "" && @a != 2) {
  3867. return "$cmd requires no parameters";
  3868. }
  3869. elsif($h !~ m/\.\.\./ && @h != @a-2) {
  3870. return "$cmd requires parameter: $h";
  3871. }
  3872. my $id = CUL_HM_IoId($defs{$devName});
  3873. if(length($id) != 6 ){# have to try to find an IO
  3874. CUL_HM_assignIO($defs{$devName});
  3875. $id = CUL_HM_IoId($defs{$devName});
  3876. return "no IO device identified" if(length($id) != 6 );
  3877. }
  3878. #convert 'old' commands to current methodes like regSet and regBulk...
  3879. # Unify the interface
  3880. if( $cmd eq "sign"){
  3881. splice @a,1,0,"regSet";# make hash,regSet,reg,value
  3882. }
  3883. elsif($cmd eq "unpair"){
  3884. splice @a,1,3, ("regSet","pairCentral","000000");
  3885. }
  3886. elsif($cmd eq "ilum") { ################################################# reg
  3887. return "$a[2] not specified. choose 0-15 for brightness" if ($a[2]>15);
  3888. return "$a[3] not specified. choose 0-127 for duration" if ($a[3]>127);
  3889. return "unsupported for channel, use $devName" if (!$roleD);
  3890. splice @a,1,3, ("regBulk","RegL_00.",sprintf("04:%02X",$a[2]),sprintf("08:%02X",$a[3]*2));
  3891. }
  3892. elsif($cmd eq "text") { ################################################# reg
  3893. my ($bn,$l1, $l2) = ($chn,$a[2],$a[3]); # Create CONFIG_WRITE_INDEX string
  3894. if ($roleD){# if used on device.
  3895. return "$a[2] is not a button number" if($a[2] !~ m/^\d*$/ || $a[2] < 1);
  3896. return "$a[3] is not on or off" if($a[3] !~ m/^(on|off)$/);
  3897. $bn = $a[2]*2-($a[3] eq "on" ? 0 : 1);
  3898. ($l1, $l2) = ($a[4],$a[5]);
  3899. $chn = sprintf("%02X",$bn)
  3900. }
  3901. else{
  3902. return "to many parameter. Try set $a[0] text $a[2] $a[3]" if($a[4]);
  3903. }
  3904. my $s = 54;
  3905. $l1 =~ s/\\_/ /g;
  3906. $l1 = substr($l1."\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0, 12);
  3907. $l1 =~ s/(.)/sprintf(" %02X:%02X",$s++,ord($1))/ge;
  3908. $s = 70;
  3909. $l2 =~ s/\\_/ /g;
  3910. $l2 = substr($l2."\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0, 12);
  3911. $l2 =~ s/(.)/sprintf(" %02X:%02X",$s++,ord($1))/ge;
  3912. @a = ($a[0],"regBulk","RegL_01.",split(" ",$l1.$l2));
  3913. }
  3914. elsif($cmd =~ m/^(displayMode|displayTemp|displayTempUnit|controlMode)/) {
  3915. if ($md =~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/){#controlMode different for RT
  3916. splice @a,1,3, ("regSet",$a[1],$a[2]);
  3917. push @postCmds,"++803F$id${dst}0204".sprintf("%02X",CUL_HM_secSince2000());
  3918. }
  3919. }
  3920. elsif($cmd eq "partyMode") { ################################################
  3921. my ($eH,$eM,$days,$prep) = ("","","","");
  3922. if ($a[2] =~ m/^(prep|exec)$/){
  3923. $prep = $a[2];
  3924. splice @a,2,1;#remove prep
  3925. }
  3926. $days = $a[3];
  3927. ($eH,$eM) = split(':',$a[2]);
  3928. my ($s,$m,$h) = localtime();
  3929. return "$eH:$eM passed at $h:$m. Please enter time in the feature"
  3930. if ($days == 0 && ($h+($m/60))>=($eH+($eM/60)) );
  3931. return "$eM illegal - use 00 or 30 minutes only" if ($eM !~ m/^(00|30)$/);
  3932. return "$eH illegal - hour must be between 0 and 23" if ($eH < 0 || $eH > 23);
  3933. return "$days illegal - days must be between 0 and 200" if ($days < 0 || $days > 200);
  3934. $eH += 128 if ($eM eq "30");
  3935. my $cHash = CUL_HM_id2Hash($dst."02");
  3936. $cHash->{helper}{partyReg} = sprintf("61%02X62%02X0000",$eH,$days);
  3937. $cHash->{helper}{partyReg} =~ s/(..)(..)/ $1:$2/g;
  3938. if ($cHash->{READINGS}{"RegL_06."}){#remove old settings
  3939. $cHash->{READINGS}{"RegL_06."}{VAL} =~ s/ 61:.*//;
  3940. $cHash->{READINGS}{"RegL_06."}{VAL} =~ s/ 00:00//;
  3941. $cHash->{READINGS}{"RegL_06."}{VAL} .= $cHash->{helper}{partyReg};
  3942. }
  3943. else{
  3944. $cHash->{READINGS}{"RegL_06."}{VAL} = $cHash->{helper}{partyReg};
  3945. }
  3946. CUL_HM_pushConfig($hash,$id,$dst,2,"000000","00",6,
  3947. sprintf("61%02X62%02X",$eH,$days),$prep);
  3948. splice @a,1,3, ("regSet","controlMode","party");
  3949. splice @a,2,0, ($prep) if ($prep);
  3950. push @postCmds,"++803F$id${dst}0204".sprintf("%02X",CUL_HM_secSince2000());
  3951. }
  3952. $cmd = $a[1];# get converted command
  3953. #if chn cmd is executed on device but refers to a channel?
  3954. my $chnHash = (!$roleC && $modules{CUL_HM}{defptr}{$dst."01"})?
  3955. $modules{CUL_HM}{defptr}{$dst."01"}:$hash;
  3956. my $devHash = CUL_HM_getDeviceHash($hash);
  3957. my $state = "set_".join(" ", @a[1..(int(@a)-1)]);
  3958. return "device on readonly. $cmd disabled"
  3959. if($activeCmds{$cmd} && CUL_HM_getAttrInt($name,"readOnly") );
  3960. if ($cmd eq "raw") { #####################################################
  3961. return "Usage: set $a[0] $cmd data [data ...]" if(@a < 3);
  3962. $state = "";
  3963. my $msg = $a[2];
  3964. foreach my $sub (@a[3..$#a]) {
  3965. last if ($sub !~ m/^[A-F0-9]*$/);
  3966. $msg .= $sub;
  3967. }
  3968. CUL_HM_PushCmdStack($hash, $msg);
  3969. }
  3970. elsif($cmd eq "clear") { ####################################################
  3971. my (undef,undef,$sectIn) = @a;
  3972. my @sectL;
  3973. if ($sectIn eq "all") {
  3974. @sectL = ("rssi","msgEvents","readings","attack");#readings is last - it schedules a reread possible
  3975. }
  3976. elsif($sectIn =~ m/(rssi|trigger|msgEvents|readings|oldRegs|register|unknownDev|attack)/){
  3977. @sectL = ($sectIn);
  3978. }
  3979. else{
  3980. return "unknown section:$sectIn. User rssi|trigger|msgEvents|readings|oldRegs|register|unknownDev|attack";
  3981. }
  3982. foreach my $sect (@sectL){
  3983. if ($sect eq "readings"){
  3984. my @cH = ($hash);
  3985. push @cH,$defs{$hash->{$_}} foreach(grep /^channel/,keys %{$hash});
  3986. delete $_->{READINGS} foreach (@cH);
  3987. delete $modules{CUL_HM}{helper}{cfgCmpl}{$name};
  3988. CUL_HM_complConfig($_->{NAME}) foreach (@cH);
  3989. CUL_HM_qStateUpdatIfEnab($_->{NAME}) foreach (@cH);
  3990. }
  3991. elsif($sect eq "unknownDev"){
  3992. delete $hash->{READINGS}{$_}
  3993. foreach (grep /^unknown_/,keys %{$hash->{READINGS}});
  3994. }
  3995. elsif($sect eq "trigger"){
  3996. delete $hash->{READINGS}{$_}
  3997. foreach (grep /^trig/,keys %{$hash->{READINGS}});
  3998. }
  3999. elsif($sect eq "register"){
  4000. my @cH = ($hash);
  4001. push @cH,$defs{$hash->{$_}} foreach(grep /^channel/,keys %{$hash});
  4002. foreach my $h(@cH){
  4003. delete $h->{READINGS}{$_}
  4004. foreach (grep /^(\.?)(R-|RegL)/,keys %{$h->{READINGS}});
  4005. delete $h->{helper}{shadowReg}{$_}
  4006. foreach (grep /^(\.?)(R-|RegL)/,keys %{$h->{helper}{shadowReg}});
  4007. delete $modules{CUL_HM}{helper}{cfgCmpl}{$name};
  4008. CUL_HM_complConfig($h->{NAME});
  4009. }
  4010. }
  4011. elsif($sect eq "oldRegs"){
  4012. my @cN = ($name);
  4013. push @cN,$hash->{$_} foreach(grep /^channel/,keys %{$hash});
  4014. CUL_HM_refreshRegs($_) foreach (@cN);
  4015. }
  4016. elsif($sect eq "msgEvents"){
  4017. CUL_HM_respPendRm($hash);
  4018. $hash->{helper}{prt}{bErr}=0;
  4019. delete $hash->{cmdStack};
  4020. delete $hash->{helper}{prt}{rspWait};
  4021. delete $hash->{helper}{prt}{rspWaitSec};
  4022. delete $hash->{helper}{prt}{mmcA};
  4023. delete $hash->{helper}{prt}{mmcS};
  4024. delete $hash->{lastMsg};
  4025. delete ($hash->{$_}) foreach (grep(/^prot/,keys %{$hash}));
  4026. if ($hash->{IODev}{NAME} &&
  4027. $modules{CUL_HM}{$hash->{IODev}{NAME}} &&
  4028. $modules{CUL_HM}{$hash->{IODev}{NAME}}{pendDev}){
  4029. @{$modules{CUL_HM}{$hash->{IODev}{NAME}}{pendDev}} =
  4030. grep !/$name/,@{$modules{CUL_HM}{$hash->{IODev}{NAME}}{pendDev}};
  4031. }
  4032. CUL_HM_unQEntity($name,"qReqConf");
  4033. CUL_HM_unQEntity($name,"qReqStat");
  4034. CUL_HM_protState($hash,"Info_Cleared");
  4035. }
  4036. elsif($sect eq "rssi"){
  4037. delete $defs{$name}{helper}{rssi};
  4038. delete ($hash->{$_}) foreach (grep(/^rssi/,keys %{$hash}))
  4039. }
  4040. elsif($sect eq "attack"){
  4041. delete $defs{$name}{helper}{rssi};
  4042. delete ($hash->{$_}) foreach (grep(/^protErrIo(Id|Attack)/,keys %{$hash}));
  4043. delete $hash->{READINGS}{$_}
  4044. foreach (grep /^sabotageAttack/,keys %{$hash->{READINGS}});
  4045. }
  4046. }
  4047. $state = "";
  4048. }
  4049. elsif($cmd eq "reset") { ####################################################
  4050. CUL_HM_PushCmdStack($hash,"++".$flag."11".$id.$dst."0400");
  4051. }
  4052. elsif($cmd eq "burstXmit") { ################################################
  4053. $state = "";
  4054. $hash->{helper}{prt}{brstWu}=1;# start burst wakeup
  4055. CUL_HM_SndCmd($hash,"++B112$id$dst");
  4056. }
  4057. elsif($cmd eq "defIgnUnknown") { ############################################
  4058. $state = "";
  4059. foreach (map {substr($_,8)}
  4060. grep /^unknown_......$/,
  4061. keys %{$hash->{READINGS}}){
  4062. if (!$modules{CUL_HM}{defptr}{$_}){
  4063. CommandDefine(undef,"unknown_$_ CUL_HM $_") ;
  4064. $attr{"unknown_$_"}{ignore} = 1;
  4065. }
  4066. delete $hash->{READINGS}{"unknown_$_"};
  4067. }
  4068. }
  4069. elsif($cmd eq "deviceRename") { #############################################
  4070. $state = "";
  4071. my $newName = $a[2];
  4072. my @chLst = ("device");# entry 00 is unsed
  4073. if ($roleV){
  4074. foreach(1..50){
  4075. push @chLst,$newName."_Btn".$_;
  4076. }
  4077. }
  4078. else{
  4079. my $mId = CUL_HM_getMId($hash);# set helper valiable and use result
  4080. foreach my $chantype (split(',',$culHmModel->{$mId}{chn})){
  4081. my ($chnTpName,$chnStart,$chnEnd) = split(':',$chantype);
  4082. my $chnNoTyp = 1;
  4083. for (my $chnNoAbs = $chnStart; $chnNoAbs <= $chnEnd;$chnNoAbs++){
  4084. my $chnId = $hash->{DEF}.sprintf("%02X",$chnNoAbs);
  4085. $chLst[$chnNoAbs] = $newName."_".$chnTpName.(($chnStart == $chnEnd)
  4086. ? ''
  4087. : '_'.sprintf("%02d",$chnNoTyp));
  4088. $chnNoTyp++;
  4089. }
  4090. }
  4091. }
  4092. foreach my $cd (grep /^channel_/,keys %{$hash}){
  4093. my $cName = InternalVal($name,$cd,"");
  4094. my $no = hex(substr($cd,8));
  4095. CommandRename(undef,$cName.' '.$chLst[$no]);
  4096. }
  4097. CommandRename(undef,$name.' '.$newName);#and the device itself
  4098. }
  4099. elsif($cmd eq "statusRequest") { ############################################
  4100. my @chnIdList = CUL_HM_getAssChnIds($name);
  4101. foreach my $channel (@chnIdList){
  4102. my $chnNo = substr($channel,6,2);
  4103. CUL_HM_PushCmdStack($hash,"++".$flag.'01'.$id.$dst.$chnNo.'0E');
  4104. }
  4105. $state = "";
  4106. }
  4107. elsif($cmd eq "getSerial") { ################################################
  4108. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.'0009');
  4109. $state = "";
  4110. }
  4111. elsif($cmd eq "getDevInfo") { ###############################################
  4112. $state = "";
  4113. my $sn = ReadingsVal($name,"D-serialNr","");
  4114. return "serial number unknown" if (! $sn);
  4115. CUL_HM_PushCmdStack($hash,'++8401'.$id.'000000010A'.uc(unpack('H*', $sn)));
  4116. }
  4117. elsif($cmd eq "getConfig") { ################################################
  4118. CUL_HM_unQEntity($name,"qReqConf");
  4119. CUL_HM_getConfig($hash);
  4120. $state = "";
  4121. }
  4122. elsif($cmd eq "peerBulk") { #################################################
  4123. $state = "";
  4124. my $pL = $a[2];
  4125. return "unknown action: $a[3] - use set or unset"
  4126. if ($a[3] && $a[3] !~ m/^(set|unset)/);
  4127. my $set = ($a[3] && $a[3] eq "unset")?"02":"01";
  4128. foreach my $peer (grep(!/^self/,split(',',$pL))){
  4129. last if($peer =~ m/^#/);
  4130. my $pID = CUL_HM_peerChId($peer,$dst);
  4131. return "unknown peer".$peer if (length($pID) != 8);# peer only to channel
  4132. my $pCh1 = substr($pID,6,2);
  4133. my $pCh2 = $pCh1;
  4134. if(($culHmSubTypeSets->{$st} &&$culHmSubTypeSets->{$st}{peerChan} )||
  4135. ($culHmModelSets->{$md} &&$culHmModelSets->{$md}{peerChan} )||
  4136. ($culHmChanSets->{$md.$chn} &&$culHmChanSets->{$md.$chn}{peerChan}) ){
  4137. $pCh2 = "00"; # button behavior
  4138. }
  4139. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.$chn.$set.
  4140. substr($pID,0,6).$pCh1.$pCh2);
  4141. }
  4142. CUL_HM_qAutoRead($name,3);
  4143. }
  4144. elsif($cmd =~ m/^(regBulk|getRegRaw)$/) { ############################### reg
  4145. my ($list,$addr,$data,$peerID);
  4146. $state = "";
  4147. if ($cmd eq "regBulk"){
  4148. $list = $a[2];
  4149. $list =~ s/[\.]?RegL_//;
  4150. ($list,$peerID) = split('\.',$list);
  4151. # return "unknown list Number:".$list if(hex($list)>6);
  4152. }
  4153. elsif ($cmd eq "getRegRaw"){
  4154. ($list,$peerID) = ($a[2],$a[3]);
  4155. return "Enter valid List0-6" if (!defined $list || $list !~ m/^List([0-6])$/);
  4156. $list ='0'.$1;
  4157. }
  4158. # as of now only hex value allowed check range and convert
  4159. $peerID = CUL_HM_peerChId(($peerID?$peerID:"00000000"),$dst);
  4160. my $peerChn = ((length($peerID) == 8)?substr($peerID,6,2):"01");# have to split chan and id
  4161. $peerID = substr($peerID,0,6);
  4162. if($cmd eq "getRegRaw"){
  4163. if ($list eq "00"){
  4164. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.'00040000000000');
  4165. }
  4166. else{# other lists are per channel
  4167. my @chnIdList = CUL_HM_getAssChnIds($name);
  4168. foreach my $channel (@chnIdList){
  4169. my $chnNo = substr($channel,6,2);
  4170. if ($list =~ m/^0[34]$/){#getPeers to see if list3 is available
  4171. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.$chnNo.'03');
  4172. my $chnHash = CUL_HM_id2Hash($channel);
  4173. $chnHash->{helper}{getCfgList} = $peerID.$peerChn;#list3 regs
  4174. $chnHash->{helper}{getCfgListNo} = int($list);
  4175. }
  4176. else{
  4177. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.$chnNo.'04'
  4178. .$peerID.$peerChn.$list);
  4179. }
  4180. }
  4181. }
  4182. }
  4183. elsif($cmd eq "regBulk"){;
  4184. my @adIn = @a;
  4185. shift @adIn;shift @adIn;shift @adIn;
  4186. my $adList;
  4187. foreach my $ad ( @adIn){
  4188. last if($ad =~ m/^#/);
  4189. ($addr,$data) = split(":",$ad);
  4190. $adList .= sprintf("%02X%02X",hex($addr),hex($data)) if ($addr ne "00");
  4191. return "wrong addr or data:".$ad if (hex($addr)>255 || hex($data)>255);
  4192. }
  4193. $chn = 0 if ($list == 0);
  4194. CUL_HM_pushConfig($hash,$id,$dst,hex($chn),$peerID,$peerChn,$list,$adList);
  4195. }
  4196. }
  4197. elsif($cmd eq "regSet") { ############################################### reg
  4198. #set <name> regSet [prep] <regName> <value> [<peerChn>]
  4199. #prep is internal use only. It allowes to prepare shadowReg only but supress
  4200. #writing. Application necessarily needs to execute writing subsequent.
  4201. my $prep = "";
  4202. if ($a[2] =~ m/^(prep|exec)$/){
  4203. $prep = $a[2];
  4204. splice @a,2,1;#remove prep
  4205. }
  4206. my (undef,undef,$regName,$data,$peerChnIn) = @a;
  4207. $state = "";
  4208. my @regArr = CUL_HM_getRegN($st,$md,($roleD?"00":""),($roleC?$chn:""));
  4209. return "$regName failed: supported register are ".join(" ",sort @regArr)
  4210. if (!grep /^$regName$/,@regArr );
  4211. my $reg = $culHmRegDefine->{$regName};
  4212. my $conv = $reg->{c};
  4213. return $st." - ".$regName # give some help
  4214. .($conv eq "lit"? " literal:".join(",",keys%{$reg->{lit}})." "
  4215. : " range:". $reg->{min}." to ".$reg->{max}.$reg->{u}
  4216. .($reg->{lit}?" special:".join(",",keys%{$reg->{lit}})." "
  4217. :""
  4218. )
  4219. )
  4220. .(($reg->{l} == 3)?" peer required":"")." : ".$reg->{t}."\n"
  4221. if ($data eq "?");
  4222. if ( $conv ne 'lit'
  4223. && $reg->{lit}
  4224. && defined $reg->{lit}{$data} ){
  4225. $data = $reg->{lit}{$data};#conv special value past to calculation
  4226. }
  4227. return "value:$data out of range $reg->{min} to $reg->{max} for Reg \""
  4228. .$regName."\""
  4229. if (!($conv =~ m/^(lit|hex|min2time)$/)&&
  4230. ($data < $reg->{min} ||$data > $reg->{max})); # none number
  4231. return"invalid value. use:". join(",",sort keys%{$reg->{lit}})
  4232. if ($conv eq 'lit' && !defined($reg->{lit}{$data}));
  4233. if ($conv ne 'lit' && $reg->{lit} && $reg->{lit}{$data}){
  4234. $data = $reg->{lit}{$data}; #conv special value prior to calculation
  4235. }
  4236. $data *= $reg->{f} if($reg->{f});# obey factor befor possible conversion
  4237. if (!$conv){;# do nothing
  4238. }elsif($conv eq "fltCvT" ){$data = CUL_HM_fltCvT($data);
  4239. }elsif($conv eq "fltCvT60"){$data = CUL_HM_fltCvT60($data);
  4240. }elsif($conv eq "min2time"){$data = CUL_HM_time2min($data);
  4241. }elsif($conv eq "m10s3") {$data = $data*10-3;
  4242. }elsif($conv eq "hex") {$data = hex($data);
  4243. }elsif($conv eq "lit") {$data = $reg->{lit}{$data};
  4244. }else{return " conv undefined - please contact admin";
  4245. }
  4246. my $addr = int($reg->{a}); # bit location later
  4247. my $list = $reg->{l};
  4248. my $bit = ($reg->{a}*10)%10; # get fraction
  4249. my $dLen = $reg->{s}; # datalength in bit
  4250. $dLen = int($dLen)*8+(($dLen*10)%10);
  4251. # only allow it level if length less then one byte!!
  4252. return "partial Word error: ".$dLen if($dLen != 8*int($dLen/8) && $dLen>7);
  4253. no warnings qw(overflow portable);
  4254. my $mask = (0xffffffff>>(32-$dLen));
  4255. use warnings qw(overflow portable);
  4256. my $dataStr = substr(sprintf("%08X",($data & $mask) << $bit),
  4257. 8-int($reg->{s}+0.99)*2,);
  4258. my ($lChn,$peerId,$peerChn) = ($chn,"000000","00");
  4259. if (($list == 3) ||($list == 4) # peer is necessary for list 3/4
  4260. ||($peerChnIn)) {# and if requested by user
  4261. return "Peer not specified" if ($peerChnIn eq "");
  4262. $peerId = CUL_HM_peerChId($peerChnIn,$dst);
  4263. ($peerId,$peerChn) = unpack 'A6A2',$peerId.'01';
  4264. if ($list == 4 &&
  4265. !AttrVal($name,"peerIDs",undef)){####check this code#################
  4266. $peerChn = "00";
  4267. }
  4268. return "Peer not valid" if (length ($peerId) < 6);
  4269. }
  4270. elsif($list == 0){
  4271. $lChn = "00";
  4272. }
  4273. else{ #if($list == 1/5/6){
  4274. $lChn = "01" if ($chn eq "00"); #by default select chan 01 for device
  4275. }
  4276. my $addrData;
  4277. if ($dLen < 8){# fractional byte see whether we have stored the register
  4278. #read full 8 bit!!!
  4279. my $rName = CUL_HM_id2Name($dst.$lChn);
  4280. $rName =~ s/_chn-\d\d$//;
  4281. my $curVal = CUL_HM_getRegFromStore($rName,$addr,$list,$peerId.$peerChn);
  4282. if ($curVal !~ m/^(set_|)(\d+)$/){
  4283. return "peer required for $regName" if ($curVal =~ m/peer/);
  4284. return "cannot calculate value. Please issue set $name getConfig first - $curVal";
  4285. }
  4286. $curVal = $2; # we expect one byte in int, strap 'set_' possibly
  4287. $data = ($curVal & (~($mask<<$bit)))|($data<<$bit);
  4288. $addrData.=sprintf("%02X%02X",$addr,$data);
  4289. }
  4290. else{
  4291. for (my $cnt = 0;$cnt<int($reg->{s}+0.99);$cnt++){
  4292. $addrData.=sprintf("%02X",$addr+$cnt).substr($dataStr,$cnt*2,2);
  4293. }
  4294. }
  4295. my $cHash = CUL_HM_id2Hash($dst.($lChn eq '00'?"":$lChn));
  4296. $cHash = $hash if (!$cHash);
  4297. CUL_HM_pushConfig($cHash,$id,$dst,hex($lChn),$peerId,hex($peerChn),$list
  4298. ,$addrData,$prep);
  4299. CUL_HM_PushCmdStack($hash,$_) foreach(@postCmds);#ugly commands after regSet
  4300. }
  4301. elsif($cmd eq "level") { ####################################################
  4302. #level =>"<level> <relockDly> <speed>..."
  4303. my (undef,undef,$lvl,$rLocDly,$speed) = @a;
  4304. $rLocDly = 111600 if (!defined($rLocDly)||$rLocDly eq "ignore");# defaults
  4305. $speed = 30 if (!defined($speed));
  4306. $lvl = 127.5 if ($lvl eq "lock");
  4307. return "please enter level 0 to 100 or lock"
  4308. if ( !defined($lvl)
  4309. || $lvl !~ m/^\d*\.?\d?$/
  4310. || ($lvl > 100 && $lvl != 127.5));
  4311. return "reloclDelay range 0..65535 or ignore"
  4312. if ( $rLocDly > 111600 ||
  4313. ($rLocDly < 0.1 && $rLocDly ne '0' ));
  4314. return "select speed range 0 to 100" if ( $speed > 100);
  4315. $rLocDly = CUL_HM_encodeTime8($rLocDly);# calculate hex value
  4316. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'81'.$chn.
  4317. sprintf("%02X%02s%02X",$lvl*2,$rLocDly,$speed*2));
  4318. }
  4319. elsif($cmd =~ m/^(on|off|toggle)$/) { #######################################
  4320. my $lvlInv = (AttrVal($name, "param", "") =~ m/levelInverse/)?1:0;
  4321. $hash->{helper}{dlvl} = ( $cmd eq 'off'||
  4322. ($cmd eq 'toggle' &&CUL_HM_getChnLvl($name) != 0))
  4323. ? ($lvlInv?'C8':'00')
  4324. : ($lvlInv?'00':'C8');
  4325. my(undef,$lvlMax)=split",",AttrVal($name, "levelRange", "0,100");
  4326. $hash->{helper}{dlvl} = sprintf("%02X",$lvlMax*2) if ($hash->{helper}{dlvl} eq 'C8');
  4327. if ($md eq "HM-LC-Ja1PBU-FM"){ $hash->{helper}{dlvlCmd} = "++$flag"."11$id$dst"."80$chn$hash->{helper}{dlvl}"."CA";}
  4328. else{ $hash->{helper}{dlvlCmd} = "++$flag"."11$id$dst"."02$chn$hash->{helper}{dlvl}".'0000';}
  4329. CUL_HM_PushCmdStack($hash,$hash->{helper}{dlvlCmd});
  4330. $hash = $chnHash; # report to channel if defined
  4331. }
  4332. elsif($cmd eq "toggleDir") { ################################################
  4333. if ($hash->{helper}{dir}{cur} && $hash->{helper}{dir}{cur} ne "err"){
  4334. my $old = $hash->{helper}{dir}{cur};
  4335. $hash->{helper}{dir}{cur} = $hash->{helper}{dir}{cur} eq "stop" ?(($hash->{helper}{dir}{rct}
  4336. && $hash->{helper}{dir}{rct} eq "up")?"down"
  4337. :"up")
  4338. :"stop";
  4339. $hash->{helper}{dir}{rct} = $old;
  4340. }
  4341. else{
  4342. $hash->{helper}{dir}{rct} = "stop";
  4343. $hash->{helper}{dir}{cur} = "up";
  4344. }
  4345. if ($hash->{helper}{dir}{cur} eq "up" ){
  4346. $hash->{helper}{dlvl} = "C8";
  4347. $hash->{helper}{dlvlCmd} = "++$flag"."11$id$dst"."02$chn".'C80000';
  4348. CUL_HM_PushCmdStack($hash,$hash->{helper}{dlvlCmd});
  4349. }elsif ($hash->{helper}{dir}{cur} eq "down"){
  4350. $hash->{helper}{dlvl} = "00";
  4351. $hash->{helper}{dlvlCmd} = "++$flag"."11$id$dst"."02$chn".'000000';
  4352. CUL_HM_PushCmdStack($hash,$hash->{helper}{dlvlCmd});
  4353. }else {
  4354. delete $hash->{helper}{dlvl};
  4355. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'03'.$chn);
  4356. }
  4357. }
  4358. elsif($cmd =~ m/^(on-for-timer|on-till)$/) { ################################
  4359. my (undef,undef,$duration,$ramp) = @a; #date prepared extention to entdate
  4360. if ($cmd eq "on-till"){
  4361. # to be extended to handle end date as well
  4362. my (undef,$eH,$eM,$eSec) = GetTimeSpec($duration);
  4363. $eSec += $eH*3600 + $eM*60;
  4364. my @lt = localtime;
  4365. my $ltSec = $lt[2]*3600+$lt[1]*60+$lt[0];# actually strip of date
  4366. $eSec += 3600*24 if ($ltSec > $eSec); # go for the next day
  4367. $duration = $eSec - $ltSec;
  4368. }
  4369. return "please enter the duration in seconds"
  4370. if (!defined $duration || $duration !~ m/^[+-]?\d+(\.\d+)?$/);
  4371. my $tval = CUL_HM_encodeTime16($duration);# onTime 0.0..85825945.6, 0=forever
  4372. # return "timer value to low" if ($tval eq "0000"); does it work for all if "0000"?
  4373. $tval = "" if ($tval eq "0000");
  4374. $ramp = ($ramp && $st eq "dimmer") ? CUL_HM_encodeTime16($ramp)
  4375. :($tval eq "" ? ""
  4376. : "0000");
  4377. delete $hash->{helper}{dlvl};#stop desiredLevel supervision
  4378. $hash->{helper}{stateUpdatDly} = ($duration>120)?$duration:120;
  4379. my(undef,$lvlMax)=split",",AttrVal($name, "levelRange", "0,100");
  4380. $lvlMax = sprintf("%02X",$lvlMax*2);
  4381. CUL_HM_PushCmdStack($hash,"++${flag}11$id${dst}02${chn}$lvlMax$ramp$tval");
  4382. $hash = $chnHash; # report to channel if defined
  4383. }
  4384. elsif($cmd eq "alarmLevel") { ###############################################
  4385. #level =>"[disarmed|armExtSens|armAll|armBlocked]"
  4386. my %lvlSet = (disarmed=>"00",armExtSens=>"32",armAll=>"C8",armBlocked=>"FF");
  4387. my (undef,undef,$lvl,$onTime) = (@a,0);#set ontime to 0 if not given.
  4388. $lvl = $lvlSet{$lvl};
  4389. return "please enter the onTime in seconds"
  4390. if ($onTime !~ m/^[+-]?\d+(\.\d+)?$/);
  4391. my $tval = CUL_HM_encodeTime16($onTime);# onTime 0.0..85825945.6, 0=forever
  4392. $tval = "" if ($tval eq "0000");
  4393. CUL_HM_PushCmdStack($hash,"++${flag}11$id${dst}02${chn}${lvl}0000$tval");
  4394. }
  4395. elsif($cmd eq "lock") { #####################################################
  4396. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'800100FF'); # LEVEL_SET
  4397. }
  4398. elsif($cmd eq "unlock") { ###################################################
  4399. my $tval = (@a > 2) ? int($a[2]) : 0;
  4400. my $delay = ($tval > 0) ? CUL_HM_encodeTime8($tval) : "FF"; # RELOCK_DELAY (FF=never)
  4401. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'800101'.$delay);# LEVEL_SET
  4402. }
  4403. elsif($cmd eq "open") { #####################################################
  4404. my $tval = (@a > 2) ? int($a[2]) : 0;
  4405. my $delay = ($tval > 0) ? CUL_HM_encodeTime8($tval) : "FF"; # RELOCK_DELAY (FF=never)
  4406. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'8001C8'.$delay);# OPEN
  4407. }
  4408. elsif($cmd eq "inhibit") { ##################################################
  4409. return "$a[2] is not on or off" if($a[2] !~ m/^(on|off)$/);
  4410. my $val = ($a[2] eq "on") ? "01" : "00";
  4411. CUL_HM_UpdtReadSingle($hash,"inhibit","set_$a[2]",1);
  4412. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.$val.$chn); # SET_LOCK
  4413. }
  4414. elsif($cmd =~ m/^(up|down|pct|old)$/) { #####################################
  4415. my ($lvl,$tval,$rval,$duration) = (($cmd eq "old"?"old":($a[2]?$a[2]:0))
  4416. ,"","",0);
  4417. my($lvlMin,$lvlMax) = split",",AttrVal($name, "levelRange", "0,100");
  4418. my $lvlInv = (AttrVal($name, "param", "") =~ m/levelInverse/)?1:0;
  4419. if ($lvl eq "old"){#keep it - it means "old value"
  4420. }
  4421. else{
  4422. $lvl =~ s/(\d*\.?\d*).*/$1/;
  4423. if ($cmd eq "pct"){
  4424. }
  4425. else{#dim [<changeValue>] ... [ontime] [ramptime]
  4426. $lvl = 10 if (!defined $a[2]); #set default step
  4427. $lvl = -1*$lvl if (($cmd eq "down" && !$lvlInv)||
  4428. ($cmd ne "down" && $lvlInv));
  4429. $lvl += CUL_HM_getChnLvl($name);
  4430. }
  4431. $lvl = $lvlMin + $lvl*($lvlMax-$lvlMin)/100; # relativ to range
  4432. $lvl = ($lvl > $lvlMax)?$lvlMax:(($lvl <= $lvlMin)?0:$lvl);
  4433. }
  4434. if ($st =~ m/^(dimmer|rgb)$/){# at least blind cannot stand ramp time...
  4435. if (!$a[3]){
  4436. $tval = "FFFF";
  4437. $duration = 0;
  4438. }
  4439. elsif ($a[3] =~ m/(..):(..):(..)/){
  4440. my ($eH,$eM,$eSec) = ($1,$2,$3);
  4441. $eSec += $eH*3600 + $eM*60;
  4442. my @lt = localtime;
  4443. my $ltSec = $lt[2]*3600+$lt[1]*60+$lt[0];# actually strip of date
  4444. $eSec += 3600*24 if ($ltSec > $eSec); # go for the next day
  4445. $duration = $eSec - $ltSec;
  4446. $tval = CUL_HM_encodeTime16($duration);
  4447. }
  4448. else{
  4449. $duration = $a[3];
  4450. $tval = CUL_HM_encodeTime16($duration);# onTime 0.05..85825945.6, 0=forever
  4451. }
  4452. $rval = CUL_HM_encodeTime16((@a > 4)?$a[4]:2.5);# rampTime 0.0..85825945.6, 0=immediate
  4453. $hash->{helper}{stateUpdatDly} = ($duration>120)?$duration:120;
  4454. }
  4455. # store desiredLevel in and its Cmd in case we have to repeat
  4456. my $plvl = ($lvl eq "old")?"C9"
  4457. :sprintf("%02X",(($lvlInv)?100-$lvl :$lvl)*2);
  4458. if (($tval ne "FFFF") || $lvl eq "old"){
  4459. delete $hash->{helper}{dlvl};#stop desiredLevel supervision
  4460. }
  4461. else{
  4462. $hash->{helper}{dlvl} = $plvl;
  4463. }
  4464. if ($md eq "HM-LC-Ja1PBU-FM"){ $hash->{helper}{dlvlCmd} = "++$flag"."11$id$dst"."80$chn$plvl"."CA";}
  4465. else{ $hash->{helper}{dlvlCmd} = "++$flag"."11$id$dst"."02$chn$plvl$rval$tval";}
  4466. CUL_HM_PushCmdStack($hash,$hash->{helper}{dlvlCmd});
  4467. $state = "set_".$lvl;
  4468. CUL_HM_UpdtReadSingle($hash,"level",$state,1);
  4469. }
  4470. elsif($cmd =~ m/^(pctSlat|pctLvlSlat)$/) { ##################################
  4471. # pctSlat =>"[0-100]|old|noChng"
  4472. # pctLvlSlat =>"-value-|old|noChng -slatValue-|old|noChng"
  4473. my ($lvl,$slat,$plvl,$pslat);
  4474. return "param missing " if (!defined $a[2]);
  4475. if ($cmd eq "pctSlat"){
  4476. $slat = $a[2];
  4477. $lvl = "noChng";
  4478. }
  4479. else{#"pctLvlSlat"
  4480. $slat = defined $a[3] ? $a[3] : "noChng";
  4481. $lvl = $a[2];
  4482. }
  4483. #--- calc slat----
  4484. if ($slat eq "old") {$pslat = "C9"}
  4485. elsif ($slat eq "noChng"){$pslat = "CA"}
  4486. else{ $slat =~ s/(\d*\.?\d*).*/$1/;
  4487. return "Value $a[2] not allowed for slat" if ($slat > 100);
  4488. $pslat = sprintf("%02X",$slat*2);
  4489. CUL_HM_UpdtReadSingle($hash,"levelSlat","set_".$slat,1);
  4490. }
  4491. #--- calc level----
  4492. if ($lvl eq "old") {$plvl = "C9"}
  4493. elsif ($lvl eq "noChng"){$plvl = "CA"}
  4494. else{
  4495. my $lvlInv = (AttrVal($name, "param", "") =~ m/levelInverse/) ? 1 : 0;
  4496. my($lvlMin,$lvlMax) = split",",AttrVal($name, "levelRange", "0,100");
  4497. $lvl = $lvlMin + $lvl*($lvlMax-$lvlMin)/100; # relativ to range
  4498. $lvl = ($lvl > $lvlMax) ? $lvlMax
  4499. : (($lvl <= $lvlMin)?0:$lvl);
  4500. $lvl =~ s/(\d*\.?\d*).*/$1/;
  4501. $plvl = sprintf("%02X",(($lvlInv) ? 100-$lvl : $lvl)*2);
  4502. CUL_HM_UpdtReadSingle($hash,"level","set_".$lvl,1);
  4503. $state = "set_".$lvl;
  4504. }
  4505. #--- execute----
  4506. CUL_HM_PushCmdStack($hash,"++$flag"."11$id$dst"."80${chn}$plvl$pslat");
  4507. }
  4508. elsif($cmd eq "stop") { #####################################################
  4509. delete $hash->{helper}{dlvl};#stop desiredLevel supervision
  4510. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'03'.$chn);
  4511. }
  4512. elsif($cmd eq "setRepeat") { ################################################
  4513. # setRepeat => "[no1..36] <sendName> <recName> [bdcast-yes|no]"}
  4514. $state = "";
  4515. my (undef,undef,$eNo,$sId,$rId,$bCst) = @a;
  4516. my ($pattern,$cnt);
  4517. my $repPeers = AttrVal($name,"repPeers",undef);
  4518. my @rPeer;
  4519. @rPeer = split ",",$repPeers;
  4520. if ($eNo eq "setAll"){
  4521. return " too many entries in repPeers" if (int(@rPeer) > 36);
  4522. return "setAll: attr repPeers undefined" if (!defined $repPeers);
  4523. my $entry = 0;
  4524. foreach my $repData (@rPeer){
  4525. $entry++;
  4526. my ($s,$d,$b) =split":",$repData;
  4527. $s = CUL_HM_name2Id($s);
  4528. $d = CUL_HM_name2Id($d);
  4529. return "attr repPeers entry $entry irregular:$repData"
  4530. if (!$s || !$d || !$b
  4531. || $s !~ m/(^[0-9A-F]{6})$/
  4532. || $d !~ m/(^[0-9A-F]{6})$/
  4533. || $b !~ m/^[yn]$/
  4534. );
  4535. $pattern .= $s.$d.(($b eq "n")?"00":"01");
  4536. }
  4537. while ($entry < 36){
  4538. $entry++;
  4539. $pattern .= "000000"."000000"."00";
  4540. }
  4541. $cnt = 1;# set first address byte
  4542. }
  4543. else{
  4544. return "entry must be between 1 and 36" if ($eNo < 1 || $eNo > 36);
  4545. my $sndID = CUL_HM_name2Id($sId);
  4546. my $recID = CUL_HM_name2Id($rId);
  4547. if ($sndID !~ m/(^[0-9A-F]{6})$/){$sndID = AttrVal($sId,"hmId","");};
  4548. if ($recID !~ m/(^[0-9A-F]{6})$/){$recID = AttrVal($rId,"hmId","");};
  4549. return "sender ID $sId unknown:".$sndID if ($sndID !~ m/(^[0-9A-F]{6})$/);
  4550. return "receiver ID $rId unknown:".$recID if ($recID !~ m/(^[0-9A-F]{6})$/);
  4551. return "broadcast must be yes or now" if ($bCst !~ m/^(yes|no)$/);
  4552. $pattern = $sndID.$recID.(($bCst eq "no")?"00":"01");
  4553. $cnt = ($eNo-1)*7+1;
  4554. $rPeer[$eNo-1] = "$sId:$rId:".(($bCst eq "no")?"n":"y");
  4555. $attr{$name}{repPeers} = join",",@rPeer;
  4556. }
  4557. my $addrData;
  4558. foreach ($pattern =~ /(.{2})/g){
  4559. $addrData .= sprintf("%02X%s",$cnt++,$_);
  4560. }
  4561. CUL_HM_pushConfig($hash, $id, $dst, 1,0,0,2, $addrData);
  4562. }
  4563. elsif($cmd eq "display") { ##################################################
  4564. my (undef,undef,undef,$t,$c,$u,$snd,$blk,$symb) = @_;
  4565. return "cmd only possible for device or its display channel"
  4566. if ($roleC && $chn ne "12");
  4567. my %symbol=(off => 0x0000,
  4568. bulb =>0x0100,switch =>0x0200,window =>0x0400,door=>0x0800,
  4569. blind=>0x1000,scene =>0x2000,phone =>0x4000,bell=>0x8000,
  4570. clock=>0x0001,arrowUp=>0x0002,arrowDown=>0x0004);
  4571. my %light=(off=>0,on=>1,slow=>2,fast=>3);
  4572. my %unit=(off =>0,Proz=>1,Watt=>2,x3=>3,C=>4,x5=>5,x6=>6,x7=>7,
  4573. F=>8,x9=>9,x10=>10,x11=>11,x12=>12,x13=>13,x14=>14,x15=>15);
  4574. my @symbList = split(',',$symb);
  4575. my $symbAdd = 0;
  4576. foreach my $symb (@symbList){
  4577. if (!defined($symbol{$symb})){# wrong parameter
  4578. return "'$symb ' unknown. Select one of ".join(" ",sort keys(%symbol));
  4579. }
  4580. $symbAdd |= $symbol{$symb};
  4581. }
  4582. return "$c not specified. Select one of [comma|no]"
  4583. if ($c ne "comma" && $c ne "no");
  4584. return "'$u' unknown. Select one of ".join(" ",sort keys(%unit))
  4585. if (!defined($unit{$u}));
  4586. return "'$snd' unknown. Select one of [off|1|2|3]"
  4587. if ($snd ne "off" && $snd > 3);
  4588. return "'$blk' unknown. Select one of ".join(" ",sort keys(%light))
  4589. if (!defined($light{$blk}));
  4590. my $beepBack = $snd | $light{$blk}*4;
  4591. $symbAdd |= 0x0008 if ($c eq "comma");
  4592. $symbAdd |= ($unit{$u} * 16);
  4593. my $text = sprintf("%5.5s",$t);#pad left with space
  4594. $text = uc(unpack("H*",$text));
  4595. CUL_HM_PushCmdStack($hash,sprintf("++%s11%s%s8012%s%04X%02X",
  4596. $flag,$id,$dst,$text,$symbAdd,$beepBack));
  4597. }
  4598. elsif($cmd =~ m/^(alarm|service)$/) { #######################################
  4599. return "$a[2] must be below 255" if ($a[2] >255 );
  4600. $chn = 18 if ($chn eq "01");
  4601. my $subtype = ($cmd eq "alarm")?"81":"82";
  4602. CUL_HM_PushCmdStack($hash,
  4603. sprintf("++%s11%s%s%s%s%02X",$flag,$id,$dst,$subtype,$chn, $a[2]));
  4604. }
  4605. elsif($cmd eq "led") { ######################################################
  4606. if ($md eq "HM-OU-LED16"){
  4607. my %color=(off=>0,red=>1,green=>2,orange=>3);
  4608. if ($roleD){# command called for a device, not a channel
  4609. my $col4all;
  4610. if (defined($color{$a[2]})){
  4611. $col4all = sprintf("%02X",$color{$a[2]}*85);#Color for 4 LEDS
  4612. $col4all = $col4all.$col4all.$col4all.$col4all;#and now for 16
  4613. }
  4614. elsif ($a[2] =~ m/^[A-Fa-f0-9]{1,8}$/i){
  4615. $col4all = sprintf("%08X",hex($a[2]));
  4616. }
  4617. else{
  4618. return "$a[2] unknown. use hex or: ".join(" ",sort keys(%color));
  4619. }
  4620. CUL_HM_UpdtReadBulk($hash,1,"color:".$col4all,
  4621. "state:set_".$col4all);
  4622. CUL_HM_PushCmdStack($hash,"++".$flag."11".$id.$dst."8100".$col4all);
  4623. }
  4624. else{# operating on a channel
  4625. return "$a[2] unknown. use: ".join(" ",sort keys(%color))
  4626. if (!defined($color{$a[2]}) );
  4627. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'80'.$chn.'0'.$color{$a[2]});
  4628. }
  4629. }
  4630. elsif($md =~ m/^HM-OU-CFM?-PL/){
  4631. my %color = (redL =>18,greenL =>34,orangeL =>50,
  4632. redS =>17,greenS =>33,orangeS =>49,
  4633. pause=>01);
  4634. my @itemList = split(',',$a[2]);
  4635. my $repeat = (defined $a[3] && $a[3] =~ m/^(\d+)$/)?$a[3]:1;
  4636. my $itemCnt = int(@itemList);
  4637. return "no more then 10 entries please" if ($itemCnt>10);
  4638. return "at least one entry must be entered" if ($itemCnt<1);
  4639. return "repetition $repeat out of range [1..255]"
  4640. if($repeat < 1 || $repeat > 255);
  4641. #<entries><multiply><MP3><MP3>
  4642. my $msgBytes = sprintf("01%02X",$repeat);
  4643. foreach my $led (@itemList){
  4644. if (!$color{$led} ){# wrong parameter
  4645. return "'$led' unknown. use: ".join(" ",sort keys(%color));
  4646. }
  4647. $msgBytes .= sprintf("%02X",$color{$led});
  4648. }
  4649. $msgBytes .= "01" if ($itemCnt == 1 && $repeat == 1);#add pause to term LED
  4650. # need to fill up empty locations for LED channel
  4651. $msgBytes = substr($msgBytes."000000000000000000",0,(10+2)*2);
  4652. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'80'.$chn.$msgBytes);
  4653. }
  4654. elsif($md =~ m/^HM-OU-CFM?-TW/){
  4655. my %color = (redL =>18,greenL =>34,yellowL =>50,blueL =>66, violettL => 82, cyanL => 98, whiteL =>114,
  4656. redS =>17,greenS =>33,yellowS =>49,blueS =>65, violettS => 81, cyanS => 97, whiteS =>113,
  4657. pause=>2);
  4658. my @itemList = split(',',$a[2]);
  4659. my $repeat = (defined $a[3] && $a[3] =~ m/^(\d+)$/)?$a[3]:1;
  4660. my $duration = (defined $a[4] && $a[4] =~ m/^(\d+)$/)?$a[4]:10800;
  4661. my $itemCnt = int(@itemList);
  4662. return "enter at least one and up to 10 items" if ($itemCnt < 1 || $itemCnt > 10);
  4663. return "repetition $repeat out of range [1..255]" if ($repeat < 1 || $repeat > 255);
  4664. return "duration $duration out of range [1..10800]" if ($duration < 1 || $duration > 10800);
  4665. my $msgBytes = sprintf("01%02X",$repeat);
  4666. foreach my $led (@itemList){
  4667. return "'$led' unknown. use: ".join(" ",sort keys(%color)) if (!$color{$led} );# wrong parameter;
  4668. $msgBytes .= sprintf("%02X",$color{$led});
  4669. }
  4670. $msgBytes .= "01" if ($itemCnt == 1 && $repeat == 1);#add pause to term LED
  4671. # need to fill up empty locations for LED channel
  4672. $msgBytes = substr($msgBytes."00000000000000000000",0,(10+2)*2);
  4673. if ($duration < 10800) {
  4674. $msgBytes .= sprintf("%02X%02X",($duration & 0x00ff), ($duration & 0xff00)>>8);
  4675. }
  4676. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'80'.$chn.$msgBytes);
  4677. }
  4678. else{
  4679. return "device for command cannot be identified";
  4680. }
  4681. }
  4682. elsif($cmd eq "brightCol") { ################################################
  4683. my (undef,undef,$bright,$colVal,$duration,$ramp) = @a; #date prepared extention to entdate
  4684. return "cmd requires brightness[0..100] step 0.5, color[0..100] step 0.5, duration, ramptime" if (!defined $ramp);
  4685. return "please enter the duration in seconds" if (!defined $duration || $duration !~ m/^[+-]?\d+(\.\d+)?$/);
  4686. ($bright,$colVal) = (int($bright*2),int($colVal*2));# convert percent to [0..200]
  4687. return "obey range for brightness[0..100] color[0..100]" if ( $bright < 0 or $bright > 200
  4688. or $colVal < 0 or $colVal > 200);
  4689. my $tval = CUL_HM_encodeTime16($duration);# onTime 0.0..85825945.6, 0=forever
  4690. $ramp = CUL_HM_encodeTime16($ramp);
  4691. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'80'.$chn.
  4692. sprintf("%02X%02X",$bright,$colVal).$ramp.$tval);
  4693. }
  4694. elsif($cmd eq "color") { ################################################
  4695. my (undef,undef,$colVal) = @a; #date prepared extention to entdate
  4696. return "cmd requires color[0..100] step 0.5" if (!defined $colVal
  4697. ||$colVal < 0 ||$colVal > 100);
  4698. $colVal = int($colVal*2);# convert percent to [0..200]
  4699. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'02'.$chn.
  4700. sprintf("%02X",$colVal)."00A0");
  4701. }
  4702. elsif($cmd eq "brightAuto") { ###############################################
  4703. my (undef,undef,$bright,$colProg,$min,$max,$duration,$ramp) = @a; #date prepared extention to entdate
  4704. return "please enter the duration in seconds"
  4705. if (defined $duration && $duration !~ m/^[+-]?\d+(\.\d+)?$/);
  4706. return "at least bright and colorprogramm need to be set" if (!defined $colProg);
  4707. my $tval;
  4708. $tval = (!defined $duration) ? "" : CUL_HM_encodeTime16($duration);# onTime 0.0..85825945.6, 0=forever
  4709. $ramp = (!defined $ramp) ? "" : CUL_HM_encodeTime16($ramp) ;
  4710. $min = (!defined $min) ? "" : sprintf("%02X",$min) ;
  4711. $max = (!defined $max) ? "" : sprintf("%02X",$max) ;
  4712. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'81'.$chn.
  4713. sprintf("%02X%02X",$bright,$colProg).$min.$max.$ramp.$tval);
  4714. }
  4715. elsif($cmd eq "colProgram") { ################################################
  4716. my (undef,undef,$colProg) = @a; #date prepared extention to entdate
  4717. return "cmd requires a colorProgram[0..255]" if (!defined $colProg
  4718. ||$colProg < 0 ||$colProg > 255);
  4719. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'02'.$chn.
  4720. sprintf("%02X",$colProg)."00A0");
  4721. }
  4722. elsif($cmd eq "playTone") { #################################################
  4723. my $msg;
  4724. if (!defined $a[2]){
  4725. return "please enter parameter";
  4726. }
  4727. elsif ($a[2] eq 'replay'){
  4728. $msg = ReadingsVal($chnHash->{NAME},".lastTone","");
  4729. }
  4730. else{
  4731. my @itemList = split(',',$a[2]);
  4732. my $repeat = (defined $a[3] && $a[3] =~ m/^(\d+)$/)?$a[3]:1;
  4733. my $itemCnt = int(@itemList);
  4734. my $volume = (defined $a[4] && $a[4] =~ m/^(\d+)$/)?$a[4]:10;
  4735. my $duration = (defined $a[5] && $a[5] =~ m/^(\d+\.)?\d+$/)?$a[5]:108000;
  4736. return "no more than 10 entries please" if ($itemCnt > 10);
  4737. return "repetition $repeat out of range [1..255]" if ($repeat < 1 || $repeat > 255);
  4738. return "volume $volume out of range [0..10]" if ($volume < 0 || $volume > 10);
  4739. return "duration $duration out of range [0.1..108000]" if ($duration < 0.1 || $duration > 108000);
  4740. #<volume><multiply><MP3><MP3>
  4741. my $msgBytes = sprintf("%02X%02X",$volume*20,$repeat);
  4742. foreach my $mp3 (@itemList){
  4743. return "input: $mp3 is not an integer below 255"
  4744. if (!defined $mp3 || $mp3 !~ /^[+-]?\d+$/ || $mp3 > 255);
  4745. $msgBytes .= sprintf("%02X",$mp3);
  4746. }
  4747. # need to fill up empty locations for MP3 numbers
  4748. $msgBytes = substr($msgBytes."00000000000000000000",0,(10+2)*2);
  4749. # add duration as a float value
  4750. #$duration = CUL_HM_decodeTime16($duration * 10);# need to be tested
  4751. my $exponent = 0;
  4752. my $mantisse = $duration * 10;
  4753. while ($mantisse >= 2048) {
  4754. $mantisse = $mantisse >> 1;
  4755. $exponent++;
  4756. }
  4757. $duration = $mantisse << 5 | $exponent;
  4758. $msgBytes .= sprintf("%04X", $duration);
  4759. $msg = '++'.$flag.'11'.$id.$dst.'80'.$chn.$msgBytes;
  4760. CUL_HM_UpdtReadSingle($chnHash,".lastTone",$msg,0);
  4761. }
  4762. CUL_HM_PushCmdStack($hash,$msg) if ($msg);
  4763. }
  4764. elsif($cmd eq "displayWM" ) { ###############################################
  4765. $state = "";
  4766. # textNo color icon
  4767. my $param = (scalar(@a)-2);
  4768. if ($a[2] eq "help"){
  4769. my $ret = "text :\n <text> max 2 char";
  4770. foreach (sort keys %disBtn){
  4771. my (undef,$ch,undef,$ln) = unpack('A3A2A1A1',$_);
  4772. $ch = sprintf("%02X",$ch);
  4773. $ret .= "\n $_ ->"
  4774. .ReadingsVal( InternalVal($devName,"channel_$ch","no")
  4775. ,"text$ln","unkown");
  4776. }
  4777. $ret .= "\n off nc(no change)"
  4778. ."\ncolor:".join(",",sort keys %disColor)
  4779. ."\n nc(no change)"
  4780. ."\nicon :".join(",",sort keys %disIcon)
  4781. ;
  4782. return $ret;
  4783. }
  4784. return "$a[2] not valid - choose short or long" if($a[2] !~ m/^(short|long)$/);
  4785. my $type = $a[2] eq "short"?"s":"l";
  4786. if(!defined $hash->{helper}{dispi}{$type}{"l1"}{d}){# setup if one is missing
  4787. $hash->{helper}{dispi}{$type}{"l$_"}{d}=1 foreach (1,2,3,4,5,6);
  4788. }
  4789. if($a[3] =~ m/^line(.)$/){
  4790. my $lnNr = $1;
  4791. return "line number wrong - use 1..6" if($lnNr !~ m/[1-6]/);
  4792. return "please add a text " if(!$a[4]);
  4793. my $lnRd = "disp_$a[2]_l$lnNr";# reading assotiated with this entry
  4794. my $dh = $hash->{helper}{dispi}{$type}{"l$lnNr"};
  4795. if ($a[4] eq "off"){ #no display in this line
  4796. delete $dh->{txt};
  4797. }
  4798. elsif($a[4] =~ m/^e:/){ # equation
  4799. $dh->{d} = 2; # mark as equation
  4800. $dh->{exe} = $a[4];
  4801. $dh->{exe} =~ s/^e://;
  4802. ($dh->{txt},$a[5],$a[6]) = eval $dh->{exe};
  4803. return "define eval must return 3 values:" if(!defined $a[6]);
  4804. }
  4805. elsif($a[4] ne "nc"){ # new text
  4806. return "text too long " .$a[4] if (length($a[4])>12);
  4807. $dh->{txt}=$a[4];
  4808. }
  4809. if($a[5]){ # set new color
  4810. if($a[5] eq "off"){ # set new color
  4811. delete $dh->{col};
  4812. }
  4813. elsif($a[5] ne "nc"){ # set new color
  4814. return "color wrong $a[5] use:".join(",",sort keys %disColor) if (!defined $disColor{$a[5]});
  4815. $dh->{col}=$a[5];
  4816. }
  4817. }
  4818. if($a[6]){ # new icon
  4819. if($a[6] eq "noIcon"){ # new icon
  4820. delete $dh->{icn};
  4821. }
  4822. elsif($a[6] ne "nc"){ # new icon
  4823. return "icon wrong $a[6] use:".join(",",sort keys %disIcon) if (!defined $disIcon {$a[6]});
  4824. $dh->{icn}=$a[6];
  4825. }
  4826. }
  4827. }
  4828. else{
  4829. return "not enough parameter - always use txtNo, color and icon in a set"
  4830. if(($param-1) %3);
  4831. for (my $cnt=3;$cnt<$param;$cnt+=3){
  4832. my $lnNr = int($cnt/3);
  4833. my $dh = $hash->{helper}{dispi}{$type}{"l$lnNr"};
  4834. return "color wrong ".$a[$cnt+1]." use:".join(",",sort keys %disColor) if (!defined $disColor{$a[$cnt+1]});
  4835. return "icon wrong " .$a[$cnt+2]." use:".join(",",sort keys %disIcon) if (!defined $disIcon {$a[$cnt+2]});
  4836. return "text too long " .$a[$cnt+0] if (length($a[$cnt+0])>12);
  4837. if ($a[$cnt+0] eq "nc") {} # nc = no change
  4838. elsif ($a[$cnt+0] eq "off"){ delete $dh->{txt} } # off = no text display
  4839. else {$dh->{txt} = $a[$cnt+0];} # nc = no change
  4840. $dh->{col} = $a[$cnt+1];
  4841. $dh->{icn} = $a[$cnt+2];
  4842. delete $dh->{icn} if ($a[$cnt+2] eq "noIcon");
  4843. }
  4844. }
  4845. foreach my $t (keys %{$hash->{helper}{dispi}}){ # prepare the messages
  4846. CUL_HM_calcDisWm($hash,$devName,$t);
  4847. }
  4848. }
  4849. elsif($cmd eq "displayEP" ) { ###############################################
  4850. $state = "displayEP";
  4851. RemoveInternalTimer($name.":reWriteDisplay");# just in case param reWriteDisplay used
  4852. my %disp_icons = (
  4853. off => '80', on => '81', open => '82', closed => '83'
  4854. ,error => '84', ok => '85', info => '86', newmsg => '87'
  4855. ,svcmsg => '88'
  4856. ,none => ''
  4857. );
  4858. my %disp_sounds = (
  4859. off => 'C0', longlong => 'C1', longshort => 'C2'
  4860. ,long2short => 'C3', short => 'C4', shortshort => 'C5'
  4861. ,long => 'C6'
  4862. );
  4863. my %disp_signals = (
  4864. off => 'F0', red => 'F1', green => 'F2', orange => 'F3'
  4865. );
  4866. # msg: 'text,icon;text,icon;text,icon'
  4867. my ($msg, $sound, $rep, $pause, $sig) = @a[2..$#a];
  4868. # set defaults
  4869. $msg = '' if (!defined ($msg));
  4870. $sound = 'off' if (!defined ($sound) || !exists ($disp_sounds{$sound}));
  4871. $sig = 'off' if (!defined ($sig) || !exists ($disp_signals{$sig} ));
  4872. $rep = (!defined ($rep)? 1 :
  4873. ($rep > 15 ? 15 :
  4874. ($rep == 0 ? 16 :
  4875. $rep)));
  4876. $pause = (!defined ($pause)?10 :
  4877. ($pause < 1 ?1 :
  4878. ($pause >160 ?160:
  4879. $pause)));
  4880. if($msg eq 'help'){ # display command info
  4881. return "command options:"
  4882. ."\n line1,icon1:line2,icon2:line3,icon3 sound repeat pause signal"
  4883. ."\n line: 12 char text to be dispalyed. No change if empty."
  4884. ."\n icon: icon per line: ".join(" ",keys(%disp_icons))
  4885. ."\n sound: ".join(" ",keys(%disp_sounds))
  4886. ."\n repeat: 1..16 default=1"
  4887. ."\n pause: 1..160 default=10"
  4888. ."\n signal: ".join(" ",keys(%disp_signals))
  4889. ."\n "
  4890. ."\n check for param reWriteDisplayxx: "
  4891. ."\n translate chars: "
  4892. ."\n [ => Ä"
  4893. ."\n # => Ö"
  4894. ."\n $ => Ü"
  4895. ."\n { => ä"
  4896. ."\n | => ö"
  4897. ."\n } => ü"
  4898. ."\n _ => ß"
  4899. ."\n ] => &"
  4900. ."\n ' => ="
  4901. ."\n @ => ∨"
  4902. ."\n > => ∧"
  4903. ."\n ; => Sandwatch"
  4904. ;
  4905. }
  4906. my $snd = '020A';
  4907. # Lines are separated by semicolon, empty lines are supported
  4908. my @disp_lines = (split (':', $msg.":::"),"","");# at least 3 entries - loop will use first 3
  4909. my $lineNr=1;
  4910. $evtDly = 1;
  4911. foreach my $line (@disp_lines[0..2]) {# only 3 lines
  4912. # Split line into text and icon part separated by comma
  4913. $snd .= '12';# start text indicator
  4914. my ($text, $icon); # add separator in case Icon is dismissed
  4915. if (!defined $line || $line eq '') {
  4916. $text = ReadingsVal($name,"line${lineNr}_text","");
  4917. $icon = ReadingsVal($name,"line${lineNr}_icon","off");
  4918. }
  4919. else{
  4920. ($text, $icon) = split (',', $line.","); # add separator in case Icon is dismissed
  4921. }
  4922. # Hex code
  4923. if ($text =~ /^0x[0-9A-F]{2}$/) {
  4924. $snd .= substr($text,2,2);
  4925. }
  4926. # Predefined text code text0-9
  4927. elsif ($text =~ /^text([0-9])$/) {
  4928. $snd .= sprintf ("8%1X", $1);
  4929. }
  4930. # Convert string to hex codes
  4931. else {
  4932. $text =~ s/\\_/ /g;
  4933. foreach my $ch (split ('', substr ($text, 0, 12))) {
  4934. $snd .= sprintf ("%02X", ord ($ch));
  4935. }
  4936. }
  4937. $snd .= '13'.$disp_icons{$icon} if ($disp_icons{$icon});
  4938. $snd .= '0A';
  4939. CUL_HM_UpdtReadBulk($hash,0,"line${lineNr}_text:$text"
  4940. ,"line${lineNr}_icon:$icon");
  4941. $lineNr++;
  4942. }
  4943. $snd .= '14'.$disp_sounds{$sound}.'1C'; # Sound
  4944. $snd .= sprintf ("%02X1D", 0xD0+$rep-1); # Repeat
  4945. $snd .= sprintf ("E%01X16", int(($pause-1)/10));# Pause
  4946. $snd .= $disp_signals{$sig}.'03'; # Signal
  4947. CUL_HM_UpdtReadBulk($hash,0,"signal:$sig");
  4948. CUL_HM_pushEvnts();
  4949. CUL_HM_PushCmdStack($hash,"++${flag}11$id${dst}80${chn}$_") foreach (unpack('(A28)*',$snd));
  4950. }
  4951. elsif($cmd =~ m/^(controlMode|controlManu|controlParty)$/) { ################
  4952. $state = "";
  4953. my $mode = $a[2];
  4954. if ($cmd ne "controlMode"){
  4955. $mode = substr($cmd,7);
  4956. $mode =~ s/^Manu$/manual/;
  4957. $a[2] = ($a[2] eq "off")?4.5:($a[2] eq "on"?30.5:$a[2]);
  4958. }
  4959. $mode = lc $mode;
  4960. return "invalid $mode:select of mode [auto|boost|day|night] or"
  4961. ." controlManu,controlParty"
  4962. if ($mode !~ m/^(auto|manual|party|boost|day|night)$/);
  4963. my ($temp,$party);
  4964. if ($mode =~ m/^(auto|boost|day|night)$/){
  4965. return "no additional params for $mode" if ($a[3]);
  4966. }
  4967. if($mode eq "manual"){
  4968. my $t = $a[2] ne "manual"?$a[2]:ReadingsVal($name,"desired-temp",18);
  4969. if ($md =~ m/CC-TC/){$t = ($t eq "off")?4.5:(($t eq "on" )?30.5:$t);}
  4970. else {$t = ($t eq "off")?5 :(($t eq "on" )?30 :$t);}
  4971. return "temperatur for manual 4.5 to 30.5 C"
  4972. if ($t < 4.5 || $t > 30.5);
  4973. $temp = $t*2;
  4974. }
  4975. elsif($mode eq "party"){
  4976. return "use party <temp> <from-time> <from-date> <to-time> <to-date>\n"
  4977. ."temperatur: 5 to 30 C\n"
  4978. ."date format: party 10 03.8.13 11:30 5.8.13 12:00"
  4979. if (!$a[2] || $a[2] < 5 || $a[2] > 30 || !$a[6] );
  4980. $temp = $a[2]*2;
  4981. # party format 03.8.13 11:30 5.8.13 12:00
  4982. my ($sd,$sm,$sy) = split('\.',$a[3]);
  4983. my ($sh,$smin) = split(':' ,$a[4]);
  4984. my ($ed,$em,$ey) = split('\.',$a[5]);
  4985. my ($eh,$emin) = split(':' ,$a[6]);
  4986. return "wrong start day $sd" if ($sd < 0 || $sd > 31);
  4987. return "wrong start month $sm" if ($sm < 0 || $sm > 12);
  4988. return "wrong start year $sy" if ($sy < 0 || $sy > 99);
  4989. return "wrong start hour $sh" if ($sh < 0 || $sh > 23);
  4990. return "wrong start minute $smin, ony 00 or 30" if ($smin != 0 && $smin != 30);
  4991. $sh = $sh * 2 + $smin/30;
  4992. return "wrong end day $ed" if ($ed < 0 || $ed > 31);
  4993. return "wrong end month $em" if ($em < 0 || $em > 12);
  4994. return "wrong end year $ey" if ($ey < 0 || $ey > 99);
  4995. return "wrong end hour $eh" if ($eh < 0 || $eh > 23);
  4996. return "wrong end minute $emin, ony 00 or 30" if ($emin != 0 && $emin != 30);
  4997. $eh = $eh * 2 + $emin/30;
  4998. $party = sprintf("%02X%02X%02X%02X%02X%02X%02X",
  4999. $sh,$sd,$sy,$eh,$ed,$ey,($sm*16+$em));
  5000. }
  5001. my %mCmd = (auto=>0,manual=>1,party=>2,boost=>3,day=>4,night=>5);
  5002. my $msg = '8'.($mCmd{$mode}).$chn;
  5003. $msg .= sprintf("%02X",$temp) if ($temp);
  5004. $msg .= $party if ($party);
  5005. my @teamList = ( split(",",AttrVal(CUL_HM_id2Name($dst."05"),"peerIDs","")) # peers of RT team
  5006. ,split(",",AttrVal(CUL_HM_id2Name($dst."02"),"peerIDs","")) # peers RT/TC team
  5007. ,CUL_HM_name2Id($name) # myself
  5008. );
  5009. foreach my $tId (@teamList){
  5010. my $teamC = CUL_HM_id2Name($tId);
  5011. $tId = substr($tId,0,6);
  5012. my $teamD = CUL_HM_id2Name($tId);
  5013. next if (!defined $defs{$teamC} );
  5014. CUL_HM_UpdtReadSingle($defs{$teamC},"controlMode","set_".$mode,1);
  5015. CUL_HM_PushCmdStack($defs{$teamD},'++'.$flag.'11'.$id.$tId.$msg);
  5016. if ( $tId ne $dst
  5017. && CUL_HM_getRxType($defs{$teamD}) & "02"){
  5018. # burst device - we need to send immediately
  5019. CUL_HM_SndCmd($defs{$teamD},"++B112$id".substr($tId,0,6));
  5020. }
  5021. }
  5022. }
  5023. elsif($cmd eq "desired-temp") { #############################################
  5024. if ($md =~ m/^(HM-CC-RT-DN|HM-TC-IT-WM-W-EU)/){
  5025. my $temp = ($a[2] eq "off")?9:($a[2] eq "on"?61:$a[2]*2);
  5026. return "invalid temp:$a[2]" if($temp <9 ||$temp > 61);
  5027. $temp = sprintf ("%02X",$temp);
  5028. CUL_HM_PushCmdStack($hash,'++'.$flag."11$id$dst"."8604$temp");
  5029. my $idTch = ($md =~ m/^HM-CC-RT-DN/ ? $dst."05" : $dst."02");
  5030. my @teamList = ( split(",",AttrVal(CUL_HM_id2Name($dst."05"),"peerIDs","")) # peers of RT team
  5031. ,split(",",AttrVal(CUL_HM_id2Name($dst."02"),"peerIDs","")) # peers RT/TC team
  5032. ,CUL_HM_name2Id($name) # myself
  5033. );
  5034. foreach my $tId (@teamList){
  5035. $tId = substr($tId,0,6);
  5036. my $teamD = CUL_HM_id2Name($tId);
  5037. my $teamCh = ("HM-CC-RT-DN" eq AttrVal($teamD,"model","")) ? "04" #what is the controls channel of the peer?
  5038. : "02";
  5039. my $teamC = CUL_HM_id2Name($tId.$teamCh);
  5040. next if (!defined $defs{$teamC} );
  5041. CUL_HM_PushCmdStack($defs{$teamD},'++'.$flag."11$id$tId"."86$teamCh$temp");
  5042. CUL_HM_UpdtReadSingle($defs{$teamC},"state",$state,1);
  5043. if ( $tId ne $dst
  5044. && CUL_HM_getRxType($defs{$teamD}) & "02"){
  5045. # burst device - we need to send immediately
  5046. CUL_HM_SndCmd($defs{$teamD},"++B112$id".substr($tId,0,6));
  5047. }
  5048. }
  5049. }
  5050. else{
  5051. my $temp = CUL_HM_convTemp($a[2]);
  5052. return $temp if($temp =~ m/Invalid/);
  5053. CUL_HM_PushCmdStack($hash,'++'.$flag.'11'.$id.$dst.'0202'.$temp);
  5054. my $chnHash = CUL_HM_id2Hash($dst."02");
  5055. my $mode = ReadingsVal($chnHash->{NAME},"R-controlMode","");
  5056. $mode =~ s/set_//;#consider set as given
  5057. CUL_HM_UpdtReadSingle($chnHash,"desired-temp-cent",$a[2],1)
  5058. if($mode =~ m/central/);
  5059. }
  5060. }
  5061. elsif($cmd =~ m/^tempList(...)$/) { ##################################### reg
  5062. my $wd = $1;
  5063. $state= "";
  5064. my ($list,$addr,$prgChn);
  5065. if ($md =~ m/^(HM-CC-RT-DN|HM-TC-IT-WM-W-EU)/){
  5066. my %day2off = ( "Sat"=>"20", "Sun"=>"46", "Mon"=>"72", "Tue"=>"98",
  5067. "Wed"=>"124","Thu"=>"150","Fri"=>"176");
  5068. ($list,$addr,$prgChn) = (7,$day2off{$wd},0);
  5069. }
  5070. else{
  5071. my %day2off = ( "Sat"=>"5 0B", "Sun"=>"5 3B", "Mon"=>"5 6B",
  5072. "Tue"=>"5 9B", "Wed"=>"5 CB", "Thu"=>"6 01",
  5073. "Fri"=>"6 31");
  5074. ($list,$addr) = split(" ", $day2off{$wd},2);
  5075. $prgChn = 2;
  5076. $addr = hex($addr);
  5077. }
  5078. my $prep = "";
  5079. if ($a[2] =~ m/^(prep|exec)$/){
  5080. $prep = $a[2];
  5081. splice @a,2,1;#remove prep
  5082. }
  5083. if ($md =~ m/^HM-TC-IT-WM-W-EU/ && $a[2] =~ m/^p([123])$/){
  5084. $list += $1 - 1;
  5085. splice @a,2,1;#remove list
  5086. }
  5087. return "To few arguments" if(@a < 4);
  5088. return "To many arguments, max 13 pairs" if(@a > 28 && $md =~ m/^(HM-CC-RT-DN|HM-TC-IT-WM-W-EU)/);
  5089. return "To many arguments, max 24 pairs" if(@a > 50 && $md !~ m/^(HM-CC-RT-DN|HM-TC-IT-WM-W-EU)/);
  5090. return "Bad format, use HH:MM TEMP ..." if(@a % 2);
  5091. return "Last time spec must be 24:00" if($a[@a-2] ne "24:00");
  5092. my ($data,$msg) = ("","");
  5093. for(my $idx = 2; $idx < @a; $idx += 2) {
  5094. return "$a[$idx] is not in HH:MM format"
  5095. if($a[$idx] !~ m/^([0-2]\d):([0-5]\d)/);
  5096. my ($h, $m) = ($1, $2);
  5097. my ($hByte,$lByte);
  5098. my $temp = $a[$idx+1];
  5099. if ($md =~ m/^(HM-CC-RT-DN|HM-TC-IT-WM-W-EU)/){
  5100. $temp = (int($temp*2)<<9) + ($h*12+($m/5));
  5101. $hByte = $temp>>8;
  5102. $lByte = $temp & 0xff;
  5103. }
  5104. else{
  5105. $temp = CUL_HM_convTemp($temp);
  5106. return $temp if($temp =~ m/Invalid/);
  5107. $hByte = $h*6+($m/10);
  5108. $lByte = hex($temp);
  5109. }
  5110. $data .= sprintf("%02X%02X%02X%02X", $addr, $hByte, $addr+1,$lByte);
  5111. $addr += 2;
  5112. $hash->{TEMPLIST}{$wd}{($idx-2)/2}{HOUR} = $h;
  5113. $hash->{TEMPLIST}{$wd}{($idx-2)/2}{MINUTE} = $m;
  5114. $hash->{TEMPLIST}{$wd}{($idx-2)/2}{TEMP} = $a[$idx+1];
  5115. $msg .= sprintf(" %02d:%02d %.1f", $h, $m, $a[$idx+1]);
  5116. }
  5117. CUL_HM_pushConfig($hash, $id, $dst, $prgChn,0,0,$list, $data,$prep);
  5118. }
  5119. elsif($cmd eq "tempListTmpl") { #############################################
  5120. $state= "";
  5121. my $action = "verify";#defaults
  5122. my ($template,$fn);
  5123. for my $ax ($a[2],$a[3]){
  5124. next if (!$ax);
  5125. if ($ax =~ m/^(verify|restore)$/){
  5126. $action = $ax;
  5127. }
  5128. else{
  5129. $template = $ax;
  5130. }
  5131. }
  5132. ($fn,$template) = split(":",($template?$template
  5133. :AttrVal($name,"tempListTmpl",$name)));
  5134. if ($modules{HMinfo}){
  5135. if (!$template){ $template = HMinfo_tempListDefFn() .":$fn" ;}
  5136. else{ $template = HMinfo_tempListDefFn($fn).":$template";}
  5137. }
  5138. else{
  5139. if (!$template){ $template = "./tempList.cfg:$fn";}
  5140. else{ $template = "$fn:$template" ;}
  5141. }
  5142. my $ret = CUL_HM_tempListTmpl($name,$action,$template);
  5143. $ret = "verifed with no faults" if (!$ret && $action eq "verify");
  5144. return $ret;
  5145. }
  5146. elsif($cmd eq "tempTmplSet") { ##############################################
  5147. $state= "";
  5148. return "template missing" if (!defined $a[2]);
  5149. CommandAttr(undef, "$name tempListTmpl $a[2]");
  5150. my ($fn,$template) = split(":",AttrVal($name,"tempListTmpl",$name));
  5151. if ($modules{HMinfo}){
  5152. if (!$template){ $template = HMinfo_tempListDefFn() .":$fn" ;}
  5153. else{ $template = HMinfo_tempListDefFn($fn).":$template";}
  5154. }
  5155. else{
  5156. if (!$template){ $template = "./tempList.cfg:$fn";}
  5157. else{ $template = "$fn:$template" ;}
  5158. }
  5159. CUL_HM_tempListTmpl($name,"restore",$template);
  5160. }
  5161. elsif($cmd eq "templateDel") { ##############################################
  5162. $state= "";
  5163. return "template missing" if (!defined $a[2]);
  5164. my ($p,$t) = split(">",$a[2]);
  5165. HMinfo_templateDel($name,$t,$p) if (eval "defined(&HMinfo_templateDel)");
  5166. return;
  5167. }
  5168. elsif($cmd eq "sysTime") { ##################################################
  5169. $state = "";
  5170. my $s2000 = sprintf("%02X", CUL_HM_secSince2000());
  5171. CUL_HM_PushCmdStack($hash,"++803F$id${dst}0204$s2000");
  5172. }
  5173. elsif($cmd =~ m/^(valvePos|virtTemp|virtHum)$/) { ###########################
  5174. my $valu = $a[2];
  5175. my %lim = (valvePos =>{min=>0 ,max=>99 ,rd =>"valvePosTC" ,u =>" %"},
  5176. virtTemp =>{min=>-20,max=>50 ,rd =>"temperature",u =>"" },
  5177. virtHum =>{min=>0 ,max=>99 ,rd =>"humidity" ,u =>"" },);
  5178. if ($md eq "HM-CC-VD"){
  5179. return "level between $lim{$cmd}{min} and $lim{$cmd}{max} allowed"
  5180. if ($valu !~ m/^[+-]?\d+\.?\d+$/||
  5181. $valu > $lim{$cmd}{max}||$valu < $lim{$cmd}{min} );
  5182. CUL_HM_PushCmdStack($hash,'++A258'.$id.$dst
  5183. ."00".sprintf("%02X",($valu * 2.56)%256));
  5184. }
  5185. else{
  5186. my $u = $lim{$cmd}{u};
  5187. if ($valu eq "off"){
  5188. $u = "";
  5189. if ($cmd eq "virtHum") {$hash->{helper}{vd}{vinH} = "";}
  5190. else {$hash->{helper}{vd}{vin} = "";}
  5191. if ((!$hash->{helper}{vd}{vinH} || $hash->{helper}{vd}{vinH} eq "") &&
  5192. (!$hash->{helper}{vd}{vin} || $hash->{helper}{vd}{vin} eq "") ){
  5193. $state = "$cmd:stopped";
  5194. RemoveInternalTimer("valvePos:$dst$chn");# remove responsePending timer
  5195. RemoveInternalTimer("valveTmr:$dst$chn");# remove responsePending timer
  5196. delete($hash->{helper}{virtTC});
  5197. }
  5198. }
  5199. if ($hash->{helper}{virtTC} || $valu ne "off") {
  5200. if ($valu ne "off"){
  5201. return "level between $lim{$cmd}{min} and $lim{$cmd}{max} or 'off' allowed"
  5202. if ($valu !~ m/^[+-]?\d+\.?\d*$/||
  5203. $valu > $lim{$cmd}{max}||$valu < $lim{$cmd}{min} );
  5204. if ($cmd eq "virtHum") {$hash->{helper}{vd}{vinH} = $valu;}
  5205. else {$hash->{helper}{vd}{vin} = $valu;}
  5206. }
  5207. $attr{$devName}{msgRepeat} = 0;#force no repeat
  5208. if ($cmd eq "valvePos"){
  5209. my @pId = grep !/^$/,split(',',AttrVal($name,"peerIDs",""));
  5210. return "virtual TC support one VD only. Correct number of peers"
  5211. if (scalar @pId != 1);
  5212. my $ph = CUL_HM_id2Hash($pId[0]);
  5213. return "peerID $pId[0] is not assigned to a device " if (!$ph);
  5214. $hash->{helper}{vd}{typ} = 1; #valvePos
  5215. my $idDev = substr($pId[0],0,6);
  5216. $hash->{helper}{vd}{nDev} = CUL_HM_id2Name($idDev);
  5217. $hash->{helper}{vd}{id} = $modules{CUL_HM}{defptr}{$pId[0]}
  5218. ?$pId[0]
  5219. :$idDev;
  5220. $hash->{helper}{vd}{cmd} = "A258$dst$idDev";
  5221. CUL_HM_UpdtReadBulk($ph,1,
  5222. "state:set_$valu %",
  5223. "ValveDesired:$valu %");
  5224. $hash->{helper}{vd}{val} = sprintf("%02X",($valu * 2.56)%256);
  5225. $state = "ValveAdjust:$valu %";
  5226. }
  5227. else{#virtTemp || virtHum
  5228. $hash->{helper}{vd}{typ} = 2; #virtTemp
  5229. $hash->{helper}{vd}{cmd} = "8470$dst"."000000";
  5230. my $t = $hash->{helper}{vd}{vin}?$hash->{helper}{vd}{vin}:0;
  5231. $t *=10;
  5232. $t -= 0x8000 if ($t < 0);
  5233. $hash->{helper}{vd}{val} = sprintf("%04X", $t & 0x7fff);
  5234. $hash->{helper}{vd}{val} .= sprintf("%02X", $hash->{helper}{vd}{vinH})
  5235. if ($hash->{helper}{vd}{vinH} && $hash->{helper}{vd}{vinH} ne "");
  5236. }
  5237. $hash->{helper}{vd}{idh} = hex(substr($dst,2,2))*20077;
  5238. $hash->{helper}{vd}{idl} = hex(substr($dst,4,2))*256;
  5239. ($hash->{helper}{vd}{msgCnt},$hash->{helper}{vd}{next}) =
  5240. split(";",ReadingsVal($name,".next","0;".gettimeofday())) if(!defined $hash->{helper}{vd}{next});
  5241. if (!$hash->{helper}{virtTC}){
  5242. my $pn = CUL_HM_id2Name($hash->{helper}{vd}{id});
  5243. $hash->{helper}{vd}{ackT} = ReadingsTimestamp($pn, "ValvePosition", "")
  5244. if(!defined $hash->{helper}{vd}{ackT});
  5245. $hash->{helper}{vd}{miss} = 0 if(!defined $hash->{helper}{vd}{miss});
  5246. $hash->{helper}{vd}{msgRed} = 0 if(!defined $hash->{helper}{vd}{msgRed});
  5247. $hash->{helper}{virtTC} = ($cmd eq "valvePos")?"03":"00";
  5248. CUL_HM_UpdtReadSingle($hash,"valveCtrl","init",1)
  5249. if ($cmd eq "valvePos");
  5250. $hash->{helper}{vd}{next} = ReadingsVal($name,".next",gettimeofday())
  5251. if (!defined $hash->{helper}{vd}{next});
  5252. CUL_HM_valvePosUpdt("valvePos:$dst$chn");
  5253. }
  5254. $hash->{helper}{virtTC} = ($cmd eq "valvePos")?"03":"00";
  5255. }
  5256. CUL_HM_UpdtReadSingle($hash,$lim{$cmd}{rd},$valu.$u,1);
  5257. }
  5258. }
  5259. elsif($cmd eq "keydef") { ############################################### reg
  5260. if ( $a[3] eq "tilt") {CUL_HM_pushConfig($hash,$id,$dst,1,$id,$a[2],3,"0B220D838B228D83");#JT_ON/OFF/RAMPON/RAMPOFF short and long
  5261. } elsif ($a[3] eq "close") {CUL_HM_pushConfig($hash,$id,$dst,1,$id,$a[2],3,"0B550D838B558D83");#JT_ON/OFF/RAMPON/RAMPOFF short and long
  5262. } elsif ($a[3] eq "closed") {CUL_HM_pushConfig($hash,$id,$dst,1,$id,$a[2],3,"0F008F00"); #offLevel (also thru register)
  5263. } elsif ($a[3] eq "bolt") {CUL_HM_pushConfig($hash,$id,$dst,1,$id,$a[2],3,"0FFF8FFF"); #offLevel (also thru register)
  5264. } elsif ($a[3] eq "speedclose"){CUL_HM_pushConfig($hash,$id,$dst,1,$id,$a[2],3,sprintf("23%02XA3%02X",$a[4]*2,$a[4]*2));#RAMPOFFspeed (also in reg)
  5265. } elsif ($a[3] eq "speedtilt") {CUL_HM_pushConfig($hash,$id,$dst,1,$id,$a[2],3,sprintf("22%02XA2%02X",$a[4]*2,$a[4]*2));#RAMPOFFspeed (also in reg)
  5266. } else {return 'unknown argument '.$a[3];
  5267. }
  5268. }
  5269. elsif($cmd =~ m/^(teamCall|teamCallBat)$/) { ################################
  5270. $state = "";
  5271. my $sId = $roleV ? $dst : $id; # ID of cmd-source must not be a physical
  5272. # device. It can cause trouble with
  5273. # subsequent alarming
  5274. $hash->{TESTNR} = ($a[2] ? $a[2] : ($hash->{TESTNR} + 1))%255;
  5275. if ($fkt eq "sdLead1"){# ($md eq "HM-CC-SCD")
  5276. my $tstNo = sprintf("%02X",$hash->{TESTNR});
  5277. my $val = ($cmd eq "teamCallBat")? "80" : "00";
  5278. CUL_HM_PushCmdStack($hash, "++9440".$dst.$sId.$val.$tstNo);
  5279. CUL_HM_parseSDteam("40",$dst,$sId,$val.$tstNo);
  5280. }
  5281. else {#($md eq "HM-SEC-SD-2"){
  5282. # 96 switch on- others unknown
  5283. my $msg = CUL_HM_generateCBCsignature($hash,
  5284. sprintf("++1441$dst${sId}01%02X9600",$hash->{TESTNR}));
  5285. CUL_HM_PushCmdStack($hash, $msg) foreach (1..6);
  5286. CUL_HM_parseSDteam_2("41",$dst,$sId,substr($msg, 18));
  5287. }
  5288. }
  5289. elsif($cmd =~ m/^alarm(.*)/) { ##############################################
  5290. $state = "";
  5291. my $sId = $roleV ? $dst : $id; # ID of cmd-source must not be a physical
  5292. # device. It can cause trouble with
  5293. # subsequent alarming
  5294. if ($fkt eq "sdLead1"){# ($md eq "HM-CC-SCD")
  5295. my $p = (($1 eq "On")?"0BC8":"0C01");
  5296. my $msg = "++9441".$dst.$sId."01".$p;
  5297. CUL_HM_PushCmdStack($hash, $msg) foreach (1..3);# 3 reps fpr non-ack msg
  5298. CUL_HM_parseSDteam("41",$dst,$sId,"01".$p);
  5299. }
  5300. else{#($md eq "HM-SEC-SD-2"){
  5301. my $p = (($1 eq "On")?"C6":"00");
  5302. $hash->{TESTNR} = ($hash->{TESTNR} + 1)%255;
  5303. my $msg = CUL_HM_generateCBCsignature($hash,
  5304. sprintf("++1441$dst${sId}01%02X${p}00",$hash->{TESTNR}));
  5305. CUL_HM_PushCmdStack($hash, $msg) foreach (1..6);
  5306. CUL_HM_parseSDteam_2("41",$dst,$sId,substr($msg, 18));
  5307. }
  5308. }
  5309. elsif($cmd eq "virtual") { ##################################################
  5310. $state = "";
  5311. my (undef,undef,$maxBtnNo) = @a;
  5312. return "please give a number between 1 and 50"
  5313. if ($maxBtnNo < 1 ||$maxBtnNo > 50);# arbitrary - 255 should be max
  5314. return $name." already defines as ".$attr{$name}{subType}
  5315. if ($attr{$name}{subType} && $attr{$name}{subType} ne "virtual");
  5316. $attr{$name}{subType} = "virtual";
  5317. $attr{$name}{model} = "virtual_".$maxBtnNo
  5318. if (!$attr{$name}{model} ||$attr{$name}{model} =~ m/^virtual_/);
  5319. my $devId = $hash->{DEF};
  5320. for (my $btn=1;$btn <= $maxBtnNo;$btn++){
  5321. my $chnName = $name."_Btn".$btn;
  5322. my $chnId = $devId.sprintf("%02X",$btn);
  5323. CommandDefine(undef,"$chnName CUL_HM $chnId")
  5324. if (!$modules{CUL_HM}{defptr}{$chnId});
  5325. }
  5326. foreach my $channel (keys %{$hash}){# remove higher numbers
  5327. my $chNo;
  5328. $chNo = $1 if($channel =~ m/^channel_(.*)/);
  5329. next if (!defined($chNo));
  5330. CommandDelete(undef,$hash->{$channel})
  5331. if (hex($chNo) > $maxBtnNo);
  5332. }
  5333. CUL_HM_UpdtCentral($name) if ($md eq "CCU_FHEM");
  5334. }
  5335. elsif($cmd eq "update") { ###################################################
  5336. $state = "";
  5337. if ($md eq "ActionDetector"){
  5338. CUL_HM_ActCheck("ActionDetector");
  5339. }
  5340. else{
  5341. CUL_HM_UpdtCentral($name);
  5342. }
  5343. }
  5344. elsif($cmd =~ m/^press(.*)/) { ##############################################
  5345. # [long|short] [<peer>] [<repCount(long only)>] [<repDelay>] [<forceTiming[0|1]>] ...
  5346. my ($repCnt,$repDly,$forceTiming,$mode) = (0,0,0,0);
  5347. if($cmd eq "pressL"){
  5348. splice @a,2,0, ("long");
  5349. }
  5350. elsif($cmd eq "pressS"){
  5351. splice @a,2,0, ("short");
  5352. }
  5353. if ($a[2]){
  5354. ##############################
  5355. if ($a[2] eq "long"){
  5356. $mode = 64;
  5357. splice @a,2,1;
  5358. (undef,undef,undef,$repCnt,$repDly,$forceTiming) = @a;
  5359. $repCnt = 1 if (!defined $repCnt );
  5360. $repDly = 0.25 if (!defined $repDly );
  5361. $forceTiming = 1 if (!defined $forceTiming);
  5362. return "repeatCount $repCnt invalid. use value 1 - 255" if ($repCnt < 1 || $repCnt>255 );
  5363. return "repDelay $repDly invalid. use value 0.25 - 1.00" if ($repDly < 0.25 || $repDly>1 );
  5364. return "forceTiming $forceTiming invalid. use value 0 or 1" if ($forceTiming ne "0" && $forceTiming ne "1" );
  5365. }
  5366. elsif($a[2] eq "short"){
  5367. splice @a,2,1;
  5368. }
  5369. }
  5370. my $vChn = $a[2]?$a[2]:"";
  5371. my $pressCnt = (!$hash->{helper}{count}?1:$hash->{helper}{count}+1)%256;
  5372. $hash->{helper}{count}=$pressCnt;# remember for next round
  5373. if ($st eq 'virtual'){#serve all peers of virtual button
  5374. my @peerLchn = split(',',AttrVal($name,"peerIDs",""));
  5375. my @peerList = map{substr($_,0,6)} @peerLchn;
  5376. @peerList = grep !/000000/,grep !/^$/,CUL_HM_noDup(@peerList);
  5377. my $pc = sprintf("%02X%02X",hex($chn)+$mode,$pressCnt);# msg end
  5378. my $snd = 0;
  5379. foreach my $peer (sort @peerList){
  5380. my ($pHash,$peerFlag,$rxt);
  5381. $pHash = CUL_HM_id2Hash($peer);
  5382. next if ( !$pHash
  5383. || !$pHash->{helper}{role}
  5384. || !$pHash->{helper}{role}{prs});
  5385. $rxt = CUL_HM_getRxType($pHash);
  5386. $peerFlag = ($rxt & 0x02)?"B4":"A4" if($vChn ne "noBurst");#burst
  5387. CUL_HM_PushCmdStack($pHash,"++${peerFlag}40$dst$peer$pc");
  5388. $snd = 1;
  5389. foreach my $pCh(grep /$peer/,@peerLchn){
  5390. my $n = CUL_HM_id2Name($pCh);
  5391. next if (!$n);
  5392. $n =~ s/_chn-\d\d$//;
  5393. delete $defs{$n}{helper}{dlvl};#stop desiredLevel supervision
  5394. CUL_HM_stateUpdatDly($n,10);
  5395. }
  5396. if ($rxt & 0x80){#burstConditional
  5397. CUL_HM_SndCmd($pHash, "++B112$id".substr($peer,0,6))
  5398. if($vChn ne "noBurst");
  5399. }
  5400. else{
  5401. CUL_HM_ProcessCmdStack($pHash);
  5402. }
  5403. }
  5404. if(!$snd){# send 2 broadcast if no relevant peers
  5405. CUL_HM_SndCmd($hash,"++8440${dst}000000$pc");
  5406. }
  5407. }
  5408. else{#serve internal channels for actor
  5409. #which button shall be simulated? We offer
  5410. # on/off: self button - on is even/off odd number. Obey channel
  5411. # name of peer
  5412. my $pId;
  5413. if ($vChn =~ m/^(on|off)$/ && $st =~ m/^(blindActuator|dimmer)$/){
  5414. $pId = $dst.sprintf("%02X",(($vChn eq "off")?-1:0) + $chn*2);
  5415. }
  5416. elsif($vChn){
  5417. $pId = CUL_HM_name2Id($vChn,$devHash)."01";#01 is default for devices
  5418. }
  5419. else{
  5420. $pId = $dst.sprintf("%02X",$chn);
  5421. }
  5422. my ($pDev,$pCh) = unpack 'A6A2',$pId;
  5423. return "button cannot be identified" if (!$pCh);
  5424. delete $hash->{helper}{dlvl};#stop desiredLevel supervision
  5425. my $msg = sprintf("3E%s%s%s40%02X%02X",
  5426. $id,$dst,$pDev,
  5427. hex($pCh)+$mode,
  5428. $pressCnt);
  5429. for (my $cnt = 1;$cnt < $repCnt; $cnt++ ){
  5430. CUL_HM_SndCmd($hash, "++80$msg"); # send direct Wont work for burst!
  5431. select(undef, undef, undef, $repDly);
  5432. }
  5433. CUL_HM_PushCmdStack($hash, "++${flag}$msg"); # send thru commandstack
  5434. }
  5435. }
  5436. elsif($cmd eq "fwUpdate") { #################################################
  5437. if ($a[2] eq "onlyEnterBootLoader") {
  5438. Log3 $name,2,"CUL_HM entering bootloader for $name";
  5439. CUL_HM_SndCmd($hash, sprintf("%02X",$modules{CUL_HM}{helper}{updateNbr})
  5440. ."3011$id${dst}CA");
  5441. return ("",1);
  5442. }
  5443. return "no filename given" if (!$a[2]);
  5444. # return "only thru CUL " if (!$hash->{IODev}->{TYPE}
  5445. # ||($hash->{IODev}->{TYPE} ne "CUL"));
  5446. # todo add version checks of CUL
  5447. my ($fName,$pos,$enterBL) = ($a[2],0,($a[3] ? $a[3]+0 : 10));
  5448. my @imA; # image array: image[block][msg]
  5449. return "Illegal waitTime $enterBL - enter a value between 10 and 300"
  5450. if ($enterBL < 10 || $enterBL>300);
  5451. open(aUpdtF, $fName) || return("Can't open $fName: $!");
  5452. while(<aUpdtF>){
  5453. my $line = $_;
  5454. my $fs = length($line);
  5455. while ($fs>$pos){
  5456. my $bs = hex(substr($line,$pos,4))*2+4;
  5457. return "file corrupt. length:$fs expected:".($pos+$bs)
  5458. if ($fs<$pos+$bs);
  5459. my @msg = grep !/^$/,unpack '(A60)*',substr($line,$pos,$bs);
  5460. push @imA,\@msg; # image[block][msg]
  5461. $pos += $bs;
  5462. }
  5463. }
  5464. close(aUpdtF);
  5465. # --- we are prepared start update---
  5466. CUL_HM_protState($hash,"CMDs_FWupdate");
  5467. $modules{CUL_HM}{helper}{updating} = 1;
  5468. $modules{CUL_HM}{helper}{updatingName} = $name;
  5469. $modules{CUL_HM}{helper}{updateData} = \@imA;
  5470. $modules{CUL_HM}{helper}{updateStep} = 0;
  5471. $modules{CUL_HM}{helper}{updateDst} = $dst;
  5472. $modules{CUL_HM}{helper}{updateId} = $id;
  5473. $modules{CUL_HM}{helper}{updateNbr} = 10;
  5474. Log3 $name,2,"CUL_HM fwUpdate started for $name";
  5475. CUL_HM_SndCmd($hash, sprintf("%02X",$modules{CUL_HM}{helper}{updateNbr})
  5476. ."3011$id${dst}CA");
  5477. $hash->{helper}{io}{newChnFwUpdate} = $hash->{helper}{io}{newChn};#temporary hide init message
  5478. $hash->{helper}{io}{newChn} = "";
  5479. InternalTimer(gettimeofday()+$enterBL,"CUL_HM_FWupdateEnd","fail:notInBootLoader",0);
  5480. #InternalTimer(gettimeofday()+0.3,"CUL_HM_FWupdateSim",$dst."00000000",0);
  5481. }
  5482. elsif($cmd eq "postEvent") { ################################################
  5483. my (undef,undef,$cond) = @a;
  5484. my $cndNo;
  5485. if ($cond =~ m/[+-]?\d+/){
  5486. return "condition value:$cond above 200 illegal" if ($cond > 200);
  5487. $cndNo = $cond;
  5488. }
  5489. else{
  5490. my @keys;
  5491. if ($chnHash->{helper}{lm}){
  5492. foreach (keys %{$chnHash->{helper}{lm}}){
  5493. if ($chnHash->{helper}{lm}{$_} eq $cond){
  5494. $cndNo = $_;
  5495. last;
  5496. }
  5497. push @keys,$chnHash->{helper}{lm};
  5498. }
  5499. }
  5500. else{
  5501. foreach my $tp (keys %lvlStr){
  5502. foreach my $mk (keys %{$lvlStr{$tp}}){
  5503. foreach (keys %{$lvlStr{$tp}{$mk}}){
  5504. $cndNo = hex($_) if ($cond eq $lvlStr{$tp}{$mk}{$_});
  5505. push @keys,$lvlStr{$tp}{$mk}{$_};
  5506. }
  5507. }
  5508. }
  5509. }
  5510. return "cond:$cond not allowed. choose one of:[0..200],"
  5511. .join(",",sort @keys)
  5512. if (!defined $cndNo);
  5513. }
  5514. my $pressCnt = (!$hash->{helper}{count}?1:$hash->{helper}{count}+1)%256;
  5515. $hash->{helper}{count}=$pressCnt;# remember for next round
  5516. my @peerLChn = split(',',AttrVal($name,"peerIDs",""));
  5517. my @peerDev;
  5518. push (@peerDev,substr($_,0,6)) foreach (@peerLChn);
  5519. @peerDev = CUL_HM_noDup(@peerDev);#only once per device!
  5520. push @peerDev,'000000' if (!@peerDev);#send to broadcast if no peer
  5521. foreach my $peer (@peerDev){
  5522. my $pHash = CUL_HM_id2Hash($peer);
  5523. my $rxt = CUL_HM_getRxType($pHash);
  5524. my $peerFlag = ($rxt & 0x02)?"B4":"A4";#burst
  5525. CUL_HM_PushCmdStack($pHash, sprintf("++%s41%s%s%02X%02X%02X"
  5526. ,$peerFlag,$dst,$peer
  5527. ,hex($chn)
  5528. ,$pressCnt
  5529. ,$cndNo));
  5530. if ($rxt & 0x80){#burstConditional
  5531. CUL_HM_SndCmd($pHash, "++B112$id".substr($peer,0,6));
  5532. }
  5533. else{
  5534. CUL_HM_ProcessCmdStack($pHash);
  5535. }
  5536. }
  5537. foreach my $peer (@peerLChn){#inform each channel
  5538. my $pName = CUL_HM_id2Name($peer);
  5539. $pName = CUL_HM_id2Name(substr($peer,0,6)) if (!$defs{$pName});
  5540. next if (!$defs{$pName});
  5541. CUL_HM_UpdtReadBulk($defs{$pName},1
  5542. ,"trig_$name:$cond"
  5543. ,"trigLast:$name:$cond");
  5544. }
  5545. }
  5546. elsif($cmd eq "peerIODev") { ################################################
  5547. # peerIODev [IO] <chn> [set|unset]...
  5548. $state = "";
  5549. return "command requires parameter" if (!$a[2]);
  5550. my ($ioId,$ioCh,$set) = ($id,$a[2],'set'); #set defaults
  5551. if ($defs{$a[2]}){ #IO device given
  5552. $ioId = AttrVal($a[2],"hmId","");
  5553. return "$a[2] not valid, attribut hmid not set"
  5554. if($ioId !~ m/^[0-9A-F]{6}$/);
  5555. splice @a,2,1;
  5556. $ioCh = $a[2];
  5557. }
  5558. $set = $a[3] if ($a[3]);
  5559. $ioCh = sprintf("%02X",$ioCh);
  5560. return "No:$ioCh invalid. Number must be <=50" if (!$ioCh || $ioCh !~ m/^(\d*)$/ || $ioCh > 50);
  5561. return "option $set unknown - use set or unset" if ($set != m/^(set|unset)$/);
  5562. $set = ($set eq "set")?"01":"02";
  5563. CUL_HM_PushCmdStack($hash,"++${flag}01$id${dst}$chn$set$ioId${ioCh}00");
  5564. }
  5565. elsif($cmd eq "peerChan") { ############################################# reg
  5566. #peerChan <btnN> <device> ... [single|dual] [set|unset] [actor|remote|both]
  5567. my ($bNo,$peerN,$single,$set,$target) = ($a[2],$a[3],($a[4]?$a[4]:"dual"),
  5568. ($a[5]?$a[5]:"set"),
  5569. ($a[6]?$a[6]:"both"));
  5570. $state = "";
  5571. if ($roleD){
  5572. $bNo = 1 if ($bNo == 0 && $roleC); # role device and channel => button=1
  5573. return "$bNo is not a button number" if($bNo < 1);
  5574. }
  5575. my $peerId = CUL_HM_name2Id($peerN);
  5576. return "please enter peer" if(!$peerId);
  5577. return "peer is not a channel" if(!$defs{$peerN}{helper}{role}{chn});
  5578. $peerId .= "01" if( length($peerId) == 6);
  5579. my @pCh;
  5580. my ($peerHash,$dSet,$cmdB);
  5581. my $peerDst = substr($peerId,0,6);
  5582. my $pmd = AttrVal(CUL_HM_id2Name($peerDst), "model" , "");
  5583. if ($md =~ m/^HM-CC-RT-DN/ && $chn eq "05" ){# rt team peers cross from 05 to 04
  5584. @pCh = (undef,"04","05");
  5585. $chn = "04";
  5586. $single = "dual";
  5587. $dSet = 1;#Dual set - set 2 channels for "remote"
  5588. }
  5589. else{ # normal devices
  5590. $pCh[1] = $pCh[2] = substr($peerId,6,2);
  5591. }
  5592. $peerHash = $modules{CUL_HM}{defptr}{$peerDst.$pCh[1]}if ($modules{CUL_HM}{defptr}{$peerDst.$pCh[1]});
  5593. $peerHash = $modules{CUL_HM}{defptr}{$peerDst} if (!$peerHash);
  5594. return "$peerN not a CUL_HM device" if( ($target ne "remote")
  5595. && (!$peerHash || $peerHash->{TYPE} ne "CUL_HM")
  5596. && $defs{$devName}{IODev}->{NAME} ne $peerN);
  5597. return "$single must be single, dual or reverse" if($single !~ m/^(single|dual|reverse)$/);
  5598. return "$set must be set or unset" if($set !~ m/^(set|unset)$/);
  5599. return "$target must be [actor|remote|both]" if($target !~ m/^(actor|remote|both)$/);
  5600. return "use - single [set|unset] actor - for smoke detector" if( $st eq "smokeDetector" && ($single ne "single" || $target ne "actor"));
  5601. return "use - single - for ".$st if(($st =~ m/^(threeStateSensor|motionDetector)$/) && ($single ne "single"));
  5602. return "TC WindowRec only peers to channel 01 single" if( $pmd =~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/ && $pCh[1] eq "03" && $chn ne "01" && $set eq "set");
  5603. my $pSt = CUL_HM_Get($peerHash,$peerHash->{NAME},"param","subType");
  5604. if ($set eq "unset"){$set = 0; $cmdB ="02";}
  5605. else {$set = 1; $cmdB ="01";}
  5606. my (@b,$nrCh2Pair);
  5607. $b[1] = ($roleD) ?(($single eq "single")?$bNo : ($bNo*2 - 1))
  5608. : hex($chn)
  5609. ;
  5610. if ($single eq "single"){
  5611. $b[2] = $b[1];
  5612. $b[1] = 0 if ($st eq "smokeDetector" ||$pSt eq "smokeDetector");
  5613. $nrCh2Pair = 1;
  5614. }
  5615. elsif($single eq "dual"){
  5616. $single = 0;
  5617. $b[2] = $b[1] + 1;
  5618. $nrCh2Pair = 2;
  5619. }
  5620. else{#($single eq "reverse")
  5621. $single = 0;
  5622. $b[2] = $b[1]++;
  5623. $nrCh2Pair = 2;
  5624. }
  5625. if ( $pSt eq "smokeDetector"){
  5626. $target = "both" if ($st eq "virtual");
  5627. }
  5628. # First the remote (one loop for on, one for off)
  5629. if ($target =~ m/^(remote|both)$/){
  5630. my $burst;
  5631. if ($culHmRegModel->{$md}{peerNeedsBurst}|| #peerNeedsBurst supported
  5632. $culHmRegType->{$st}{peerNeedsBurst}){
  5633. $burst = (CUL_HM_getRxType($peerHash) & 0x82) #burst |burstConditional
  5634. ?"0101"
  5635. :"0100";
  5636. }
  5637. for(my $i = 1; $i <= $nrCh2Pair; $i++) {
  5638. if ($st eq "virtual"){
  5639. my $btnName = $pSt eq "smokeDetector" ? $name :CUL_HM_id2Name($dst.sprintf("%02X",$b[$i]));
  5640. next if (!defined $attr{$btnName});
  5641. CUL_HM_ID2PeerList ($btnName,$peerDst.$pCh[$i],$set); #upd. peerlist
  5642. }
  5643. else{
  5644. my $bStr = sprintf("%02X",$b[$i]);
  5645. CUL_HM_PushCmdStack($hash,
  5646. "++".$flag."01${id}${dst}${bStr}$cmdB${peerDst}$pCh[$i]00");
  5647. # my ($hash,$src,$dst,$chn ,$peerAddr,$peerChn ,$list,$content,$prep) = @_;
  5648. CUL_HM_pushConfig($hash,$id, $dst,$b[$i],$peerDst ,hex($pCh[$i]),4 ,$burst)
  5649. if($burst && $cmdB eq "01"); # only if set
  5650. CUL_HM_qAutoRead($name,3);
  5651. }
  5652. }
  5653. # need to send data here- this is a 2 device command... thats why.
  5654. my $rxType = CUL_HM_getRxType($devHash);
  5655. if($rxType & 0x01){#allways
  5656. CUL_HM_ProcessCmdStack($devHash);
  5657. }
  5658. elsif($devHash->{cmdStack} &&
  5659. $devHash->{helper}{prt}{sProc} != 1 # not processing
  5660. ){
  5661. if($rxType & 0x02){# handle burst Access devices - add burst Bit
  5662. my ($pre,$tp,$tail) = unpack 'A2A2A*',$devHash->{cmdStack}[0];
  5663. $devHash->{cmdStack}[0] = sprintf("%s%02X%s",$pre,(hex($tp)|0x10),$tail);
  5664. CUL_HM_ProcessCmdStack($devHash);
  5665. }
  5666. elsif (CUL_HM_getAttrInt($name,"burstAccess")){ #burstConditional - have a try
  5667. $hash->{helper}{prt}{brstWu}=1;# start auto-burstWakeup
  5668. CUL_HM_SndCmd($devHash,"++B112$id$dst");
  5669. }
  5670. }
  5671. }
  5672. if ($target =~ m/^(actor|both)$/ ){
  5673. if ($modules{CUL_HM}{defptr}{$peerDst}){# is defined or ID only?
  5674. if ($pSt eq "virtual"){
  5675. CUL_HM_ID2PeerList ($peerN,$dst.sprintf("%02X",$b[2]),$set);
  5676. CUL_HM_ID2PeerList ($peerN,$dst.sprintf("%02X",$b[1]),$set)
  5677. if ($b[1] & !$single);
  5678. }
  5679. else{
  5680. my $peerFlag = 'A0';
  5681. if ($dSet){
  5682. CUL_HM_PushCmdStack($peerHash, sprintf("++%s01%s%s%s%s%s%02X00",$peerFlag,$id,$peerDst,$pCh[1],$cmdB,$dst,$b[1]));
  5683. CUL_HM_PushCmdStack($peerHash, sprintf("++%s01%s%s%s%s%s%02X00",$peerFlag,$id,$peerDst,$pCh[2],$cmdB,$dst,$b[2] ));
  5684. }
  5685. else{
  5686. CUL_HM_PushCmdStack($peerHash, sprintf("++%s01%s%s%s%s%s%02X%02X",$peerFlag,$id,$peerDst,$pCh[1],$cmdB,$dst,$b[2],$b[1] ));
  5687. }
  5688. if(CUL_HM_getRxType($peerHash) & 0x80){
  5689. my $pDevHash = CUL_HM_id2Hash($peerDst);#put on device
  5690. CUL_HM_pushConfig($pDevHash,$id,$peerDst,0,0,0,0,"0101");#set burstRx
  5691. }
  5692. CUL_HM_qAutoRead($peerHash->{NAME},3);
  5693. }
  5694. $devHash = CUL_HM_getDeviceHash($peerHash); # Exchange the hash, as the switch is always alive.
  5695. }
  5696. }
  5697. return ("",1) if ($target && $target eq "remote");#Nothing for actor
  5698. }
  5699. elsif($cmd =~ m/^(pair|getVersion)$/) { ####################################
  5700. $state = "";
  5701. my $serial = ReadingsVal($name, "D-serialNr", undef);
  5702. return "serial $serial - wrong length or Reading D-serialNr not present"
  5703. if(length($serial) != 10);
  5704. CUL_HM_PushCmdStack($hash,"++A401".$id."000000010A".uc( unpack("H*",$serial)));
  5705. $hash->{hmPairSerial} = $serial if ($cmd eq "pair");
  5706. }
  5707. elsif($cmd eq "hmPairForSec") { #############################################
  5708. $state = "";
  5709. my $arg = $a[2]?$a[2]:"";
  5710. $arg = 60 if( $arg !~ m/^\d+$/);
  5711. CUL_HM_RemoveHMPair("hmPairForSec:$name");
  5712. $hash->{hmPair} = 1;
  5713. InternalTimer(gettimeofday()+$arg, "CUL_HM_RemoveHMPair", "hmPairForSec:$name", 1);
  5714. }
  5715. elsif($cmd eq "hmPairSerial") { #############################################
  5716. $state = "";
  5717. my $serial = $a[2]?$a[2]:"";
  5718. return "Usage: set $name hmPairSerial <10-character-serialnumber>"
  5719. if(length($serial) != 10);
  5720. CUL_HM_PushCmdStack($hash, "++8401${dst}000000010A".uc( unpack('H*', $serial)));
  5721. CUL_HM_RemoveHMPair("hmPairForSec:$name");
  5722. $hash->{hmPair} = 1;
  5723. $hash->{hmPairSerial} = $serial;
  5724. InternalTimer(gettimeofday()+30, "CUL_HM_RemoveHMPair", "hmPairForSec:$name", 1);
  5725. }
  5726. elsif($cmd eq "assignIO") { #################################################
  5727. $state = "";
  5728. my $io = $a[2];
  5729. return "use set of unset - $a[3] not allowed"
  5730. if ($a[3] && $a[3] != m/^(set|unset)$/);
  5731. my $set = ($a[3] && $a[3] eq "unset")?0:1;
  5732. if ($set){
  5733. CommandAttr(undef, "$io hmId $dst");
  5734. }
  5735. else{
  5736. CommandDeleteAttr(undef, "$io hmId");
  5737. }
  5738. CUL_HM_UpdtCentral($name);
  5739. }
  5740. elsif($cmd eq "assignHmKey") { ##############################################
  5741. $state = "";
  5742. my $oldKeyIdx = ReadingsVal($name, "aesKeyNbr", "00");
  5743. return "current key unknown" if (!defined $oldKeyIdx || $oldKeyIdx eq "");
  5744. my ($key1,$key2);
  5745. if (AttrVal($hash->{IODev}{NAME},"rfmode","") eq "HomeMatic" ) {
  5746. return "$cmd needs Crypt::Rijndael for updating keys with CUL"
  5747. if ($cryptFunc != 1);
  5748. my ($newKeyIdx, %keys) = CUL_HM_getKeys($hash);
  5749. my $oldKey = $keys{hex($oldKeyIdx)/2};
  5750. return "$cmd requires VCCU with hmKeys" if ($newKeyIdx == 0);
  5751. return "$cmd needs old key with index ".(hex($oldKeyIdx)/2) if (!defined($oldKey));
  5752. my $newKey = $keys{$newKeyIdx};
  5753. my $payload1 = pack("CCa8nN",1 #changekey?
  5754. ,$newKeyIdx*2 #index for first part of key
  5755. ,substr($newKey, 0, 8) #first 8 bytes of new key
  5756. ,rand(0xffff) #random
  5757. ,0x7e296fa5); #magic
  5758. my $payload2 = pack("CCa8nN",1 #changekey?
  5759. ,($newKeyIdx*2)+1 #index for second part of key
  5760. ,substr($newKey, 8, 8) #second 8 bytes of new key
  5761. ,rand(0xffff) #random
  5762. ,0x7e296fa5); #magic
  5763. my $cipher = Crypt::Rijndael->new($oldKey, Crypt::Rijndael::MODE_ECB());
  5764. Log3 $name,2,"CUL_HM $name assignHmKey index ".(hex($oldKeyIdx)/2)." to ".$newKeyIdx
  5765. ." Key1: ".unpack("H*", $payload1)
  5766. ." Key2: ".unpack("H*", $payload2);
  5767. $key1 = unpack("H*", $cipher->encrypt($payload1));
  5768. $key2 = unpack("H*", $cipher->encrypt($payload2));
  5769. }
  5770. else {
  5771. $key1 = sprintf("01%02X",$oldKeyIdx);
  5772. $key2 = sprintf("01%02X",($oldKeyIdx+1));
  5773. }
  5774. CUL_HM_PushCmdStack($hash,'++'.$flag.'04'.$id.$dst.$key1);
  5775. CUL_HM_PushCmdStack($hash,'++'.$flag.'04'.$id.$dst.$key2);
  5776. }
  5777. else{
  5778. return "$cmd not implemented - contact sysop";
  5779. }
  5780. CUL_HM_UpdtReadSingle($hash,"state",$state,1) if($state);
  5781. my $rxType = CUL_HM_getRxType($devHash);
  5782. Log3 $name,3,"CUL_HM set $name $act";
  5783. if($rxType & 0x01){#allways
  5784. CUL_HM_ProcessCmdStack($devHash);
  5785. }
  5786. elsif($devHash->{cmdStack} &&
  5787. $devHash->{helper}{prt}{sProc} != 1 # not processing
  5788. ){
  5789. if($rxType & 0x02){# handle burst Access devices - add burst Bit
  5790. if($st eq "thermostat"){ # others do not support B112
  5791. CUL_HM_SndCmd($devHash,"++B112$id$dst");
  5792. }
  5793. else{# set burst flag
  5794. my ($pre,$tp,$tail) = unpack 'A2A2A*',$devHash->{cmdStack}[0];
  5795. $devHash->{cmdStack}[0] = sprintf("%s%02X%s",$pre,(hex($tp)|0x10),$tail);
  5796. CUL_HM_ProcessCmdStack($devHash);
  5797. }
  5798. }
  5799. elsif (CUL_HM_getAttrInt($name,"burstAccess")){ #burstConditional - have a try
  5800. $hash->{helper}{prt}{brstWu}=1;# start auto-burstWakeup
  5801. CUL_HM_SndCmd($devHash,"++B112$id$dst");
  5802. }
  5803. }
  5804. return ("",1);# no not generate trigger outof command
  5805. }
  5806. #+++++++++++++++++ set/get support subroutines+++++++++++++++++++++++++++++++++
  5807. sub CUL_HM_valvePosUpdt(@) {#update valve position periodically to please valve
  5808. my($in ) = @_;
  5809. my(undef,$vId) = split(':',$in);
  5810. my $hash = CUL_HM_id2Hash($vId);
  5811. my $hashVd = $hash->{helper}{vd};
  5812. my $name = $hash->{NAME};
  5813. my $msgCnt = $hashVd->{msgCnt};
  5814. my ($idl,$lo,$hi,$nextTimer);
  5815. my $tn = gettimeofday();
  5816. my $nextF = $hashVd->{next};
  5817. # int32_t result = (((_address << 8) | messageCounter) * 1103515245 + 12345) >> 16;
  5818. # 4e6d = 20077 12996205 = C64E6D
  5819. # return (result & 0xFF) + 480;
  5820. if ($tn > ($nextF + 3000)){# missed 20 periods;
  5821. Log3 $name,3,"CUL_HM $name virtualTC timer off by:".int($tn - $nextF);
  5822. $nextF = $tn;
  5823. }
  5824. while ($nextF < ($tn+0.05)) {# calculate next time from last successful
  5825. $msgCnt = ($msgCnt +1) %256;
  5826. $idl = $hashVd->{idl}+$msgCnt;
  5827. $lo = int(($idl*0x4e6d +12345)/0x10000);#&0xff;
  5828. $hi = ($hashVd->{idh}+$idl*198); #&0xff;
  5829. $nextTimer = (($lo+$hi)&0xff)/4 + 120;
  5830. $nextF += $nextTimer;
  5831. }
  5832. my $offset = AttrVal($name, "cyclicMsgOffset", 200) / 1000.0;
  5833. $nextTimer += $offset;
  5834. $nextF += $offset;
  5835. Log3 $name,5,"CUL_HM $name m:$hashVd->{msgCnt} ->$msgCnt t:$hashVd->{next}->$nextF M:$tn :$nextTimer";
  5836. $hashVd->{next} = $nextF;
  5837. $hashVd->{nextM} = $tn+$nextTimer;# new adjust if we will match
  5838. $hashVd->{msgCnt} = $msgCnt;
  5839. if ($hashVd->{cmd}){
  5840. if ($hashVd->{typ} == 1){
  5841. my $vc = ReadingsVal($name,"valveCtrl","init");
  5842. if ($vc eq 'restart'){
  5843. CUL_HM_UpdtReadSingle($hash,"valveCtrl","unknown",1);
  5844. my $pn = CUL_HM_id2Name($hashVd->{id});
  5845. $hashVd->{ackT} = ReadingsTimestamp($pn, "ValvePosition", "");
  5846. $hashVd->{msgSent} = 0;
  5847. }
  5848. elsif( ($vc ne "init" && $hashVd->{msgRed} <= $hashVd->{miss})
  5849. || $hash->{helper}{virtTC} ne "00") {
  5850. $hashVd->{msgSent} = 1;
  5851. CUL_HM_SndCmd($defs{$hashVd->{nDev}},sprintf("%02X%s%s%s"
  5852. ,$msgCnt
  5853. ,$hashVd->{cmd}
  5854. ,$hash->{helper}{virtTC}
  5855. ,$hashVd->{val}));
  5856. }
  5857. InternalTimer($tn+10,"CUL_HM_valvePosTmr","valveTmr:$vId",0);
  5858. $hashVd->{virtTC} = $hash->{helper}{virtTC};#save for repeat
  5859. $hash->{helper}{virtTC} = "00";
  5860. }
  5861. elsif ($hashVd->{typ} == 2){#send to broadcast
  5862. CUL_HM_PushCmdStack($hash,sprintf("%02X%s%s"
  5863. ,$msgCnt
  5864. ,$hashVd->{cmd}
  5865. ,$hashVd->{val}));
  5866. $hashVd->{next} = $hashVd->{nextM};
  5867. InternalTimer($hashVd->{next},"CUL_HM_valvePosUpdt","valvePos:$vId",0);
  5868. }
  5869. }
  5870. else{
  5871. delete $hash->{helper}{virtTC};
  5872. CUL_HM_UpdtReadSingle($hash,"state","stopped",1);
  5873. return;# terminate processing
  5874. }
  5875. CUL_HM_ProcessCmdStack($hash);
  5876. }
  5877. sub CUL_HM_valvePosTmr(@) {#calc next vd wakeup
  5878. my($in ) = @_;
  5879. my(undef,$vId) = split(':',$in);
  5880. my $hash = CUL_HM_id2Hash($vId);
  5881. my $hashVd = $hash->{helper}{vd};
  5882. my $name = $hash->{NAME};
  5883. my $vc = ReadingsVal($name,"valveCtrl","init");
  5884. my $vcn = $vc;
  5885. if ($hashVd->{msgSent}) {
  5886. my $pn = CUL_HM_id2Name($hashVd->{id});
  5887. my $ackTime = ReadingsTimestamp($pn, "ValvePosition", "");
  5888. if (!$ackTime || $ackTime eq $hashVd->{ackT} ){
  5889. $vcn = (++$hashVd->{miss} > 5) ? "lost"
  5890. :"miss_".$hashVd->{miss};
  5891. Log3 $name,5,"CUL_HM $name virtualTC use fail-timer";
  5892. }
  5893. else{#successful - store sendtime and msgCnt that calculated it
  5894. CUL_HM_UpdtReadSingle($hash,".next","$hashVd->{msgCnt};$hashVd->{nextM}",0);
  5895. $hashVd->{next} = $hashVd->{nextM};#use adjusted value if ack
  5896. $vcn = "ok";
  5897. $hashVd->{miss} = 0;
  5898. }
  5899. $hashVd->{msgSent} = 0;
  5900. $hashVd->{ackT} = $ackTime;
  5901. }
  5902. else {
  5903. $hash->{helper}{virtTC} = $hashVd->{virtTC} if($hash->{helper}{virtTC} eq "00" && $hashVd->{virtTC});
  5904. $hashVd->{miss}++;
  5905. }
  5906. CUL_HM_UpdtReadSingle($hash,"valveCtrl",$vcn,1) if($vc ne $vcn);
  5907. InternalTimer($hashVd->{next},"CUL_HM_valvePosUpdt","valvePos:$vId",0);
  5908. }
  5909. sub CUL_HM_weather(@) {#periodically send weather data
  5910. my($in ) = @_;
  5911. my(undef,$name) = split(':',$in);
  5912. my $hash = $defs{$name};
  5913. my $dName = CUL_HM_getDeviceName($name) ;
  5914. my $ioId = CUL_HM_IoId($defs{$dName});
  5915. CUL_HM_SndCmd($hash,"++8470".$ioId."00000000".$hash->{helper}{weather});
  5916. InternalTimer(gettimeofday()+150,"CUL_HM_weather","weather:$name",0);
  5917. }
  5918. sub CUL_HM_infoUpdtDevData($$$) {#autoread config
  5919. my($name,$hash,$p) = @_;
  5920. my($fw1,$fw2,$mId,$serNo,$stc,$devInfo) = unpack('A1A1A4A20A2A*', $p);
  5921. my $md = $culHmModel->{$mId}{name} ? $culHmModel->{$mId}{name}:"unknown";
  5922. my $serial = pack('H*',$serNo);
  5923. my $fw = sprintf("%d.%d", hex($fw1),hex($fw2));
  5924. $attr{$name}{model} = $md;
  5925. $attr{$name}{subType} = $culHmModel->{$mId}{st};
  5926. $attr{$name}{serialNr} = $serial; # to be removed from attributes
  5927. $attr{$name}{firmware} = $fw; # to be removed from attributes
  5928. # $attr{$name}{".devInfo"} = $devInfo; # to be removed from attributes
  5929. # $attr{$name}{".stc"} = $stc; # to be removed from attributes
  5930. CUL_HM_configUpdate($name) if(ReadingsVal($name,"D-firmware","") ne $fw
  5931. ||ReadingsVal($name,"D-serialNr","") ne $serial
  5932. ||ReadingsVal($name,".D-devInfo","") ne $devInfo
  5933. ||ReadingsVal($name,".D-stc" ,"") ne $stc
  5934. ) ;
  5935. CUL_HM_UpdtReadBulk($hash,1,"D-firmware:$fw",
  5936. "D-serialNr:$serial",
  5937. ".D-devInfo:$devInfo",
  5938. ".D-stc:$stc");
  5939. delete $hash->{helper}{rxType};
  5940. CUL_HM_getRxType($hash); #will update rxType
  5941. $mId = CUL_HM_getMId($hash);# set helper valiable and use result
  5942. # autocreate undefined channels
  5943. my @chanTypesList = split(',',$culHmModel->{$mId}{chn});
  5944. foreach my $chantype (@chanTypesList){
  5945. my ($chnTpName,$chnStart,$chnEnd) = split(':',$chantype);
  5946. my $chnNoTyp = 1;
  5947. for (my $chnNoAbs = $chnStart; $chnNoAbs <= $chnEnd;$chnNoAbs++){
  5948. my $chnId = $hash->{DEF}.sprintf("%02X",$chnNoAbs);
  5949. if (!$modules{CUL_HM}{defptr}{$chnId}){
  5950. my $chnName = $name."_".$chnTpName.(($chnStart == $chnEnd)?
  5951. '':'_'.sprintf("%02d",$chnNoTyp));
  5952. CommandDefine(undef,$chnName.' CUL_HM '.$chnId);
  5953. $attr{CUL_HM_id2Name($chnId)}{model} = $md;
  5954. }
  5955. $attr{CUL_HM_id2Name($chnId)}{model} = $md;
  5956. $chnNoTyp++;
  5957. }
  5958. }
  5959. if ($culHmModel->{$mId}{cyc}){
  5960. CUL_HM_ActAdd($hash->{DEF},AttrVal($name,"actCycle",
  5961. $culHmModel->{$mId}{cyc}));
  5962. }
  5963. }
  5964. sub CUL_HM_getConfig($){
  5965. my $hash = shift;
  5966. my $flag = 'A0';
  5967. my $id = CUL_HM_IoId($hash);
  5968. my $dst = substr($hash->{DEF},0,6);
  5969. my $name = $hash->{NAME};
  5970. CUL_HM_configUpdate($name);
  5971. delete $modules{CUL_HM}{helper}{cfgCmpl}{$name};
  5972. CUL_HM_complConfigTest($name);
  5973. CUL_HM_PushCmdStack($hash,'++'.$flag.'01'.$id.$dst.'00040000000000')
  5974. if ($hash->{helper}{role}{dev});
  5975. my @chnIdList = CUL_HM_getAssChnIds($name);
  5976. delete $hash->{READINGS}{$_}
  5977. foreach (grep /^[\.]?(RegL_)/,keys %{$hash->{READINGS}});
  5978. foreach my $channel (@chnIdList){
  5979. my $cHash = CUL_HM_id2Hash($channel);
  5980. my $chn = substr($channel,6,2);
  5981. delete $cHash->{READINGS}{$_}
  5982. foreach (grep /^[\.]?(RegL_)/,keys %{$cHash->{READINGS}});
  5983. my $lstAr = $culHmModel->{CUL_HM_getMId($cHash)}{lst};
  5984. if($lstAr){
  5985. my $pReq = 0; # Peer request not issued, do only once for channel
  5986. $cHash->{helper}{getCfgListNo}= "";
  5987. foreach my $listEntry (split(",",$lstAr)){#lists define for this channel
  5988. # e.g."1, 5:2.3p ,6:2"
  5989. my ($peerReq,$chnValid)= (0,0);
  5990. my ($listNo,$chnLst1) = split(":",$listEntry);
  5991. if (!$chnLst1){
  5992. $chnValid = 1; #if no entry go for all channels
  5993. $peerReq = 1 if($listNo eq 'p' || $listNo==3 ||$listNo==4); #default
  5994. }
  5995. else{
  5996. my @chnLst = split('\.',$chnLst1);
  5997. foreach my $lchn (@chnLst){
  5998. no warnings;#know that lchan may be followed by 'p' causing a warning
  5999. $chnValid = 1 if (int($lchn) == hex($chn));
  6000. use warnings;
  6001. $peerReq = 1 if ($chnValid && $lchn =~ m/p/);
  6002. last if ($chnValid);
  6003. }
  6004. }
  6005. if ($chnValid){# yes, we will go for a list
  6006. if ($peerReq){# need to get the peers first
  6007. if($listNo ne 'p'){# not if 'only peers'!
  6008. $cHash->{helper}{getCfgList} = "all";
  6009. $cHash->{helper}{getCfgListNo} .= ",".$listNo;
  6010. }
  6011. if (!$pReq){#get peers first, but only once per channel
  6012. CUL_HM_PushCmdStack($cHash,sprintf("++%s01%s%s%s03"
  6013. ,$flag,$id,$dst,$chn));
  6014. $pReq = 1;
  6015. }
  6016. }
  6017. else{
  6018. my $ln = sprintf("%02X",$listNo);
  6019. my $mch = CUL_HM_lstCh($cHash,$ln,$chn);
  6020. CUL_HM_PushCmdStack($cHash,"++$flag"."01$id$dst$mch"."0400000000$ln");
  6021. }
  6022. }
  6023. }
  6024. }
  6025. }
  6026. }
  6027. sub CUL_HM_calcDisWmSet($){
  6028. my $dh = shift;
  6029. my ($txt,$col,$icon) = eval $dh->{exe};
  6030. if ($txt eq "off") { delete $dh->{txt};}
  6031. elsif($txt ne "nc") { $dh->{txt} = substr($txt,0,12);}
  6032. if (!$col ||$col eq "off") { delete $dh->{col};}
  6033. elsif($col ne "nc"){
  6034. if (!defined $disColor{$col}){ delete $dh->{col};}
  6035. else { $dh->{col}=$col; }
  6036. }
  6037. if (!$icon ||$icon eq "noIcon"){delete $dh->{icn};}
  6038. elsif($icon ne "nc"){
  6039. if (!defined $disIcon {$icon}){delete $dh->{icn}}
  6040. else {$dh->{icn}=$icon;}
  6041. }
  6042. }
  6043. sub CUL_HM_calcDisWm($$$){
  6044. my ($hash,$devName,$t)= @_; # t = s or l
  6045. my $msg;
  6046. my $ts = $t eq "s"?"short":"long";
  6047. foreach my $l (sort keys %{$hash->{helper}{dispi}{$t}}){
  6048. my $dh = $hash->{helper}{dispi}{$t}{"$l"};
  6049. CUL_HM_calcDisWmSet($dh) if ($dh->{d} == 2);
  6050. my ($ch,$ln);
  6051. if($dh->{txt}){
  6052. (undef,$ch,undef,$ln) = unpack('A3A2A1A1',$dh->{txt});
  6053. $ch = sprintf("%02X",$ch) if ($ch =~ m/^\d+\d+$/);
  6054. my $rd = ($dh->{txt}?"$dh->{txt} ":"- ")
  6055. .($dh->{col}?"$dh->{col} ":"- ")
  6056. .($dh->{icn}?"$dh->{icn} ":"- ")
  6057. ;
  6058. $rd .= "->". ReadingsVal(InternalVal($devName,"channel_$ch","no")
  6059. ,"text$ln","unkown")
  6060. if (defined $disBtn{$dh->{txt} });
  6061. readingsSingleUpdate($hash,"disp_${ts}_$l"
  6062. ,$rd
  6063. ,0);
  6064. if (defined $disBtn{$dh->{txt} }){
  6065. $msg .= sprintf("12%02X",$disBtn{$dh->{txt} }+0x80);
  6066. }
  6067. else{
  6068. $msg .= "12";
  6069. $msg .= uc( unpack("H*",$dh->{txt})) if ($dh->{txt});
  6070. }
  6071. }
  6072. $msg .= sprintf("11%02X",$disColor{$dh->{col}}+0x80)if ($dh->{col});
  6073. $msg .= sprintf("13%02X",$disIcon{$dh->{icn} }+0x80)if ($dh->{icn});
  6074. $msg .= "0A";# end of line indicator
  6075. }
  6076. my $msgh = "800102";
  6077. $msg .= "03";
  6078. my @txtMsg2;
  6079. foreach (unpack('(A28)*',$msg)){
  6080. push @txtMsg2,$msgh.$_;
  6081. $msgh = "8001";
  6082. }
  6083. $hash->{helper}{disp}{$t} = \@txtMsg2;
  6084. }
  6085. sub CUL_HM_RemoveHMPair($) {####################################################
  6086. my($in ) = shift;
  6087. my(undef,$name) = split(':',$in);
  6088. RemoveInternalTimer("hmPairForSec:$name");
  6089. return if (!$name || !defined $defs{$name});
  6090. delete($defs{$name}{hmPair});
  6091. delete($defs{$name}{hmPairSerial});
  6092. }
  6093. #+++++++++++++++++ Protocol stack, sending, repeat+++++++++++++++++++++++++++++
  6094. sub CUL_HM_pushConfig($$$$$$$$@) {#generate messages to config data to register
  6095. my ($hash,$src,$dst,$chn,$peerAddr,$peerChn,$list,$content,$prep) = @_;
  6096. my $flag = 'A0';
  6097. my $tl = length($content);
  6098. $chn = sprintf("%02X",$chn);
  6099. $peerChn = sprintf("%02X",$peerChn);
  6100. $list = sprintf("%02X",$list);
  6101. $prep = "" if (!defined $prep);
  6102. # --store pending changes in shadow to handle bit manipulations cululativ--
  6103. $peerAddr = "000000" if(!$peerAddr);
  6104. my $peerN = ($peerAddr ne "000000")?CUL_HM_peerChName($peerAddr.$peerChn,$dst):"";
  6105. $peerN =~ s/broadcast//;
  6106. $peerN =~ s/ /_/g;#remote blanks
  6107. my $regLNp = "RegL_".$list.".".$peerN;
  6108. my $regPre = ($hash->{helper}{expert}{raw}?"":".");
  6109. my $regLN = $regPre.$regLNp;
  6110. #--- copy data from readings to shadow
  6111. my $chnhash = $modules{CUL_HM}{defptr}{$dst.$chn};
  6112. $chnhash = $hash if (!$chnhash);
  6113. my $sdH = CUL_HM_shH($chnhash,$list,$dst);
  6114. my $rRd = ReadingsVal($chnhash->{NAME},$regLN,"");
  6115. if (!$sdH->{helper}{shadowReg} ||
  6116. !$sdH->{helper}{shadowReg}{$regLNp}){
  6117. $sdH->{helper}{shadowReg}{$regLNp} = $rRd;
  6118. }
  6119. #--- update with ne value
  6120. my $regs = $sdH->{helper}{shadowReg}{$regLNp};
  6121. for(my $l = 0; $l < $tl; $l+=4) { #substitute changed bytes in shadow
  6122. my $addr = substr($content,$l,2);
  6123. my $data = substr($content,$l+2,2);
  6124. if(!$regs || !($regs =~ s/$addr:../$addr:$data/)){
  6125. $regs .= " ".$addr.":".$data;
  6126. }
  6127. }
  6128. $sdH->{helper}{shadowReg}{$regLNp} = $regs; # update shadow
  6129. my @changeList;
  6130. if ($prep eq "exec"){#update complete registerset
  6131. @changeList = keys%{$sdH->{helper}{shadowReg}};
  6132. }
  6133. elsif ($prep eq "prep"){
  6134. return; #prepare shadowReg only. More data expected.
  6135. }
  6136. else{
  6137. push @changeList,$regLNp;
  6138. }
  6139. my $changed = 0;# did we write
  6140. foreach my $nrn(@changeList){
  6141. my $change;
  6142. my $nrRd = ReadingsVal($chnhash->{NAME},$regPre.$nrn,"");
  6143. foreach (sort split " ",$sdH->{helper}{shadowReg}{$nrn}){
  6144. $change .= $_." " if ($nrRd !~ m/$_/);# filter only changes
  6145. }
  6146. next if (!$change);#no changes
  6147. $change =~ s/00:00//;
  6148. $change =~ s/(\ |:)//g;
  6149. if ($nrRd){
  6150. $chnhash->{READINGS}{$regPre.$nrn}{VAL} =~ s/00:00// #mark incomplete as wego for a change;
  6151. }
  6152. my $pN;
  6153. $changed = 1;# yes, we did
  6154. ($list,$pN) = ($1,$2) if($nrn =~ m/RegL_(..)\.(.*)/);
  6155. if ($pN){($peerAddr,$peerChn) = unpack('A6A2', CUL_HM_name2Id($pN,$hash));}
  6156. else {($peerAddr,$peerChn) = ('000000','00');}
  6157. if (AttrVal($chnhash->{NAME},"peerIDs",0) =~ m/${peerAddr}00/){$peerChn = "00"}# if device we are not sure about device or channel. Check peers
  6158. CUL_HM_updtRegDisp($hash,$list,$peerAddr.$peerChn);
  6159. ############partition
  6160. # my @chSplit = unpack('(A28)*',$change);
  6161. my @chSplit = unpack('(A1120)*',$change);# makes max 40 lines, 280 byte
  6162. foreach my $chSpl(@chSplit){
  6163. my $mch = CUL_HM_lstCh($chnhash,$list,$chn);
  6164. CUL_HM_PushCmdStack($hash, "++".$flag.'01'.$src.$dst.$mch.'05'.
  6165. $peerAddr.$peerChn.$list);
  6166. $tl = length($chSpl);
  6167. for(my $l = 0; $l < $tl; $l+=28) {
  6168. my $ml = $tl-$l < 28 ? $tl-$l : 28;
  6169. CUL_HM_PushCmdStack($hash, "++A001".$src.$dst.$chn."08".
  6170. substr($chSpl,$l,$ml));
  6171. }
  6172. CUL_HM_PushCmdStack($hash,"++A001".$src.$dst.$mch."06");
  6173. }
  6174. #########
  6175. }
  6176. if ($changed){
  6177. CUL_HM_complConfig($hash->{NAME},1);
  6178. CUL_HM_qAutoRead($hash->{NAME},3) ;
  6179. }
  6180. }
  6181. sub CUL_HM_PushCmdStack($$) {
  6182. my ($chnhash, $cmd) = @_;
  6183. my @arr = ();
  6184. my $hash = CUL_HM_getDeviceHash($chnhash);
  6185. my $name = $hash->{NAME};
  6186. if(!$hash->{cmdStack}){# this is a new 'burst' of messages
  6187. $hash->{cmdStack} = \@arr;
  6188. $hash->{helper}{prt}{bErr}=0 if ($hash->{helper}{prt}{sProc} != 1);# not processing
  6189. }
  6190. push(@{$hash->{cmdStack}}, $cmd);
  6191. my $entries = scalar @{$hash->{cmdStack}};
  6192. $hash->{protCmdPend} = $entries." CMDs_pending";
  6193. CUL_HM_protState($hash,"CMDs_pending") if($hash->{helper}{prt}{sProc} != 1);# not processing
  6194. }
  6195. sub CUL_HM_ProcessCmdStack($) {
  6196. my ($chnhash) = @_;
  6197. my $hash = CUL_HM_getDeviceHash($chnhash);
  6198. if (!$hash->{helper}{prt}{rspWait}{cmd}){
  6199. if($hash->{cmdStack} && @{$hash->{cmdStack}}){
  6200. CUL_HM_SndCmd($hash, shift @{$hash->{cmdStack}});
  6201. }
  6202. elsif($hash->{helper}{prt}{sProc} != 0){
  6203. CUL_HM_protState($hash,"CMDs_done");
  6204. }
  6205. }
  6206. return;
  6207. }
  6208. sub CUL_HM_respWaitSu($@){ #setup response for multi-message response
  6209. # single commands
  6210. # cmd: single msg that needs to be ACKed
  6211. # mNo: number of message (needs to be in ACK)
  6212. # mNoWu: number of message if wakeup
  6213. # reSent: number of resends already done - usually init with 1
  6214. # wakeup: was wakeup message (burst devices)
  6215. #
  6216. # commands with multi-message answer
  6217. # PendCmd: command message
  6218. # Pending: type of answer we are awaiting
  6219. # forChn: which channel are we working on?
  6220. # forList: which list are we waiting for? (optional)
  6221. # forPeer: which peer are we waiting for? (optional)
  6222. my ($hash,@a)=@_;
  6223. my $mHsh = $hash->{helper}{prt};
  6224. $modules{CUL_HM}{prot}{rspPend}++ if(!$mHsh->{rspWait}{cmd});
  6225. foreach (@a){
  6226. next if (!$_);
  6227. my ($f,$d)=split ":=",$_;
  6228. $mHsh->{rspWait}{$f}=$d;
  6229. }
  6230. my $to = gettimeofday() + (($mHsh->{rspWait}{Pending})?rand(20)/10+4:
  6231. rand(40)/10+2);
  6232. if ($mHsh->{rspWait}{cmd}) {
  6233. my (undef,$mFlg) = unpack 'A6A2',$mHsh->{rspWait}{cmd};
  6234. $to += 1 if($mFlg && (hex($mFlg) & 0x10)); # burst wakeup
  6235. }
  6236. InternalTimer($to,"CUL_HM_respPendTout","respPend:$hash->{DEF}", 0);
  6237. }
  6238. sub CUL_HM_responseSetup($$) {#store all we need to handle the response
  6239. #setup repeatTimer and cmdStackControll
  6240. my ($hash,$cmd) = @_;
  6241. return if($hash->{helper}{prt}{sProc} == 3);#not relevant while FW update
  6242. my (undef,$mNo,$mFlg,$mTp,$src,$dst,$chn,$sTp,$dat) =
  6243. unpack 'A4A2A2A2A6A6A2A2A*',$cmd;
  6244. $mFlg = hex($mFlg);
  6245. if (($mFlg & 0x20) && ($dst ne '000000')){#msg wants ack
  6246. my $rss = $hash->{helper}{prt}{wuReSent}
  6247. ? $hash->{helper}{prt}{wuReSent}
  6248. :1;#resend count - may need preloaded for WU device
  6249. if ($mTp eq '01' && $sTp) {
  6250. if ($sTp eq "03"){ #PeerList-----------
  6251. #--- remember request params in device level
  6252. CUL_HM_respWaitSu ($hash,"Pending:=PeerList"
  6253. ,"cmd:=$cmd" ,"forChn:=$chn"
  6254. ,"mNo:=".hex($mNo)
  6255. ,"reSent:=$rss");
  6256. #--- remove readings in channel
  6257. my $chnhash = $modules{CUL_HM}{defptr}{"$dst$chn"};
  6258. $chnhash = $hash if (!$chnhash);
  6259. delete $chnhash->{READINGS}{peerList};#empty old list
  6260. delete $chnhash->{peerList};#empty old list
  6261. delete $chnhash->{helper}{peerIDsRaw};
  6262. $attr{$chnhash->{NAME}}{peerIDs} = '';
  6263. }
  6264. elsif($sTp eq "04"){ #RegisterRead-------
  6265. my ($peer, $list) = unpack 'A8A2',$dat;
  6266. $peer = ($peer ne "00000000")?CUL_HM_peerChName($peer,$dst):"";
  6267. #--- set messaging items
  6268. my $chnhash = $modules{CUL_HM}{defptr}{"$dst$chn"};
  6269. $chnhash = $hash if(!$chnhash);
  6270. my $fch = CUL_HM_shC($chnhash,$list,$chn);
  6271. CUL_HM_respWaitSu ($hash,"Pending:=RegisterRead"
  6272. ,"cmd:=$cmd" ,"forChn:=$fch"
  6273. ,"forList:=$list","forPeer:=$peer"
  6274. ,"mNo:=".hex($mNo)
  6275. ,"nAddr:=0"
  6276. ,"reSent:=$rss");
  6277. #--- remove channel entries that will be replaced
  6278. #empty val since reading will be cumulative
  6279. my $rlName = ($chnhash->{helper}{expert}{raw}?"":".")."RegL_".$list.".".$peer;
  6280. $chnhash->{READINGS}{$rlName}{VAL}="";
  6281. my $chnHash = $modules{CUL_HM}{defptr}{$dst.$chn};
  6282. delete ($chnhash->{READINGS}{$rlName}{TIME});
  6283. }
  6284. elsif($sTp eq "09"){ #SerialRead-------
  6285. CUL_HM_respWaitSu ($hash,"Pending:=SerialRead"
  6286. ,"cmd:=$cmd" ,"reSent:=$rss");
  6287. }
  6288. else{
  6289. CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss");
  6290. }
  6291. $hash->{helper}{cSnd} =~ s/.*,// if($hash->{helper}{cSnd});
  6292. $hash->{helper}{cSnd} .= ",".substr($cmd,8);
  6293. }
  6294. elsif($mTp eq '03') {#AES response - keep former wait and start timer again
  6295. #
  6296. if ($hash->{helper}{prt}{rspWait}){
  6297. RemoveInternalTimer("respPend:$hash->{DEF}");
  6298. my $mHsh = $hash->{helper}{prt};
  6299. my $to = gettimeofday() + (($mHsh->{helper}{prt}{rspWait}{Pending})?rand(20)/10+4:
  6300. rand(40)/10+2);
  6301. if ($mHsh->{rspWait}{cmd}) {
  6302. my (undef,$mFlg) = unpack 'A6A2',$mHsh->{rspWait}{cmd};
  6303. $to += 1 if($mFlg && (hex($mFlg) & 0x10)); # burst wakeup
  6304. }
  6305. InternalTimer($to,"CUL_HM_respPendTout","respPend:$hash->{DEF}", 0);
  6306. }
  6307. else{
  6308. # nothing - we dont know the origonal message
  6309. }
  6310. }
  6311. elsif($mTp eq '11') {
  6312. my $to = "";
  6313. if ($chn eq "02"){#!!! chn is subtype!!!
  6314. if ($dat =~ m/(..)....(....)/){#lvl ne 0 and timer on
  6315. # store Channel in this datafield.
  6316. # dimmer may answer with wrong virtual channel - then dont resent!
  6317. $hash->{helper}{tmdOn} = $sTp if ($1 ne "00" && $2 !~ m/(0000|FFFF)/);
  6318. $to = "timedOn:=1";
  6319. }
  6320. }
  6321. CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss",$to);
  6322. $hash->{helper}{cSnd} =~ s/.*,// if($hash->{helper}{cSnd});
  6323. $hash->{helper}{cSnd} .= ",".substr($cmd,8);
  6324. }
  6325. elsif($mTp eq '12' && $mFlg & 0x10){#wakeup with burst
  6326. # response setup - do not repeat, set counter to 250
  6327. CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss","brstWu:=1");
  6328. }
  6329. elsif($mTp !~ m/C./) {#
  6330. CUL_HM_respWaitSu ($hash,"cmd:=$cmd","mNo:=$mNo","reSent:=$rss");
  6331. }
  6332. CUL_HM_protState($hash,"CMDs_processing...");#if($mTp ne '03');
  6333. }
  6334. else{# no answer expected
  6335. if($hash->{cmdStack} && scalar @{$hash->{cmdStack}}){
  6336. if (!$hash->{helper}{prt}{sleeping}){
  6337. CUL_HM_protState($hash,"CMDs_processing...");
  6338. InternalTimer(gettimeofday()+.1, "CUL_HM_ProcessCmdStack", $hash, 0);
  6339. }
  6340. else{
  6341. delete $hash->{helper}{prt}{sleeping};
  6342. }
  6343. }
  6344. elsif(!$hash->{helper}{prt}{rspWait}{cmd}){
  6345. CUL_HM_protState($hash,"CMDs_done");
  6346. }
  6347. }
  6348. my $mmcS = $hash->{helper}{prt}{mmcS}?$hash->{helper}{prt}{mmcS}:0;
  6349. if ($mTp eq '01'){
  6350. my $oCmd = "++".substr($cmd,6);
  6351. if ($sTp eq "05"){
  6352. my @arr = ($oCmd);
  6353. $hash->{helper}{prt}{mmcA}=\@arr;
  6354. $hash->{helper}{prt}{mmcS} = 1;
  6355. }
  6356. elsif ($sTp =~ m/^(07|08)$/ && ($mmcS == 1||$mmcS == 2)){
  6357. push @{$hash->{helper}{prt}{mmcA}},$oCmd;
  6358. $hash->{helper}{prt}{mmcS} = 2;
  6359. }
  6360. elsif ($sTp eq "06" && ($mmcS == 2)){
  6361. push @{$hash->{helper}{prt}{mmcA}},$oCmd;
  6362. $hash->{helper}{prt}{mmcS} = 3;
  6363. }
  6364. elsif ($mmcS){ #
  6365. delete $hash->{helper}{prt}{mmcA};
  6366. delete $hash->{helper}{prt}{mmcS};
  6367. }
  6368. }
  6369. elsif($mmcS){
  6370. delete $hash->{helper}{prt}{mmcA};
  6371. delete $hash->{helper}{prt}{mmcS};
  6372. }
  6373. if($hash->{cmdStack} && scalar @{$hash->{cmdStack}}){
  6374. $hash->{protCmdPend} = scalar @{$hash->{cmdStack}}." CMDs pending";
  6375. }
  6376. else{
  6377. delete($hash->{protCmdPend});
  6378. }
  6379. }
  6380. sub CUL_HM_sndIfOpen($) {
  6381. my(undef,$io) = split(':',$_[0]);
  6382. RemoveInternalTimer("sndIfOpen:$io");# should not be necessary, but
  6383. my $ioHash = $defs{$io};
  6384. if ( ReadingsVal($io,"state","") !~ m/^(opened|Initialized)$/
  6385. ||(defined $ioHash->{XmitOpen} && $ioHash->{XmitOpen} != 1)
  6386. # ||$modules{CUL_HM}{prot}{rspPend}>=$maxPendCmds
  6387. ){#still no send allowed
  6388. if ( $modules{CUL_HM}{$io}{tmrStart} &&
  6389. ($modules{CUL_HM}{$io}{tmrStart} < gettimeofday() - $modules{CUL_HM}{hmIoMaxDly})){
  6390. # we need to clean up - this is way to long Stop delay
  6391. if ($modules{CUL_HM}{$io}{pendDev}) {
  6392. while(@{$modules{CUL_HM}{$io}{pendDev}}){
  6393. my $name = shift(@{$modules{CUL_HM}{$io}{pendDev}});
  6394. CUL_HM_eventP($defs{$name},"IOerr");
  6395. }
  6396. }
  6397. $modules{CUL_HM}{$io}{tmr} = 0;
  6398. }
  6399. else{
  6400. if ($modules{CUL_HM}{$io}{pendDev} && @{$modules{CUL_HM}{$io}{pendDev}}){
  6401. InternalTimer(gettimeofday()+$IOpoll,"CUL_HM_sndIfOpen",
  6402. "sndIfOpen:$io", 0);
  6403. }
  6404. }
  6405. }
  6406. else{
  6407. $modules{CUL_HM}{$io}{tmr} = 0;
  6408. if ($modules{CUL_HM}{$io}{pendDev} && @{$modules{CUL_HM}{$io}{pendDev}}){
  6409. my $name = shift(@{$modules{CUL_HM}{$io}{pendDev}});
  6410. CUL_HM_ProcessCmdStack($defs{$name});
  6411. if (@{$modules{CUL_HM}{$io}{pendDev}}){#tmr = 0, clearing queue slowly
  6412. InternalTimer(gettimeofday()+$IOpoll,"CUL_HM_sndIfOpen",
  6413. "sndIfOpen:$io", 0);
  6414. }
  6415. }
  6416. }
  6417. }
  6418. sub CUL_HM_SndCmd($$) {
  6419. my ($hash, $cmd) = @_;
  6420. $hash = CUL_HM_getDeviceHash($hash);
  6421. if( AttrVal($hash->{NAME},"ignore",0) != 0
  6422. || AttrVal($hash->{NAME},"dummy" ,0) != 0){
  6423. CUL_HM_eventP($hash,"dummy");
  6424. return;
  6425. }
  6426. CUL_HM_assignIO($hash) ;
  6427. if(!defined $hash->{IODev} ||!defined $hash->{IODev}{NAME}){
  6428. CUL_HM_eventP($hash,"IOerr");
  6429. CUL_HM_UpdtReadSingle($hash,"state","ERR_IOdev_undefined",1);
  6430. return;
  6431. }
  6432. my $io = $hash->{IODev};
  6433. my $ioName = $io->{NAME};
  6434. if ( ReadingsVal($ioName,"state","") !~ m/^(opened|Initialized)$/ # we need to queue
  6435. ||(hex substr($cmd,2,2) & 0x20) && ( # check for commands with resp-req
  6436. $modules{CUL_HM}{$ioName}{tmr} # queue already running
  6437. ||(defined $io->{XmitOpen} && $io->{XmitOpen} != 1)#overload, dont send
  6438. )
  6439. ){
  6440. # push device to list
  6441. if (!defined $modules{CUL_HM}{$ioName}{tmr}){
  6442. # some setup work for this timer
  6443. $modules{CUL_HM}{$ioName}{tmr} = 0;
  6444. if (!$modules{CUL_HM}{$ioName}{pendDev}){# generate if not exist
  6445. my @arr2 = ();
  6446. $modules{CUL_HM}{$ioName}{pendDev} = \@arr2;
  6447. }
  6448. }
  6449. # shall we delay commands if IO device is not present?
  6450. # it could cause trouble if light switches on after a long period
  6451. # repetition will be stopped after 1min forsecurity reason.
  6452. # so do: return cmd to queue and set state to pending again.
  6453. # device will be queued @ CUL_HM. Timer will perform cyclic check for IO to return.
  6454. #
  6455. my @arr = ();
  6456. $hash->{cmdStack} = \@arr if(!$hash->{cmdStack});
  6457. if( $hash->{helper}{prt}{rspWait} && $hash->{helper}{prt}{rspWait}{cmd}){
  6458. (undef,$cmd) = unpack 'A4A*',$hash->{helper}{prt}{rspWait}{cmd};
  6459. }
  6460. unshift (@{$hash->{cmdStack}}, $cmd);#pushback cmd, wait for opportunity
  6461. @{$modules{CUL_HM}{$ioName}{pendDev}} =
  6462. CUL_HM_noDup(@{$modules{CUL_HM}{$ioName}{pendDev}},$hash->{NAME});
  6463. CUL_HM_respPendRm($hash);#rm timer - we are out
  6464. CUL_HM_protState($hash,"CMDs_pending");
  6465. if ($modules{CUL_HM}{$ioName}{tmr} != 1){# need to start timer
  6466. my $tn = gettimeofday();
  6467. InternalTimer($tn+$IOpoll, "CUL_HM_sndIfOpen", "sndIfOpen:$ioName", 0);
  6468. $modules{CUL_HM}{$ioName}{tmr} = 1;
  6469. $modules{CUL_HM}{$ioName}{tmrStart} = $tn; # abort if to long
  6470. }
  6471. return;
  6472. }
  6473. $cmd =~ m/^(..)(.*)$/;
  6474. my ($mn, $cmd2) = unpack 'A2A*',$cmd;
  6475. if($mn eq "++") {
  6476. $mn = ($hash->{helper}{HM_CMDNR} + 1) & 0xff;
  6477. $hash->{helper}{HM_CMDNR} = $mn;
  6478. }
  6479. elsif($cmd =~ m/^[+-]/){; #continue pure
  6480. IOWrite($hash, "", $cmd);
  6481. return;
  6482. }
  6483. else {
  6484. $mn = hex($mn);
  6485. }
  6486. $cmd = sprintf("As%02X%02X%s", length($cmd2)/2+1, $mn, $cmd2);
  6487. IOWrite($hash, "", $cmd);
  6488. CUL_HM_statCnt($ioName,"s");
  6489. CUL_HM_eventP($hash,"Snd");
  6490. CUL_HM_responseSetup($hash,$cmd);
  6491. $cmd =~ m/^As(..)(..)(..)(..)(......)(......)(.*)/;
  6492. CUL_HM_DumpProtocol("SND", $io, ($1,$2,$3,$4,$5,$6,$7));
  6493. }
  6494. sub CUL_HM_statCnt($$) {# set msg statistics for (r)ecive (s)end or (u)pdate
  6495. my ($ioName,$dir) = @_;
  6496. my $stat = $modules{CUL_HM}{stat};
  6497. if (!$stat->{$ioName}){
  6498. $stat->{r}{$ioName}{h}{$_} = 0 foreach(0..23);
  6499. $stat->{r}{$ioName}{d}{$_} = 0 foreach(0..6);
  6500. $stat->{s}{$ioName}{h}{$_} = 0 foreach(0..23);
  6501. $stat->{s}{$ioName}{d}{$_} = 0 foreach(0..6);
  6502. $stat->{$ioName}{last} = 0;
  6503. }
  6504. my @l = localtime(gettimeofday());
  6505. if ($l[2] != $stat->{$ioName}{last}){#next field
  6506. if ($l[2] < $stat->{$ioName}{last}){#next day
  6507. my $recentD = ($l[6]+5)%7;
  6508. foreach my $ud ("r","s"){
  6509. $stat->{$ud}{$ioName}{d}{$recentD} = 0;
  6510. $stat->{$ud}{$ioName}{d}{$recentD} += $stat->{$ud}{$ioName}{h}{$_}
  6511. foreach (0..23);
  6512. }
  6513. }
  6514. $stat->{r}{$ioName}{h}{$l[2]} = 0;
  6515. $stat->{s}{$ioName}{h}{$l[2]} = 0;
  6516. $stat->{$ioName}{last} = $l[2];
  6517. }
  6518. $stat->{$dir}{$ioName}{h}{$l[2]}++ if ($dir ne "u");
  6519. }
  6520. sub CUL_HM_statCntRfresh($) {# update statistic once a day
  6521. my ($ioName,$dir) = @_;
  6522. foreach (keys %{$modules{CUL_HM}{stat}{r}}){
  6523. if (!$defs{$ioName}){#IO device is deleted, clear counts
  6524. delete $modules{CUL_HM}{stat}{$ioName};
  6525. delete $modules{CUL_HM}{stat}{r}{$ioName};
  6526. delete $modules{CUL_HM}{stat}{s}{$ioName};
  6527. next;
  6528. }
  6529. CUL_HM_statCnt($_,"u") if ($_ ne "dummy");
  6530. }
  6531. RemoveInternalTimer("StatCntRfresh");
  6532. InternalTimer(gettimeofday()+3600*20,"CUL_HM_statCntRfresh","StatCntRfresh",0);
  6533. }
  6534. sub CUL_HM_respPendRm($) {#del response related entries in messageing entity
  6535. my ($hash) = @_;
  6536. return if (!defined($hash->{DEF}));
  6537. $modules{CUL_HM}{prot}{rspPend}-- if($hash->{helper}{prt}{rspWait}{cmd});
  6538. delete $hash->{helper}{prt}{rspWait};
  6539. delete $hash->{helper}{prt}{wuReSent};
  6540. delete $hash->{helper}{tmdOn};
  6541. # delete $hash->{helper}{prt}{mmcA};
  6542. # delete $hash->{helper}{prt}{mmcS};
  6543. RemoveInternalTimer($hash); # remove resend-timer
  6544. RemoveInternalTimer("respPend:$hash->{DEF}");# remove responsePending timer
  6545. $respRemoved = 1;
  6546. }
  6547. sub CUL_HM_respPendTout($) {
  6548. my ($HMidIn) = @_;
  6549. my(undef,$HMid) = split(":",$HMidIn,2);
  6550. my $hash = $modules{CUL_HM}{defptr}{$HMid};
  6551. my $pHash = $hash->{helper}{prt};#shortcut
  6552. if ($hash && $hash->{DEF} ne '000000'){# we know the device
  6553. my $name = $hash->{NAME};
  6554. $pHash->{awake} = 0 if (defined $pHash->{awake});# set to asleep
  6555. return if(!$pHash->{rspWait}{reSent}); # Double timer?
  6556. my $rxt = CUL_HM_getRxType($hash);
  6557. if ($pHash->{rspWait}{brstWu}){#burst-wakeup try failed (conditionalBurst)
  6558. CUL_HM_respPendRm($hash);# don't count problems, was just a try
  6559. $hash->{protCondBurst} = "off" if (!$hash->{protCondBurst}||
  6560. $hash->{protCondBurst} !~ m/forced/);;
  6561. $pHash->{brstWu} = 0;# finished
  6562. $pHash->{awake} = 0;# set to asleep
  6563. CUL_HM_protState($hash,"CMDs_pending");
  6564. # commandstack will be executed when device wakes up itself
  6565. }
  6566. elsif ($pHash->{try}){ #send try failed - revert, wait for wakeup
  6567. # device might still be busy with writing flash or similar
  6568. # we have to wait for next wakeup
  6569. unshift (@{$hash->{cmdStack}}, "++".substr($pHash->{rspWait}{cmd},6));
  6570. delete $pHash->{try};
  6571. CUL_HM_respPendRm($hash);# do not count problems with wakeup try, just wait
  6572. CUL_HM_protState($hash,"CMDs_pending");
  6573. }
  6574. elsif (ReadingsVal($hash->{IODev}->{NAME},"state","") !~ m/^(opened|Initialized)$/){#IO errors
  6575. CUL_HM_eventP($hash,"IOdly");
  6576. CUL_HM_ProcessCmdStack($hash) if($rxt & 0x03);#burst/all
  6577. }
  6578. elsif ($pHash->{rspWait}{reSent} > AttrVal($name,"msgRepeat",($rxt & 0x9B)?3:0)#too many
  6579. ){#config cannot retry
  6580. my $pendCmd = "MISSING ACK";
  6581. if ($pHash->{rspWait}{Pending}){
  6582. $pendCmd = "RESPONSE TIMEOUT:".$pHash->{rspWait}{Pending};
  6583. CUL_HM_complConfig($name,1);# check with delay
  6584. }
  6585. CUL_HM_eventP($hash,"ResndFail");
  6586. CUL_HM_UpdtReadSingle($hash,"state",$pendCmd,1);
  6587. }
  6588. else{# manage retries
  6589. $pHash->{rspWait}{reSent}++;
  6590. CUL_HM_eventP($hash,"Resnd");
  6591. Log3 $name,4,"CUL_HM_Resend: $name nr ".$pHash->{rspWait}{reSent};
  6592. if ($hash->{protCondBurst}&&$hash->{protCondBurst} eq "on" ){
  6593. #timeout while conditional burst was active. try re-wakeup
  6594. my $addr = CUL_HM_IoId($hash);
  6595. $pHash->{rspWaitSec}{$_} = $pHash->{rspWait}{$_}
  6596. foreach (keys%{$pHash->{rspWait}});
  6597. CUL_HM_SndCmd($hash,"++B112$addr$HMid");
  6598. $hash->{helper}{prt}{awake}=4;# start re-wakeup
  6599. }
  6600. elsif($rxt & 0x18){# wakeup/lazy devices
  6601. #need to fill back command to queue and wait for next wakeup
  6602. if ($pHash->{mmcA}){#fillback multi-message command
  6603. unshift @{$hash->{cmdStack}},$_ foreach (reverse@{$pHash->{mmcA}});
  6604. delete $pHash->{mmcA};
  6605. delete $pHash->{mmcS};
  6606. }
  6607. else{#fillback simple command
  6608. unshift (@{$hash->{cmdStack}},"++".substr($pHash->{rspWait}{cmd},6))
  6609. if (substr($pHash->{rspWait}{cmd},8,2) ne '12');# not wakeup
  6610. }
  6611. my $wuReSent = $pHash->{rspWait}{reSent};# save 'invalid' count
  6612. CUL_HM_respPendRm($hash);#clear
  6613. CUL_HM_protState($hash,"CMDs_pending");
  6614. $pHash->{wuReSent} = $wuReSent;# save 'invalid' count
  6615. }
  6616. else{# normal device resend
  6617. if ($rxt & 0x02){# type = burst - need to set burst-Bit for retry
  6618. if ($pHash->{mmcA}){#fillback multi-message command
  6619. unshift @{$hash->{cmdStack}},$_ foreach (reverse@{$pHash->{mmcA}});
  6620. delete $pHash->{mmcA};
  6621. delete $pHash->{mmcS};
  6622. my $cmd = shift @{$hash->{cmdStack}};
  6623. $cmd = sprintf("As%02X01%s", length($cmd)/2, substr($cmd,2));
  6624. $pHash->{rspWait}{cmd} = $cmd;
  6625. CUL_HM_responseSetup($hash,$cmd);
  6626. }
  6627. my ($pre,$tp,$tail) = unpack 'A6A2A*',$pHash->{rspWait}{cmd};
  6628. $pHash->{rspWait}{cmd} = sprintf("%s%02X%s",$pre,(hex($tp)|0x10),$tail);
  6629. }
  6630. IOWrite($hash, "", $pHash->{rspWait}{cmd});
  6631. CUL_HM_statCnt($hash->{IODev}{NAME},"s");
  6632. InternalTimer(gettimeofday()+rand(20)/10+4,"CUL_HM_respPendTout","respPend:$hash->{DEF}", 0);
  6633. }
  6634. }
  6635. }
  6636. }
  6637. sub CUL_HM_respPendToutProlong($) {#used when device sends part responses
  6638. my ($hash) = @_;
  6639. RemoveInternalTimer("respPend:$hash->{DEF}");
  6640. InternalTimer(gettimeofday()+2, "CUL_HM_respPendTout", "respPend:$hash->{DEF}", 0);
  6641. }
  6642. sub CUL_HM_FWupdateSteps($){#steps for FW update
  6643. my $mIn = shift;
  6644. my $step = $modules{CUL_HM}{helper}{updateStep};
  6645. my $name = $modules{CUL_HM}{helper}{updatingName};
  6646. my $dst = $modules{CUL_HM}{helper}{updateDst};
  6647. my $id = $modules{CUL_HM}{helper}{updateId};
  6648. my $mNo = $modules{CUL_HM}{helper}{updateNbr};
  6649. my $hash = $defs{$name};
  6650. my $mNoA = sprintf("%02X",$mNo);
  6651. return "" if ($mIn !~ m/$mNoA..02$dst${id}00/ && $mIn !~ m/..10${dst}00000000/);
  6652. if ($mIn =~ m/$mNoA..02$dst${id}00/){
  6653. $modules{CUL_HM}{helper}{updateRetry} = 0;
  6654. $modules{CUL_HM}{helper}{updateNbrPassed} = $mNo;
  6655. }
  6656. if ($step == 0){#check bootloader entered - now change speed
  6657. return "" if ($mIn =~ m/$mNoA..02$dst${id}00/);
  6658. Log3 $name,2,"CUL_HM fwUpdate $name entered mode. IO-speed: fast";
  6659. $mNo = (++$mNo)%256; $mNoA = sprintf("%02X",$mNo);
  6660. CUL_HM_SndCmd($hash,"${mNoA}00CB$id${dst}105B11F81547");
  6661. # CUL_HM_SndCmd($hash,"${mNoA}20CB$id${dst}105B11F815470B081A1C191D1BC71C001DB221B623EA");
  6662. select(undef, undef, undef, (0.04));
  6663. CUL_HM_FWupdateSpeed($name,100);
  6664. select(undef, undef, undef, (0.04));
  6665. $mNo = (++$mNo)%256; $mNoA = sprintf("%02X",$mNo);
  6666. $modules{CUL_HM}{helper}{updateStep} = $step = 1;
  6667. $modules{CUL_HM}{helper}{updateNbr} = $mNo;
  6668. RemoveInternalTimer("fail:notInBootLoader");
  6669. #InternalTimer(gettimeofday()+0.3,"CUL_HM_FWupdateSim","${dst}${id}00",0);
  6670. }
  6671. ##16.130 CUL_Parse: A 0A 30 0002 235EDB 255E91 00
  6672. ##16.338 CUL_Parse: A 0A 39 0002 235EDB 255E91 00
  6673. ##16.716 CUL_Parse: A 0A 42 0002 235EDB 255E91 00
  6674. ##17.093 CUL_Parse: A 0A 4B 0002 235EDB 255E91 00
  6675. ##17.471 CUL_Parse: A 0A 54 0002 235EDB 255E91 00
  6676. ##17.848 CUL_Parse: A 0A 5D 0002 235EDB 255E91 00
  6677. ##...
  6678. ##43.621 4: CUL_Parse: iocu1 A 0A 58 0002 235EDB 255E91 00
  6679. ##44.034 4: CUL_Parse: iocu1 A 0A 61 0002 235EDB 255E91 00
  6680. ##44.161 4: CUL_Parse: iocu1 A 1D 6A 20CA 255E91 235EDB 00121642446D1C3F45F240ED84DC5E7C1AB7554D
  6681. ##44.180 4: CUL_Parse: iocu1 A 0A 6A 0002 235EDB 255E91 00
  6682. ## one block = 10 messages in 200-1000ms
  6683. my $blocks = scalar(@{$modules{CUL_HM}{helper}{updateData}});
  6684. RemoveInternalTimer("respPend:$hash->{DEF}");
  6685. RemoveInternalTimer("fail:Block".($step-1));
  6686. if ($blocks < $step){#last block
  6687. CUL_HM_FWupdateEnd("done");
  6688. Log3 $name,2,"CUL_HM fwUpdate completed";
  6689. return "done";
  6690. }
  6691. else{# programming continue
  6692. my $bl = ${$modules{CUL_HM}{helper}{updateData}}[$step-1];
  6693. my $no = scalar(@{$bl});
  6694. Log3 $name,5,"CUL_HM fwUpdate write block $step of $blocks: $no messages";
  6695. foreach my $msgP (@{$bl}){
  6696. $mNo = (++$mNo)%256; $mNoA = sprintf("%02X",$mNo);
  6697. CUL_HM_SndCmd($hash, $mNoA.((--$no)?"00":"20")."CA$id$dst".$msgP);
  6698. # select(undef, undef, undef, (0.01));# no wait necessary - FHEM is slow anyway
  6699. }
  6700. $modules{CUL_HM}{helper}{updateStep}++;
  6701. $modules{CUL_HM}{helper}{updateNbr} = $mNo;
  6702. #InternalTimer(gettimeofday()+0.3,"CUL_HM_FWupdateSim","${dst}${id}00",0);
  6703. InternalTimer(gettimeofday()+5,"CUL_HM_FWupdateBTo","fail:Block$step",0);
  6704. return "";
  6705. }
  6706. }
  6707. sub CUL_HM_FWupdateBTo($){# FW update block timeout
  6708. my $in = shift;
  6709. $modules{CUL_HM}{helper}{updateRetry}++;
  6710. if ($modules{CUL_HM}{helper}{updateRetry} > 5){#retry exceeded
  6711. CUL_HM_FWupdateEnd($in);
  6712. }
  6713. else{# have a retry
  6714. $modules{CUL_HM}{helper}{updateStep}--;
  6715. $modules{CUL_HM}{helper}{updateNbr} = $modules{CUL_HM}{helper}{updateNbrPassed};
  6716. CUL_HM_FWupdateSteps("0010".$modules{CUL_HM}{helper}{updateDst}."00000000");
  6717. }
  6718. }
  6719. sub CUL_HM_FWupdateEnd($){#end FW update
  6720. my $in = shift;
  6721. my $hash = $defs{$modules{CUL_HM}{helper}{updatingName}};
  6722. CUL_HM_UpdtReadSingle($hash,"fwUpdate",$in,1);
  6723. CUL_HM_FWupdateSpeed($modules{CUL_HM}{helper}{updatingName},10);
  6724. $hash->{helper}{io}{newChn} = $hash->{helper}{io}{newChnFwUpdate}
  6725. if(defined $hash->{helper}{io}{newChnFwUpdate});#restore initMsg
  6726. delete $hash->{helper}{io}{newChnFwUpdate};
  6727. delete $defs{$modules{CUL_HM}{helper}{updatingName}}->{cmdStack};
  6728. delete $modules{CUL_HM}{helper}{updating};
  6729. delete $modules{CUL_HM}{helper}{updatingName};
  6730. delete $modules{CUL_HM}{helper}{updateData};
  6731. delete $modules{CUL_HM}{helper}{updateStep};
  6732. delete $modules{CUL_HM}{helper}{updateDst};
  6733. delete $modules{CUL_HM}{helper}{updateId};
  6734. delete $modules{CUL_HM}{helper}{updateNbr};
  6735. CUL_HM_respPendRm($hash);
  6736. CUL_HM_protState($hash,"CMDs_done_FWupdate");
  6737. Log3 $hash->{NAME},2,"CUL_HM fwUpdate $hash->{NAME} end. IO-speed: normal";
  6738. }
  6739. sub CUL_HM_FWupdateSpeed($$){#set IO speed
  6740. my ($name,$speed) = @_;
  6741. my $hash = $defs{$name};
  6742. if (AttrVal($hash->{IODev}{NAME},"rfmode","") ne "HomeMatic"){
  6743. my $msg = sprintf("G%02X",$speed);
  6744. IOWrite($hash, "cmd",$msg);
  6745. }
  6746. else{
  6747. IOWrite($hash, "cmd","speed".$speed);
  6748. }
  6749. }
  6750. sub CUL_HM_FWupdateSim($){#end FW Simulation
  6751. my $msg = shift;
  6752. my $ioName = $defs{$modules{CUL_HM}{helper}{updatingName}}->{IODev}->{NAME};
  6753. my $mNo = sprintf("%02X",$modules{CUL_HM}{helper}{updateNbr});
  6754. if (0 == $modules{CUL_HM}{helper}{updateStep}){
  6755. CUL_HM_Parse($defs{$ioName},"A00${mNo}0010$msg");
  6756. }
  6757. else{
  6758. Log3 "",5,"FWupdate simulate No:$mNo";
  6759. CUL_HM_Parse($defs{$ioName},"A00${mNo}8002$msg");
  6760. }
  6761. }
  6762. sub CUL_HM_eventP($$) {#handle protocol events
  6763. # Current Events are Rcv,NACK,IOerr,Resend,ResendFail,Snd
  6764. # additional variables are protCmdDel,protCmdPend,protState,protLastRcv
  6765. my ($hash, $evntType) = @_;
  6766. return if (!defined $hash);
  6767. if ($evntType eq "Rcv"){
  6768. $hash->{"protLastRcv"} = TimeNow();
  6769. CUL_HM_UpdtReadSingle($hash,".protLastRcv",$hash->{"protLastRcv"},0);
  6770. return;
  6771. }
  6772. my $evnt = $hash->{"prot".$evntType}?$hash->{"prot".$evntType}:"0";
  6773. my ($evntCnt,undef) = split(' last_at:',$evnt);
  6774. $hash->{"prot".$evntType} = ++$evntCnt." last_at:".TimeNow();
  6775. if ($evntType =~ m/^(Nack|ResndFail|IOerr|dummy)/){# unrecoverable Error
  6776. CUL_HM_UpdtReadSingle($hash,"state",$evntType,1);
  6777. $hash->{helper}{prt}{bErr}++;
  6778. $hash->{protCmdDel} = 0 if(!$hash->{protCmdDel});
  6779. $hash->{protCmdDel} += scalar @{$hash->{cmdStack}} + 1
  6780. if ($hash->{cmdStack});
  6781. CUL_HM_protState($hash,"CMDs_done");
  6782. CUL_HM_respPendRm($hash);
  6783. }
  6784. elsif($evntType eq "IOdly"){ # IO problem - will see whether it recovers
  6785. my $pHash = $hash->{helper}{prt};
  6786. if ($pHash->{mmcA}){
  6787. unshift @{$hash->{cmdStack}},$_ foreach (reverse@{$pHash->{mmcA}});
  6788. delete $pHash->{mmcA};
  6789. delete $pHash->{mmcS};
  6790. }
  6791. else{
  6792. unshift (@{$hash->{cmdStack}},"++".substr($pHash->{rspWait}{cmd},6));
  6793. # unshift @{$hash->{cmdStack}}, $pHash->{rspWait}{cmd};#pushback
  6794. }
  6795. CUL_HM_respPendRm($hash);
  6796. }
  6797. }
  6798. sub CUL_HM_protState($$){
  6799. my ($hash,$state) = @_;
  6800. if (!$hash || !$hash->{NAME}){#General remove when fixed
  6801. Log 4,"CUL_HM protstate undeviced hash to set $state";
  6802. return;
  6803. }
  6804. my $name = $hash->{NAME};
  6805. my $sProcIn = $hash->{helper}{prt}{sProc};
  6806. if ($sProcIn == 3){#FW update processing
  6807. # do not change state - commandstack is bypassed
  6808. return if ( $state !~ m/(Info_Cleared|_FWupdate)/);
  6809. }
  6810. if ($state =~ m/processing/) {
  6811. $hash->{helper}{prt}{sProc} = 1;
  6812. }
  6813. elsif($state =~ m/^CMDs_done/) {
  6814. $state .= ($hash->{helper}{prt}{bErr}?
  6815. ("_Errors:".$hash->{helper}{prt}{bErr})
  6816. :"");
  6817. delete($hash->{cmdStack});
  6818. delete($hash->{protCmdPend});
  6819. $hash->{helper}{prt}{bErr} = 0;
  6820. $hash->{helper}{prt}{sProc} = 0;
  6821. $hash->{helper}{prt}{awake} = 0 if (defined $hash->{helper}{prt}{awake});
  6822. }
  6823. elsif($state eq "Info_Cleared"){
  6824. $hash->{helper}{prt}{sProc} = 0;
  6825. $hash->{helper}{prt}{awake} = 0 if (defined $hash->{helper}{prt}{awake});
  6826. }
  6827. elsif($state eq "CMDs_pending"){
  6828. $hash->{helper}{prt}{sProc} = 2;
  6829. }
  6830. elsif($state eq "CMDs_FWupdate"){
  6831. $hash->{helper}{prt}{sProc} = 3;
  6832. }
  6833. $hash->{protState} = $state;
  6834. if (!$hash->{helper}{role}{chn}){
  6835. CUL_HM_UpdtReadSingle($hash,"state",$state,
  6836. ($hash->{helper}{prt}{sProc} == 1)?0:1);
  6837. }
  6838. Log3 $name,5,"CUL_HM $name protEvent:$state".
  6839. ($hash->{cmdStack}?" pending:".scalar @{$hash->{cmdStack}}:"");
  6840. CUL_HM_hmInitMsgUpdt($hash) if ( $hash->{helper}{prt}{sProc} != $sProcIn
  6841. && ( $hash->{helper}{prt}{sProc} < 2
  6842. ||($hash->{helper}{prt}{sProc} == 2 && $sProcIn == 0 )));
  6843. }
  6844. ###################-----------helper and shortcuts--------#####################
  6845. ################### Peer Handling ################
  6846. sub CUL_HM_ID2PeerList ($$$) {
  6847. my($name,$peerID,$set) = @_;
  6848. my $peerIDs = AttrVal($name,"peerIDs","");
  6849. return if (!$peerID && !$peerIDs); # nothing to do
  6850. my $hash = $defs{$name};
  6851. $peerIDs =~ s/$peerID//g; #avoid duplicate, support unset
  6852. $peerID =~ s/^000000../00000000/; #correct end detector
  6853. $peerIDs.= $peerID."," if($set);
  6854. my %tmpHash = map { $_ => 1 } split(",",$peerIDs);#remove duplicates
  6855. $peerIDs = ""; #clear list
  6856. my $peerNames = ""; #prepare names
  6857. my $dId = substr(CUL_HM_name2Id($name),0,6); #get own device ID
  6858. foreach my $pId (sort(keys %tmpHash)){
  6859. next if ($pId !~ m/^[0-9A-Fx]{8}$/); #ignore non-channel IDs
  6860. $peerIDs .= $pId.","; #append ID
  6861. next if ($pId eq "00000000"); # and end detection
  6862. $peerNames .= CUL_HM_peerChName($pId,$dId).",";
  6863. }
  6864. $attr{$name}{peerIDs} = $peerIDs; # make it public
  6865. my $dHash = CUL_HM_getDeviceHash($hash);
  6866. my $st = AttrVal($dHash->{NAME},"subType","");
  6867. my $md = AttrVal($dHash->{NAME},"model","");
  6868. my $chn = InternalVal($name,"chanNo","");
  6869. if ($peerNames){
  6870. $peerNames =~ s/_chn-01//g; # channel 01 is part of device
  6871. $peerNames =~ s/_chn-01//g; # channel 01 is part of device
  6872. CUL_HM_UpdtReadSingle($hash,"peerList",$peerNames,0);
  6873. $hash->{peerList} = $peerNames;
  6874. if ($st eq "virtual"){
  6875. #if any of the peers is an SD we are team master
  6876. my ($tMstr,$tcSim,$thSim) = (0,0,0);
  6877. foreach (split(",",$peerNames)){
  6878. if(AttrVal($_,"subType","") eq "smokeDetector"){#have smoke detector
  6879. $tMstr = AttrVal($_,"model","") eq "HM-SEC-SD-2"? 2:1;#differentiate SD and SD2
  6880. }
  6881. $tcSim = 1 if(AttrVal($_,"model","") =~ m/^(HM-CC-VD|ROTO_ZEL-STG-RM-FSA)/);
  6882. my $pch = (substr(CUL_HM_name2Id($_),6,2));
  6883. $thSim = 1 if(AttrVal($_,"model","") =~ m/^HM-CC-RT-DN/ && $pch eq "01");
  6884. }
  6885. if ($tMstr){
  6886. $hash->{helper}{fkt} = "sdLead".$tMstr;
  6887. $hash->{sdTeam} = "sdLead";
  6888. $hash->{TESTNR} = 1 if(!exists $hash->{TESTNR});#must be defined for all sdLead
  6889. CUL_HM_updtSDTeam($name);
  6890. }
  6891. elsif($tcSim){
  6892. $hash->{helper}{fkt}="vdCtrl";}
  6893. elsif($thSim){
  6894. $hash->{helper}{fkt}="virtThSens";}
  6895. else {
  6896. delete $hash->{helper}{fkt};}
  6897. if(!$tMstr) {delete $hash->{sdTeam};}
  6898. }
  6899. elsif ($st eq "smokeDetector"){
  6900. foreach (split(",",$peerNames)){
  6901. my $tn = ($_ =~ m/self/)?$name:$_;
  6902. next if (!$defs{$tn});
  6903. $defs{$tn}{helper}{fkt} = "sdLead".(AttrVal($name,"model","") eq "HM-SEC-SD-2"? 2:1);
  6904. $defs{$tn}{sdTeam} = "sdLead" ;
  6905. $defs{$tn}{TESTNR} = 1 if(!exists $defs{$tn}{TESTNR});#must be defined for all sdLead
  6906. }
  6907. if($peerNames !~ m/self/){
  6908. delete $hash->{sdTeam};
  6909. delete $hash->{helper}{fkt};
  6910. }
  6911. }
  6912. elsif( ($md =~ m/^HM-CC-RT-DN/ && $chn =~ m/^(02|05|04)$/)
  6913. ||($md eq "HM-TC-IT-WM-W-EU" && $chn eq "07")){
  6914. if ($chn eq "04"){
  6915. #if 04 is peered we are "teamed" -> set channel 05
  6916. my $ch05H = $modules{CUL_HM}{defptr}{$dHash->{DEF}."05"};
  6917. CUL_HM_UpdtReadSingle($ch05H,"state","peered",0) if($ch05H);
  6918. }
  6919. else{
  6920. CUL_HM_UpdtReadSingle($hash,"state","peered",0);
  6921. }
  6922. }
  6923. elsif( ($md =~ m/^HM-CC-RT-DN/ && $chn =~ m/^(03|06)$/)
  6924. ||($md eq "HM-TC-IT-WM-W-EU" && $chn =~ m/^(03|06)$/)){
  6925. if (AttrVal($hash,"state","unpeered") eq "unpeered"){
  6926. CUL_HM_UpdtReadSingle($hash,"state","unknown",0);
  6927. }
  6928. }
  6929. }
  6930. else{# no peer set - clean up: delete entries
  6931. delete $hash->{READINGS}{peerList};
  6932. delete $hash->{peerList};
  6933. if (($md =~ m/^HM-CC-RT-DN/ && $chn=~ m/^(02|03|04|05|06)$/)
  6934. ||($md eq "HM-TC-IT-WM-W-EU" && $chn=~ m/^(03|06|07)$/)){
  6935. if ($chn eq "04"){
  6936. my $ch05H = $modules{CUL_HM}{defptr}{$dHash->{DEF}."05"};
  6937. CUL_HM_UpdtReadSingle($ch05H,"state","unpeered") if($ch05H);
  6938. }
  6939. else{
  6940. CUL_HM_UpdtReadSingle($hash,"state","unpeered");
  6941. }
  6942. }
  6943. }
  6944. }
  6945. sub CUL_HM_peerChId($$) {# in:<IDorName> <deviceID>, out:channelID
  6946. my($pId,$dId)=@_;
  6947. return "" if (!$pId);
  6948. my $iId = CUL_HM_id2IoId($dId);
  6949. my ($pSc,$pScNo) = unpack 'A4A*',$pId; #helper for shortcut spread
  6950. return $dId.sprintf("%02X",'0'.$pScNo) if ($pSc eq 'self');
  6951. return $iId.sprintf("%02X",'0'.$pScNo) if ($pSc eq 'fhem');
  6952. return "all" if ($pId eq 'all');#used by getRegList
  6953. my $p = CUL_HM_name2Id($pId).'01';
  6954. return "" if (length($p)<8);
  6955. return substr(CUL_HM_name2Id($pId).'01',0,8);# default chan is 01
  6956. }
  6957. sub CUL_HM_peerChName($$) {#in:<IDorName> <deviceID>, out:name
  6958. my($pId,$dId)=@_;
  6959. my $iId = CUL_HM_id2IoId($dId);
  6960. my($pDev,$pChn) = unpack'A6A2',$pId;
  6961. return 'self'.$pChn if ($pDev eq $dId);
  6962. return 'fhem'.$pChn if ($pDev eq $iId && !defined $modules{CUL_HM}{defptr}{$pDev});
  6963. $pId = $pDev if($pChn =~ m/0[0x]/); # both means device directly. This may be used by remotes and pusdbuttons
  6964. return CUL_HM_id2Name($pId);
  6965. }
  6966. sub CUL_HM_getMId($) {#in: hash(chn or dev) out:model key (key for %culHmModel)
  6967. # Will store result in device helper
  6968. my $hash = shift;
  6969. $hash = CUL_HM_getDeviceHash($hash);
  6970. return "" if (!$hash->{NAME});
  6971. my $mId = $hash->{helper}{mId};
  6972. if (!$mId){
  6973. my $model = AttrVal($hash->{NAME}, "model", "");
  6974. foreach my $mIdKey(keys%{$culHmModel}){
  6975. next if (!$culHmModel->{$mIdKey}{name} ||
  6976. $culHmModel->{$mIdKey}{name} ne $model);
  6977. $hash->{helper}{mId} = $mIdKey ;
  6978. return $mIdKey;
  6979. }
  6980. return "";
  6981. }
  6982. return $mId;
  6983. }
  6984. sub CUL_HM_getRxType($) { #in:hash(chn or dev) out:binary coded Rx type
  6985. # Will store result in device helper
  6986. my ($hash) = @_;
  6987. $hash = CUL_HM_getDeviceHash($hash);
  6988. no warnings; #convert regardless of content
  6989. my $rxtEntity = int($hash->{helper}{rxType});
  6990. use warnings;
  6991. if (!$rxtEntity){ #at least one bit must be set
  6992. my $MId = CUL_HM_getMId($hash);
  6993. my $rxtOfModel = ($MId && $culHmModel->{$MId}{rxt} ? $culHmModel->{$MId}{rxt} : "");
  6994. if ($rxtOfModel){
  6995. $rxtEntity |= ($rxtOfModel =~ m/b/)?0x02:0;#burst
  6996. $rxtEntity |= ($rxtOfModel =~ m/3/)?0x02:0;#tripple-burst todo currently unknown how it works
  6997. $rxtEntity |= ($rxtOfModel =~ m/c/)?0x04:0;#config
  6998. $rxtEntity |= ($rxtOfModel =~ m/w/)?0x08:0;#wakeup
  6999. $rxtEntity |= ($rxtOfModel =~ m/l/)?0x10:0;#lazyConfig
  7000. $rxtEntity |= ($rxtOfModel =~ m/f/)?0x80:0;#burstConditional
  7001. }
  7002. $rxtEntity = 1 if (!$rxtEntity);#always
  7003. $hash->{helper}{rxType} = $rxtEntity if ($MId);#store if ID is prooven
  7004. }
  7005. return $rxtEntity;
  7006. }
  7007. sub CUL_HM_getAssChnIds($) { #in: name out:ID list of assotiated channels
  7008. # if it is a channel only return itself
  7009. # if device and no channel
  7010. my ($name) = @_;
  7011. my @chnIdList;
  7012. if ($defs{$name}){
  7013. my $hash = $defs{$name};
  7014. foreach my $channel (grep /^channel_/, keys %{$hash}){
  7015. my $chnHash = $defs{$hash->{$channel}};
  7016. push @chnIdList,$chnHash->{DEF} if ($chnHash);
  7017. }
  7018. my $dId = CUL_HM_name2Id($name);
  7019. push @chnIdList,$dId."01" if (length($dId) == 6 && !$hash->{channel_01});
  7020. push @chnIdList,$dId if (length($dId) == 8);
  7021. }
  7022. return sort(@chnIdList);
  7023. }
  7024. sub CUL_HM_getAssChnNames($) { #in: name out:list of assotiated chan and device
  7025. my ($name) = @_;
  7026. my @chnN = ($name);
  7027. if ($defs{$name}){
  7028. my $hash = $defs{$name};
  7029. push @chnN,$defs{$name}{$_} foreach (grep /^channel_/, keys %{$defs{$name}});
  7030. }
  7031. return sort(@chnN);
  7032. }
  7033. sub CUL_HM_getKeys($) { #in: device-hash out:highest index, hash with keys
  7034. my ($hash) = @_;
  7035. my $highestIdx = 0;
  7036. my %keys = ();
  7037. $keys{0} = pack("H*", "A4E375C6B09FD185F27C4E96FC273AE4"); #index 0: eQ-3 default
  7038. my $vccu = $hash->{IODev}->{owner_CCU};
  7039. $vccu = $hash->{IODev}->{NAME} if(!defined($vccu) || !AttrVal($vccu,"hmKey",""));# if keys are not in vccu
  7040. if (defined($vccu)) {
  7041. foreach my $i (1..3){
  7042. my ($kNo,$k) = split(":",AttrVal($vccu,"hmKey".($i== 1?"":$i),""));
  7043. if (defined($kNo) && defined($k)) {
  7044. $kNo = hex($kNo);
  7045. $keys{$kNo} = pack("H*", $k);
  7046. $highestIdx = $kNo if ($kNo > $highestIdx);
  7047. }
  7048. }
  7049. }
  7050. return ($highestIdx, %keys);
  7051. }
  7052. sub CUL_HM_generateCBCsignature($$) { #in: device-hash,msg out: signed message
  7053. my ($hash,$msg) = @_;
  7054. my $oldcounter = ReadingsVal($hash->{NAME},"aesCBCCounter","000000");
  7055. my $counter = substr($oldcounter, 0, 4);
  7056. my ($mNo,$mFlg,$mTg,$mSnd,$mPay) = unpack 'A2A2A2A12A*',$msg;
  7057. my $devH = CUL_HM_getDeviceHash($hash);
  7058. if ($cryptFunc != 1) {
  7059. Log3 $hash,1,"CUL_HM $hash->{NAME} need Crypt::Rijndael to generate AES-CBC signature";
  7060. return $msg;
  7061. }
  7062. my ($kNo, %keys) = CUL_HM_getKeys($devH);
  7063. $kNo = AttrVal($devH->{NAME},"aesKey",$kNo);
  7064. if (!defined($keys{$kNo})) {
  7065. Log3 $hash,1,"CUL_HM $devH->{NAME} AES key ${kNo} not defined!";
  7066. return $msg;
  7067. }
  7068. #generate message number
  7069. if($mNo eq "++") {
  7070. $mNo = ($devH->{helper}{HM_CMDNR} + 1) & 0xff;
  7071. my $oldNo = hex(substr($oldcounter, 4, 2));
  7072. if ($mNo <= $oldNo && (($oldNo + 1) & 0xff) > $oldNo) {
  7073. $mNo = ($oldNo + 1) & 0xff;
  7074. }
  7075. $devH->{helper}{HM_CMDNR} = $mNo;
  7076. $mNo = sprintf("%02X", $mNo);
  7077. }
  7078. if (hex($counter.$mNo) <= hex($oldcounter)) {
  7079. $counter = sprintf("%04X", (hex($counter) + 1) & 0xffff);
  7080. }
  7081. push @evtEt,[$hash,1,"aesCBCCounter:".$counter.$mNo];
  7082. CUL_HM_pushEvnts();
  7083. my $cipher = Crypt::Rijndael->new($keys{$kNo}, Crypt::Rijndael::MODE_ECB());
  7084. my $iv = "49"
  7085. .$mSnd #sender receiver
  7086. .$counter #generation counter
  7087. .$mNo
  7088. ."000000000005";
  7089. my $ivC = $cipher->encrypt(pack("H32", $iv));
  7090. my $d = $mNo
  7091. .$mFlg #Flags
  7092. .$mPay; #payload
  7093. $d .= "00" x ((32 - length($d)) / 2) if (length($d) < 32);
  7094. my $cbc = $cipher->encrypt(pack("H32", $d) ^ $ivC);
  7095. #2016.09.04 06:52:54.227 3: CUL_HM
  7096. Log3 $hash,5, "CUL_HM $hash->{NAME} CBC IV: " . $iv
  7097. ."\n".(" "x30)."$hash->{NAME} CBC D: " . $d
  7098. ."\n".(" "x30)."$hash->{NAME} CBC E: " . unpack("H*", $cbc);
  7099. return uc( $mNo
  7100. . $mFlg.$mTg.$mSnd.$mPay
  7101. . $counter
  7102. . unpack("H8", substr($cbc, 12, 4)));
  7103. }
  7104. #+++++++++++++++++ Conversions names, hashes, ids++++++++++++++++++++++++++++++
  7105. #Performance opti: subroutines may consume up to 5 times the performance
  7106. #
  7107. #get Attr: $val = $attr{$hash->{NAME}}{$attrName}?$attr{$hash->{NAME}}{$attrName} :"";
  7108. # $val = $attr{$name}{$attrName} ?$attr{$name}{$attrName} :"";
  7109. #getRead: $val = $hash->{READINGS}{$rlName} ?$hash->{READINGS}{$rlName}{VAL} :"";
  7110. # $val = $defs{$name}{READINGS}{$rlName}?$defs{$name}{READINGS}{$rlName}{VAL} :"";
  7111. # $time = $hash->{READINGS}{$rlName} ?$hash->{READINGS}{$rlName}{time} :"";
  7112. sub CUL_HM_h2IoId($) { #in: ioHash out: ioHMid
  7113. my ($io) = @_;
  7114. return "000000" if (ref($io) ne 'HASH');
  7115. my $fhtid = defined($io->{FHTID}) ? $io->{FHTID} : "0000";
  7116. return AttrVal($io->{NAME},"hmId","F1$fhtid");
  7117. }
  7118. sub CUL_HM_IoId($) { #in: hash out: IO_id
  7119. my ($hash) = @_;
  7120. my $dHash = CUL_HM_getDeviceHash($hash);
  7121. my $ioHash = $dHash->{IODev};
  7122. return "" if (!$ioHash->{NAME});
  7123. my $fhtid = defined($ioHash->{FHTID}) ? $ioHash->{FHTID} : "0000";
  7124. return AttrVal($ioHash->{NAME},"hmId","F1$fhtid");
  7125. }
  7126. sub CUL_HM_id2IoId($) { #in: id, out:Id of assigned IO
  7127. my ($id) = @_;
  7128. ($id) = unpack 'A6',$id;#get device ID
  7129. return "" if (!$modules{CUL_HM}{defptr}{$id} ||
  7130. !$modules{CUL_HM}{defptr}{$id}->{IODev} ||
  7131. !$modules{CUL_HM}{defptr}{$id}->{IODev}->{NAME});
  7132. my $ioHash = $modules{CUL_HM}{defptr}{$id}->{IODev};
  7133. my $fhtid = defined($ioHash->{FHTID}) ? $ioHash->{FHTID} : "0000";
  7134. return AttrVal($ioHash->{NAME},"hmId","F1$fhtid");
  7135. }
  7136. sub CUL_HM_name2IoName($) { #in: hash out: IO_id
  7137. my ($name) = @_;
  7138. my $dHash = CUL_HM_getDeviceHash($defs{$name});
  7139. my $ioHash = $dHash->{IODev};
  7140. return $ioHash->{NAME} ? $ioHash->{NAME} : "";
  7141. }
  7142. sub CUL_HM_hash2Id($) { #in: id, out:hash
  7143. my ($hash) = @_;
  7144. return $hash->{DEF};
  7145. }
  7146. sub CUL_HM_hash2Name($) {#in: hash, out:name
  7147. my ($hash) = @_;
  7148. return $hash->{NAME};
  7149. }
  7150. sub CUL_HM_name2Hash($) {#in: name, out:hash
  7151. my ($name) = @_;
  7152. return $defs{$name};
  7153. }
  7154. sub CUL_HM_name2Id(@) { #in: name or HMid ==>out: HMid, "" if no match
  7155. my ($name,$idHash) = @_;
  7156. my $hash = $defs{$name};
  7157. return $hash->{DEF} if($hash && $hash->{TYPE} eq "CUL_HM");#name is entity
  7158. return $name if($name =~ m/^[A-F0-9]{6,8}$/i);#was already HMid
  7159. return $defs{$1}->{DEF}.$2 if($name =~ m/(.*)_chn-(..)$/); #<devname> chn-xx
  7160. return "000000" if($name eq "broadcast"); #broadcast
  7161. return substr($idHash->{DEF},0,6).sprintf("%02X",$1)
  7162. if($idHash && ($name =~ m/self(.*)/));
  7163. return CUL_HM_IoId($idHash).sprintf("%02X",$1)
  7164. if($idHash && ($name =~ m/fhem(.*)/));
  7165. return AttrVal($name,"hmId",""); # could be IO device
  7166. }
  7167. sub CUL_HM_id2Name($) { #in: name or HMid out: name
  7168. my ($p) = @_;
  7169. $p = "" if (!defined $p);
  7170. return $p if($defs{$p}||$p =~ m/_chn-\d\d$/
  7171. || $p !~ m/^[A-F0-9]{6,8}$/i);
  7172. my ($devId,$chn) = unpack 'A6A2',$p;
  7173. return "broadcast" if($devId eq "000000");
  7174. my $defPtr = $modules{CUL_HM}{defptr};
  7175. if (length($p) == 8 && $chn ne "00"){
  7176. return $defPtr->{$p}{NAME} if(defined $defPtr->{$p});#channel
  7177. return $defPtr->{$devId}{NAME}."_chn-$chn"
  7178. if($defPtr->{$devId});#dev, add chn
  7179. return $p; #not defined, return ID only
  7180. }
  7181. else{
  7182. return $defPtr->{$devId}{NAME} if($defPtr->{$devId});#device only
  7183. return $devId; #not defined, return ID only
  7184. }
  7185. }
  7186. sub CUL_HM_id2Hash($) { #in: id, out:hash
  7187. my ($id) = @_;
  7188. return $modules{CUL_HM}{defptr}{$id} if (defined $modules{CUL_HM}{defptr}{$id});
  7189. $id = substr($id,0,6);
  7190. return defined $modules{CUL_HM}{defptr}{$id}?($modules{CUL_HM}{defptr}{$id}):undef;
  7191. }
  7192. sub CUL_HM_getDeviceHash($) {#in: hash out: devicehash
  7193. my ($hash) = @_;
  7194. return $hash if(!$hash->{DEF});
  7195. my $devHash = $modules{CUL_HM}{defptr}{substr($hash->{DEF},0,6)};
  7196. return ($devHash)?$devHash:$hash;
  7197. }
  7198. sub CUL_HM_getDeviceName($) {#in: name out: name of device
  7199. my $name = shift;
  7200. return $name if(!$defs{$name});#unknown, return input
  7201. my $devHash = $modules{CUL_HM}{defptr}{substr($defs{$name}{DEF},0,6)};
  7202. return ($devHash)?$devHash->{NAME}:$name;
  7203. }
  7204. sub CUL_HM_shH($$$){
  7205. my ($h,$l,$d) = @_;
  7206. if ( $h->{helper}{shRegW}
  7207. && $h->{helper}{shRegW}{$l}
  7208. && $modules{CUL_HM}{defptr}{$d.$h->{helper}{shRegW}{$l}}){
  7209. return $modules{CUL_HM}{defptr}{$d.$h->{helper}{shRegW}{$l}};
  7210. }
  7211. return $h;
  7212. }
  7213. sub CUL_HM_shC($$$){
  7214. my ($h,$l,$c) = @_;
  7215. if ( $h->{helper}{shRegW}
  7216. && $h->{helper}{shRegW}{$l}){
  7217. return $h->{helper}{shRegW}{$l};
  7218. }
  7219. return $c;
  7220. }
  7221. sub CUL_HM_lstCh($$$){
  7222. my ($h,$l,$c) = @_;
  7223. if ( $h->{helper}{shRegR}
  7224. && $h->{helper}{shRegR}{$l}){
  7225. return $h->{helper}{shRegR}{$l};
  7226. }
  7227. return $c;
  7228. }
  7229. #+++++++++++++++++ debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7230. sub CUL_HM_DumpProtocol($$@) {
  7231. my ($prefix, $iohash, $len,$cnt,$msgFlags,$mTp,$src,$dst,$p) = @_;
  7232. my $iname = $iohash->{NAME};
  7233. no warnings;# conv 2 number would cause a warning - which is ok
  7234. my $hmProtocolEvents = int (AttrVal(CUL_HM_id2Name($src), "hmProtocolEvents",
  7235. AttrVal(InternalVal($iname,"owner_CCU",$iname), "hmProtocolEvents", 0)));
  7236. use warnings;
  7237. return if(!$hmProtocolEvents);
  7238. my $p01 = substr($p,0,2);
  7239. my $p02 = substr($p,0,4);
  7240. my $p11 = (length($p) > 2 ? substr($p,2,2) : "");
  7241. # decode message flags for printing
  7242. my $msgFlLong="";
  7243. my $msgFlagsHex = hex($msgFlags);
  7244. for(my $i = 0; $i < @{$culHmCmdFlags}; $i++) {
  7245. $msgFlLong .= ",".${$culHmCmdFlags}[$i] if($msgFlagsHex & (1<<$i));
  7246. }
  7247. my $ps;
  7248. $ps = $culHmBits->{"$mTp;p11=$p11"} if(!$ps);
  7249. $ps = $culHmBits->{"$mTp;p01=$p01"} if(!$ps);
  7250. $ps = $culHmBits->{"$mTp;p02=$p02"} if(!$ps);
  7251. $ps = $culHmBits->{"$mTp"} if(!$ps);
  7252. my $txt = "";
  7253. if($ps) {
  7254. $txt = $ps->{txt};
  7255. if($ps->{params}) {
  7256. $ps = $ps->{params};
  7257. foreach my $k (sort {$ps->{$a} cmp $ps->{$b} } keys %{$ps}) {
  7258. my ($o,$l,$expr) = split(",", $ps->{$k}, 3);
  7259. last if(length($p) <= $o);
  7260. my $val = $l ? substr($p,$o,$l) : substr($p,$o);
  7261. eval $expr if($hmProtocolEvents > 1 && $expr);
  7262. $txt .= " $k:".(($hmProtocolEvents > 1 && $expr)?"":"0x")."$val";
  7263. }
  7264. }
  7265. $txt = " ($txt)" if($txt);
  7266. }
  7267. $src=CUL_HM_id2Name($src);
  7268. $dst=CUL_HM_id2Name($dst);
  7269. my $msg ="$prefix L:$len N:$cnt F:$msgFlags CMD:$mTp SRC:$src DST:$dst $p$txt ($msgFlLong)";
  7270. Log3 $iname,1,$msg;
  7271. DoTrigger($iname, $msg) if($hmProtocolEvents > 2);
  7272. }
  7273. #+++++++++++++++++ handling register updates ++++++++++++++++++++++++++++++++++
  7274. sub CUL_HM_getRegFromStore($$$$@) {#read a register from backup data
  7275. my($name,$regName,$list,$peerId,$regLN)=@_;
  7276. my $hash = $defs{$name};
  7277. my ($size,$pos,$conv,$factor,$unit) = (8,0,"",1,""); # default
  7278. my $addr = $regName;
  7279. my $reg = $culHmRegDefine->{$regName};
  7280. if ($reg) { # get the register's information
  7281. $addr = $reg->{a};
  7282. $pos = ($addr*10)%10;
  7283. $addr = int($addr);
  7284. $list = $reg->{l};
  7285. $size = $reg->{s};
  7286. $size = int($size)*8 + ($size*10)%10;
  7287. $conv = $reg->{c}; #unconvert formula
  7288. $factor = $reg->{f};
  7289. $unit = ($reg->{u}?" ".$reg->{u}:"");
  7290. }
  7291. else{
  7292. return "invalid:regname or address"
  7293. if($addr<1 ||$addr>255);
  7294. }
  7295. my $dst = substr(CUL_HM_name2Id($name),0,6);
  7296. if(!$regLN){
  7297. $regLN = ($hash->{helper}{expert}{raw}?"":".")
  7298. .sprintf("RegL_%02X.",$list)
  7299. .($peerId?CUL_HM_peerChName($peerId,
  7300. $dst)
  7301. :"");
  7302. }
  7303. $regLN =~ s/broadcast//;
  7304. my $regLNp = $regLN;
  7305. $regLNp =~ s/^\.//; #remove leading '.' in case ..
  7306. my $sdH = CUL_HM_shH($hash,sprintf("%02X",$list),$dst);
  7307. my $sRL = ( $sdH->{helper}{shadowReg} # shadowregList
  7308. && $sdH->{helper}{shadowReg}{$regLNp})
  7309. ?$sdH->{helper}{shadowReg}{$regLNp}
  7310. :"";
  7311. my $rRL = ($hash->{READINGS}{$regLN}) #realRegList
  7312. ?$hash->{READINGS}{$regLN}{VAL}
  7313. :"";
  7314. my $data=0;
  7315. my $convFlg = "";# confirmation flag - indicates data not confirmed by device
  7316. for (my $size2go = $size;$size2go>0;$size2go -=8){
  7317. my $addrS = sprintf("%02X",$addr);
  7318. my ($dReadS,$dReadR) = (undef,"");
  7319. $dReadS = $1 if( $sRL =~ m/$addrS:(..)/);#shadowReg
  7320. $dReadR = $1 if( $rRL =~ m/$addrS:(..)/);#realReg
  7321. my $dRead = $dReadR;
  7322. if (defined $dReadS){
  7323. $convFlg = "set_" if ($dReadR ne $dReadS);
  7324. $dRead = $dReadS;
  7325. }
  7326. else{
  7327. return "invalid:peer missing" if (grep /$regLN../,keys %{$hash->{READINGS}} &&
  7328. !$peerId);
  7329. if (!defined($dRead) || $dRead eq ""){
  7330. return "invalid: not supported by FW version" if ($rRL =~ m/00:00/);#reglist is complete but still address cannot be found
  7331. return "invalid";
  7332. }
  7333. }
  7334. $data = ($data<< 8)+hex($dRead);
  7335. $addr++;
  7336. }
  7337. $data = ($data>>$pos) & (0xffffffff>>(32-$size));
  7338. if (!$conv){ ;# do nothing
  7339. } elsif($conv eq "lit" ){$data = defined $reg->{litInv}{$data}?$reg->{litInv}{$data}:"undef lit:$data";
  7340. } elsif($conv eq "fltCvT" ){$data = CUL_HM_CvTflt($data);
  7341. } elsif($conv eq "fltCvT60"){$data = CUL_HM_CvTflt60($data);
  7342. } elsif($conv eq "min2time"){$data = CUL_HM_min2time($data);
  7343. } elsif($conv eq "m10s3" ){$data = ($data+3)/10;
  7344. } elsif($conv eq "hex" ){$data = sprintf("0x%06X",$data);#06 only for paired to. Currently not used by others
  7345. } else { return " conv undefined - please contact admin";
  7346. }
  7347. $data /= $factor if ($factor);# obey factor after possible conversion
  7348. if ($conv ne "lit" && $reg->{litInv} && $reg->{litInv}{$data} ){
  7349. $data = $reg->{litInv}{$data};#conv special value past to calculation
  7350. $unit = "";
  7351. }
  7352. return $convFlg.$data.$unit;
  7353. }
  7354. sub CUL_HM_chgExpLvl($){# update visibility and set internal values for expert
  7355. my $tHash = shift;
  7356. my $exLvl = CUL_HM_getAttrInt($tHash->{NAME},"expert");
  7357. $tHash->{helper}{expert}{def} = (!($exLvl & 0x04))?1:0;#default register on
  7358. $tHash->{helper}{expert}{det} = ( ($exLvl & 0x01))?1:0;#detail register on
  7359. $tHash->{helper}{expert}{raw} = ( ($exLvl & 0x02))?1:0;#raw register on
  7360. $tHash->{helper}{expert}{tpl} = ( ($exLvl & 0x08))?1:0;#template on
  7361. my ($nTag,$grp);
  7362. if ($tHash->{helper}{expert}{def}){($nTag,$grp) = ("",".R-")}
  7363. else{ ($nTag,$grp) = (".","R-")}
  7364. foreach my $rdEntry (grep /^$grp/ ,keys %{$tHash->{READINGS}}){
  7365. my $reg = $rdEntry;
  7366. my $p = "";
  7367. $p = "-".$1 if($rdEntry =~ m/R-(.*)-(lg|sh)/);
  7368. $reg =~ s/^\.?R-(.*?-)?//;
  7369. next if(!$culHmRegDefine->{$reg} || $culHmRegDefine->{$reg}{d} eq '0');
  7370. $tHash->{READINGS}{$nTag."R$p-".$reg} = $tHash->{READINGS}{$rdEntry};
  7371. delete $tHash->{READINGS}{$rdEntry};
  7372. }
  7373. if ($tHash->{helper}{expert}{det}){($nTag,$grp) = ("",".R-")}
  7374. else{ ($nTag,$grp) = (".","R-")}
  7375. foreach my $rdEntry (grep /^$grp/ ,keys %{$tHash->{READINGS}}){
  7376. my $reg = $rdEntry;
  7377. my $p = "";
  7378. $p = "-".$1 if($rdEntry =~ m/R-(.*)-(lg|sh)/);
  7379. $reg =~ s/^\.?R-(.*-)?//;
  7380. next if(!$culHmRegDefine->{$reg} || $culHmRegDefine->{$reg}{d} eq '1');
  7381. $tHash->{READINGS}{$nTag."R$p-".$reg} = $tHash->{READINGS}{$rdEntry};
  7382. delete $tHash->{READINGS}{$rdEntry};
  7383. }
  7384. if ($tHash->{helper}{expert}{raw}){($nTag,$grp) = ("",".RegL_")}
  7385. else{ ($nTag,$grp) = (".","RegL_")}
  7386. foreach my $rdEntry (grep /^$grp/ ,keys %{$tHash->{READINGS}}){
  7387. my $reg = $rdEntry;
  7388. $reg =~ s/^\.//;
  7389. $tHash->{READINGS}{$nTag.$reg} = $tHash->{READINGS}{$rdEntry};
  7390. delete $tHash->{READINGS}{$rdEntry};
  7391. }
  7392. CUL_HM_setTmplDisp($tHash);
  7393. }
  7394. sub CUL_HM_setTmplDisp($){ # remove register if outdated
  7395. my $tHash = shift;
  7396. delete $tHash->{READINGS}{$_} foreach (grep /^tmpl_/ ,keys %{$tHash->{READINGS}});
  7397. if ($tHash->{helper}{expert}{tpl} && defined %HMConfig::culHmTpl){
  7398. foreach (keys %{$tHash->{helper}{tmpl}}){
  7399. my ($p,$t) = split(">",$_);
  7400. my @param;
  7401. if($tHash->{helper}{tmpl}{$_}){
  7402. @param = split(" ",$HMConfig::culHmTpl{$t}{p});
  7403. my @value = split(" ",$tHash->{helper}{tmpl}{$_});
  7404. for (my $i = 0; $i<scalar(@value); $i++){
  7405. $param[$i] .= ":".$value[$i];
  7406. }
  7407. $t .= ":".join(" ",@param);
  7408. }
  7409. $tHash->{READINGS}{"tmpl_".$p}{VAL} .= $t.",";#could be more than one!
  7410. $tHash->{READINGS}{"tmpl_".$p}{TIME} .= "-";# time does not make sense
  7411. }
  7412. }
  7413. }
  7414. sub CUL_HM_updtRegDisp($$$) {
  7415. my($hash,$list,$peerId)=@_;
  7416. my $listNo = $list+0;
  7417. my $name = $hash->{NAME};
  7418. my $devId = substr(CUL_HM_name2Id($name),0,6);
  7419. my $ioId = CUL_HM_IoId(CUL_HM_id2Hash($devId));
  7420. my $pReg = ($peerId && $peerId ne '00000000' )
  7421. ? CUL_HM_peerChName($peerId,$devId)."-"
  7422. : "";
  7423. $pReg =~ s/:/-/;
  7424. $pReg = "R-".$pReg;
  7425. my $devName =CUL_HM_getDeviceHash($hash)->{NAME};# devName as protocol entity
  7426. my $st = $attr{$devName}{subType} ?$attr{$devName}{subType} :"";
  7427. my $md = $attr{$devName}{model} ?$attr{$devName}{model} :"";
  7428. my $chn = $hash->{DEF};
  7429. $chn = (length($chn) == 8)?substr($chn,6,2):"";
  7430. my @regArr = CUL_HM_getRegN($st,$md,$chn);
  7431. my @changedRead;
  7432. my $regLN = ($hash->{helper}{expert}{raw}?"":".")
  7433. .sprintf("RegL_%02X.",$listNo)
  7434. .($peerId?CUL_HM_peerChName($peerId,$devId):"");
  7435. if (($md eq "HM-MOD-Re-8") && $listNo == 0){#handle Fw bug
  7436. CUL_HM_ModRe8($hash,$regLN);
  7437. }
  7438. foreach my $rgN (@regArr){
  7439. next if ($culHmRegDefine->{$rgN}->{l} ne $listNo);
  7440. my $rgVal = CUL_HM_getRegFromStore($name,$rgN,$list,$peerId,$regLN);
  7441. next if (!defined $rgVal || $rgVal =~ m/invalid/);
  7442. my $rdN = ($culHmRegDefine->{$rgN}->{d} ? ($hash->{helper}{expert}{def} ?"":".")
  7443. : ($hash->{helper}{expert}{det} ?"":"."))
  7444. .$pReg.$rgN;
  7445. push (@changedRead,$rdN.":".$rgVal)
  7446. if (ReadingsVal($name,$rdN,"") ne $rgVal);
  7447. }
  7448. CUL_HM_UpdtReadBulk($hash,1,@changedRead) if (@changedRead);
  7449. # --- handle specifics - Devices with abnormal or long register
  7450. if ($md =~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/){#handle temperature readings
  7451. CUL_HM_TCtempReadings($hash) if (($list == 5 ||$list == 6) &&
  7452. substr($hash->{DEF},6,2) eq "02");
  7453. }
  7454. elsif ($md =~ m/^HM-CC-RT-DN/){#handle temperature readings
  7455. CUL_HM_TCITRTtempReadings($hash,$md,7) if ($list == 7 && $chn eq "04");
  7456. }
  7457. elsif ($md =~ m/^HM-TC-IT-WM-W-EU/){#handle temperature readings
  7458. CUL_HM_TCITRTtempReadings($hash,$md,$list) if ($list >= 7 && $chn eq "02");
  7459. }
  7460. elsif ($md =~ m/(^HM-PB-4DIS-WM|HM-Dis-WM55|HM-Dis-EP-WM55|HM-RC-Dis-H-x-EU|ROTO_ZEL-STG-RM-DWT-10)/){#add text
  7461. CUL_HM_4DisText($hash) if ($list == 1) ;
  7462. }
  7463. elsif ($st eq "repeater"){
  7464. CUL_HM_repReadings($hash) if ($list == 2);
  7465. }
  7466. elsif ($md eq "HM-SEC-SD-2"){
  7467. CUL_HM_SD_2($hash) if ($list == 0);
  7468. }
  7469. # CUL_HM_dimLog($hash) if(CUL_HM_Get($hash,$name,"param","subType") eq "dimmer");
  7470. }
  7471. sub CUL_HM_rmOldRegs($){ # remove register i outdated
  7472. #will remove register for deleted peers
  7473. my $name = shift;
  7474. my $hash = $defs{$name};
  7475. return if (!$hash->{peerList});# so far only peer-regs are removed
  7476. my @pList = split",",$hash->{peerList};
  7477. my @rpList;
  7478. foreach(grep /^R-(.*)-/,keys %{$hash->{READINGS}}){
  7479. push @rpList,$1 if ($_ =~ m/^R-(.*)-/);
  7480. }
  7481. @rpList = CUL_HM_noDup(@rpList);
  7482. return if (!@rpList);
  7483. foreach my $peer(@rpList){
  7484. next if($hash->{peerList} =~ m/\b$peer\b/);
  7485. delete $hash->{READINGS}{$_} foreach (grep /^R-$peer-/,keys %{$hash->{READINGS}})
  7486. }
  7487. }
  7488. sub CUL_HM_refreshRegs($){ # renew all register readings from Regl_
  7489. my $name = shift;
  7490. foreach(grep /\.?R-/,keys %{$defs{$name}{READINGS}}){
  7491. delete $defs{$name}{READINGS}{$_};
  7492. }
  7493. my $peers = ReadingsVal($name,"peerList","");
  7494. my $dH = CUL_HM_getDeviceHash($defs{$name});
  7495. foreach(grep /\.?RegL_/,keys %{$defs{$name}{READINGS}}){
  7496. my ($l,$p);
  7497. ($l,$p) = ($1,$2) if($_ =~ m/RegL_(..)\.(.*)/);
  7498. my $ps = $p;
  7499. $ps =~ s/_chn-\d\d$//;
  7500. if (!$p || $peers =~ m/$ps/){
  7501. CUL_HM_updtRegDisp($defs{$name},$l,CUL_HM_name2Id($p,$dH));
  7502. }
  7503. else{
  7504. delete $defs{$name}{READINGS}{$_};# peer for This List not found
  7505. }
  7506. }
  7507. }
  7508. #############################
  7509. #+++++++++++++++++ parameter cacculations +++++++++++++++++++++++++++++++++++++
  7510. my @culHmTimes8 = ( 0.1, 1, 5, 10, 60, 300, 600, 3600 );
  7511. sub CUL_HM_encodeTime8($) {#####################
  7512. my $v = shift;
  7513. return "00" if($v < 0.1);
  7514. for(my $i = 0; $i < @culHmTimes8; $i++) {
  7515. if($culHmTimes8[$i] * 32 > $v) {
  7516. for(my $j = 0; $j < 32; $j++) {
  7517. if($j*$culHmTimes8[$i] >= $v) {
  7518. return sprintf("%X", $i*32+$j);
  7519. }
  7520. }
  7521. }
  7522. }
  7523. return "FF";
  7524. }
  7525. sub CUL_HM_decodeTime8($) {#####################
  7526. my $v = hex(shift);
  7527. return "undef" if($v > 255);
  7528. my $v1 = int($v/32);
  7529. my $v2 = $v%32;
  7530. return $v2 * $culHmTimes8[$v1];
  7531. }
  7532. sub CUL_HM_encodeTime16($) {####################
  7533. my $v = shift;
  7534. return "0000" if($v < 0.05 || $v !~ m/^[+-]?\d+(\.\d+)?$/);
  7535. my $ret = "FFFF";
  7536. my $mul = 10;
  7537. for(my $i = 0; $i < 32; $i++) {
  7538. if($v*$mul < 0x7ff) {
  7539. $ret=sprintf("%04X", ((($v*$mul)<<5)+$i));
  7540. last;
  7541. }
  7542. $mul /= 2;
  7543. }
  7544. return ($ret);
  7545. }
  7546. sub CUL_HM_convTemp($) {########################
  7547. my ($val) = @_;
  7548. if(!($val eq "on" || $val eq "off" ||
  7549. ($val =~ m/^\d*\.?\d+$/ && $val >= 6 && $val <= 30))) {
  7550. my @list = map { ($_.".0", $_+0.5) } (6..30);
  7551. pop @list;
  7552. return "Invalid temperature $val, choose one of on off " . join(" ",@list);
  7553. }
  7554. $val = 100 if($val eq "on");
  7555. $val = 0 if($val eq "off");
  7556. return sprintf("%02X", $val*2);
  7557. }
  7558. sub CUL_HM_decodeTime16($) {####################
  7559. my $v = hex(shift);
  7560. my $m = int($v>>5);
  7561. my $e = $v & 0x1f;
  7562. return (2**$e)*$m*0.1;
  7563. }
  7564. sub CUL_HM_secSince2000() {#####################
  7565. # Calculate the local time in seconds from 2000.
  7566. my $t = time();
  7567. my @l = localtime($t);
  7568. my @g = gmtime($t);
  7569. my $t2 = $t + 60*(($l[2]-$g[2] + ((($l[5]<<9)|$l[7]) <=> (($g[5]<<9)|$g[7])) * 24) * 60 + $l[1]-$g[1])
  7570. # timezone and daylight saving...
  7571. - 946684800 # seconds between 01.01.2000, 00:00 and THE EPOCH (1970)
  7572. - 7200; # HM Special
  7573. return $t2;
  7574. }
  7575. sub CUL_HM_getChnLvl($){# in: name out: vit or phys level
  7576. my $name = shift;
  7577. my $curVal = ReadingsVal($name,"level",undef);
  7578. $curVal = ReadingsVal($name,".level",0)if (!defined $curVal);
  7579. $curVal =~ s/set_//;
  7580. $curVal =~ s/ .*//;#strip unit
  7581. return $curVal;
  7582. }
  7583. #--------------- Conversion routines for register settings---------------------
  7584. sub CUL_HM_initRegHash() { #duplicate short and long press register
  7585. my $mp = "$attr{global}{modpath}/FHEM";
  7586. opendir(DH, $mp) || return;
  7587. foreach my $m (grep /^HMConfig_(.*)\.pm$/,readdir(DH)) {
  7588. my $file = "${mp}/$m";
  7589. no strict "refs";
  7590. my $ret = do $file;
  7591. use strict "refs";
  7592. if(!$ret){ Log3 undef, 1, "Error loading file: $file:\n $@";}
  7593. else { Log3 undef, 3, "additional HM config file loaded: $file";}
  7594. }
  7595. closedir(DH);
  7596. }
  7597. my %fltCvT60 = (1=>127,60=>7620);
  7598. sub CUL_HM_fltCvT60($) { # float -> config time
  7599. my ($inValue) = @_;
  7600. my $exp = 0;
  7601. my $div2;
  7602. foreach my $div(sort{$a <=> $b} keys %fltCvT60){
  7603. $div2 = $div;
  7604. last if ($inValue < $fltCvT60{$div});
  7605. $exp++;
  7606. }
  7607. return ($exp << 7)+int($inValue/$div2+.1);
  7608. }
  7609. sub CUL_HM_CvTflt60($) { # config time -> float
  7610. my ($inValue) = @_;
  7611. return ($inValue & 0x7f)*((sort {$a <=> $b} keys(%fltCvT60))[$inValue >> 7]);
  7612. }
  7613. my %fltCvT = (0.1=>3.1,1=>31,5=>155,10=>310,60=>1860,300=>9300,
  7614. 600=>18600,3600=>111601);
  7615. sub CUL_HM_fltCvT($) { # float -> config time
  7616. my ($inValue) = @_;
  7617. my $exp = 0;
  7618. my $div2;
  7619. foreach my $div(sort{$a <=> $b} keys %fltCvT){
  7620. $div2 = $div;
  7621. last if ($inValue < $fltCvT{$div});
  7622. $exp++;
  7623. }
  7624. return ($exp << 5)+int($inValue/$div2+.1);
  7625. }
  7626. sub CUL_HM_CvTflt($) { # config time -> float
  7627. my ($inValue) = @_;
  7628. return ($inValue & 0x1f)*((sort {$a <=> $b} keys(%fltCvT))[$inValue >> 5]);
  7629. }
  7630. sub CUL_HM_flt6CvT($) { # float -> config time
  7631. my ($inValue) = @_;
  7632. my $exp = ($inValue>127)?1:0;
  7633. return ($exp << 7)+int($inValue/($exp?60:1));
  7634. }
  7635. sub CUL_HM_CvTflt6($) { # config time -> float
  7636. my ($inValue) = @_;
  7637. $inValue = 129 if ($inValue == 128);
  7638. return ($inValue & 0x7f)*(($inValue >> 7)?60:1);
  7639. }
  7640. sub CUL_HM_min2time($) { # minutes -> time
  7641. my $min = shift;
  7642. $min = $min * 30;
  7643. return sprintf("%02d:%02d",int($min/60),$min%60);
  7644. }
  7645. sub CUL_HM_time2min($) { # minutes -> time
  7646. my $time = shift;
  7647. my ($h,$m) = split ":",$time;
  7648. $m = ($h*60 + $m)/30;
  7649. $m = 0 if($m < 0);
  7650. $m = 47 if($m > 47);
  7651. return $m;
  7652. }
  7653. sub CUL_HM_getRegInfo($$$) { #
  7654. my ($regArr,$roleD,$roleC) = @_;
  7655. my @rI;
  7656. foreach my $regName (@$regArr){
  7657. my $reg = $culHmRegDefine->{$regName};
  7658. my $help = $reg->{t};
  7659. my ($min,$max) = ($reg->{min},"to ".$reg->{max});
  7660. if ($reg->{c} eq "lit"){
  7661. $help .= " options:".join(",",keys%{$reg->{lit}});
  7662. $min = "";
  7663. $max = "literal";
  7664. }
  7665. elsif (defined($reg->{lit})){
  7666. $help .= " special:".join(",",keys%{$reg->{lit}});
  7667. }
  7668. push @rI,sprintf("%4d: %-16s | %3s %-14s | %8s | %s\n",
  7669. $reg->{l},$regName,$min,$max.$reg->{u},
  7670. ((($reg->{l} == 3)||($reg->{l} == 4))?"required":""),
  7671. $help)
  7672. if (($roleD && $reg->{l} == 0)||
  7673. ($roleC && $reg->{l} != 0));
  7674. }
  7675. my $info = sprintf("list: %16s | %-18s | %-8s | %s\n",
  7676. "register","range","peer","description");
  7677. foreach(sort(@rI)){$info .= $_;}
  7678. return $info;
  7679. }
  7680. sub CUL_HM_getRegN($$@){ # get list of register for a model
  7681. my ($st,$md,@chn) = @_;
  7682. my @regArr = keys %{$culHmRegGeneral};
  7683. push @regArr, keys %{$culHmRegType->{$st}} if($culHmRegType->{$st});
  7684. push @regArr, keys %{$culHmRegModel->{$md}} if($culHmRegModel->{$md});
  7685. foreach (@chn){
  7686. push @regArr, keys %{$culHmRegChan->{$md.$_}} if($culHmRegChan->{$md.$_});
  7687. }
  7688. return @regArr;
  7689. }
  7690. sub CUL_HM_4DisText($) { # convert text for 4dis
  7691. #text1: start at 54 (0x36) length 12 (0x0c)
  7692. #text2: start at 70 (0x46) length 12 (0x0c)
  7693. my ($hash)=@_;
  7694. my $name = $hash->{NAME};
  7695. my $regPre = ($hash->{helper}{expert}{raw}?"":".");
  7696. my $reg1 = ReadingsVal($name,$regPre."RegL_01." ,"");
  7697. my $pref = "";
  7698. if ($hash->{helper}{shadowReg}{"RegL_01."}){
  7699. $pref = "set_";
  7700. $reg1 = $hash->{helper}{shadowReg}{"RegL_01."};
  7701. }
  7702. my %txt;
  7703. foreach my $sAddr (54,70){
  7704. my $txtHex = $reg1; #one row
  7705. my $sStr = sprintf("%02X:",$sAddr);
  7706. $txtHex =~ s/.* $sStr//; #remove reg prior to string
  7707. $sStr = sprintf("%02X:",$sAddr+11);
  7708. $txtHex =~ s/$sStr(..).*/,$1/; #remove reg after string
  7709. $txtHex =~ s/ ..:/,/g; #remove addr
  7710. $txtHex =~ s/ //g; #remove space
  7711. $txtHex =~ s/,00.*//; #remove trailing string
  7712. $txt{$sAddr} = "";
  7713. my @ch = split(",",$txtHex,12);
  7714. foreach (@ch){$txt{$sAddr}.=chr(hex($_)) if (length($_)==2)};
  7715. }
  7716. CUL_HM_UpdtReadBulk($hash,1,"text1:".$pref.$txt{54},
  7717. "text2:".$pref.$txt{70});
  7718. return "text1:".$txt{54}."\n".
  7719. "text2:".$txt{70}."\n";
  7720. }
  7721. sub CUL_HM_TCtempReadings($) {# parse TC temperature readings
  7722. my ($hash) = @_;
  7723. my $name = $hash->{NAME};
  7724. my $regPre = ($hash->{helper}{expert}{raw}?"":".");
  7725. my $reg5 = ReadingsVal($name,$regPre."RegL_05." ,"");
  7726. my $reg6 = ReadingsVal($name,$regPre."RegL_06." ,"");
  7727. { #update readings in device - oldfashioned style, copy from Readings
  7728. my @histVals;
  7729. foreach my $var ("displayMode","displayTemp","controlMode","decalcDay","displayTempUnit","day-temp","night-temp","party-temp"){
  7730. my $varV = ReadingsVal($name,"R-".$var,"???");
  7731. foreach my $e( grep {${$_}[2] =~ m/$var/}# see if change is pending
  7732. grep {$hash eq ${$_}[0]}
  7733. grep {scalar(@{$_} == 3)}
  7734. @evtEt){
  7735. $varV = ${$e}[2];
  7736. $varV =~ s/^R-$var:// ;
  7737. }
  7738. push @histVals,"$var:$varV";
  7739. }
  7740. if (@histVals){
  7741. CUL_HM_UpdtReadBulk($hash,1,@histVals) ;
  7742. CUL_HM_UpdtReadBulk(CUL_HM_getDeviceHash($hash),1,@histVals);
  7743. }
  7744. }
  7745. if (ReadingsVal($name,"R-controlMode","") =~ m/^party/){
  7746. if ( $reg6 # ugly handling to add vanishing party register
  7747. && $reg6 !~ m/ 61:/
  7748. && $hash->{helper}{partyReg}){
  7749. $hash->{READINGS}{"RegL_06."}{VAL} =~ s/ 00:00/$hash->{helper}{partyReg}/;
  7750. }
  7751. }
  7752. else{
  7753. delete $hash->{helper}{partyReg};
  7754. }
  7755. my @days = ("Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri");
  7756. $reg5 =~ s/.* 0B://; #remove register up to addr 11 from list 5
  7757. my $tempRegs = $reg5.$reg6; #one row
  7758. $tempRegs =~ s/ 00:00/ /g; #remove regline termination
  7759. $tempRegs =~ s/ ..:/,/g; #remove addr Info
  7760. $tempRegs =~ s/ //g; #blank
  7761. my @Tregs = split(",",$tempRegs);
  7762. my @time = @Tregs[grep !($_ % 2), 0..$#Tregs]; # even-index =time
  7763. my @temp = @Tregs[grep $_ % 2, 0..$#Tregs]; # odd-index =data
  7764. my @changedRead;
  7765. my $setting;
  7766. if (scalar( @time )<168){
  7767. push (@changedRead,"R_tempList_State:incomplete");
  7768. $setting = "reglist incomplete\n" ;
  7769. }
  7770. else{
  7771. delete $hash->{READINGS}{$_}
  7772. foreach (grep !/_/,grep /tempList/,keys %{$hash->{READINGS}});
  7773. foreach (@time){$_=hex($_)*10};
  7774. foreach (@temp){$_=hex($_)/2};
  7775. push (@changedRead,"R_tempList_State:".
  7776. (($hash->{helper}{shadowReg}{"RegL_05."} ||
  7777. $hash->{helper}{shadowReg}{"RegL_06."} )?"set":"verified"));
  7778. for (my $day = 0; $day < 7; $day++){
  7779. my $tSpan = 0;
  7780. my $dayRead = "";
  7781. for (my $entry = 0;$entry<24;$entry++){
  7782. my $reg = $day *24 + $entry;
  7783. last if ($tSpan > 1430);
  7784. $tSpan = $time[$reg];
  7785. my $entry = sprintf("%02d:%02d %3.01f",($tSpan/60),($tSpan%60),$temp[$reg]);
  7786. $setting .= "Temp set: ${day}_".$days[$day]." ".$entry." C\n";
  7787. $dayRead .= " ".$entry;
  7788. $tSpan = $time[$reg];
  7789. }
  7790. push (@changedRead,"R_${day}_tempList$days[$day]:$dayRead");
  7791. }
  7792. }
  7793. CUL_HM_UpdtReadBulk($hash,1,@changedRead) if (@changedRead);
  7794. return $setting;
  7795. }
  7796. sub CUL_HM_SD_2($) {# parse SD2
  7797. my ($hash)=@_;
  7798. my $rep = CUL_HM_getRegFromStore($hash->{NAME},"devRepeatCntMax",0,"","");
  7799. if ($rep eq "1"){
  7800. CUL_HM_UpdtReadBulk($hash,1,"sdRepeat:on");
  7801. $hash->{sdRepeat} = "on";
  7802. }
  7803. elsif($rep eq "0"){
  7804. CUL_HM_UpdtReadBulk($hash,1,"sdRepeat:off");
  7805. }
  7806. else{
  7807. CUL_HM_UpdtReadBulk($hash,1,"sdRepeat:$rep");
  7808. }
  7809. }
  7810. sub CUL_HM_TCITRTtempReadings($$@) {# parse RT - TC-IT temperature readings
  7811. my ($hash,$md,@list)=@_;
  7812. my $name = $hash->{NAME};
  7813. my $regPre = ($hash->{helper}{expert}{raw}?"":".");
  7814. my @changedRead;
  7815. my $setting="";
  7816. my %idxN = (7=>"P1_",8=>"P2_",9=>"P3_");
  7817. $idxN{7} = "" if($md =~ m/CC-RT/);# not prefix for RT
  7818. my @days = ("Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri");
  7819. delete $hash->{READINGS}{hyst2pointWrite};
  7820. foreach my $lst (@list){
  7821. my @r1;
  7822. $lst +=0;
  7823. # cleanup old value formats
  7824. my $ln = length($idxN{$lst})?substr($idxN{$lst},0,2):"";
  7825. delete $hash->{READINGS}{$_}
  7826. foreach (grep !/_/,grep /tempList$ln/,keys %{$hash->{READINGS}});
  7827. my $tempRegs = ReadingsVal($name,$regPre."RegL_0$lst.","");
  7828. if ($tempRegs !~ m/00:00/){
  7829. for (my $day = 0;$day<7;$day++){
  7830. push (@changedRead,"R_$idxN{$lst}${day}_tempList".$days[$day].":incomplete");
  7831. }
  7832. push (@changedRead,"R_$idxN{$lst}tempList_State:incomplete");
  7833. CUL_HM_UpdtReadBulk($hash,1,@changedRead) if (@changedRead);
  7834. next;
  7835. }
  7836. foreach(split " ",$tempRegs){
  7837. my ($a,$d) = split ":",$_;
  7838. $r1[hex($a)] = $d;
  7839. }
  7840. if ($hash->{helper}{shadowReg}{"RegL_0$lst."}){
  7841. my $ch = 0;
  7842. foreach(split " ",$hash->{helper}{shadowReg}{"RegL_0$lst."}){
  7843. my ($a,$d) = split ":",$_;
  7844. $a = hex($a);
  7845. $ch = 1 if ((!$r1[$a] || $r1[$a] ne $d) && $a >= 20);
  7846. $r1[$a] = $d;
  7847. }
  7848. push (@changedRead,"R_$idxN{$lst}tempList_State:set") if ($ch);
  7849. }
  7850. else{
  7851. push (@changedRead,"R_$idxN{$lst}tempList_State:verified");
  7852. }
  7853. $tempRegs = join("",@r1[20..scalar@r1-1]);
  7854. for (my $day = 0;$day<7;$day++){
  7855. my $dayRead = "";
  7856. my @time;
  7857. my @temp;
  7858. if (length($tempRegs)<($day+1) *13*4) {
  7859. push (@changedRead,"R_$idxN{$lst}${day}_tempList$days[$day]:incomplete");
  7860. $setting .= "Temp set $idxN{$lst}: ${day}_".$days[$day]." incomplete\n";
  7861. }
  7862. else{
  7863. foreach (unpack '(A4)*',substr($tempRegs,$day *13*4,13*4)){
  7864. my $h = hex($_);
  7865. push @temp,($h >> 9)/2;
  7866. $h = ($h & 0x1ff) * 5;
  7867. $h = sprintf("%02d:%02d",int($h / 60),($h%60));
  7868. push @time,$h;
  7869. }
  7870. for (my $idx = 0;$idx<13;$idx++){
  7871. my $entry = sprintf(" %s %04.01f",$time[$idx],$temp[$idx]);
  7872. $setting .= "Temp set $idxN{$lst}: ${day}_".$days[$day].$entry." C\n";
  7873. $dayRead .= $entry;
  7874. last if ($time[$idx] eq "24:00");
  7875. }
  7876. push (@changedRead,"R_$idxN{$lst}${day}_tempList$days[$day]:$dayRead");
  7877. }
  7878. }
  7879. }
  7880. CUL_HM_UpdtReadBulk($hash,1,@changedRead) if (@changedRead);
  7881. return $setting;
  7882. }
  7883. sub CUL_HM_repReadings($) { # parse repeater
  7884. my ($hash)=@_;
  7885. my %pCnt;
  7886. my $cnt = 0;
  7887. return "" if (!$hash->{helper}{peerIDsRaw});
  7888. foreach my$pId(split',',$hash->{helper}{peerIDsRaw}){
  7889. next if (!$pId || $pId eq "00000000");
  7890. $pCnt{$pId.$cnt}{cnt}=$cnt++;
  7891. }
  7892. delete $hash->{repeater} foreach(devspec2array("TYPE=CUL_HM"
  7893. .":FILTER=DEF=......"
  7894. .":FILTER=repeater=$hash->{NAME}"));
  7895. my @pS;
  7896. my @pD;
  7897. my @pB;
  7898. foreach (split",",(AttrVal($hash->{NAME},"repPeers",undef))){
  7899. my ($s,$d,$b) = split":",$_;
  7900. push @pS,$s;
  7901. push @pD,$d;
  7902. push @pB,$b;
  7903. }
  7904. my @readList;
  7905. push @readList,"repPeer_".sprintf("%02d",$_+1).":undefined" for(0..35);#set default empty
  7906. my @retL;
  7907. my @repAttr;
  7908. push @repAttr," " for(0..35);
  7909. foreach my$pId(sort keys %pCnt){
  7910. my ($pdID,$bdcst,$no) = unpack('A6A2A2',$pId);
  7911. my $fNo = $no-1;#shorthand field number, often used
  7912. my $sName = CUL_HM_id2Name($pdID);
  7913. if ($sName eq $pdID && $pD[$fNo] && $defs{$pD[$fNo]}){
  7914. $sName = $defs{$pD[$fNo]}->{IODev}{NAME}
  7915. if($attr{$defs{$pD[$fNo]}->{IODev}{NAME}}{hmId} eq $pdID);
  7916. }
  7917. my $eS = sprintf("%02d:%-15s %-15s %-3s %-4s",
  7918. $no
  7919. ,$sName
  7920. ,((!$pS[$fNo] || $pS[$fNo] ne $sName)?"unknown":" dst>$pD[$fNo]")
  7921. ,($bdcst eq "01"?"yes":"no ")
  7922. ,($pB[$fNo] && ( ($bdcst eq "01" && $pB[$fNo] eq "y")
  7923. ||($bdcst eq "00" && $pB[$fNo] eq "n")) ?"ok":"fail")
  7924. );
  7925. $repAttr[$fNo] = "$sName:"
  7926. .((!$pS[$fNo] || $pS[$fNo] ne $sName)?"-":$pD[$fNo])
  7927. .":".($pB[$fNo]?$pB[$fNo]:"-");
  7928. my $dName = CUL_HM_getDeviceName($sName);
  7929. $defs{$dName}{repeater} = $hash->{NAME} if ($defs{$dName});
  7930. push @retL,$eS;
  7931. $readList[$fNo]="repPeer_".$eS;
  7932. }
  7933. $attr{$hash->{NAME}}->{repPeers} = join",",@repAttr;
  7934. CUL_HM_UpdtReadBulk($hash,0,@readList);
  7935. return "No Source Dest Bcast\n". join"\n", sort @retL;
  7936. }
  7937. sub CUL_HM_ModRe8($$) { # repair FW bug
  7938. #Register 18 may come with a wrong address - we will corrent that
  7939. my ($hash,$regN)=@_;
  7940. my $rl0 = ReadingsVal($hash->{NAME},$regN,"empty");
  7941. return if( $rl0 !~ m/00:00/ # not if List is incomplete
  7942. ||$rl0 =~ m/12:/ ); # reg 18 present, dont touch
  7943. foreach my $ad (split(" ",$rl0)){
  7944. my ($a,$d) = split(":",$ad);
  7945. my $ah = hex($a);
  7946. if ($ah & 0xe0 && (($ah & 0x1F) == 0x12)){
  7947. Log3 $hash,3,"CUL_HM replace address $a to 0x12";
  7948. $hash->{READINGS}{$regN}{VAL} =~ s/ $a:/ 12:/;
  7949. last;
  7950. }
  7951. }
  7952. }
  7953. sub CUL_HM_dimLog($) {# dimmer readings - support virtual chan - unused so far
  7954. my ($hash)=@_;
  7955. my $lComb = CUL_HM_Get($hash,$hash->{NAME},"reg","logicCombination");
  7956. return if (!$lComb);
  7957. my %logicComb=(
  7958. inactive=>{calc=>'$val=$val' ,txt=>'unused'},
  7959. or =>{calc=>'$val=$in>$val?$in:$val' ,txt=>'max(state,chan)'},
  7960. and =>{calc=>'$val=$in<$val?$in:$val' ,txt=>'min(state,chan)'},
  7961. xor =>{calc=>'$val=!($in!=0&&$val!=0)?($in>$val?$in:$val): 0' ,txt=>'0 if both are != 0, else max'},
  7962. nor =>{calc=>'$val=100-($in>$val?$in : $val)' ,txt=>'100-max(state,chan)'},
  7963. nand =>{calc=>'$val=100-($in<$val?$in : $val)' ,txt=>'100-min(state,chan)'},
  7964. orinv =>{calc=>'$val=(100-$in)>$val?(100-$in) : $val' ,txt=>'max((100-chn),state)'},
  7965. andinv =>{calc=>'$val=(100-$in)<$val?(100-$in) : $val' ,txt=>'min((100-chn),state)'},
  7966. plus =>{calc=>'$val=($in + $val)<100?($in + $val) : 100' ,txt=>'state + chan'},
  7967. minus =>{calc=>'$val=($in - $val)>0?($in + $val) : 0' ,txt=>'state - chan'},
  7968. mul =>{calc=>'$val=($in * $val)<100?($in + $val) : 100' ,txt=>'state * chan'},
  7969. plusinv =>{calc=>'$val=($val+100-$in)<100?($val+100-$in) : 100' ,txt=>'state + 100 - chan'},
  7970. minusinv=>{calc=>'$val=($val-100+$in)>0?($val-100+$in) : 0' ,txt=>'state - 100 + chan'},
  7971. mulinv =>{calc=>'$val=((100-$in)*$val)<100?(100-$in)*$val) : 100',txt=>'state * (100 - chan)'},
  7972. invPlus =>{calc=>'$val=(100-$val-$in)>0?(100-$val-$in) : 0' ,txt=>'100 - state - chan'},
  7973. invMinus=>{calc=>'$val=(100-$val+$in)<100?(100-$val-$in) : 100' ,txt=>'100 - state + chan'},
  7974. invMul =>{calc=>'$val=(100-$val*$in)>0?(100-$val*$in) : 0' ,txt=>'100 - state * chan'},
  7975. );
  7976. CUL_HM_UpdtReadBulk($hash,0,"R-logicCombTxt:".$logicComb{$lComb}{txt}
  7977. ,"R-logicCombCalc:".$logicComb{$lComb}{calc});
  7978. return "";
  7979. }
  7980. #+++++++++++++++++ Action Detector ++++++++++++++++++++++++++++++++++++++++++++
  7981. # verify that devices are seen in a certain period of time
  7982. # It will generate events if no message is seen sourced by the device during
  7983. # that period.
  7984. # ActionDetector will use the fixed HMid 000000
  7985. sub CUL_HM_ActGetCreateHash() {# get ActionDetector - create if necessary
  7986. if (!$modules{CUL_HM}{defptr}{"000000"}){
  7987. CommandDefine(undef,"ActionDetector CUL_HM 000000");
  7988. $attr{ActionDetector}{actCycle} = 600;
  7989. $attr{ActionDetector}{"event-on-change-reading"} = ".*";
  7990. }
  7991. my $actHash = $modules{CUL_HM}{defptr}{"000000"};
  7992. my $actName = ($actHash ? $actHash->{NAME} : "");
  7993. my $ac = AttrVal($actName,"actCycle",600);
  7994. if (!$actHash->{helper}{actCycle} ||
  7995. $actHash->{helper}{actCycle} != $ac){
  7996. $actHash->{helper}{actCycle} = $ac;
  7997. RemoveInternalTimer("ActionDetector");
  7998. $actHash->{STATE} = "active";
  7999. InternalTimer(gettimeofday()+$ac,"CUL_HM_ActCheck", "ActionDetector", 0);
  8000. }
  8001. return $actHash;
  8002. }
  8003. sub CUL_HM_time2sec($) {
  8004. my ($timeout) = @_;
  8005. my ($h,$m) = split(":",$timeout);
  8006. no warnings 'numeric';
  8007. $h = int($h);
  8008. $m = int($m);
  8009. use warnings 'numeric';
  8010. return ((sprintf("%03s:%02d",$h,$m)),((int($h)*60+int($m))*60));
  8011. }
  8012. sub CUL_HM_ActAdd($$) {# add an HMid to list for activity supervision
  8013. my ($devId,$timeout) = @_; #timeout format [hh]h:mm
  8014. $timeout = 0 if (!$timeout);
  8015. return $devId." is not an HM device - action detection cannot be added"
  8016. if (length($devId) != 6);
  8017. my ($cycleString,undef)=CUL_HM_time2sec($timeout);
  8018. my $devName = CUL_HM_id2Name($devId);
  8019. my $devHash = $defs{$devName};
  8020. $attr{$devName}{actCycle} = $cycleString;
  8021. $attr{$devName}{actStatus}=""; # force trigger
  8022. my $actHash = CUL_HM_ActGetCreateHash();
  8023. $actHash->{helper}{$devId}{start} = TimeNow();
  8024. $actHash->{helper}{peers} = CUL_HM_noDupInString(
  8025. ($actHash->{helper}{peers}?$actHash->{helper}{peers}:"")
  8026. .",$devId");
  8027. Log3 $actHash, 3,"Device ".$devName." added to ActionDetector with "
  8028. .$cycleString." time";
  8029. #run ActionDetector
  8030. RemoveInternalTimer("ActionDetector");
  8031. CUL_HM_ActCheck("add");
  8032. return;
  8033. }
  8034. sub CUL_HM_ActDel($) {# delete HMid for activity supervision
  8035. my ($devId) = @_;
  8036. my $devName = CUL_HM_id2Name($devId);
  8037. CUL_HM_setAttrIfCh($devName,"actStatus","deleted","Activity");#post trigger
  8038. delete $attr{$devName}{actCycle};
  8039. delete $attr{$devName}{actStatus};
  8040. my $actHash = CUL_HM_ActGetCreateHash();
  8041. delete ($actHash->{helper}{$devId});
  8042. my $peerIDs = $actHash->{helper}{peers};
  8043. $peerIDs =~ s/$devId//g if($peerIDs);
  8044. $actHash->{helper}{peers} = CUL_HM_noDupInString($peerIDs);
  8045. Log3 $actHash,3,"Device ".$devName." removed from ActionDetector";
  8046. RemoveInternalTimer("ActionDetector");
  8047. CUL_HM_ActCheck("del");
  8048. return;
  8049. }
  8050. sub CUL_HM_ActCheck($) {# perform supervision
  8051. my ($call) = @_;
  8052. my $actHash = CUL_HM_ActGetCreateHash();
  8053. my $tod = int(gettimeofday());
  8054. my $actName = $actHash->{NAME};
  8055. my $peerIDs = $actHash->{helper}{peers}?$actHash->{helper}{peers}:"";
  8056. my @event;
  8057. my ($cntUnkn,$cntAliv,$cntDead,$cnt_Off) =(0,0,0,0);
  8058. my $autoTry = CUL_HM_getAttrInt($actName,"actAutoTry",0);
  8059. foreach my $devId (split(",",$peerIDs)){
  8060. next if (!$devId);
  8061. my $devName = CUL_HM_id2Name($devId);
  8062. if(AttrVal($devName,"ignore",0)){
  8063. delete $actHash->{READINGS}{"status_".$devName};
  8064. next;
  8065. }
  8066. if(!$devName || !defined($attr{$devName}{actCycle})){
  8067. CUL_HM_ActDel($devId);
  8068. next;
  8069. }
  8070. my $state;
  8071. my $oldState = AttrVal($devName,"actStatus","unset");
  8072. my (undef,$tSec)=CUL_HM_time2sec($attr{$devName}{actCycle});
  8073. if ($tSec == 0){# detection switched off
  8074. $state = "switchedOff";
  8075. }
  8076. else{
  8077. my $tLast = ReadingsVal($devName,".protLastRcv",0);
  8078. my @t = localtime($tod - $tSec); #time since when a trigger is expected
  8079. my $tSince = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
  8080. $t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0]);
  8081. if (!$tLast #cannot determine time
  8082. || $tSince gt $tLast){ #no message received in window
  8083. if ($actHash->{helper}{$devId}{start} lt $tSince){
  8084. if($autoTry) { #try to send a statusRequest?
  8085. if (!$actHash->{helper}{$devId}{try} || $actHash->{helper}{$devId}{try}<2){
  8086. $actHash->{helper}{$devId}{try} = $actHash->{helper}{$devId}{try}
  8087. ? ($actHash->{helper}{$devId}{try} +1)
  8088. : 1;
  8089. my $cmds = CUL_HM_Set($defs{$devName},$devName,"help");
  8090. if ($cmds =~ m/^(statusRequest|getSerial)/){
  8091. # send statusrequest if possible
  8092. CUL_HM_Set($defs{$devName},$devName,
  8093. ($cmds =~ m/^statusRequest/ ? "statusRequest"
  8094. : "getSerial" ));
  8095. $state = $oldState eq "unset" ? "unknown"
  8096. : $oldState;
  8097. }
  8098. else{
  8099. $actHash->{helper}{$devId}{try} = 99;
  8100. $state = "dead";
  8101. }
  8102. }
  8103. else{
  8104. $state = "dead";
  8105. }
  8106. }
  8107. else{
  8108. $state = "dead";
  8109. }
  8110. }
  8111. else{
  8112. $state = "unknown";
  8113. }
  8114. }
  8115. else{ #message in time
  8116. $state = "alive";
  8117. delete $actHash->{helper}{$devId}{try};
  8118. }
  8119. }
  8120. if ($oldState ne $state){
  8121. CUL_HM_UpdtReadSingle($defs{$devName},"Activity",$state,1);
  8122. $attr{$devName}{actStatus} = $state;
  8123. Log3 $actHash,4,"Device ".$devName." is ".$state;
  8124. }
  8125. if ($state eq "unknown") {$cntUnkn++;}
  8126. elsif ($state eq "alive") {$cntAliv++;}
  8127. elsif ($state eq "dead") {$cntDead++;}
  8128. elsif ($state eq "switchedOff"){$cnt_Off++;}
  8129. push @event, "status_".$devName.":".$state;
  8130. }
  8131. push @event, "state:"."alive:".$cntAliv
  8132. ." dead:".$cntDead
  8133. ." unkn:".$cntUnkn
  8134. ." off:" .$cnt_Off;
  8135. my $allState = join " ",@event;# search and remove outdated readings
  8136. if ($call eq "ActionDetector"){#delete only in routine call
  8137. foreach (keys %{$actHash->{READINGS}}){
  8138. delete $actHash->{READINGS}{$_} if ($allState !~ m/$_:/);
  8139. }
  8140. }
  8141. CUL_HM_UpdtReadBulk($actHash,1,@event);
  8142. $actHash->{helper}{actCycle} = AttrVal($actName,"actCycle",600);
  8143. RemoveInternalTimer("ActionDetector");
  8144. InternalTimer(gettimeofday()+$actHash->{helper}{actCycle}
  8145. ,"CUL_HM_ActCheck", "ActionDetector", 0);
  8146. }
  8147. sub CUL_HM_ActInfo() {# print detailed status information
  8148. my $actHash = CUL_HM_ActGetCreateHash();
  8149. my $tod = int(gettimeofday());
  8150. my $peerIDs = $actHash->{helper}{peers}?$actHash->{helper}{peers}:"";
  8151. my @info;
  8152. foreach my $devId (split(",",$peerIDs)){
  8153. next if (!$devId);
  8154. my $devName = CUL_HM_id2Name($devId);
  8155. next if(!$devName || !defined($attr{$devName}{actCycle}));
  8156. next if(AttrVal($devName,"ignore",0));
  8157. my $state;
  8158. my (undef,$tSec)=CUL_HM_time2sec($attr{$devName}{actCycle});
  8159. if ($tSec != 0){
  8160. my $tLast = ReadingsVal($devName,".protLastRcv",0);
  8161. $tLast =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/;
  8162. my $x = $2*30*24*3600 + $3*24*3600 + $4*3600 + $5*60 +$6;
  8163. my @t = localtime($tod - $tSec); #time since when a trigger is expected
  8164. my $y = $x -
  8165. (( $t[4]+1)*30*24*3600
  8166. + $t[3]*24*3600
  8167. + $t[2]*3600
  8168. + $t[1]*60
  8169. + $t[0]);
  8170. my $sign = "next ";
  8171. if ($y < 0){
  8172. $sign = "late -";
  8173. $y *= -1;
  8174. }
  8175. my @c;
  8176. $c[1] = int($y/3600);$y -= $c[1] * 3600;
  8177. $c[0] = int($y/60) ;$y -= $c[0] * 60;
  8178. $state .= sprintf("%-8s %s %s %3d:%02d:%02d %s"
  8179. ,ReadingsVal($devName,"Activity","")
  8180. ,$tLast,$sign,$c[1],$c[0],$y
  8181. ,$devName);
  8182. }
  8183. else{
  8184. $state = sprintf ("%-8s :%30s : "
  8185. ,ReadingsVal($devName,"Activity","")
  8186. ,$devName);
  8187. }
  8188. push @info,$state;
  8189. }
  8190. return sprintf ("%-8s %-19s %s %s\n\n","state"
  8191. ,"last"
  8192. ,"next h:mm:ss"
  8193. ,"name").
  8194. join("\n", sort @info);
  8195. }
  8196. #+++++++++++++++++ helper +++++++++++++++++++++++++++++++++++++++++++++++++++++
  8197. sub CUL_HM_UpdtReadBulk(@) { #update a bunch of readings and trigger the events
  8198. my ($hash,$doTrg,@readings) = @_;
  8199. return if (!@readings ||!defined $hash|| !defined $hash->{NAME} );
  8200. if($evtDly && $doTrg){#delay trigger if in parser and trigger ist requested
  8201. push @evtEt,[$hash,1,"$_"] foreach(@readings);
  8202. }
  8203. else{
  8204. readingsBeginUpdate($hash);
  8205. foreach my $rd (CUL_HM_noDup(@readings)){
  8206. next if (!$rd);
  8207. my ($rdName, $rdVal) = split(":",$rd, 2);
  8208. readingsBulkUpdate($hash,$rdName,
  8209. ((defined($rdVal) && $rdVal ne "")?$rdVal:"-"));
  8210. }
  8211. readingsEndUpdate($hash,$doTrg);
  8212. }
  8213. return $hash->{NAME};
  8214. }
  8215. sub CUL_HM_UpdtReadSingle(@) { #update single reading and trigger the event
  8216. my ($hash,$rName,$val,$doTrg) = @_;
  8217. return if (!defined $hash->{NAME});
  8218. if($evtDly && $doTrg){#delay trigger if in parser and trigger ist requested
  8219. push @evtEt,[$hash,1,"$rName:$val"];
  8220. }
  8221. else{
  8222. readingsSingleUpdate($hash,$rName,$val,$doTrg);
  8223. }
  8224. return $hash->{NAME};
  8225. }
  8226. sub CUL_HM_setAttrIfCh($$$$) {
  8227. my ($name,$att,$val,$trig) = @_;
  8228. if(AttrVal($name,$att,"") ne $val){
  8229. DoTrigger($name,$trig.":".$val) if($trig);
  8230. $attr{$name}{$att} = $val;
  8231. }
  8232. }
  8233. sub CUL_HM_noDup(@) {#return list with no duplicates
  8234. my %all;
  8235. return "" if (scalar(@_) == 0);
  8236. $all{$_}=0 foreach (grep {defined $_ && $_ !~ m/^$/} @_);
  8237. delete $all{""}; #remove empties if present
  8238. return (sort keys %all);
  8239. }
  8240. sub CUL_HM_noDupInString($) {#return string with no duplicates, comma separated
  8241. my ($str) = @_;
  8242. return join ",",CUL_HM_noDup(split ",",$str);
  8243. }
  8244. sub CUL_HM_storeRssi(@){
  8245. my ($name,$peerName,$val,$mNo) = @_;
  8246. return if (!$val || !$name|| !defined $defs{$name});
  8247. my $hash = $defs{$name};
  8248. if (AttrVal($peerName,"subType","") eq "virtual"){
  8249. my $h = InternalVal($name,"IODev","");#CUL_HM_name2IoName($peerName);
  8250. return if (!$h);
  8251. $peerName = $h->{NAME};
  8252. }
  8253. else{
  8254. return if (length($peerName)<3);
  8255. }
  8256. if ($peerName =~ m/^at_/){
  8257. if ($hash->{helper}{mRssi}{mNo} ne $mNo){# new message
  8258. delete $hash->{helper}{mRssi};
  8259. $hash->{helper}{mRssi}{mNo} = $mNo;
  8260. }
  8261. my ($mVal,$mPn) = ($val,substr($peerName,3));
  8262. if ($mPn =~ m/^rpt_(.*)/){# map repeater to io device, use max rssi
  8263. $mPn = $1;
  8264. $mVal = $hash->{helper}{mRssi}{io}{$mPn}
  8265. if( $hash->{helper}{mRssi}{io}{$mPn}
  8266. && $hash->{helper}{mRssi}{io}{$mPn} > $mVal);
  8267. }
  8268. $mVal +=2 if(CUL_HM_name2IoName($name) eq $mPn);
  8269. $hash->{helper}{mRssi}{io}{$mPn} = $mVal;
  8270. }
  8271. $hash->{helper}{rssi}{$peerName}{lst} = $val;
  8272. my $rssiP = $hash->{helper}{rssi}{$peerName};
  8273. $rssiP->{min} = $val if (!$rssiP->{min} || $rssiP->{min} > $val);
  8274. $rssiP->{max} = $val if (!$rssiP->{max} || $rssiP->{max} < $val);
  8275. $rssiP->{cnt} ++;
  8276. $rssiP->{cnt} = 10000 if(!$rssiP->{cnt}); # avoid division by zero on overflow!
  8277. if ($rssiP->{cnt} == 1){
  8278. $rssiP->{avg} = $val;
  8279. }
  8280. else{
  8281. $rssiP->{avg} += ($val - $rssiP->{avg}) /$rssiP->{cnt};
  8282. }
  8283. my $rssi;
  8284. foreach (keys %{$rssiP}){
  8285. my $val = $rssiP->{$_}?$rssiP->{$_}:0;
  8286. $rssi .= $_.":".(int($val*100)/100)." ";
  8287. }
  8288. $hash->{"rssi_".$peerName} = $rssi;
  8289. CUL_HM_UpdtReadSingle($hash,"rssi_".$peerName,$val,1)
  8290. if (AttrVal($name,"rssiLog",undef));
  8291. return ;
  8292. }
  8293. sub CUL_HM_UpdtCentral($){
  8294. my $name = shift;
  8295. my $id = CUL_HM_name2Id($name);
  8296. return if(!$init_done || length($id) != 6);
  8297. foreach (keys %defs){# remove existing IO assignements
  8298. next if ( AttrVal($_,"hmId","") ne $id
  8299. && InternalVal($_,"owner_CCU","") ne $name);
  8300. delete $defs{$_}{owner_CCU};
  8301. }
  8302. $defs{$name}{assignedIOs} = join(",",devspec2array("hmId=$id"));
  8303. foreach my $ioN(split",",AttrVal($name,"IOList","")){# set parameter in IO
  8304. next if (!$defs{$ioN});
  8305. my $t = $defs{$ioN}{TYPE};
  8306. if ( $t =~ m/^(HMLAN|HMUARTLGW)$/){
  8307. ; # nothing special to do on device
  8308. }
  8309. elsif( $t =~ m/^(CUL|TSCUL|TSSTACKED|STACKABLE_CC)$/){ # nonsi: required for usage of TSCUL/TSSTACKED !!!
  8310. CommandAttr(undef, "$ioN rfmode HomeMatic") # set device to HomeMatic mode
  8311. if (AttrVal($ioN,"rfmode","") ne "HomeMatic");
  8312. }
  8313. else {
  8314. next;
  8315. }
  8316. CommandAttr(undef, "$ioN hmId $id")
  8317. if (AttrVal($ioN,"hmId","") ne $id);
  8318. $defs{$ioN}{owner_CCU} = $name;
  8319. }
  8320. # --- search for peers to CCU and potentially device this channel
  8321. foreach my $ccuBId (CUL_HM_noDup(grep /$id/ ,map{split ",",AttrVal($_,"peerIDs","")}keys %defs)){
  8322. next if (length($ccuBId) !=8);
  8323. # now for each ccu Channel, that ist peered with someone.
  8324. my $btn = hex(substr($ccuBId,6,2)) + 0;
  8325. next if (!$btn);
  8326. CommandDefine(undef,$name."_Btn$btn CUL_HM $ccuBId")
  8327. if (!$modules{CUL_HM}{defptr}{$ccuBId});
  8328. my $ccuChnName = $modules{CUL_HM}{defptr}{$ccuBId}{NAME};
  8329. foreach my $pn (grep !/^$/,
  8330. map{$_ if (AttrVal($_,"peerIDs","") =~ m/$ccuBId/)}
  8331. keys %defs){
  8332. CUL_HM_ID2PeerList ($ccuChnName,unpack('A8',CUL_HM_name2Id($pn)."01"),1);
  8333. }
  8334. }
  8335. my @ioList = grep /.+/,map{$defs{$_} ? $_ : ""} split(",",AttrVal($name,"IOList",""));
  8336. $defs{$name}{helper}{io}{ioList} = \@ioList;
  8337. my $io = AttrVal($name,"IODev","empty");# assign IODev to vccu
  8338. if (AttrVal($name,"IOList","") !~ m/$io/){
  8339. foreach(@ioList){
  8340. if ($defs{$_}){
  8341. $attr{$name}{IODev} = $_;
  8342. last;
  8343. }
  8344. }
  8345. }
  8346. CUL_HM_UpdtCentralState($name);
  8347. }
  8348. sub CUL_HM_UpdtCentralState($){
  8349. my $name = shift;
  8350. return if (!$defs{$name});
  8351. my $state = "";
  8352. my @IOl = split",",AttrVal($name,"IOList","");
  8353. foreach my $e (split",",$defs{$name}{assignedIOs}){
  8354. $state .= "$e:UAS," if (!grep /$e/,@IOl);
  8355. }
  8356. foreach my $ioN (@IOl){
  8357. next if (!defined($defs{$ioN})); # remove undefined IO devices
  8358. my $cnd = ReadingsVal($ioN,"cond","");
  8359. if ($cnd){ # covering all HMLAN/USB
  8360. $state .= "$ioN:$cnd,";
  8361. }
  8362. else{ # handling CUL
  8363. my $st = ReadingsVal($ioN,"state","unknown");
  8364. $state .= "$ioN:".($st ne "Initialized"?$st:"ok").",";
  8365. }
  8366. if (AttrVal($ioN,"hmId","") ne $defs{$name}{DEF}){
  8367. Log 1,"CUL_HM correct hmId for assigned IO $ioN";
  8368. $attr{$ioN}{hmId} = $defs{$name}{DEF};
  8369. }
  8370. };
  8371. $state = "IOs_ok" if (!$state);
  8372. CUL_HM_UpdtReadSingle($defs{$name},"state",$state,1);
  8373. }
  8374. sub CUL_HM_assignIO($){ #check and assign IO
  8375. # assign IO device
  8376. my $hash = shift;
  8377. if (!defined $hash->{helper}{prt}{sProc}
  8378. || ( $hash->{helper}{prt}{sProc} == 1
  8379. && defined $hash->{IODev})){#don't change while send in process
  8380. return;
  8381. }
  8382. my $oldIODev = $hash->{IODev} ? $hash->{IODev} : "";
  8383. my $newIODev = "";
  8384. my $haveIOList = 0;
  8385. my $ioCCU = $hash->{helper}{io}{vccu};
  8386. if ( $ioCCU
  8387. && defined $defs{$ioCCU}
  8388. && AttrVal($ioCCU,"model","") eq "CCU-FHEM"
  8389. && ref($defs{$ioCCU}{helper}{io}{ioList}) eq 'ARRAY'){
  8390. $haveIOList = 1;
  8391. my @ioccu = @{$defs{$ioCCU}{helper}{io}{ioList}};
  8392. my @ios = ((sort {$hash->{helper}{mRssi}{io}{$b} <=>
  8393. $hash->{helper}{mRssi}{io}{$a} }
  8394. grep {defined $hash->{helper}{mRssi}{io}{$_}} @ioccu)
  8395. ,(grep {!defined $hash->{helper}{mRssi}{io}{$_}} @ioccu));
  8396. unshift @ios,@{$hash->{helper}{io}{prefIO}} if ($hash->{helper}{io}{prefIO});# set prefIO to first choice
  8397. foreach my $iom (@ios){
  8398. last if ($iom eq "none"); # if "none" is detected stop vccu auto assignment and try normal
  8399. next if ( !$defs{$iom}
  8400. || ReadingsVal($iom,"state","") eq "disconnected"
  8401. || InternalVal($iom,"XmitOpen",1) == 0); # HMLAN/HMUSB/TSCUL?
  8402. $newIODev = $defs{$iom};# suitable CCU IO found - continue to assign
  8403. last;
  8404. }
  8405. }
  8406. if (!$newIODev) {# not assigned thru CCU - try normal
  8407. my $dIo = AttrVal($hash->{NAME},"IODev","");
  8408. if ( $defs{$dIo}
  8409. &&(!$oldIODev || $dIo ne $oldIODev->{NAME})) {
  8410. $newIODev = $defs{$dIo}; # assign according to Attribut
  8411. }
  8412. else {
  8413. AssignIoPort($hash); #let kernal decide
  8414. $newIODev = $hash->{IODev};
  8415. }
  8416. }
  8417. if ($oldIODev ne $newIODev) {# have a change - Assign the device at IO and remove from old one
  8418. my $ID = CUL_HM_hash2Id($hash);
  8419. if ( $oldIODev
  8420. && $oldIODev ne $newIODev
  8421. && ReadingsVal($oldIODev->{NAME},"state","") ne "disconnected"
  8422. # && InternalVal($oldIODev->{NAME},"XmitOpen",1) != 0
  8423. &&( $oldIODev->{helper}{VTS_AES} #if this unselected IO is TSCUL 0.14+ we have to remove the device from IO
  8424. || ( $oldIODev->{TYPE} && $oldIODev->{TYPE} =~ m/^(HMLAN|HMUARTLGW)$/ ))) {#if this unselected IO is HMLAN we have to remove the device from IO
  8425. IOWrite($hash, "", "remove:".$ID); # remove assignment from old IO
  8426. }
  8427. $hash->{IODev} = $newIODev; # finally assign IO
  8428. if ( $newIODev->{TYPE} && $newIODev->{TYPE} =~ m/^(HMLAN|HMUARTLGW)$/ #if selected IO IO is HMLAN we have to set the device in IO
  8429. || ( $newIODev->{helper}{VTS_AES}
  8430. && $hash->{helper}{io}{newChn})){
  8431. IOWrite($hash, "", "init:".$ID); # assign to new IO
  8432. }
  8433. }
  8434. }
  8435. sub CUL_HM_stateUpdatDly($$){#delayed queue of status-request
  8436. my ($name,$time) = @_;
  8437. CUL_HM_unQEntity($name,"qReqStat");#remove requests, wait for me.
  8438. RemoveInternalTimer("sUpdt:$name");
  8439. InternalTimer(gettimeofday()+$time,"CUL_HM_qStateUpdatIfEnab","sUpdt:$name",0);
  8440. }
  8441. sub CUL_HM_qStateUpdatIfEnab($@){#in:name or id, queue stat-request
  8442. my ($name,$force) = @_;
  8443. $name = substr($name,6) if ($name =~ m/^sUpdt:/);
  8444. $name = CUL_HM_id2Name($name) if ($name =~ m/^[A-F0-9]{6,8}$/i);
  8445. $name =~ s/_chn-\d\d$//;
  8446. return if ( !$defs{$name} #device unknown, ignore
  8447. || CUL_HM_Set($defs{$name},$name,"help") !~ m/statusRequest/);
  8448. if ($force || ((CUL_HM_getAttrInt($name,"autoReadReg") & 0x0f) > 3)){
  8449. CUL_HM_qEntity($name,"qReqStat") ;
  8450. }
  8451. }
  8452. sub CUL_HM_qAutoRead($$){
  8453. my ($name,$lvl) = @_;
  8454. CUL_HM_configUpdate($name);
  8455. return if (!$defs{$name}
  8456. ||$lvl >= (0x07 & CUL_HM_getAttrInt($name,"autoReadReg")));
  8457. CUL_HM_qEntity($name,"qReqConf");
  8458. }
  8459. sub CUL_HM_unQEntity($$){# remove entity from q
  8460. my ($name,$q) = @_;
  8461. my $devN = CUL_HM_getDeviceName($name);
  8462. return if (AttrVal($devN,"subType","") eq "virtual");
  8463. my $dq = $defs{$devN}{helper}{q};
  8464. RemoveInternalTimer("sUpdt:$name") if ($q eq "qReqStat");#remove delayed
  8465. return if ($dq->{$q} eq "");
  8466. if ($devN eq $name){#all channels included
  8467. $dq->{$q}="";
  8468. }
  8469. else{
  8470. my @chns = split(",",$dq->{$q});
  8471. my $chn = substr(CUL_HM_name2Id($name),6,2);
  8472. @chns = grep !/$chn/,@chns;
  8473. @chns = grep !/00/,@chns;#remove device as well - just in case
  8474. $dq->{$q} = join",",@chns;
  8475. }
  8476. my $cq = (CUL_HM_getRxType($defs{$name}) & 0x1C)?($q."Wu") : $q;
  8477. return if( !$modules{CUL_HM}{helper}{$cq}
  8478. || scalar(@{$modules{CUL_HM}{helper}{$cq}}) == 0);
  8479. my $mQ = $modules{CUL_HM}{helper}{$cq};
  8480. return if(!$mQ || scalar(@{$mQ}) == 0);
  8481. @{$mQ} = grep !/^$devN$/,@{$mQ} if ($dq->{$q} eq "");
  8482. }
  8483. sub CUL_HM_qEntity($$){ # add to queue
  8484. my ($name,$q) = @_;
  8485. return if ($modules{CUL_HM}{helper}{hmManualOper});#no autoaction when manual
  8486. my $devN = CUL_HM_getDeviceName($name);
  8487. return if (AttrVal($devN,"subType","") eq "virtual");
  8488. $name = $devN if ($defs{$devN}{helper}{q}{$q} eq "00"); #already requesting all
  8489. if ($devN eq $name){#config for all device
  8490. $defs{$devN}{helper}{q}{$q}="00";
  8491. }
  8492. else{
  8493. $defs{$devN}{helper}{q}{$q} = CUL_HM_noDupInString(
  8494. $defs{$devN}{helper}{q}{$q}
  8495. .",".substr(CUL_HM_name2Id($name),6,2));
  8496. }
  8497. $q .= "Wu" if (!(CUL_HM_getRxType($defs{$name}) & 0x03));#normal or wakeup q?
  8498. $q = $modules{CUL_HM}{helper}{$q};
  8499. @{$q} = CUL_HM_noDup(@{$q},$devN); #we only q device - channels are stored in the device
  8500. my $wT = (@{$modules{CUL_HM}{helper}{qReqStat}})?
  8501. "1":
  8502. $modules{CUL_HM}{hmAutoReadScan};
  8503. RemoveInternalTimer("CUL_HM_procQs");
  8504. InternalTimer(gettimeofday()+ $wT,"CUL_HM_procQs","CUL_HM_procQs", 0);
  8505. }
  8506. sub CUL_HM_readStateTo($){#staterequest not working
  8507. my ($eN) = @_;
  8508. $eN = substr($eN,6) if ($eN =~ m/^sUpdt:/);
  8509. CUL_HM_UpdtReadSingle($defs{$eN},"state","unreachable",1);
  8510. CUL_HM_stateUpdatDly($eN,1800 );
  8511. }
  8512. sub CUL_HM_procQs($){#process non-wakeup queues
  8513. # --- verify send is possible
  8514. my $mq = $modules{CUL_HM}{helper};
  8515. foreach my $q ("qReqStat","qReqConf"){
  8516. if (@{$mq->{$q}}){
  8517. my $devN = ${$mq->{$q}}[0];
  8518. my $devH = $defs{$devN};
  8519. CUL_HM_assignIO($devH);
  8520. next if(!defined $devH->{IODev}{NAME});
  8521. my $ioName = $devH->{IODev}{NAME};
  8522. if ( ( ReadingsVal($ioName,"cond","") =~ m/^(ok|Overload-released|Warning-HighLoad|init)$/
  8523. && $q eq "qReqStat")
  8524. ||( CUL_HM_autoReadReady($ioName)
  8525. && !$devH->{cmdStack}
  8526. && $q eq "qReqConf")){
  8527. my $dq = $devH->{helper}{q};
  8528. my @chns = split(",",$dq->{$q});
  8529. my $nOpen = scalar @chns;
  8530. if (@chns > 1){$dq->{$q} = join ",",@chns[1..$nOpen-1];}
  8531. else{ $dq->{$q} = "";
  8532. @{$mq->{$q}} = grep !/^$devN$/,@{$mq->{$q}};
  8533. }
  8534. my $dId = CUL_HM_name2Id($devN);
  8535. my $eN=($chns[0] && $chns[0]ne "00")?CUL_HM_id2Name($dId.$chns[0]):$devN;
  8536. next if(!defined $defs{$eN});
  8537. if ($q eq "qReqConf"){
  8538. $mq->{autoRdActive} = $devN;
  8539. CUL_HM_Set($defs{$eN},$eN,"getConfig");
  8540. }
  8541. else{
  8542. CUL_HM_Set($defs{$eN},$eN,"statusRequest");
  8543. CUL_HM_unQEntity($eN,"qReqStat") if (!$dq->{$q});
  8544. InternalTimer(gettimeofday()+20,"CUL_HM_readStateTo","sUpdt:$eN",0);
  8545. }
  8546. }
  8547. last; # execute only one!
  8548. }
  8549. }
  8550. delete $mq->{autoRdActive}
  8551. if ($mq->{autoRdActive} &&
  8552. $defs{$mq->{autoRdActive}}{helper}{prt}{sProc} != 1);
  8553. my $next;# how long to wait for next timer
  8554. if (@{$mq->{qReqStat}}){$next = 1}
  8555. elsif (@{$mq->{qReqConf}}){$next = $modules{CUL_HM}{hmAutoReadScan}}
  8556. InternalTimer(gettimeofday()+$next,"CUL_HM_procQs","CUL_HM_procQs",0)
  8557. if ($next);
  8558. }
  8559. sub CUL_HM_appFromQ($$){#stack commands if pend in WuQ
  8560. my ($name,$reason) = @_;
  8561. my $devN = CUL_HM_getDeviceName($name);
  8562. my $dId = CUL_HM_name2Id($devN);
  8563. my $dq = $defs{$devN}{helper}{q};
  8564. if ($reason eq "cf"){# reason is config. add all since User has control
  8565. foreach my $q ("qReqStat","qReqConf"){
  8566. if ($dq->{$q} ne ""){# need update
  8567. my @eName;
  8568. if ($dq->{$q} eq "00"){
  8569. push @eName,$devN;
  8570. }
  8571. else{
  8572. my @chns = split(",",$dq->{$q});
  8573. push @eName,CUL_HM_id2Name($dId.$_)foreach (@chns);
  8574. }
  8575. $dq->{$q} = "";
  8576. @{$modules{CUL_HM}{helper}{$q."Wu"}} =
  8577. grep !/^$devN$/,@{$modules{CUL_HM}{helper}{$q."Wu"}};
  8578. foreach my $eN(@eName){
  8579. next if (!$eN);
  8580. CUL_HM_Set($defs{$eN},$eN,"getConfig") if ($q eq "qReqConf");
  8581. CUL_HM_Set($defs{$eN},$eN,"statusRequest") if ($q eq "qReqStat");
  8582. }
  8583. }
  8584. }
  8585. }
  8586. elsif($reason eq "wu"){#wakeup - just add one step
  8587. my $ioName = $defs{$devN}{IODev}{NAME};
  8588. return if (!CUL_HM_autoReadReady($ioName));# no sufficient performance
  8589. foreach my $q ("qReqStat","qReqConf"){
  8590. if ($dq->{$q} ne ""){# need update
  8591. my @chns = split(",",$dq->{$q});
  8592. my $nOpen = scalar @chns;
  8593. if ($nOpen > 1){$dq->{$q} = join ",",@chns[1..$nOpen-1];}
  8594. else{ $dq->{$q} = "";
  8595. @{$modules{CUL_HM}{helper}{$q."Wu"}} =
  8596. grep !/^$devN$/,@{$modules{CUL_HM}{helper}{$q."Wu"}};
  8597. }
  8598. my $eN=($chns[0]ne "00")?CUL_HM_id2Name($dId.$chns[0]):$devN;
  8599. CUL_HM_Set($defs{$eN},$eN,"getConfig") if ($q eq "qReqConf");
  8600. CUL_HM_Set($defs{$eN},$eN,"statusRequest") if ($q eq "qReqStat");
  8601. return;# Only one per step - very defensive.
  8602. }
  8603. }
  8604. }
  8605. }
  8606. sub CUL_HM_autoReadReady($){# capacity for autoread available?
  8607. my $ioName = shift;
  8608. my $mHlp = $modules{CUL_HM}{helper};
  8609. if ( $mHlp->{autoRdActive} # predecessor available
  8610. && $defs{$mHlp->{autoRdActive}}){
  8611. return 0 if ($defs{$mHlp->{autoRdActive}}{helper}{prt}{sProc} == 1); # predecessor still on
  8612. }
  8613. if ( !$ioName
  8614. || ReadingsVal($ioName,"cond","init") !~ m/^(ok|Overload-released|init)$/#default init for CUL
  8615. || ( defined $defs{$ioName}->{msgLoadCurrent}
  8616. && ( $defs{$ioName}->{msgLoadCurrent}>
  8617. (defined $defs{$ioName}{helper}{loadLvl}?$defs{$ioName}{helper}{loadLvl}{bl}:40)))){
  8618. return 0;
  8619. }
  8620. return 1;
  8621. }
  8622. sub CUL_HM_readValIfTO($){#
  8623. my ($name,$rd,$val) = split(":",shift);# uncertain:$name:$reading:$value
  8624. readingsSingleUpdate($defs{$name},$rd,$val,1);
  8625. }
  8626. sub CUL_HM_motionCheck($){#
  8627. my ($name) = split(":",shift);# uncertain:$name:$reading:$value
  8628. if (defined $defs{$name}{helper}{moStart}){
  8629. CUL_HM_UpdtReadBulk($defs{$name},1,"state:noMotion"
  8630. ,"motion:off"
  8631. ,"motionDuration:".(int(gettimeofday())-int($defs{$name}{helper}{moStart})));
  8632. delete $defs{$name}{helper}{moStart};
  8633. }
  8634. else{
  8635. CUL_HM_UpdtReadBulk($defs{$name},1,"state:noMotion"
  8636. ,"motion:off");
  8637. }
  8638. }
  8639. sub CUL_HM_reWriteDisplay($){
  8640. my ($name) = split(":",shift);# uncertain:$name:$reading:$value
  8641. CUL_HM_Set($defs{$name},$name,"displayEP",":::");
  8642. }
  8643. sub CUL_HM_getAttr($$$){#return attrValue - consider device if empty
  8644. my ($name,$attrName,$default) = @_;
  8645. my $val;
  8646. if($defs{$name}){
  8647. $val = (defined $attr{$name}{$attrName})
  8648. ? $attr{$name}{$attrName}
  8649. : undef;
  8650. if (!defined $val){
  8651. my $devN = $defs{$name}{device}?$defs{$name}{device}:$name;
  8652. $val = (defined $attr{$devN}{$attrName})
  8653. ? $attr{$devN}{$attrName}
  8654. : ($modules{CUL_HM}{AttrListDef} && $modules{CUL_HM}{AttrListDef}{$attrName})?$modules{CUL_HM}{AttrListDef}{$attrName}
  8655. :$default;
  8656. }
  8657. }
  8658. return $val;
  8659. }
  8660. sub CUL_HM_getAttrInt($@){#return attrValue as integer
  8661. my ($name,$attrName,$default) = @_;
  8662. $default = 0 if (!defined $default);
  8663. if($modules{CUL_HM}{AttrListDef} && $modules{CUL_HM}{AttrListDef}{$attrName}){
  8664. }
  8665. if($name && $defs{$name}){
  8666. my $devN = $defs{$name}{device}?$defs{$name}{device}:$name;
  8667. my $val = "0".AttrVal($name,$attrName
  8668. ,AttrVal($devN,$attrName
  8669. ,($modules{CUL_HM}{AttrListDef} && $modules{CUL_HM}{AttrListDef}{$attrName})?$modules{CUL_HM}{AttrListDef}{$attrName}
  8670. :$default));
  8671. $val =~ s/(\d*).*/$1/;
  8672. return int($val);
  8673. }
  8674. else{
  8675. return $default;
  8676. }
  8677. }
  8678. #+++++++++++++++++ external use +++++++++++++++++++++++++++++++++++++++++++++++
  8679. sub CUL_HM_peerUsed($) {# are peers expected?
  8680. # return 0: no peers expected
  8681. # 1: peers expected, list valid
  8682. # 2: peers expected, list invalid
  8683. # 3: peers possible (virtuall actor)
  8684. my $name = shift;
  8685. my $hash = $defs{$name};
  8686. return 0 if (!$hash->{helper}{role}{chn});#device has no channels
  8687. return 3 if ($hash->{helper}{role}{vrt});
  8688. my $mId = CUL_HM_getMId($hash);
  8689. my $cNo = hex(substr($hash->{DEF}."01",6,2))."p"; #default to channel 01
  8690. return 0 if (!$mId || !$culHmModel->{$mId});
  8691. foreach my $ls (split ",",$culHmModel->{$mId}{lst}){
  8692. my ($l,$c) = split":",$ls;
  8693. if ( ($l =~ m/^(p|3|4)$/ && !$c ) # 3,4,p without chanspec
  8694. ||($c && $c =~ m/$cNo/ )){
  8695. return (AttrVal($name,"peerIDs","") =~ m/00000000/?1:2);
  8696. }
  8697. }
  8698. }
  8699. sub CUL_HM_reglUsed($) {# provide data for HMinfo
  8700. my $name = shift;
  8701. my $hash = $defs{$name};
  8702. my ($devId,$chn) = unpack 'A6A2',$hash->{DEF}."01";
  8703. return undef if (AttrVal(CUL_HM_id2Name($devId),"subType","") eq "virtual");
  8704. my @pNames;
  8705. push @pNames,CUL_HM_peerChName($_,$devId)
  8706. foreach (grep !/00000000/,split(",",AttrVal($name,"peerIDs","")));
  8707. my @lsNo;
  8708. my $mId = CUL_HM_getMId($hash);
  8709. return undef if (!$mId || !$culHmModel->{$mId});
  8710. if ($hash->{helper}{role}{dev}){
  8711. push @lsNo,"0.";
  8712. }
  8713. if ($hash->{helper}{role}{chn}){
  8714. foreach my $ls (split ",",$culHmModel->{$mId}{lst}){
  8715. my ($l,$c) = split":",$ls;
  8716. if ($l ne "p"){# ignore peer-only entries
  8717. if ($c){
  8718. my $chNo = hex($chn);
  8719. if ($c =~ m/($chNo)p/){push @lsNo,"$l.$_" foreach (@pNames);}
  8720. elsif($c =~ m/$chNo/ ){push @lsNo,"$l.";}
  8721. }
  8722. else{
  8723. if ($l == 3 || $l == 4){push @lsNo,"$l.$_" foreach (@pNames);
  8724. }else{ push @lsNo,"$l." ;}
  8725. }
  8726. }
  8727. }
  8728. }
  8729. my $pre = $hash->{helper}{expert}{raw}?"":".";
  8730. $_ = $pre."RegL_0".$_ foreach (@lsNo);
  8731. return @lsNo;
  8732. }
  8733. sub CUL_HM_complConfigTest($){# Q - check register consistancy some time later
  8734. my $name = shift;
  8735. return if ($modules{CUL_HM}{helper}{hmManualOper});#no autoaction when manual
  8736. push @{$modules{CUL_HM}{helper}{confCheckArr}},$name;
  8737. if (scalar @{$modules{CUL_HM}{helper}{confCheckArr}} == 1){
  8738. RemoveInternalTimer("CUL_HM_complConfigTO");
  8739. InternalTimer(gettimeofday()+ 1800,"CUL_HM_complConfigTO","CUL_HM_complConfigTO", 0);
  8740. }
  8741. }
  8742. sub CUL_HM_complConfigTestRm($){# Q - check register consistancy some time later
  8743. my $name = shift;
  8744. my $mQ = $modules{CUL_HM}{helper}{confCheckArr};
  8745. @{$mQ} = grep !/^$name$/,@{$mQ};
  8746. }
  8747. sub CUL_HM_complConfigTO($) {# now perform consistancy check of register
  8748. my @arr = @{$modules{CUL_HM}{helper}{confCheckArr}};
  8749. @{$modules{CUL_HM}{helper}{confCheckArr}} = ();
  8750. CUL_HM_complConfig($_) foreach (CUL_HM_noDup(@arr));
  8751. }
  8752. sub CUL_HM_complConfig($;$) {# read config if enabled and not complete
  8753. my ($name,$dly) = @_;
  8754. my $devN = CUL_HM_getDeviceName($name);
  8755. return if (AttrVal($devN,"subType","") eq "virtual");
  8756. return if ($modules{CUL_HM}{helper}{hmManualOper});#no autoaction when manual
  8757. return if ((CUL_HM_getAttrInt($name,"autoReadReg") & 0x07) < 5);
  8758. if ($defs{$devN}{helper}{prt}{sProc} != 0){# we wait till device is idle.
  8759. CUL_HM_complConfigTest($name); # requeue and wait patient
  8760. }
  8761. elsif (CUL_HM_peerUsed($name) == 2){
  8762. CUL_HM_qAutoRead($name,0) if(!$dly);
  8763. CUL_HM_complConfigTest($name);
  8764. delete $modules{CUL_HM}{helper}{cfgCmpl}{$name};
  8765. Log3 $name,5,"CUL_HM $name queue configRead, peers incomplete";
  8766. }
  8767. else{
  8768. my @regList = CUL_HM_reglUsed($name);
  8769. foreach (@regList){
  8770. if (ReadingsVal($name,$_,"") !~ m/00:00/){
  8771. CUL_HM_qAutoRead($name,0) if(!$dly);
  8772. CUL_HM_complConfigTest($name);
  8773. delete $modules{CUL_HM}{helper}{cfgCmpl}{$name};
  8774. Log3 $name,5,"CUL_HM $name queue configRead, register incomplete";
  8775. last;
  8776. }
  8777. }
  8778. $modules{CUL_HM}{helper}{cfgCmpl}{$name} = 1;#mark config as complete
  8779. }
  8780. }
  8781. sub CUL_HM_configUpdate($) {# mark entities with changed data
  8782. my $name = shift;
  8783. @{$modules{CUL_HM}{helper}{confUpdt}} =
  8784. CUL_HM_noDup(@{$modules{CUL_HM}{helper}{confUpdt}},$name);
  8785. }
  8786. sub CUL_HM_cleanShadowReg($){
  8787. # remove shadow-regs if those are identical to readings or
  8788. # the reading does not exist.
  8789. # return dirty "1" if some shadowregs still remain active
  8790. my ($name) = @_;
  8791. my $hash = $defs{$name};
  8792. my $dirty = 0;
  8793. foreach my $rLn (keys %{$hash->{helper}{shadowReg}}){
  8794. my $rLnP = ($hash->{helper}{expert}{raw} ? "" : ".").$rLn;
  8795. if ( !$hash->{READINGS}{$rLnP}
  8796. || !$hash->{helper}{shadowReg}{$rLn}
  8797. || $hash->{helper}{shadowReg}{$rLn} eq $hash->{READINGS}{$rLnP}{VAL}){
  8798. delete $hash->{helper}{shadowReg}{$rLn};
  8799. }
  8800. else{
  8801. $dirty = 1;
  8802. }
  8803. }
  8804. return $dirty;
  8805. }
  8806. #+++++++++++++++++ templates ++++++++++++++++++++++++++++++++++++++++++++++++++
  8807. sub CUL_HM_tempListTmpl(@) { ##################################################
  8808. # $name is comma separated list of names
  8809. # $template is formated <file>:template - file is optional
  8810. my ($name,$action,$template)=@_;
  8811. my %dl = (Sat=>0,Sun=>1,Mon=>2,Tue=>3,Wed=>4,Thu=>5,Fri=>6);
  8812. my %dlf = (1=>{Sat=>0,Sun=>0,Mon=>0,Tue=>0,Wed=>0,Thu=>0,Fri=>0},
  8813. 2=>{Sat=>0,Sun=>0,Mon=>0,Tue=>0,Wed=>0,Thu=>0,Fri=>0},
  8814. 3=>{Sat=>0,Sun=>0,Mon=>0,Tue=>0,Wed=>0,Thu=>0,Fri=>0});
  8815. return "unused" if ($template =~ m/^(none|0) *$/);
  8816. my $ret = "";
  8817. my @el = split",",$name;
  8818. my ($fName,$tmpl) = split":",$template;
  8819. if(!$tmpl){ # just a template - switch
  8820. $tmpl = $fName ? $fName: $name;
  8821. $fName = (eval "defined(&HMinfo_tempListDefFn)")
  8822. ? HMinfo_tempListDefFn()
  8823. : "./tempList.cfg";
  8824. }
  8825. return "file: $fName for $name does not exist" if (!(-e $fName));
  8826. open(aSave, "$fName") || return("Can't open $fName: $!");
  8827. my $found = 0;
  8828. my @entryFail = ();
  8829. my @exec = ();
  8830. if ($template =~ m/defaultWeekplan$/){
  8831. $found = 1;
  8832. foreach my $eN(@el){
  8833. if ($action eq "verify"){
  8834. my $val = "24:00 18.0";
  8835. foreach ( "R_0_tempListSat"
  8836. ,"R_1_tempListSun"
  8837. ,"R_2_tempListMon"
  8838. ,"R_3_tempListTue"
  8839. ,"R_4_tempListWed"
  8840. ,"R_5_tempListThu"
  8841. ,"R_6_tempListFri"){
  8842. my $nv = ReadingsVal($eN,$_,"empty");
  8843. $nv = join(" ",split(" ",$nv));
  8844. push @entryFail,$eN." :".$_." mismatch $val ne $nv ##" if ($val ne $nv);
  8845. }
  8846. $dlf{1}{Sat} = 1;
  8847. $dlf{1}{Sun} = 1;
  8848. $dlf{1}{Mon} = 1;
  8849. $dlf{1}{Tue} = 1;
  8850. $dlf{1}{Wed} = 1;
  8851. $dlf{1}{Thu} = 1;
  8852. $dlf{1}{Fri} = 1;
  8853. }
  8854. elsif($action eq "restore"){
  8855. foreach ( "tempListSat"
  8856. ,"tempListSun"
  8857. ,"tempListMon"
  8858. ,"tempListTue"
  8859. ,"tempListWed"
  8860. ,"tempListThu"
  8861. ,"tempListFri"){
  8862. my $x = CUL_HM_Set($defs{$eN},$eN,$_,"prep",split(" "," 24:00 18.0"));
  8863. push @entryFail,$eN." :".$_." respose:$x" if ($x ne "1");
  8864. push @exec,"$eN $_ exec 24:00 18.0";
  8865. }
  8866. }
  8867. }
  8868. }
  8869. else{
  8870. while(<aSave>){
  8871. chomp;
  8872. my $line = $_;
  8873. $line =~ s/\r//g;
  8874. next if($line =~ m/#/);
  8875. if($line =~ m/^entities:/){
  8876. last if ($found != 0);
  8877. $line =~ s/.*://;
  8878. foreach my $eN (split(",",$line)){
  8879. $eN =~ s/ //g;
  8880. $found = 1 if ($eN eq $tmpl);
  8881. }
  8882. }
  8883. elsif($found == 1 && $line =~ m/(R_)?(P[123])?(_?._)?tempList[SMFWT].*\>/){
  8884. my ($prg,$tln,$val);
  8885. $prg = $1 if ($line =~ m/P(.)_/);
  8886. $prg = 1 if (!$prg);
  8887. ($tln,$val) = ($1,$2) if ($line =~ m/(.*)>(.*)/);
  8888. $tln =~ s/ //g;
  8889. $tln = "R_".$tln if($tln !~ m/^R_/);
  8890. my $dayTxt = ($tln =~ m/tempList(...)/ ? $1 : "");
  8891. if (!defined $dl{$dayTxt}){
  8892. push @entryFail," undefined daycode:$dayTxt";
  8893. next;
  8894. }
  8895. if ($dlf{$prg}{$dayTxt}){
  8896. push @entryFail," duplicate daycode:$dayTxt";
  8897. next;
  8898. }
  8899. $dlf{$prg}{$dayTxt} = 1;
  8900. my $day = $dl{$dayTxt};
  8901. $tln =~ s/tempList/${day}_tempList/ if ($tln !~ m/_[0-6]_/);
  8902. if (AttrVal($name,"model","") =~ m/^HM-TC-IT-WM-W/){
  8903. $tln =~ s/^R_/R_P1_/ if ($tln !~ m/^R_P/);# add P1 as default
  8904. }
  8905. else{
  8906. $tln =~ s/^R_P1_/R_/ if ($tln =~ m/^R_P/);# remove P1 default
  8907. }
  8908. $val =~ tr/ +/ /;
  8909. $val =~ s/^ //;
  8910. $val =~ s/ $//;
  8911. @exec = ();
  8912. foreach my $eN(@el){
  8913. if ($action eq "verify"){
  8914. $val = join(" ",map{(my $foo = $_) =~ s/^(.\.)/0$1/;$foo} split(" ",$val));
  8915. my $nv = ReadingsVal($eN,$tln,"empty");
  8916. $nv = join(" ",map{(my $foo = $_) =~ s/^(.\.)/0$1/;$foo} split(" ",$nv));
  8917. push @entryFail,$eN." :".$tln." mismatch $val ne $nv ##" if ($val ne $nv);
  8918. }
  8919. elsif($action eq "restore"){
  8920. $val = lc($1)." ".$val if ($tln =~ m/(P.)_._tempList/);
  8921. $tln =~ s/R_(P._)?._//;
  8922. my $x = CUL_HM_Set($defs{$eN},$eN,$tln,"prep",split(" ",$val));
  8923. push @entryFail,$eN." :".$tln." respose:$x" if ($x ne "1");
  8924. push @exec,"$eN $tln exec $val";
  8925. }
  8926. }
  8927. }
  8928. $ret = "failed Entries:\n " .join("\n ",@entryFail) if (scalar@entryFail);
  8929. }
  8930. }
  8931. if (!$found){
  8932. $ret .= "$tmpl not found in file $fName";
  8933. }
  8934. else{
  8935. if(CUL_HM_Get($defs{$name},$name,"param","model") ne "HM-TC-IT-WM-W-EU02"){
  8936. delete $dlf{2};
  8937. delete $dlf{3};
  8938. }
  8939. foreach my $p (keys %dlf){
  8940. my @unprg = grep !/^$/,map {$dlf{$p}{$_}?"":$_} keys %{$dlf{$p}};
  8941. my $cnt = scalar @unprg;
  8942. if ($cnt > 0 && $cnt < 7) {$ret .= "\n $name: incomplete template for prog $p days:".join(",",@unprg);}
  8943. elsif ($cnt == 7) {$ret .= "\n $name: unprogrammed prog $p ";}
  8944. else{
  8945. $ret .= "\n $name: tempList not verified " if (grep {$defs{$name}{READINGS}{$_}{VAL} ne "verified"}
  8946. grep /tempList_State/,
  8947. keys %{$defs{$name}{READINGS}});
  8948. }
  8949. }
  8950. }
  8951. foreach (@exec){
  8952. my @param = split(" ",$_);
  8953. CUL_HM_Set($defs{$param[0]},@param);
  8954. }
  8955. close(aSave);
  8956. return $ret;
  8957. }
  8958. 1;
  8959. =pod
  8960. =item device
  8961. =item summary controls wireless homematic devices
  8962. =item summary_DE steuert HomeMatic devices auf Funk Basis
  8963. =begin html
  8964. <a name="CUL_HM"></a><h3>CUL_HM</h3>
  8965. <ul>
  8966. Support for eQ-3 HomeMatic devices via the <a href="#CUL">CUL</a> or the <a href="#HMLAN">HMLAN</a>.<br>
  8967. <br>
  8968. <a name="CUL_HMdefine"></a><b>Define</b>
  8969. <ul>
  8970. <code><B>define &lt;name&gt; CUL_HM &lt;6-digit-hex-code|8-digit-hex-code&gt;</B></code>
  8971. <br><br>
  8972. Correct device definition is the key for HM environment simple maintenance.
  8973. <br>
  8974. Background to define entities:<br>
  8975. HM devices has a 3 byte (6 digit hex value) HMid - which is key for
  8976. addressing. Each device hosts one or more channels. HMid for a channel is
  8977. the device's HMid plus the channel number (1 byte, 2 digit) in hex.
  8978. Channels should be defined for all multi-channel devices. Channel entities
  8979. cannot be defined if the hosting device does not exist<br> Note: FHEM
  8980. mappes channel 1 to the device if it is not defined explicitely. Therefore
  8981. it does not need to be defined for single channel devices.<br>
  8982. Note: if a device is deleted all assotiated channels will be removed as
  8983. well. <br> An example for a full definition of a 2 channel switch is given
  8984. below:<br>
  8985. <ul><code>
  8986. define livingRoomSwitch CUL_HM 123456<br>
  8987. define LivingroomMainLight CUL_HM 12345601<br>
  8988. define LivingroomBackLight CUL_HM 12345602<br><br></code>
  8989. </ul>
  8990. livingRoomSwitch is the device managing communication. This device is
  8991. defined prior to channels to be able to setup references. <br>
  8992. LivingroomMainLight is channel 01 dealing with status of light, channel
  8993. peers and channel assotiated register. If not defined channel 01 is covered
  8994. by the device entity.<br> LivingRoomBackLight is the second 'channel',
  8995. channel 02. Its definition is mandatory to operate this function.<br><br>
  8996. Sender specials: HM threats each button of remotes, push buttons and
  8997. similar as channels. It is possible (not necessary) to define a channel per
  8998. button. If all channels are defined access to pairing informatin is
  8999. possible as well as access to channel related register. Furthermore names
  9000. make the traces better readable.<br><br>
  9001. define may also be invoked by the <a href="#autocreate">autocreate</a>
  9002. module, together with the necessary subType attribute.
  9003. Usually you issue a <a href="#CULset">hmPairForSec</a> and press the
  9004. corresponding button on the device to be paired, or issue a <a
  9005. href="#CULset">hmPairSerial</a> set command if the device is a receiver
  9006. and you know its serial number. Autocreate will then create a fhem
  9007. device and set all necessary attributes. Without pairing the device
  9008. will not accept messages from fhem. fhem may create the device even if
  9009. the pairing is not successful. Upon a successful pairing you'll see a
  9010. CommandAccepted entry in the details section of the CUL_HM device.<br><br>
  9011. If you cannot use autocreate, then you have to specify:<br>
  9012. <ul>
  9013. <li>the &lt;6-digit-hex-code&gt;or HMid+ch &lt;8-digit-hex-code&gt;<br>
  9014. It is the unique, hardcoded device-address and cannot be changed (no,
  9015. you cannot choose it arbitrarily like for FS20 devices). You may
  9016. detect it by inspecting the fhem log.</li>
  9017. <li>the subType attribute<br>
  9018. which is one of switch dimmer blindActuator remote sensor swi
  9019. pushButton threeStateSensor motionDetector keyMatic winMatic
  9020. smokeDetector</li>
  9021. </ul>
  9022. Without these attributes fhem won't be able to decode device messages
  9023. appropriately. <br><br>
  9024. <b>Notes</b>
  9025. <ul>
  9026. <li>If the interface is a CUL device, the <a href="#rfmode">rfmode </a>
  9027. attribute of the corresponding CUL/CUN device must be set to HomeMatic.
  9028. Note: this mode is BidCos/Homematic only, you will <b>not</b> receive
  9029. FS20/HMS/EM/S300 messages via this device. Previously defined FS20/HMS
  9030. etc devices must be assigned to a different input device (CUL/FHZ/etc).
  9031. </li>
  9032. <li>Currently supported device families: remote, switch, dimmer,
  9033. blindActuator, motionDetector, smokeDetector, threeStateSensor,
  9034. THSensor, winmatic. Special devices: KS550, HM-CC-TC and the KFM100.
  9035. </li>
  9036. <li>Device messages can only be interpreted correctly if the device type is
  9037. known. fhem will extract the device type from a "pairing request"
  9038. message, even if it won't respond to it (see <a
  9039. href="#hmPairSerial">hmPairSerial</a> and <a
  9040. href="#hmPairForSec">hmPairForSec</a> to enable pairing).
  9041. As an alternative, set the correct subType and model attributes, for a
  9042. list of possible subType values see "attr hmdevice ?".</li>
  9043. <a name="HMAES"></a>
  9044. <li>The so called "AES-Encryption" is in reality a signing request: if it is
  9045. enabled, an actor device will only execute a received command, if a
  9046. correct answer to a request generated by the actor is received. This
  9047. means:
  9048. <ul>
  9049. <li>Reaction to commands is noticably slower, as 3 messages are sent
  9050. instead of one before the action is processed by the actor.</li>
  9051. <li>Every command and its final ack from the device is sent in clear,
  9052. so an outside observer will know the status of each device.</li>
  9053. <li>The firmware implementation is buggy: the "toggle" event is executed
  9054. <b>before</b> the answer for the signing request is received, at
  9055. least by some switches (HM-LC-Sw1-Pl and HM-LC-SW2-PB-FM).</li>
  9056. <li>The <a href="#HMLAN">HMLAN</a> configurator will answer signing
  9057. requests by itself, and if it is configured with the 3-byte address
  9058. of a foreign CCU which is still configurerd with the default
  9059. password, it is able to answer signing requests correctly.</li>
  9060. <li>AES-Encryption is useable with a HMLAN or a CUL. When using
  9061. a CUL, the perl-module Crypt::Rijndael needs to be installed.
  9062. Due to the issues above I do not recommend using Homematic
  9063. encryption at all.</li>
  9064. </ul>
  9065. </li>
  9066. </ul>
  9067. </ul><br>
  9068. <a name="CUL_HMset"></a><b>Set</b>
  9069. <ul>
  9070. Note: devices which are normally send-only (remote/sensor/etc) must be set
  9071. into pairing/learning mode in order to receive the following commands.
  9072. <br><br>
  9073. Universal commands (available to most hm devices):
  9074. <ul>
  9075. <li><B>assignHmKey</B><a name="CUL_HMassignHmKey"></a><br>
  9076. Initiates a key-exchange with the device, exchanging the old AES-key of the device with the key with the highest
  9077. index defined by the attribute hmKey* in the HMLAN or VCCU. The old key is determined by the reading aesKeyNbr,
  9078. which specifies the index of the old key when the reading is divided by 2.
  9079. </li>
  9080. <li><B>clear &lt;[rssi|readings|register|msgEvents|attack|all]&gt;</B><a name="CUL_HMclear"></a><br>
  9081. A set of variables can be removed.<br>
  9082. <ul>
  9083. readings: all readings will be deleted. Any new reading will be added usual. May be used to eliminate old data<br>
  9084. register: all captured register-readings in FHEM will be removed. This has NO impact to the values in the device.<br>
  9085. msgEvents: all message event counter will be removed. Also commandstack will be cleared. <br>
  9086. rssi: collected rssi values will be cleared. <br>
  9087. attack: information regarding an attack will be removed. <br>
  9088. all: all of the above. <br>
  9089. </ul>
  9090. </li>
  9091. <li><B>getConfig</B><a name="CUL_HMgetConfig"></a><br>
  9092. Will read major configuration items stored in the HM device. Executed
  9093. on a channel it will read pair Inforamtion, List0, List1 and List3 of
  9094. the 1st internal peer. Furthermore the peerlist will be retrieved for
  9095. teh given channel. If executed on a device the command will get the
  9096. above info or all assotated channels. Not included will be the
  9097. configuration for additional peers. <br> The command is a shortcut
  9098. for a selection of other commands.
  9099. </li>
  9100. <li><B>getRegRaw [List0|List1|List2|List3|List4|List5|List6]&lt;peerChannel&gt; </B><a name="CUL_HMgetRegRaw"></a><br>
  9101. Read registerset in raw format. Description of the registers is beyond
  9102. the scope of this documentation.<br>
  9103. Registers are structured in so called lists each containing a set of
  9104. registers.<br>
  9105. List0: device-level settings e.g. CUL-pairing or dimmer thermal limit
  9106. settings.<br>
  9107. List1: per channel settings e.g. time to drive the blind up and
  9108. down.<br>
  9109. List3: per 'link' settings - means per peer-channel. This is a lot of
  9110. data!. It controlls actions taken upon receive of a trigger from the
  9111. peer.<br>
  9112. List4: settings for channel (button) of a remote<br><br>
  9113. &lt;PeerChannel&gt; paired HMid+ch, i.e. 4 byte (8 digit) value like
  9114. '12345601'. It is mendatory for List 3 and 4 and can be left out for
  9115. List 0 and 1. <br>
  9116. 'all' can be used to get data of each paired link of the channel. <br>
  9117. 'selfxx' can be used to address data for internal channels (associated
  9118. with the build-in switches if any). xx is the number of the channel in
  9119. decimal.<br>
  9120. Note1: execution depends on the entity. If List1 is requested on a
  9121. device rather then a channel the command will retrieve List1 for all
  9122. channels assotiated. List3 with peerChannel = all will get all link
  9123. for all channel if executed on a device.<br>
  9124. Note2: for 'sender' see <a href="#CUL_HMremote">remote</a> <br>
  9125. Note3: the information retrieval may take a while - especially for
  9126. devices with a lot of channels and links. It may be necessary to
  9127. refresh the web interface manually to view the results <br>
  9128. Note4: the direct buttons on a HM device are hidden by default.
  9129. Nevertheless those are implemented as links as well. To get access to
  9130. the 'internal links' it is necessary to issue <br>
  9131. 'set &lt;name&gt; <a href="#CUL_HMregSet">regSet</a> intKeyVisib visib'<br>
  9132. or<br>
  9133. 'set &lt;name&gt; <a href="#CUL_HMregBulk">regBulk</a> RegL_0. 2:81'<br>
  9134. Reset it by replacing '81' with '01'<br> example:<br>
  9135. <ul><code>
  9136. set mydimmer getRegRaw List1<br>
  9137. set mydimmer getRegRaw List3 all <br>
  9138. </code></ul>
  9139. </li>
  9140. <li><B>getSerial</B><a name="CUL_HMgetSerial"></a><br>
  9141. Read serial number from device and write it to attribute serialNr.
  9142. </li>
  9143. <li><B>inhibit [on|off]</B><br>
  9144. Block / unblock all changes to the actor channel, i.e. actor state is frozen
  9145. until inhibit is set off again. Inhibit can be executed on any actor channel
  9146. but obviously not on sensors - would not make any sense.<br>
  9147. Practically it can be used to suspend any notifies as well as peered channel action
  9148. temporarily without the need to delete them. <br>
  9149. Examples:
  9150. <ul><code>
  9151. # Block operation<br>
  9152. set keymatic inhibit on <br><br>
  9153. </ul></code>
  9154. </li>
  9155. <li><B>pair</B><a name="CUL_HMpair"></a><br>
  9156. Pair the device with a known serialNumber (e.g. after a device reset)
  9157. to FHEM Central unit. FHEM Central is usualy represented by CUL/CUNO,
  9158. HMLAN,...
  9159. If paired, devices will report status information to
  9160. FHEM. If not paired, the device won't respond to some requests, and
  9161. certain status information is also not reported. Paring is on device
  9162. level. Channels cannot be paired to central separate from the device.
  9163. See also <a href="#CUL_HMgetpair">getPair</a> and
  9164. <a href="#CUL_HMunpair">unpair</a>.<br>
  9165. Don't confuse pair (to a central) with peer (channel to channel) with
  9166. <a href="#CUL_HMpeerChan">peerChan</a>.<br>
  9167. </li>
  9168. <li><B>peerBulk</B> &lt;peerch1,peerch2,...&gt; [set|unset]<a name="CUL_HMpeerBulk"></a><br>
  9169. peerBulk will add peer channels to the channel. All peers in the list will be added. <br>
  9170. with unset option the peers in the list will be subtracted from the device's peerList.<br>
  9171. peering sets the configuration of this link to its defaults. As peers are not
  9172. added in pairs default will be as defined for 'single' by HM for this device. <br>
  9173. More suffisticated funktionality is provided by
  9174. <a href="#CUL_HMpeerChan">peerChan</a>.<br>
  9175. peerBulk will not delete existing peers, just handle the given peerlist.
  9176. Other already installed peers will not be touched.<br>
  9177. peerBulk may be used to remove peers using <B>unset</B> option while default ist set.<br>
  9178. Main purpose of this command is to re-store data to a device.
  9179. It is recommended to restore register configuration utilising
  9180. <a href="#CUL_HMregBulk">regBulk</a> subsequent. <br>
  9181. Example:<br>
  9182. <ul><code>
  9183. set myChannel peerBulk 12345601,<br>
  9184. set myChannel peerBulk self01,self02,FB_Btn_04,FB_Btn_03,<br>
  9185. set myChannel peerBulk 12345601 unset # remove peer 123456 channel 01<br>
  9186. </code></ul>
  9187. </li>
  9188. <li><B>regBulk &lt;reg List&gt;:&lt;peer&gt; &lt;addr1:data1&gt; &lt;addr2:data2&gt;...</B><a name="CUL_HMregBulk"></a><br>
  9189. This command will replace the former regRaw. It allows to set register
  9190. in raw format. Its main purpose is to restore a complete register list
  9191. to values secured before. <br>
  9192. Values may be read by <a href="#CUL_HMgetConfig">getConfig</a>. The
  9193. resulting readings can be used directly for this command.<br>
  9194. &lt;reg List&gt; is the list data should be written to. Format could be
  9195. '00', 'RegL_00', '01'...<br>
  9196. &lt;peer&gt; is an optional adder in case the list requires a peer.
  9197. The peer can be given as channel name or the 4 byte (8 chars) HM
  9198. channel ID.<br>
  9199. &lt;addr1:data1&gt; is the list of register to be written in hex
  9200. format.<br>
  9201. Example:<br>
  9202. <ul><code>
  9203. set myChannel regBulk RegL_00. 02:01 0A:17 0B:43 0C:BF 15:FF 00:00<br>
  9204. RegL_03.FB_Btn_07
  9205. 01:00 02:00 03:00 04:32 05:64 06:00 07:FF 08:00 09:FF 0A:01 0B:44 0C:54 0D:93 0E:00 0F:00 11:C8 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 1A:00 1B:00 1C:00 1D:FF 1E:93 1F:00 81:00 82:00 83:00 84:32 85:64 86:00 87:FF 88:00 89:FF 8A:21 8B:44 8C:54 8D:93 8E:00 8F:00 91:C8 92:00 93:00 94:00 95:00 96:00 97:00 98:00 99:00 9A:00 9B:00 9C:00 9D:05 9E:93 9F:00 00:00<br>
  9206. set myblind regBulk 01 0B:10<br>
  9207. set myblind regBulk 01 0C:00<br>
  9208. </code></ul>
  9209. myblind will set the max drive time up for a blind actor to 25,6sec
  9210. </li>
  9211. <li><B>regSet [prep|exec] &lt;regName&gt; &lt;value&gt; &lt;peerChannel&gt;</B><a name="CUL_HMregSet"></a><br>
  9212. For some major register a readable version is implemented supporting
  9213. register names &lt;regName&gt; and value conversionsing. Only a subset
  9214. of register can be supproted.<br>
  9215. Optional parameter [prep|exec] allowes to pack the messages and therefore greatly
  9216. improve data transmission.
  9217. Usage is to send the commands with paramenter "prep". The data will be accumulated for send.
  9218. The last command must have the parameter "exec" in order to transmitt the information.<br>
  9219. &lt;value&gt; is the data in human readable manner that will be written
  9220. to the register.<br>
  9221. &lt;peerChannel&gt; is required if this register is defined on a per
  9222. 'peerChan' base. It can be set to '0' other wise.See <a
  9223. href="#CUL_HMgetRegRaw">getRegRaw</a> for full description<br>
  9224. Supported register for a device can be explored using<br>
  9225. <ul><code>set regSet ? 0 0</code></ul>
  9226. Condensed register description will be printed
  9227. using<br>
  9228. <ul><code>set regSet &lt;regname&gt; ? 0</code></ul>
  9229. </li>
  9230. <li><B>reset</B><a name="CUL_HMreset"></a><br>
  9231. Factory reset the device. You need to pair it again to use it with
  9232. fhem.
  9233. </li>
  9234. <li><B>sign [on|off]</B><a name="CUL_HMsign"></a><br>
  9235. Activate or deactivate signing (also called AES encryption, see the <a
  9236. href="#HMAES">note</a> above). Warning: if the device is attached via
  9237. a CUL, you need to install the perl-module Crypt::Rijndael to be
  9238. able to switch it (or deactivate signing) from fhem.
  9239. </li>
  9240. <li><B>statusRequest</B><a name="CUL_HMstatusRequest"></a><br>
  9241. Update device status. For multichannel devices it should be issued on
  9242. an per channel base
  9243. </li>
  9244. <li><B>unpair</B><a name="CUL_HMunpair"></a><br>
  9245. "Unpair" the device, i.e. make it available to pair with other master
  9246. devices. See <a href="#CUL_HMpair">pair</a> for description.</li>
  9247. <li><B>virtual &lt;number of buttons&gt;</B><a name="CUL_HMvirtual"></a><br>
  9248. configures a defined curcuit as virtual remote controll. Then number
  9249. of button being added is 1 to 255. If the command is issued a second
  9250. time for the same entity additional buttons will be added. <br>
  9251. Example for usage:
  9252. <ul><code>
  9253. define vRemote CUL_HM 100000 # the selected HMid must not be in use<br>
  9254. set vRemote virtual 20 # define 20 button remote controll<br>
  9255. set vRemote_Btn4 peerChan 0 &lt;actorchannel&gt; # peers Button 4 and 5 to the given channel<br>
  9256. set vRemote_Btn4 press<br>
  9257. set vRemote_Btn5 press long<br>
  9258. </code></ul>
  9259. see also <a href="#CUL_HMpress">press</a>
  9260. </li>
  9261. <li><B>deviceRename &lt;newName&gt;</B><a name="CUL_HMdeviceRename"></a><br>
  9262. rename the device and all its channels.
  9263. </li>
  9264. <li><B>fwUpdate [onlyEnterBootLoader] &lt;filename&gt; [&lt;waitTime&gt;]</B><br>
  9265. update Fw of the device. User must provide the appropriate file.
  9266. waitTime can be given optionally. In case the device needs to be set to
  9267. FW update mode manually this is the time the system will wait.<br>
  9268. "onlyEnterBootLoader" tells the device to enter the boot loader so it can be
  9269. flashed using the eq3 firmware update tool. Mainly useful for flush-mounted devices
  9270. in FHEM environments solely using HM-LAN adapters.
  9271. </li>
  9272. </ul>
  9273. <br>
  9274. <B>subType dependent commands:</B>
  9275. <ul>
  9276. <br>
  9277. <li>switch
  9278. <ul>
  9279. <li><B>on</B> <a name="CUL_HMon"> </a> - set level to 100%</li>
  9280. <li><B>off</B><a name="CUL_HMoff"></a> - set level to 0%</li>
  9281. <li><B>on-for-timer &lt;sec&gt;</B><a name="CUL_HMonForTimer"></a> -
  9282. set the switch on for the given seconds [0-85825945].<br> Note:
  9283. off-for-timer like FS20 is not supported. It may to be programmed
  9284. thru channel register.</li>
  9285. <li><B>on-till &lt;time&gt;</B><a name="CUL_HMonTill"></a> - set the switch on for the given end time.<br>
  9286. <ul><code>set &lt;name&gt; on-till 20:32:10<br></code></ul>
  9287. Currently a max of 24h is supported with endtime.<br>
  9288. </li>
  9289. <li><B>press &lt;[short|long]&gt; &lt;[on|off|&lt;peer&gt;]&gt; &lt;btnNo&gt;</B><a name="CUL_HMpress"></a><br>
  9290. simulate a press of the local button or direct connected switch of the actor.<br>
  9291. <B>[short|long]</B> select simulation of short or long press of the button.
  9292. Parameter is optional, short is default<br>
  9293. <B>[on|off|&lt;peer&gt;]</B> is relevant for devices with direct buttons per channel (blind or dimmer).
  9294. Those are available for dimmer and blind-actor, usually not for switches<br>
  9295. <B>&lt;peer&gt;</B> allows to stimulate button-press of any peer of the actor.
  9296. i.e. if the actor is peered to any remote, virtual or io (HMLAN/CUL)
  9297. press can trigger the action defined. <br>
  9298. <B>[noBurst]</B> relevant for virtual only <br>
  9299. It will cause the command being added to the command queue of the peer. <B>No</B> burst is
  9300. issued subsequent thus the command is pending until the peer wakes up. It therefore
  9301. <B>delays the button-press</B>, but will cause less traffic and performance cost. <br>
  9302. <B>Example:</B>
  9303. <code>
  9304. set actor press # trigger short of internal peer self assotiated to the channel<br>
  9305. set actor press long # trigger long of internal peer self assotiated to the channel<br>
  9306. set actor press on # trigger short of internal peer self related to 'on'<br>
  9307. set actor press long off # trigger long of internal peer self related to 'of'<br>
  9308. set actor press long FB_Btn01 # trigger long peer FB button 01<br>
  9309. set actor press long FB_chn-8 # trigger long peer FB button 08<br>
  9310. set actor press self01 # trigger short of internal peer 01<br>
  9311. set actor press fhem02 # trigger short of FHEM channel 2<br>
  9312. </code>
  9313. </li>
  9314. <li><B>pressL &lt;peer&gt;</B><a name="CUL_HMpressL"></a><br>
  9315. simulates a long press for a given peer. See press for details
  9316. </li>
  9317. <li><B>pressS &lt;peer&gt;</B><a name="CUL_HMpressS"></a><br>
  9318. simulates a long press for a given peer. See press for details
  9319. </li>
  9320. <li><B>toggle</B><a name="CUL_HMtoggle"></a> - toggle the Actor. It will switch from any current
  9321. level to off or from off to 100%</li>
  9322. </ul>
  9323. <br>
  9324. </li>
  9325. <li>dimmer, blindActuator<br>
  9326. Dimmer may support virtual channels. Those are autocrated if applicable. Usually there are 2 virtual channels
  9327. in addition to the primary channel. Virtual dimmer channels are inactive by default but can be used in
  9328. in parallel to the primay channel to control light. <br>
  9329. Virtual channels have default naming SW&lt;channel&gt;_V&lt;no&gt;. e.g. Dimmer_SW1_V1 and Dimmer_SW1_V2.<br>
  9330. Dimmer virtual channels are completely different from FHEM virtual buttons and actors but
  9331. are part of the HM device. Documentation and capabilities for virtual channels is out of scope.<br>
  9332. <ul>
  9333. <li><B>0 - 100 [on-time] [ramp-time]</B><br>
  9334. set the actuator to the given value (in percent)
  9335. with a resolution of 0.5.<br>
  9336. Optional for dimmer on-time and ramp time can be choosen, both in seconds with 0.1s granularity.<br>
  9337. On-time is analog "on-for-timer".<br>
  9338. Ramp-time default is 2.5s, 0 means instantanous<br>
  9339. </li>
  9340. <li><B><a href="#CUL_HMon">on</a></B></li>
  9341. <li><B><a href="#CUL_HMoff">off</a></B></li>
  9342. <li><B><a href="#CUL_HMpress">press &lt;[short|long]&gt;&lt;[on|off]&gt;</a></B></li>
  9343. <li><B><a href="#CUL_HMtoggle">toggle</a></B></li>
  9344. <li><B>toggleDir</B><a name="CUL_HMtoggleDir"></a> - toggled drive direction between up/stop/down/stop</li>
  9345. <li><B><a href="#CUL_HMonForTimer">on-for-timer &lt;sec&gt;</a></B> - Dimmer only! <br></li>
  9346. <li><B><a href="#CUL_HMonTill">on-till &lt;time&gt;</a></B> - Dimmer only! <br></li>
  9347. <li><B>stop</B> - stop motion (blind) or dim ramp</li>
  9348. <li><B>old</B> - switch back to old value after a change. Dimmer only.</li>
  9349. <li><B>pct &lt;level&gt [&lt;ontime&gt] [&lt;ramptime&gt]</B> - set actor to a desired <B>absolut level</B>.<br>
  9350. Optional ontime and ramptime could be given for dimmer.<br>
  9351. ontime may be time in seconds. It may also be entered as end-time in format hh:mm:ss
  9352. </li>
  9353. <li><B>up [changeValue] [&lt;ontime&gt] [&lt;ramptime&gt]</B> dim up one step</li>
  9354. <li><B>down [changeValue] [&lt;ontime&gt] [&lt;ramptime&gt]</B> dim up one step<br>
  9355. changeValue is optional an gives the level to be changed up or down in percent. Granularity is 0.5%, default is 10%. <br>
  9356. ontime is optional an gives the duration of the level to be kept. '0' means forever and is default.<br>
  9357. ramptime is optional an defines the change speed to reach the new level. It is meaningful only for dimmer.
  9358. <br></li>
  9359. </ul>
  9360. <br>
  9361. </li>
  9362. <li>remotes, pushButton<a name="CUL_HMremote"></a><br>
  9363. This class of devices does not react on requests unless they are put
  9364. to learn mode. FHEM obeys this behavior by stacking all requests until
  9365. learn mode is detected. Manual interaction of the user is necessary to
  9366. activate learn mode. Whether commands are pending is reported on
  9367. device level with parameter 'protCmdPend'.
  9368. </li>
  9369. <ul>
  9370. <li><B>peerIODev [IO] &lt;btn_no&gt; [<u>set</u>|unset]</B><a name="CUL_HMpeerIODev"></a><br>
  9371. The command is similar to <B><a href="#CUL_HMpeerChan">peerChan</a></B>.
  9372. While peerChan
  9373. is executed on a remote and peers any remote to any actor channel peerIODev is
  9374. executed on an actor channel and peer this to an channel of an FHEM IO device.<br>
  9375. An IO device according to eQ3 supports up to 50 virtual buttons. Those
  9376. will be peered/unpeerd to the actor. <a href="CUL_HMpress">press</a> can be
  9377. used to stimulate the related actions as defined in the actor register.
  9378. <li><B>peerChan &lt;btn_no&gt; &lt;actChan&gt; [single|<u>dual</u>|reverse][<u>set</u>|unset] [<u>both</u>|actor|remote]</B>
  9379. <a name="CUL_HMpeerChan"></a><br>
  9380. peerChan will establish a connection between a sender- <B>channel</B> and
  9381. an actuator-<B>channel</B> called link in HM nomenclatur. Peering must not be
  9382. confused with pairing.<br>
  9383. <B>Pairing</B> refers to assign a <B>device</B> to the central.<br>
  9384. <B>Peering</B> refers to virtally connect two <B>channels</B>.<br>
  9385. Peering allowes direkt interaction between sender and aktor without
  9386. the necessity of a CCU<br>
  9387. Peering a sender-channel causes the sender to expect an ack from -each-
  9388. of its peers after sending a trigger. It will give positive feedback (e.g. LED green)
  9389. only if all peers acknowledged.<br>
  9390. Peering an aktor-channel will setup a parameter set which defines the action to be
  9391. taken once a trigger from -this- peer arrived. In other words an aktor will <br>
  9392. - process trigger from peers only<br>
  9393. - define the action to be taken dedicated for each peer's trigger<br>
  9394. An actor channel will setup a default action upon peering - which is actor dependant.
  9395. It may also depend whether one or 2 buttons are peered <B>in one command</B>.
  9396. A swich may setup oen button for 'on' and the other for 'off' if 2 button are
  9397. peered. If only one button is peered the funktion will likely be 'toggle'.<br>
  9398. The funtion can be modified by programming the register (aktor dependant).<br>
  9399. Even though the command is executed on a remote or push-button it will
  9400. as well take effect on the actuator directly. Both sides' peering is
  9401. virtually independant and has different impact on sender and receiver
  9402. side.<br>
  9403. Peering of one actuator-channel to multiple sender-channel as
  9404. well as one sender-channel to multiple Actuator-channel is
  9405. possible.<br>
  9406. &lt;actChan&gt; is the actuator-channel to be peered.<br>
  9407. &lt;btn_no&gt; is the sender-channel (button) to be peered. If
  9408. 'single' is choosen buttons are counted from 1. For 'dual' btn_no is
  9409. the number of the Button-pair to be used. I.e. '3' in dual is the
  9410. 3rd button pair correcponding to button 5 and 6 in single mode.<br>
  9411. If the command is executed on a channel the btn_no is ignored.
  9412. It needs to be set, should be 0<br>
  9413. [single|dual]: this mode impacts the default behavior of the
  9414. Actuator upon using this button. E.g. a dimmer can be learned to a
  9415. single button or to a button pair. <br>
  9416. Defaults to dual.<br>
  9417. 'dual' (default) Button pairs two buttons to one actuator. With a
  9418. dimmer this means one button for dim-up and one for dim-down. <br>
  9419. 'reverse' identical to dual - but button order is reverse.<br>
  9420. 'single' uses only one button of the sender. It is useful for e.g. for
  9421. simple switch actuator to toggle on/off. Nevertheless also dimmer can
  9422. be learned to only one button. <br>
  9423. [set|unset]: selects either enter a peering or remove it.<br>
  9424. Defaults to set.<br>
  9425. 'set' will setup peering for the channels<br>
  9426. 'unset' will remove the peering for the channels<br>
  9427. [actor|remote|both] limits the execution to only actor or only remote.
  9428. This gives the user the option to redo the peering on the remote
  9429. channel while the settings in the actor will not be removed.<br>
  9430. Defaults to both.<br>
  9431. Example:
  9432. <ul><code>
  9433. set myRemote peerChan 2 mySwActChn single set #peer second button to an actuator channel<br>
  9434. set myRmtBtn peerChan 0 mySwActChn single set #myRmtBtn is a button of the remote. '0' is not processed here<br>
  9435. set myRemote peerChan 2 mySwActChn dual set #peer button 3 and 4<br>
  9436. set myRemote peerChan 3 mySwActChn dual unset #remove peering for button 5 and 6<br>
  9437. set myRemote peerChan 3 mySwActChn dual unset aktor #remove peering for button 5 and 6 in actor only<br>
  9438. set myRemote peerChan 3 mySwActChn dual set remote #peer button 5 and 6 on remote only. Link settings il mySwActChn will be maintained<br>
  9439. </code></ul>
  9440. </li>
  9441. </li>
  9442. </ul>
  9443. <li>virtual<a name="CUL_HMvirtual"></a><br>
  9444. <ul>
  9445. <li><B><a href="#CUL_HMpeerChan">peerChan</a></B> see remote</li>
  9446. <li><B><a name="CUL_HMpress"></a>press [long|short] [&lt;peer&gt;] [&lt;repCount&gt;] [&lt;repDelay&gt;] </B>
  9447. <ul>
  9448. simulates button press for an actor from a peered sensor.
  9449. will be sent of type "long".
  9450. <li>[long|short] defines whether long or short press shall be simulated. Defaults to short</li>
  9451. <li>[&lt;peer&gt;] define which peer's trigger shall be simulated.Defaults to self(channelNo).</li>
  9452. <li>[&lt;repCount&gt;] Valid for long press only. How long shall the button be pressed? Number of repetition of the messages is defined. Defaults to 1</li>
  9453. <li>[&lt;repDelay&gt;] Valid for long press only. defines wait time between the single messages. </li>
  9454. </ul>
  9455. </li>
  9456. <li><B>virtTemp &lt;[off -10..50]&gt;<a name="CUL_HMvirtTemp"></a></B>
  9457. simulates a thermostat. If peered to a device it periodically sends the
  9458. temperature until "off" is given. See also <a href="#CUL_HMvirtHum">virtHum</a><br>
  9459. </li>
  9460. <li><B>virtHum &lt;[off -10..50]&gt;<a name="CUL_HMvirtHum"></a></B>
  9461. simulates the humidity part of a thermostat. If peered to a device it periodically sends
  9462. the temperature and humidity until both are "off". See also <a href="#CUL_HMvirtTemp">virtTemp</a><br>
  9463. </li>
  9464. <li><B>valvePos &lt;[off 0..100]&gt;<a name="CUL_HMvalvePos"></a></B>
  9465. stimulates a VD<br>
  9466. </li>
  9467. </ul>
  9468. </li>
  9469. <li>smokeDetector<br>
  9470. Note: All these commands work right now only if you have more then one
  9471. smoekDetector, and you peered them to form a group. For issuing the
  9472. commands you have to use the master of this group, and currently you
  9473. have to guess which of the detectors is the master.<br>
  9474. smokeDetector can be setup to teams using
  9475. <a href="#CUL_HMpeerChan">peerChan</a>. You need to peer all
  9476. team-members to the master. Don't forget to also peerChan the master
  9477. itself to the team - i.e. peer it to itself! doing that you have full
  9478. controll over the team and don't need to guess.<br>
  9479. <ul>
  9480. <li><B>teamCall</B> - execute a network test to all team members</li>
  9481. <li><B>teamCallBat</B> - execute a network test simulate bat low</li>
  9482. <li><B>alarmOn</B> - initiate an alarm</li>
  9483. <li><B>alarmOff</B> - switch off the alarm</li>
  9484. </ul>
  9485. </li>
  9486. <li>4Dis (HM-PB-4DIS-WM|HM-RC-Dis-H-x-EU|ROTO_ZEL-STG-RM-DWT-10)
  9487. <ul>
  9488. <li><B>text &lt;btn_no&gt; [on|off] &lt;text1&gt; &lt;text2&gt;</B><br>
  9489. Set the text on the display of the device. To this purpose issue
  9490. this set command first (or a number of them), and then choose from
  9491. the teach-in menu of the 4Dis the "Central" to transmit the data.<br>
  9492. If used on a channel btn_no and on|off must not be given but only pure text.<br>
  9493. \_ will be replaced by blank character.<br>
  9494. Example:
  9495. <ul><code>
  9496. set 4Dis text 1 on On Lamp<br>
  9497. set 4Dis text 1 off Kitchen Off<br>
  9498. <br>
  9499. set 4Dis_chn4 text Kitchen Off<br>
  9500. </code></ul>
  9501. </li>
  9502. </ul>
  9503. <br></li>
  9504. <li>Climate-Control (HM-CC-TC)
  9505. <ul>
  9506. <li><B>desired-temp &lt;temp&gt;</B><br>
  9507. Set different temperatures. &lt;temp&gt; must be between 6 and 30
  9508. Celsius, and precision is half a degree.</li>
  9509. <li><B>tempListSat [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9510. <li><B>tempListSun [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9511. <li><B>tempListMon [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9512. <li><B>tempListTue [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9513. <li><B>tempListThu [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9514. <li><B>tempListWed [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9515. <li><B>tempListFri [prep|exec] HH:MM temp ... 24:00 temp</B><br>
  9516. Specify a list of temperature intervals. Up to 24 intervals can be
  9517. specified for each week day, the resolution is 10 Minutes. The
  9518. last time spec must always be 24:00.<br>
  9519. Example: until 6:00 temperature shall be 19, from then until 23:00 temperature shall be
  9520. 22.5, thereafter until midnight, 19 degrees celsius is desired.<br>
  9521. <code> set th tempListSat 06:00 19 23:00 22.5 24:00 19<br></code>
  9522. </li>
  9523. <br>
  9524. <li><B>tempListTmpl =>"[verify|restore] [[ &lt;file&gt; :]templateName] ...</B><br>
  9525. The tempList for one or more devices can be stored in a file. User can compare the
  9526. tempList in the file with the data read from the device. <br>
  9527. Restore will write the tempList to the device.<br>
  9528. Default opeartion is verify.<br>
  9529. Default file is tempList.cfg.<br>
  9530. Default templateName is the name of the actor<br>
  9531. Default for file and templateName can be set with attribut <B>tempListTmpl</B><br>
  9532. Example for templist file. room1 and room2 are the names of the template: <br>
  9533. <code>entities:room1
  9534. tempListSat>08:00 16.0 15:00 18.0 21:30 19.0 24:00 14.0
  9535. tempListSun>08:00 16.0 15:00 18.0 21:30 19.0 24:00 14.0
  9536. tempListMon>07:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  9537. tempListTue>07:00 16.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 15.0
  9538. tempListWed>07:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  9539. tempListThu>07:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  9540. tempListFri>07:00 16.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  9541. entities:room2
  9542. tempListSat>08:00 14.0 15:00 18.0 21:30 19.0 24:00 14.0
  9543. tempListSun>08:00 14.0 15:00 18.0 21:30 19.0 24:00 14.0
  9544. tempListMon>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
  9545. tempListTue>07:00 14.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 15.0
  9546. tempListWed>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
  9547. tempListThu>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
  9548. tempListFri>07:00 14.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  9549. </code>
  9550. Specials:<br>
  9551. <li>none: template will be ignored</li>
  9552. <li>defaultWeekplan: as default each day is set to 18.0 degree.
  9553. useful if peered to a TC controller. Implicitely teh weekplan of TC will be used.</li>
  9554. </li>
  9555. <li><B>tempTmplSet =>"[[ &lt;file&gt; :]templateName]</B><br>
  9556. Set the attribut and apply the change to the device
  9557. </li>
  9558. <li><B>templateDel =>" &lt;template&gt; </B><br>
  9559. Delete templateentry for this entity
  9560. </li>
  9561. <li><B>partyMode &lt;HH:MM&gt;&lt;durationDays&gt;</B><br>
  9562. set control mode to party and device ending time. Add the time it ends
  9563. and the <b>number of days</b> it shall last. If it shall end next day '1'
  9564. must be entered<br></li>
  9565. <li><B>sysTime</B><br>
  9566. set time in climate channel to system time</li>
  9567. </ul><br>
  9568. </li>
  9569. <li>Climate-Control (HM-CC-RT-DN|HM-CC-RT-DN-BoM)
  9570. <ul>
  9571. <li><B>controlMode &lt;auto|boost|day|night&gt;</B><br></li>
  9572. <li><B>controlManu &lt;temp&gt;</B><br></li>
  9573. <li><B>controlParty &lt;temp&gt;&lt;startDate&gt;&lt;startTime&gt;&lt;endDate&gt;&lt;endTime&gt;</B><br>
  9574. set control mode to party, define temp and timeframe.<br>
  9575. example:<br>
  9576. <code>set controlParty 15 03.8.13 20:30 5.8.13 11:30</code></li>
  9577. <li><B>sysTime</B><br>
  9578. set time in climate channel to system time</li>
  9579. <li><B>desired-temp &lt;temp&gt;</B><br>
  9580. Set different temperatures. &lt;temp&gt; must be between 6 and 30
  9581. Celsius, and precision is half a degree.</li>
  9582. <li><B>tempListSat [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9583. <li><B>tempListSun [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9584. <li><B>tempListMon [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9585. <li><B>tempListTue [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9586. <li><B>tempListThu [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9587. <li><B>tempListWed [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  9588. <li><B>tempListFri [prep|exec] HH:MM temp ... 24:00 temp</B><br>
  9589. Specify a list of temperature intervals. Up to 24 intervals can be
  9590. specified for each week day, the resolution is 10 Minutes. The
  9591. last time spec must always be 24:00.<br>
  9592. Optional parameter [prep|exec] allowes to pack the messages and therefore greatly
  9593. improve data transmission. This is especially helpful if device is operated in wakeup mode.
  9594. Usage is to send the commands with paramenter "prep". The data will be accumulated for send.
  9595. The last command must have the parameter "exec" in order to transmitt the information.<br>
  9596. Example: until 6:00 temperature shall be 19, from then until 23:00 temperature shall be
  9597. 22.5, thereafter until midnight, 19 degrees celsius is desired.<br>
  9598. <code> set th tempListSat 06:00 19 23:00 22.5 24:00 19<br></code>
  9599. <br>
  9600. <code> set th tempListSat prep 06:00 19 23:00 22.5 24:00 19<br>
  9601. set th tempListSun prep 06:00 19 23:00 22.5 24:00 19<br>
  9602. set th tempListMon prep 06:00 19 23:00 22.5 24:00 19<br>
  9603. set th tempListTue exec 06:00 19 23:00 22.5 24:00 19<br></code>
  9604. </li>
  9605. </ul><br>
  9606. </li>
  9607. <li>OutputUnit (HM-OU-LED16)
  9608. <ul>
  9609. <li><B>led [off|red|green|yellow]</B><br>
  9610. switches the LED of the channel to the color. If the command is
  9611. executed on a device it will set all LEDs to the specified
  9612. color.<br>
  9613. For Expert all LEDs can be set individual by providing a 8-digit hex number to the device.<br></li>
  9614. <li><B>ilum &lt;brightness&gt;&lt;duration&gt; </B><br>
  9615. &lt;brightness&gt; [0-15] of backlight.<br>
  9616. &lt;duration&gt; [0-127] in sec. 0 is permanent 'on'.<br></li>
  9617. </ul><br>
  9618. </li>
  9619. <li>OutputUnit (HM-OU-CFM-PL)
  9620. <ul>
  9621. <li><B>led &lt;color&gt;[,&lt;color&gt;..] [&lt;repeat&gt..]</B><br>
  9622. Possible colors are [redL|greenL|yellowL|redS|greenS|yellowS|pause]. A
  9623. sequence of colors can be given separating the color entries by ','.
  9624. White spaces must not be used in the list. 'S' indicates short and
  9625. 'L' long ilumination. <br>
  9626. <b>repeat</b> defines how often the sequence shall be executed. Defaults to 1.<br>
  9627. </li>
  9628. <li><B>playTone &lt;MP3No&gt[,&lt;MP3No&gt..] [&lt;repeat&gt;] [&lt;volume&gt;]</B><br>
  9629. Play a series of tones. List is to be entered separated by ','. White
  9630. spaces must not be used in the list.<br>
  9631. <b>replay</b> can be entered to repeat the last sound played once more.<br>
  9632. <b>repeat</b> defines how often the sequence shall be played. Defaults to 1.<br>
  9633. <b>volume</b> is defined between 0 and 10. 0 stops any sound currently playing. Defaults to 10 (100%).<br>
  9634. Example:
  9635. <ul><code>
  9636. # "hello" in display, symb bulb on, backlight, beep<br>
  9637. set cfm_Mp3 playTone 3 # MP3 title 3 once<br>
  9638. set cfm_Mp3 playTone 3 3 # MP3 title 3 3 times<br>
  9639. set cfm_Mp3 playTone 3,6,8,3,4 # MP3 title list 3,6,8,3,4 once<br>
  9640. set cfm_Mp3 playTone 3,6,8,3,4 255# MP3 title list 3,6,8,3,4 255 times<br>
  9641. set cfm_Mp3 playTone replay # repeat last sequence<br>
  9642. <br>
  9643. set cfm_Led led redL 4 # led red blink 3 times long<br>
  9644. set cfm_Led led redS,redS,redS,redL,redL,redL,redS,redS,redS 255 # SOS 255 times<br>
  9645. </ul></code>
  9646. </li>
  9647. </ul><br>
  9648. </li>
  9649. <li>HM-RC-19xxx
  9650. <ul>
  9651. <li><B>alarm &lt;count&gt;</B><br>
  9652. issue an alarm message to the remote<br></li>
  9653. <li><B>service &lt;count&gt;</B><br>
  9654. issue an service message to the remote<br></li>
  9655. <li><B>symbol &lt;symbol&gt; [set|unset]</B><br>
  9656. activate a symbol as available on the remote.<br></li>
  9657. <li><B>beep [off|1|2|3]</B><br>
  9658. activate tone<br></li>
  9659. <li><B>backlight [off|on|slow|fast]</B><br>
  9660. activate backlight<br></li>
  9661. <li><B>display &lt;text&gt; comma unit tone backlight &lt;symbol(s)&gt;
  9662. </B><br>
  9663. control display of the remote<br>
  9664. &lt;text&gt; : up to 5 chars <br>
  9665. comma : 'comma' activates the comma, 'no' leaves it off <br>
  9666. [unit] : set the unit symbols.
  9667. [off|Proz|Watt|x3|C|x5|x6|x7|F|x9|x10|x11|x12|x13|x14|x15]. Currently
  9668. the x3..x15 display is not tested. <br>
  9669. tone : activate one of the 3 tones [off|1|2|3]<br>
  9670. backlight: activate backlight flash mode [off|on|slow|fast]<br>
  9671. &lt;symbol(s)&gt; activate symbol display. Multople symbols can be
  9672. acticated at the same time, concatinating them comma separated. Don't
  9673. use spaces here. Possiblesymbols are
  9674. [bulb|switch|window|door|blind|scene|phone|bell|clock|arrowUp|arrowDown]<br><br>
  9675. Example:
  9676. <ul><code>
  9677. # "hello" in display, symb bulb on, backlight, beep<br>
  9678. set FB1 display Hello no off 1 on bulb<br>
  9679. # "1234,5" in display with unit 'W'. Symbols scene,phone,bell and
  9680. # clock are active. Backlight flashing fast, Beep is second tone<br>
  9681. set FB1 display 12345 comma Watt 2 fast scene,phone,bell,clock
  9682. </ul></code>
  9683. </li>
  9684. </ul><br>
  9685. </li>
  9686. <li>HM-Dis-WM55
  9687. <ul>
  9688. <li><B>displayWM help </B><br>
  9689. <B>displayWM [long|short] &lt;text1&gt; &lt;color1&gt; &lt;icon1&gt; ... &lt;text6&gt; &lt;color6&gt; &lt;icon6&gt;</B><br>
  9690. <B>displayWM [long|short] &lt;lineX&gt; &lt;text&gt; &lt;color&gt; &lt;icon&gt;</B><br>
  9691. up to 6 lines can be addressed.<br>
  9692. <B>lineX</B> line number that shall be changed. If this is set the 3 parameter of a line can be adapted. <br>
  9693. <B>textNo</B> is the text to be dispalyed in line No. The text is assotiated with the text defined for the buttons.
  9694. txt&lt;BtnNo&gt;_&lt;lineNo&gt; references channel 1 to 10 and their lines 1 or 2.
  9695. Alternaly a free text of up to 12 char can be used<br>
  9696. <B>color</B> is one white, red, orange, yellow, green, blue<br>
  9697. <B>icon</B> is one off, on, open, closed, error, ok, noIcon<br>
  9698. Example:
  9699. <ul><code>
  9700. set disp01 displayWM short txt02_2 green noIcon txt10_1 red error txt05_2 yellow closed txt02_2 orange open <br>
  9701. set disp01 displayWM long line3 txt02_2 green noIcon<br>
  9702. set disp01 displayWM long line2 nc yellow noIcon<br>
  9703. set disp01 displayWM long line6 txt02_2<br>
  9704. set disp01 displayWM long line1 nc nc closed<br>
  9705. </ul></code>
  9706. </li>
  9707. </ul><br>
  9708. </li>
  9709. <li>HM-Dis-EP-WM55
  9710. <ul>
  9711. <li><B>displayEP help </B><br>
  9712. <B>displayEP &lt;text1,icon1:text2,icon2:text3,icon3&gt; &lt;sound&gt; &lt;repetition&gt; &lt;pause&gt; &lt;signal&gt;</B><br>
  9713. up to 3 lines can be addressed.<br>
  9714. If help is given a <i><B>help</B></i> on the command is given. Options for all parameter will be given.<br>
  9715. <B>textx</B> 12 char text for the given line.
  9716. If empty the value as per reading will be transmittet - i.e. typically no change.
  9717. text0-9 will display predefined text of channels 4 to 8.
  9718. 0xHH allows to display a single char in hex format.<br>
  9719. <B>iconx</B> Icon for this line.
  9720. If empty the value as per reading will be transmittet - i.e. typically no change.<br>
  9721. <B>sound</B> sound to be played<br>
  9722. <B>repetition</B> 0..15 <br>
  9723. <B>pause</B> 1..160<br>
  9724. <B>signal</B> signal color to be displayed<br>
  9725. <br>
  9726. <B>Note: param reWriteDisplayxx</B> <br>
  9727. <li>
  9728. upon button press the device will overwrite the 3 middles lines. When set <br>
  9729. attr chan param reWriteDisplayxx<br>
  9730. the 3 lines will be rewritten to the latest value after xx seconds. xx is between 01 and 99<br>
  9731. </li>
  9732. </li>
  9733. </ul><br>
  9734. </li>
  9735. <li>keyMatic<br><br>
  9736. <ul>The Keymatic uses the AES signed communication. Control
  9737. of the Keymatic is possible with the HM-LAN adapter and the CUL.
  9738. To control the KeyMatic with a CUL, the perl-module Crypt::Rijndael
  9739. needs to be installed.</ul><br>
  9740. <ul>
  9741. <li><B>lock</B><br>
  9742. The lock bolt moves to the locking position<br></li>
  9743. <li><B>unlock [sec]</B><br>
  9744. The lock bolt moves to the unlocking position.<br>
  9745. [sec]: Sets the delay in seconds after the lock automatically locked again.<br>
  9746. 0 - 65535 seconds</li>
  9747. <li><B>open [sec]</B><br>
  9748. Unlocked the door so that the door can be opened.<br>
  9749. [sec]: Sets the delay in seconds after the lock automatically locked
  9750. again.<br>0 - 65535 seconds</li>
  9751. </ul>
  9752. </li>
  9753. <li>winMatic <br><br>
  9754. <ul>winMatic provides 2 channels, one for the window control and a second
  9755. for the accumulator.</ul><br>
  9756. <ul>
  9757. <li><B>level &lt;level&gt; &lt;relockDelay&gt; &lt;speed&gt;</B><br>
  9758. set the level. <br>
  9759. &lt;level&gt;: range is 0 to 100%<br>
  9760. &lt;relockDelay&gt;: range 0 to 65535 sec. 'ignore' can be used to igneore the value alternaly <br>
  9761. &lt;speed&gt;: range is 0 to 100%<br>
  9762. </li>
  9763. <li><B>stop</B><br>
  9764. stop movement<br>
  9765. </li>
  9766. </ul>
  9767. </li>
  9768. <li>CCU_FHEM<br>
  9769. <ul>
  9770. <li>defIgnUnknown<br>
  9771. define unknown devices which are present in the readings.
  9772. set attr ignore and remove the readingfrom the list. <br>
  9773. </li>
  9774. </ul>
  9775. </li>
  9776. <li>HM-Sys-sRP-Pl<br><br>
  9777. setup the repeater's entries. Up to 36entries can be applied.
  9778. <ul>
  9779. <li><B>setRepeat &lt;entry&gt; &lt;sender&gt; &lt;receiver&gt; &lt;broadcast&gt;</B><br>
  9780. &lt;entry&gt; [1..36] entry number in repeater table. The repeater can handle up to 36 entries.<br>
  9781. &lt;sender&gt; name or HMID of the sender or source which shall be repeated<br>
  9782. &lt;receiver&gt; name or HMID of the receiver or destination which shall be repeated<br>
  9783. &lt;broadcast&gt; [yes|no] determines whether broadcast from this ID shall be repeated<br>
  9784. <br>
  9785. short application: <br>
  9786. <code>setRepeat setAll 0 0 0<br></code>
  9787. will rewrite the complete list to the deivce. Data will be taken from attribut repPeers. <br>
  9788. attribut repPeers is formated:<br>
  9789. src1:dst1:[y/n],src2:dst2:[y/n],src2:dst2:[y/n],...<br>
  9790. <br>
  9791. Reading repPeer is formated:<br>
  9792. <ul>
  9793. Number src dst broadcast verify<br>
  9794. number: entry sequence number<br>
  9795. src: message source device - read from repeater<br>
  9796. dst: message destination device - assembled from attributes<br>
  9797. broadcast: shall broadcast be repeated for this source - read from repeater<br>
  9798. verify: do attributes and readings match?<br>
  9799. </ul>
  9800. </li>
  9801. </ul>
  9802. </li>
  9803. <br>
  9804. Debugging:
  9805. <ul>
  9806. <li><B>raw &lt;data&gt; ...</B><br>
  9807. Only needed for experimentation.
  9808. send a list of "raw" commands. The first command will be
  9809. immediately sent, the next one after the previous one is acked by
  9810. the target. The length will be computed automatically, and the
  9811. message counter will be incremented if the first two charcters are
  9812. ++. Example (enable AES):
  9813. <pre>
  9814. set hm1 raw ++A001F100001234560105000000001\
  9815. ++A001F10000123456010802010AF10B000C00\
  9816. ++A001F1000012345601080801\
  9817. ++A001F100001234560106</pre>
  9818. </li>
  9819. </ul>
  9820. </ul>
  9821. </ul>
  9822. <br>
  9823. <a name="CUL_HMget"></a><b>Get</b><br>
  9824. <ul>
  9825. <li><B>configSave &lt;filename&gt;</B><a name="CUL_HMconfigSave"></a><br>
  9826. Saves the configuration of an entity into a file. Data is stored in a
  9827. format to be executed from fhem command prompt.<br>
  9828. The file is located in the fhem home directory aside of fhem.cfg. Data
  9829. will be stored cumulative - i.e. new data will be appended to the
  9830. file. It is up to the user to avoid duplicate storage of the same
  9831. entity.<br>
  9832. Target of the data is ONLY the HM-device information which is located
  9833. IN the HM device. Explicitely this is the peer-list and the register.
  9834. With the register also the peering is included.<br>
  9835. The file is readable and editable by the user. Additionaly timestamps
  9836. are stored to help user to validate.<br>
  9837. Restrictions:<br>
  9838. Even though all data of the entity will be secured to the file FHEM
  9839. stores the data that is avalilable to FHEM at time of save!. It is up
  9840. to the user to read the data from the HM-hardware prior to execution.
  9841. See recommended flow below.<br>
  9842. This command will not store any FHEM attributes o device definitions.
  9843. This continues to remain in fhem.cfg.<br>
  9844. Furthermore the secured data will not automatically be reloaded to the
  9845. HM-hardware. It is up to the user to perform a restore.<br><br>
  9846. As with other commands also 'configSave' is best executed on a device
  9847. rather then on a channel. If executed on a device also the assotiated
  9848. channel data will be secured. <br><br>
  9849. <code>
  9850. Recommended work-order for device 'HMdev':<br>
  9851. set HMdev clear msgEvents # clear old events to better check flow<br>
  9852. set HMdev getConfig # read device & channel inforamtion<br>
  9853. # wait until operation is complete<br>
  9854. # protState should be CMDs_done<br>
  9855. # there shall be no warnings amongst prot... variables<br>
  9856. get configSave myActorFile<br>
  9857. </code>
  9858. </li>
  9859. <li><B>param &lt;paramName&gt;</B><br>
  9860. returns the content of the relevant parameter for the entity. <br>
  9861. Note: if this command is executed on a channel and 'model' is
  9862. requested the content hosting device's 'model' will be returned.
  9863. </li>
  9864. <li><B>reg &lt;addr&gt; &lt;list&gt; &lt;peerID&gt;</B><a name="CUL_HMget_reg"></a><br>
  9865. returns the value of a register. The data is taken from the storage in FHEM and not
  9866. read directly outof the device.
  9867. If register content is not present please use getConfig, getReg in advance.<br>
  9868. &lt;addr&gt; address in hex of the register. Registername can be used alternaly
  9869. if decoded by FHEM. "all" will return all decoded register for this entity in one list.<br>
  9870. &lt;list&gt; list from which the register is taken. If rgistername is used list
  9871. is ignored and can be set to 0.<br>
  9872. &lt;peerID&gt; identifies the registerbank in case of list3 and list4. It an be set to dummy if not used.<br>
  9873. </li>
  9874. <li><B>regVal &lt;addr&gt; &lt;list&gt; &lt;peerID&gt;</B><br>
  9875. returns the value of a register. It does the same as <a href="#CUL_HMget_reg">reg</a> but strips off units<br>
  9876. </li>
  9877. <li><B>regList</B><br>
  9878. returns a list of register that are decoded by FHEM for this device.<br>
  9879. Note that there could be more register implemented for a device.<br>
  9880. </li>
  9881. <li><B>saveConfig &lt;file&gt;</B><a name="CUL_HMsaveConfig"></a><br>
  9882. stores peers and register to the file.<br>
  9883. Stored will be the data as available in fhem. It is necessary to read the information from the device prior to the save.<br>
  9884. The command supports device-level action. I.e. if executed on a device also all related channel entities will be stored implicitely.<br>
  9885. Storage to the file will be cumulative.
  9886. If an entity is stored multiple times to the same file data will be appended.
  9887. User can identify time of storage in the file if necessary.<br>
  9888. Content of the file can be used to restore device configuration.
  9889. It will restore all peers and all register to the entity.<br>
  9890. Constrains/Restrictions:<br>
  9891. prior to rewrite data to an entity it is necessary to pair the device with FHEM.<br>
  9892. restore will not delete any peered channels, it will just add peer channels.<br>
  9893. </li>
  9894. <li><B>listDevice</B><br>
  9895. <ul>
  9896. <li>when used with ccu it returns a list of Devices using the ccu service to assign an IO.<br>
  9897. </li>
  9898. <li>when used with ActionDetector user will get a comma separated list of entities being assigned to the action detector<br>
  9899. get ActionDetector listDevice # returns all assigned entities<br>
  9900. get ActionDetector listDevice notActive# returns entities which habe not status alive<br>
  9901. get ActionDetector listDevice alive # returns entities with status alive<br>
  9902. get ActionDetector listDevice unknown # returns entities with status unknown<br>
  9903. get ActionDetector listDevice dead # returns entities with status dead<br>
  9904. </li>
  9905. </ul>
  9906. </li>
  9907. <li><B>info</B><br>
  9908. <ul>
  9909. <li>provides information about entities using ActionDetector<br>
  9910. </li>
  9911. </ul>
  9912. </li>
  9913. </ul><br>
  9914. <a name="CUL_HMattr"></a><b>Attributes</b>
  9915. <ul>
  9916. <li><a href="#eventMap">eventMap</a></li>
  9917. <li><a href="#do_not_notify">do_not_notify</a></li>
  9918. <li><a href="#ignore">ignore</a></li>
  9919. <li><a href="#dummy">dummy</a></li>
  9920. <li><a href="#showtime">showtime</a></li>
  9921. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  9922. <li><a name="CUL_HMaesCommReq">aesCommReq</a>
  9923. if set HMLAN/USB is forced to request AES signature before sending ACK to the device.<br>
  9924. This funktion strictly works with HMLAN/USB - it doesn't work for CUL type IOs.<br>
  9925. </li>
  9926. <li><a name="#CUL_HMactAutoTry">actAutoTry</a>
  9927. actAutoTry 0_off,1_on<br>
  9928. setting this option enables Action Detector to send a statusrequest in case of a device is going to be marked dead.
  9929. The attribut may be useful in case a device is being checked that does not send messages regularely - e.g. an ordinary switch.
  9930. </li>
  9931. <li><a name="#CUL_HMactCycle">actCycle</a>
  9932. actCycle &lt;[hhh:mm]|off&gt;<br>
  9933. Supports 'alive' or better 'not alive' detection for devices. [hhh:mm] is the maximum silent time for the device.
  9934. Upon no message received in this period an event will be raised "&lt;device&gt; is dead".
  9935. If the device sends again another notification is posted "&lt;device&gt; is alive". <br>
  9936. This actiondetect will be autocreated for each device with build in cyclic status report.<br>
  9937. Controlling entity is a pseudo device "ActionDetector" with HMId "000000".<br>
  9938. Due to performance considerations the report latency is set to 600sec (10min).
  9939. It can be controlled by the attribute "actCycle" of "ActionDetector".<br>
  9940. Once entered to the supervision the HM device has 2 attributes:<br>
  9941. <ul>
  9942. actStatus: activity status of the device<br>
  9943. actCycle: detection period [hhh:mm]<br>
  9944. </ul>
  9945. The overall function can be viewed checking out the "ActionDetector" entity. The status of all entities is present in the READING section.<br>
  9946. Note: This function can be enabled for devices with non-cyclic messages as well. It is up to the user to enter a reasonable cycletime.
  9947. </li>
  9948. <li><a name="#CUL_HMautoReadReg">autoReadReg</a><br>
  9949. '0' autoReadReg will be ignored.<br>
  9950. '1' will execute a getConfig for the device automatically after each reboot of FHEM. <br>
  9951. '2' like '1' plus execute after power_on.<br>
  9952. '3' includes '2' plus updates on writes to the device<br>
  9953. '4' includes '3' plus tries to request status if it seems to be missing<br>
  9954. '5' checks reglist and peerlist. If reading seems incomplete getConfig will be scheduled<br>
  9955. '8_stateOnly' will only update status information but not configuration
  9956. data like register and peer<br>
  9957. Execution will be delayed in order to prevent congestion at startup. Therefore the update
  9958. of the readings and the display will be delayed depending on the size of the database.<br>
  9959. Recommendations and constrains upon usage:<br>
  9960. <ul>
  9961. use this attribute on the device or channel 01. Do not use it separate on each channel
  9962. of a multi-channel device to avoid duplicate execution<br>
  9963. usage on devices which only react to 'config' mode is not recommended since executen will
  9964. not start until config is triggered by the user<br>
  9965. usage on devices which support wakeup-mode is usefull. But consider that execution is delayed
  9966. until the device "wakes up".<br>
  9967. </ul>
  9968. </li>
  9969. <li><a name="#CUL_HMburstAccess">burstAccess</a><br>
  9970. can be set for the device entity if the model allowes conditionalBurst.
  9971. The attribut will switch off burst operations (0_off) which causes less message load
  9972. on HMLAN and therefore reduces the chance of HMLAN overload.<br>
  9973. Setting it on (1_auto) allowes shorter reaction time of the device. User does not
  9974. need to wait for the device to wake up. <br>
  9975. Note that also the register burstRx needs to be set in the device.</li>
  9976. <li><a name="#CUL_HMexpert">expert</a><br>
  9977. This attribut controls the visibility of the register readings. This attibute controls
  9978. the presentation of device parameter in the readings.<br>
  9979. it is a binary coded number with following presets:<br>
  9980. <ul>
  9981. 0_defReg : default register<br>
  9982. 1_allReg : all register<br>
  9983. 2_defReg+raw : default register and raw reading<br>
  9984. 3_allReg+raw : all register and raw reading<br>
  9985. 4_off : no register<br>
  9986. 8_templ+default: templates and default register<br>
  9987. 12_templOnly : templates only<br>
  9988. 251_anything : anything available<br>
  9989. </ul>
  9990. If expert is applied a device it is used for assotiated channels.
  9991. It can be overruled if expert attibute is also applied to the channel device.<br>
  9992. Make sure to check out attribut showInternalValues in the global values as well.
  9993. extert takes benefit of the implementation.
  9994. Nevertheless - by definition - showInternalValues overrules expert.
  9995. </li>
  9996. <li><a name="#CUL_HMreadOnly">readOnly</a><br>
  9997. restircts commands to read od observ only.
  9998. </li>
  9999. <li><a name="#CUL_HMIOgrp">IOgrp</a><br>
  10000. can be given to devices and shall point to a virtual CCU. As a consequence the
  10001. CCU will take care of the assignment to the best suitable IO. It is necessary that a
  10002. virtual CCU is defined and all relevant IO devices are assigned to it. Upon sending the CCU will
  10003. check which IO is operational and has the best RSSI performance for this device.<br>
  10004. Optional a prefered IO - perfIO can be given. In case this IO is operational it will be selected regardless
  10005. of rssi values. <br>
  10006. If none is detected in the prefIO list the mechanism is stopped and the IO as of IOdev is assigned<br>
  10007. Example:<br>
  10008. <ul><code>
  10009. attr myDevice1 IOgrp vccu<br>
  10010. attr myDevice2 IOgrp vccu:prefIO<br>
  10011. attr myDevice2 IOgrp vccu:prefIO1,prefIO2,prefIO3<br>
  10012. attr myDevice2 IOgrp vccu:prefIO1,prefIO2,none<br>
  10013. </code></ul>
  10014. </li>
  10015. <li><a name="#CUL_HMlevelRange">levelRange</a><br>
  10016. can be used with dimmer only. It defines the dimmable range to be used with this dimmer-channel.
  10017. It is meant to support e.g. LED light that starts at 10% and reaches maxbrightness at 40%.
  10018. levelrange will normalize the level to this range. I.e. set to 100% will physically set the
  10019. dimmer to 40%, 1% will set to 10% physically. 0% still switches physially off.<br>
  10020. Impacted are commands on, up, down, toggle and pct. <b>Not</b> effected is the off command
  10021. which still set physically 0%.<br>
  10022. To be considered:<br>
  10023. dimmer level set by peers and buttons is not impacted. Those are controlled by device register<br>
  10024. Readings level may go to negative or above 100%. This simply results from the calculation and reflects
  10025. physical level is above or below the given range.<br>
  10026. In case of virtual dimmer channels available present the attribut needs to be set for
  10027. each channel<br>
  10028. User should be careful to set min level other then '0'<br>
  10029. Example:<br>
  10030. <ul><code>
  10031. attr myChannel levelRange 0,40<br>
  10032. attr myChannel levelRange 10,80<br>
  10033. </code></ul>
  10034. </li>
  10035. <li><a name="#CUL_HMmodel">model</a>,
  10036. <a name="subType">subType</a><br>
  10037. These attributes are set automatically after a successful pairing.
  10038. They are not supposed to be set by hand, and are necessary in order to
  10039. correctly interpret device messages or to be able to send them.</li>
  10040. <li><a name="#CUL_HMmsgRepeat">msgRepeat</a><br>
  10041. defines number of repetitions if a device doesn't answer in time. <br>
  10042. Devices which donly support config mode no repeat ist allowed. <br>
  10043. For devices with wakeup mode the device will wait for next wakeup. Lonng delay might be
  10044. considered in this case. <br>
  10045. Repeat for burst devices will impact HMLAN transmission capacity.</li>
  10046. <li><a name="#CUL_HMparam">param</a><br>
  10047. param defines model specific behavior or functions. See <a href="#CUL_HMparams"><b>available parameter</b></a> for details</li>
  10048. <li><a name="#CUL_HMrawToReadable">rawToReadable</a><br>
  10049. Used to convert raw KFM100 values to readable data, based on measured
  10050. values. E.g. fill slowly your container, while monitoring the
  10051. values reported with <a href="#inform">inform</a>. You'll see:
  10052. <ul>
  10053. 10 (at 0%)<br>
  10054. 50 (at 20%)<br>
  10055. 79 (at 40%)<br>
  10056. 270 (at 100%)<br>
  10057. </ul>
  10058. Apply these values with: "attr KFM100 rawToReadable 10:0 50:20 79:40 270:100".
  10059. fhem will do a linear interpolation for values between the bounderies.
  10060. </li>
  10061. <li><a name="#CUL_HMrssiLog">rssiLog</a><br>
  10062. can be given to devices, denied for channels. If switched '1' each RSSI entry will be
  10063. written to a reading. User may use this to log and generate a graph of RSSI level.<br>
  10064. Due to amount of readings and events it is NOT RECOMMENDED to switch it on by default.
  10065. </li>
  10066. <li><a name="#CUL_HMtempListTmpl">tempListTmpl</a><br>
  10067. Sets the default template for a heating controller. If not given the detault template is taken from
  10068. file tempList.cfg using the enitity name as template name (e.g. ./tempLict.cfg:RT1_Clima <br>
  10069. To avoid template usage set this attribut to '0'.<br>
  10070. Format is &lt;file&gt;:&lt;templatename&gt;. lt
  10071. </li>
  10072. <li><a name="unit">unit</a><br>
  10073. set the reported unit by the KFM100 if rawToReadable is active. E.g.<br>
  10074. attr KFM100 unit Liter
  10075. </li>
  10076. <li><a name="cyclicMsgOffset">cyclicMsgOffset</a><br>
  10077. when calculating the timestamp for sending the next cyclic message (e.g. weather or valve data) then the value of this attribute<br>
  10078. in milliseconds is added to the result. So adjusting this might fix problems for example when weather messages of virtual devices are not received reliably
  10079. </li>
  10080. </ul> <br>
  10081. <a name="CUL_HMparams"><b>available parameter for attribut "param"</b></a>
  10082. <ul>
  10083. <li><B>HM-Sen-RD-O</B><br>
  10084. <B>offAtPon</B> heat channel only: force heating off after powerOn<br>
  10085. <B>onAtRain</B> heat channel only: force heating on while status changes to 'rain' and off when it changes to 'dry'<br>
  10086. </li>
  10087. <li><B>virtuals</B><br>
  10088. <B>noOnOff</B> virtual entity will not toggle state when trigger is received. If this parameter is
  10089. not given the entity will toggle its state between On and Off with each trigger<br>
  10090. <B>msgReduce:&lt;No&gt;</B> if channel is used for <a ref="CUL_HMvalvePos"></a> it skips every No message
  10091. in order to reduce transmit load. Numbers from 0 (no skip) up to 9 can be given.
  10092. VD will lose connection with more then 5 skips<br>
  10093. </li>
  10094. <li><B>blind</B><br>
  10095. <B>levelInverse</B> while HM considers 100% as open and 0% as closed this may not be
  10096. intuitive to all user. Ny default 100% is open and will be dislayed as 'on'. Setting this param the display will be inverted - 0% will be open and 100% is closed.<br>
  10097. NOTE: This will apply to readings and set commands. <B>It does not apply to any register. </B><br>
  10098. <B>ponRestoreSmart</B> upon powerup of the device the Blind will drive to expected closest endposition followed by driving to the pre-PON level<br>
  10099. <B>ponRestoreForce</B> upon powerup of the device the Blind will drive to level 0, then to level 100 followed by driving to the pre-PON level<br>
  10100. </li>
  10101. <li><B>sensRain</B><br>
  10102. <B>siren</B><br>
  10103. <B>powerMeter</B><br>
  10104. <B>switch</B><br>
  10105. <B>dimmer</B><br>
  10106. <B>rgb</B><br>
  10107. <B>showTimed</B> if timmed is running -till will be added to state.
  10108. This results eventually in state on-till which allowes better icon handling.<br>
  10109. </li>
  10110. </ul><br>
  10111. <a name="CUL_HMevents"><b>Generated events:</b></a>
  10112. <ul>
  10113. <li><B>general</B><br>
  10114. recentStateType:[ack|info] # cannot be used ti trigger notifies<br>
  10115. <ul>
  10116. <li>ack indicates that some statusinfo is derived from an acknowledge</li>
  10117. <li>info indicates an autonomous message from the device</li>
  10118. <li><a name="CUL_HMsabotageAttackId"><b>sabotageAttackId</b></a><br>
  10119. Alarming configuration access to the device from a unknown source<br></li>
  10120. <li><a name="CUL_HMsabotageAttack"><b>sabotageAttack</b></a><br>
  10121. Alarming configuration access to the device that was not issued by our system<br></li>
  10122. <li><a name="CUL_HMtrigDst"><b>trigDst_&lt;name&gt;: noConfig</b></a><br>
  10123. A sensor triggered a Device which is not present in its peerList. Obviously the peerList is not up to date<br></li>
  10124. </ul>
  10125. </li>
  10126. <li><B>HM-CC-TC,ROTO_ZEL-STG-RM-FWT</B><br>
  10127. T: $t H: $h<br>
  10128. battery:[low|ok]<br>
  10129. measured-temp $t<br>
  10130. humidity $h<br>
  10131. actuator $vp %<br>
  10132. desired-temp $dTemp<br>
  10133. desired-temp-manu $dTemp #temperature if switchen to manual mode<br>
  10134. desired-temp-cent $dTemp #temperature if switchen to central mode<br>
  10135. windowopen-temp-%d %.1f (sensor:%s)<br>
  10136. tempList$wd hh:mm $t hh:mm $t ...<br>
  10137. displayMode temp-[hum|only]<br>
  10138. displayTemp [setpoint|actual]<br>
  10139. displayTempUnit [fahrenheit|celsius]<br>
  10140. controlMode [auto|manual|central|party]<br>
  10141. tempValveMode [Auto|Closed|Open|unknown]<br>
  10142. param-change offset=$o1, value=$v1<br>
  10143. ValveErrorPosition_for_$dname $vep %<br>
  10144. ValveOffset_for_$dname : $of %<br>
  10145. ValveErrorPosition $vep %<br>
  10146. ValveOffset $of %<br>
  10147. time-request<br>
  10148. trig_&lt;src&gt; &lt;value&gt; #channel was triggered by &lt;src&gt; channel.
  10149. This event relies on complete reading of channels configuration, otherwise Data can be
  10150. incomplete or incorrect.<br>
  10151. trigLast &lt;channel&gt; #last receiced trigger<br>
  10152. </li>
  10153. <li><B>HM-CC-RT-DN and HM-CC-RT-DN-BoM</B><br>
  10154. state:T: $actTemp desired: $setTemp valve: $vp %<br>
  10155. motorErr: [ok|ValveTight|adjustRangeTooLarge|adjustRangeTooSmall|communicationERR|unknown|lowBat|ValveErrorPosition]
  10156. measured-temp $actTemp<br>
  10157. desired-temp $setTemp<br>
  10158. ValvePosition $vp %<br>
  10159. mode [auto|manual|party|boost]<br>
  10160. battery [low|ok]<br>
  10161. batteryLevel $bat V<br>
  10162. measured-temp $actTemp<br>
  10163. desired-temp $setTemp<br>
  10164. actuator $vp %<br>
  10165. time-request<br>
  10166. trig_&lt;src&gt; &lt;value&gt; #channel was triggered by &lt;src&gt; channel.
  10167. </li>
  10168. <li><B>HM-CC-VD,ROTO_ZEL-STG-RM-FSA</B><br>
  10169. $vp %<br>
  10170. battery:[critical|low|ok]<br>
  10171. motorErr:[ok|blocked|loose|adjusting range too small|opening|closing|stop]<br>
  10172. ValvePosition:$vp %<br>
  10173. ValveErrorPosition:$vep %<br>
  10174. ValveOffset:$of %<br>
  10175. ValveDesired:$vp % # set by TC <br>
  10176. operState:[errorTargetNotMet|onTarget|adjusting|changed] # operational condition<br>
  10177. operStateErrCnt:$cnt # number of failed settings<br>
  10178. </li>
  10179. <li><B>HM-CC-SCD</B><br>
  10180. [normal|added|addedStrong]<br>
  10181. battery [low|ok]<br>
  10182. </li>
  10183. <li><B>HM-SEC-SFA-SM</B><br>
  10184. powerError [on|off]<br>
  10185. sabotageError [on|off]<br>
  10186. battery: [critical|low|ok]<br>
  10187. </li>
  10188. <li><B>HM-LC-BL1-PB-FM</B><br>
  10189. motor: [opening|closing]<br>
  10190. </li>
  10191. <li><B>HM-LC-SW1-BA-PCB</B><br>
  10192. battery: [low|ok]<br>
  10193. </li>
  10194. <li><B>HM-OU-LED16</B><br>
  10195. color $value # hex - for device only<br>
  10196. $value # hex - for device only<br>
  10197. color [off|red|green|orange] # for channel <br>
  10198. [off|red|green|orange] # for channel <br>
  10199. </li>
  10200. <li><B>HM-OU-CFM-PL</B><br>
  10201. [on|off|$val]<br>
  10202. </li>
  10203. <li><B>HM-Sen-Wa-Od</B><br>
  10204. $level%<br>
  10205. level $level%<br>
  10206. </li>
  10207. <li><B>KFM100</B><br>
  10208. $v<br>
  10209. $cv,$unit<br>
  10210. rawValue:$v<br>
  10211. Sequence:$seq<br>
  10212. content:$cv,$unit<br>
  10213. </li>
  10214. <li><B>KS550/HM-WDS100-C6-O</B><br>
  10215. T: $t H: $h W: $w R: $r IR: $ir WD: $wd WDR: $wdr S: $s B: $b<br>
  10216. temperature $t<br>
  10217. humidity $h<br>
  10218. windSpeed $w<br>
  10219. windDirection $wd<br>
  10220. windDirRange $wdr<br>
  10221. rain $r<br>
  10222. isRaining $ir<br>
  10223. sunshine $s<br>
  10224. brightness $b<br>
  10225. unknown $p<br>
  10226. </li>
  10227. <li><B>HM-Sen-RD-O</B><br>
  10228. lastRain: timestamp # no trigger generated. Begin of previous Rain -
  10229. timestamp of the reading is the end of rain. <br>
  10230. </li>
  10231. <li><B>THSensor and HM-WDC7000</B><br>
  10232. T: $t H: $h AP: $ap<br>
  10233. temperature $t<br>
  10234. humidity $h<br>
  10235. airpress $ap #HM-WDC7000 only<br>
  10236. </li>
  10237. <li><B>dimmer</B><br>
  10238. overload [on|off]<br>
  10239. overheat [on|off]<br>
  10240. reduced [on|off]<br>
  10241. dim: [up|down|stop]<br>
  10242. </li>
  10243. <li><B>motionDetector</B><br>
  10244. brightness:$b<br>
  10245. alive<br>
  10246. motion on (to $dest)<br>
  10247. motionCount $cnt _next:$nextTr"-"[0x0|0x1|0x2|0x3|15|30|60|120|240|0x9|0xa|0xb|0xc|0xd|0xe|0xf]<br>
  10248. cover [closed|open] # not for HM-Sec-MDIR<br>
  10249. sabotageError [on|off] # only HM-Sec-MDIR<br>
  10250. battery [low|ok]<br>
  10251. devState_raw.$d1 $d2<br>
  10252. </li>
  10253. <li><B>remote/pushButton/outputUnit</B><br>
  10254. <ul> (to $dest) is added if the button is peered and does not send to broadcast<br>
  10255. Release is provided for peered channels only</ul>
  10256. Btn$x onShort<br>
  10257. Btn$x offShort<br>
  10258. Btn$x onLong $counter<br>
  10259. Btn$x offLong $counter<br>
  10260. Btn$x onLongRelease $counter<br>
  10261. Btn$x offLongRelease $counter<br>
  10262. Btn$x onShort (to $dest)<br>
  10263. Btn$x offShort (to $dest)<br>
  10264. Btn$x onLong $counter (to $dest)<br>
  10265. Btn$x offLong $counter (to $dest)<br>
  10266. Btn$x onLongRelease $counter (to $dest)<br>
  10267. Btn$x offLongRelease $counter (to $dest)<br>
  10268. </li>
  10269. <li><B>remote/pushButton</B><br>
  10270. battery [low|ok]<br>
  10271. trigger [Long|Short]_$no trigger event from channel<br>
  10272. </li>
  10273. <li><B>swi</B><br>
  10274. Btn$x Short<br>
  10275. Btn$x Short (to $dest)<br>
  10276. battery: [low|ok]<br>
  10277. </li>
  10278. <li><B>switch/dimmer/blindActuator</B><br>
  10279. $val<br>
  10280. powerOn [on|off|$val]<br>
  10281. [unknown|motor|dim] [up|down|stop]:$val<br>
  10282. timedOn [running|off]<br> # on is temporary - e.g. started with on-for-timer
  10283. </li>
  10284. <li><B>sensRain</B><br>
  10285. $val<br>
  10286. powerOn <br>
  10287. level &lt;val&ge;<br>
  10288. timedOn [running|off]<br> # on is temporary - e.g. started with on-for-timer
  10289. trigger [Long|Short]_$no trigger event from channel<br>
  10290. </li>
  10291. <li><B>smokeDetector</B><br>
  10292. [off|smoke-Alarm|alive] # for team leader<br>
  10293. [off|smoke-forward|smoke-alarm] # for team members<br>
  10294. [normal|added|addedStrong] #HM-CC-SCD<br>
  10295. SDteam [add|remove]_$dname<br>
  10296. battery [low|ok]<br>
  10297. smoke_detect [none|&lt;src&gt;]<br>
  10298. teamCall:from $src<br>
  10299. </li>
  10300. <li><B>threeStateSensor</B><br>
  10301. [open|tilted|closed]<br>
  10302. [wet|damp|dry] #HM-SEC-WDS only<br>
  10303. cover [open|closed] #HM-SEC-WDS and HM-Sec-RHS<br>
  10304. alive yes<br>
  10305. battery [low|ok]<br>
  10306. contact [open|tilted|closed]<br>
  10307. contact [wet|damp|dry] #HM-SEC-WDS only<br>
  10308. sabotageError [on|off] #HM-SEC-SC only<br>
  10309. </li>
  10310. <li><B>winMatic</B><br>
  10311. [locked|$value]<br>
  10312. motorErr [ok|TurnError|TiltError]<br>
  10313. direction [no|up|down|undefined]<br>
  10314. charge [trickleCharge|charge|dischange|unknown]<br>
  10315. airing [inactiv|$air]<br>
  10316. course [tilt|close]<br>
  10317. airing [inactiv|$value]<br>
  10318. contact tesed<br>
  10319. </li>
  10320. <li><B>keyMatic</B><br>
  10321. unknown:40<br>
  10322. battery [low|ok]<br>
  10323. uncertain [yes|no]<br>
  10324. error [unknown|motor aborted|clutch failure|none']<br>
  10325. lock [unlocked|locked]<br>
  10326. [unlocked|locked|uncertain]<br>
  10327. </li>
  10328. </ul>
  10329. <a name="CUL_HMinternals"><b>Internals</b></a>
  10330. <ul>
  10331. <li><B>aesCommToDev</B><br>
  10332. gives information about success or fail of AES communication between IO-device and HM-Device<br>
  10333. </li>
  10334. </ul><br>
  10335. <br>
  10336. </ul>
  10337. =end html
  10338. =begin html_DE
  10339. <a name="CUL_HM"></a><h3>CUL_HM</h3>
  10340. <ul>
  10341. Unterst&uuml;tzung f&uuml;r eQ-3 HomeMatic Ger&auml;te via <a href="#CUL">CUL</a> oder <a href="#HMLAN">HMLAN</a>.<br>
  10342. <br>
  10343. <a name="CUL_HMdefine"></a><b>Define</b>
  10344. <ul>
  10345. <code><B>define &lt;name&gt; CUL_HM &lt;6-digit-hex-code|8-digit-hex-code&gt;</B></code>
  10346. <br><br>
  10347. Eine korrekte Ger&auml;tedefinition ist der Schl&uuml;ssel zur einfachen Handhabung der HM-Umgebung.
  10348. <br>
  10349. Hintergrund zur Definition:<br>
  10350. HM-Ger&auml;te haben eine 3 Byte (6 stelliger HEX-Wert) lange HMid - diese ist Grundlage
  10351. der Adressierung. Jedes Ger&auml;t besteht aus einem oder mehreren Kan&auml;len. Die HMid f&uuml;r einen
  10352. Kanal ist die HMid des Ger&auml;tes plus die Kanalnummer (1 Byte, 2 Stellen) in
  10353. hexadezimaler Notation.
  10354. Kan&auml;le sollten f&uuml;r alle mehrkanaligen Ger&auml;te definiert werden. Eintr&auml;ge f&uuml;r Kan&auml;le
  10355. k&ouml;nnen nicht angelegt werden wenn das zugeh&ouml;rige Ger&auml;t nicht existiert.<br> Hinweis: FHEM
  10356. belegt das Ger&auml;t automatisch mit Kanal 1 falls dieser nicht explizit angegeben wird. Daher
  10357. ist bei einkanaligen Ger&auml;ten keine Definition n&ouml;tig.<br>
  10358. Hinweis: Wird ein Ger&auml;t gel&ouml;scht werden auch die zugeh&ouml;rigen Kan&auml;le entfernt. <br> Beispiel einer
  10359. vollst&auml;ndigen Definition eines Ger&auml;tes mit 2 Kan&auml;len:<br>
  10360. <ul><code>
  10361. define livingRoomSwitch CUL_HM 123456<br>
  10362. define LivingroomMainLight CUL_HM 12345601<br>
  10363. define LivingroomBackLight CUL_HM 12345602<br><br>
  10364. </code></ul>
  10365. livingRoomSwitch bezeichnet das zur Kommunikation verwendete Ger&auml;t. Dieses wird
  10366. vor den Kan&auml;len definiert um entsprechende Verweise einstellen zu k&ouml;nnen. <br>
  10367. LivingroomMainLight hat Kanal 01 und behandelt den Lichtstatus, Kanal-Peers
  10368. sowie zugeh&ouml;rige Kanalregister. Falls nicht definiert wird Kanal 01 durch die Ger&auml;teinstanz
  10369. abgedeckt.<br> LivingRoomBackLight ist der zweite "Kanal", Kanal 02. Seine
  10370. Definition ist verpflichtend um die Funktion ausf&uuml;hren zu k&ouml;nnen.<br><br>
  10371. Sonderfall Sender: HM behandelt jeden Knopf einer Fernbedienung, Drucktaster und
  10372. &auml;hnliches als Kanal . Es ist m&ouml;glich (nicht notwendig) einen Kanal pro Knopf zu
  10373. definieren. Wenn alle Kan&auml;le definiert sind ist der Zugriff auf Pairing-Informationen
  10374. sowie auf Kanalregister m&ouml;glich. Weiterhin werden Verkn&uuml;pfungen durch Namen besser
  10375. lesbar.<br><br>
  10376. define kann auch durch das <a href="#autocreate">autocreate</a>
  10377. Modul aufgerufen werden, zusammen mit dem notwendigen subType Attribut.
  10378. Normalerweise erstellt man <a href="#CULset">hmPairForSec</a> und dr&uuml;ckt dann den
  10379. zugeh&ouml;rigen Knopf am Ger&auml;t um die Verkn&uuml;pfung herzustellen oder man verwendet <a
  10380. href="#CULset">hmPairSerial</a> falls das Ger&auml;t ein Empf&auml;nger und die Seriennummer
  10381. bekannt ist. Autocreate wird dann ein FHEM-Ger&auml;t mit allen notwendigen Attributen anlegen.
  10382. Ohne Pairing wird das Ger&auml;t keine Befehle von FHEM akzeptieren. Selbst wenn das Pairing
  10383. scheitert legt FHEM m&ouml;glicherweise das Ger&auml;t an. Erfolgreiches Pairen wird
  10384. durch den Eintrag CommandAccepted in den Details zum CUL_HM Ger&auml;t angezeigt.<br><br>
  10385. Falls autocreate nicht verwendet werden kann muss folgendes spezifiziert werden:<br>
  10386. <ul>
  10387. <li>Der &lt;6-stellige-Hex-Code&gt;oder HMid+ch &lt;8-stelliger-Hex-Code&gt;<br>
  10388. Das ist eine einzigartige, festgelegte Ger&auml;teadresse die nicht ge&auml;ndert werden kann (nein,
  10389. man kann sie nicht willk&uuml;rlich ausw&auml;hlen wie z.B. bei FS20 Ger&auml;ten). Man kann sie feststellen
  10390. indem man das FHEM-Log durchsucht.</li>
  10391. <li>Das subType Attribut<br>
  10392. Dieses lautet: switch dimmer blindActuator remote sensor swi
  10393. pushButton threeStateSensor motionDetector keyMatic winMatic
  10394. smokeDetector</li>
  10395. <li>Das model Attribut<br>
  10396. ist entsprechend der HM Nomenklatur zu vergeben</li>
  10397. </ul>
  10398. Ohne diese Angaben kann FHEM nicht korrekt mit dem Ger&auml;t arbeiten.<br><br>
  10399. <b>Hinweise</b>
  10400. <ul>
  10401. <li>Falls das Interface ein Ger&auml;t vom Typ CUL ist muss <a href="#rfmode">rfmode </a>
  10402. des zugeh&ouml;rigen CUL/CUN Ger&auml;tes auf HomeMatic gesetzt werden.
  10403. Achtung: Dieser Modus ist nur f&uuml;r BidCos/Homematic. Nachrichten von FS20/HMS/EM/S300
  10404. werden durch diese Ger&auml;t <b>nicht</b> empfangen. Bereits definierte FS20/HMS
  10405. Ger&auml;te m&uuml;ssen anderen Eing&auml;ngen zugeordnet werden (CUL/FHZ/etc).
  10406. </li>
  10407. <li>Nachrichten eines Ger&auml;ts werden nur richtig interpretiert wenn der Ger&auml;tetyp
  10408. bekannt ist. FHEM erh&auml;lt den Ger&auml;tetyp aus einer"pairing request"
  10409. Nachricht, selbst wenn es darauf keine Antwort erh&auml;lt (siehe <a
  10410. href="#hmPairSerial">hmPairSerial</a> und <a
  10411. href="#hmPairForSec">hmPairForSec</a> um Parinig zu erm&ouml;glichen).
  10412. Alternativ, setzen des richtigen subType sowie Modelattributes, f&uuml;r eine Liste der
  10413. m&ouml;glichen subType-Werte siehe "attr hmdevice ?".</li>
  10414. <a name="HMAES"></a>
  10415. <li>Die sogenannte "AES-Verschl&uuml;sselung" ist eigentlich eine Signaturanforderung: Ist sie
  10416. aktiviert wird ein Aktor den erhaltenen Befehl nur ausf&uuml;hren falls er die korrekte
  10417. Antwort auf eine zuvor durch den Aktor gestellte Anfrage erh&auml;lt. Das bedeutet:
  10418. <ul>
  10419. <li>Die Reaktion auf Befehle ist merklich langsamer, da 3 Nachrichten anstatt einer &uuml;bertragen
  10420. werden bevor der Befehl vom Aktor ausgef&uuml;hrt wird.</li>
  10421. <li>Jeder Befehl sowie seine Best&auml;tigung durch das Ger&auml;t wird in Klartext &uuml;bertragen, ein externer
  10422. Beobachter kennt somit den Status jedes Ger&auml;ts.</li>
  10423. <li>Die eingebaute Firmware ist fehlerhaft: Ein "toggle" Befehl wir ausgef&uuml;hrt <b>bevor</b> die
  10424. entsprechende Antwort auf die Signaturanforderung empfangen wurde, zumindest bei einigen Schaltern
  10425. (HM-LC-Sw1-Pl und HM-LC-SW2-PB-FM).</li>
  10426. <li>Der <a href="#HMLAN">HMLAN</a> Konfigurator beantwortet Signaturanforderungen selbstst&auml;ndig,
  10427. ist dabei die 3-Byte-Adresse einer anderen CCU eingestellt welche noch immer das Standardpasswort hat,
  10428. kann dieser Signaturanfragen korrekt beantworten.</li>
  10429. <li>AES-Verschl&uuml;sselung wird durch HMLAN und CUL unterst&uuml;tzt. Bei Einsatz eines CUL
  10430. ist das Perl-Modul Crypt::Rijndael notwendig. Aufgrund dieser Einschr&auml;nkungen ist der
  10431. Einsatz der Homematic-Verschl&uuml;sselung nicht zu empfehlen!</li>
  10432. </ul>
  10433. </li>
  10434. </ul>
  10435. </ul><br>
  10436. <a name="CUL_HMset"></a><b>Set</b>
  10437. <ul>
  10438. Hinweis: Ger&auml;te die normalerweise nur senden (Fernbedienung/Sensor/etc.) m&uuml;ssen in den
  10439. Pairing/Lern-Modus gebracht werden um die folgenden Befehle zu empfangen.
  10440. <br>
  10441. <br>
  10442. Allgemeine Befehle (verf&uuml;gbar f&uuml;r die meisten HM-Ger&auml;te):
  10443. <ul>
  10444. <li><B>clear &lt;[rssi|readings|register|msgEvents|attack|all]&gt;</B><a name="CUL_HMclear"></a><br>
  10445. Eine Reihe von Variablen kann entfernt werden.<br>
  10446. <ul>
  10447. readings: Alle Messwerte werden gel&ouml;scht, neue Werte werden normal hinzugef&uuml;gt. Kann benutzt werden um alte Daten zu entfernen<br>
  10448. register: Alle in FHEM aufgezeichneten Registerwerte werden entfernt. Dies hat KEINEN Einfluss auf Werte im Ger&auml;t.<br>
  10449. msgEvents: Alle Anchrichtenz&auml;hler werden gel&ouml;scht. Ebenso wird der Befehlsspeicher zur&uuml;ckgesetzt. <br>
  10450. rssi: gesammelte RSSI-Werte werden gel&ouml;scht.<br>
  10451. attack: Einträge bezüglich einer Attack werden gelöscht.<br>
  10452. all: alles oben genannte.<br>
  10453. </ul>
  10454. </li>
  10455. <li><B>getConfig</B><a name="CUL_HMgetConfig"></a><br>
  10456. Liest die Hauptkonfiguration eines HM_Ger&auml;tes aus. Angewendet auf einen Kanal
  10457. erh&auml;lt man Pairing-Information, List0, List1 und List3 des ersten internen Peers.
  10458. Außerdem erh&auml;lt man die Liste der Peers f&uuml;r den gegebenen Kanal. Wenn auf ein Ger&auml;t
  10459. angewendet so bekommt man mit diesem Befehl die vorherigen Informationen f&uuml;r alle
  10460. zugeordneten Kan&auml;le. Ausgeschlossen davon sind Konfigurationen zus&auml;tzlicher Peers.
  10461. <br> Der Befehl ist eine Abk&uuml;rzung f&uuml;r eine Reihe anderer Befehle.
  10462. </li>
  10463. <li><B>getRegRaw [List0|List1|List2|List3|List4|List5|List6]&lt;peerChannel&gt; </B><a name="CUL_HMgetRegRaw"></a><br>
  10464. Auslesen der Rohdaten des Registersatzes. Eine Beschreibung der Register sprengt
  10465. den Rahmen dieses Dokuments.<br>
  10466. Die Register sind in sog. Listen strukturiert welche einen Satz Register enthalten.<br>
  10467. List0: Ger&auml;teeinstellungen z.B: Einstellungen f&uuml;r CUL-Pairing Temperaturlimit eines Dimmers.<br>
  10468. List1: Kanaleinstellungen z.B. ben&ouml;tigte Zeit um Rollo hoch und runter zu fahren.<br>
  10469. List3: "link" Einstellungen - d.h. Einstellungen f&uuml;r Peer-Kanal. Das ist eine große Datenmenge!
  10470. Steuert Aktionen bei Empfang eines Triggers vom Peer.<br>
  10471. List4: Einstellungen f&uuml;r den Kanal (Taster) einer Fernbedienung.<br><br>
  10472. &lt;PeerChannel&gt; verkn&uuml;pfte HMid+ch, z.B. 4 byte (8 stellige) Zahl wie
  10473. '12345601'. Ist verpflichtend f&uuml;r List3 und List4 und kann ausgelassen werden
  10474. f&uuml;r List0 und 1. <br>
  10475. 'all' kann verwendet werden um Daten von jedem mit einem Kanal verkn&uuml;pften Link zu bekommen. <br>
  10476. 'selfxx' wird verwendet um interne Kan&auml;le zu adressieren (verbunden mit den eingebauten Schaltern
  10477. falls vorhanden). xx ist die Kanalnummer in dezimaler Notation.<br>
  10478. Hinweis 1: Ausf&uuml;hrung ist abh&auml;ngig vom Entity. Wenn List1 f&uuml;r ein Ger&auml;t statt einem Kanal
  10479. abgefragt wird gibt der Befehl List1 f&uuml;r alle zugeh&ouml;rigen Kan&auml;le aus.
  10480. List3 mit 'peerChannel = all' gibt alle Verbindungen f&uuml;r alle Kan&auml;le eines Ger&auml;tes zur&uuml;ck.<br>
  10481. Hinweis 2: f&uuml;r 'Sender' siehe auch <a href="#CUL_HMremote">remote</a> <br>
  10482. Hinweis 3: Das Abrufen von Informationen kann dauern - besonders f&uuml;r Ger&auml;te
  10483. mit vielen Kan&auml;len und Verkn&uuml;pfungen. Es kann n&ouml;tig sein das Webinterface manuell neu zu laden
  10484. um die Ergebnisse angezeigt zu bekommen.<br>
  10485. Hinweis 4: Direkte Schalter eines HM-Ger&auml;ts sind standardm&auml;ßig ausgeblendet.
  10486. Dennoch sind sie genauso als Verkn&uuml;pfungen implemetiert. Um Zugriff auf 'internal links'
  10487. zu bekommen ist es notwendig folgendes zu erstellen:<br>
  10488. 'set &lt;name&gt; <a href="#CUL_HMregSet">regSet</a> intKeyVisib visib'<br>
  10489. oder<br>
  10490. 'set &lt;name&gt; <a href="#CUL_HMregBulk">regBulk</a> RegL_0. 2:81'<br>
  10491. Zur&uuml;cksetzen l&auml;sst es sich indem '81' mit '01' ersetzt wird.<br> example:<br>
  10492. <ul><code>
  10493. set mydimmer getRegRaw List1<br>
  10494. set mydimmer getRegRaw List3 all <br>
  10495. </code></ul>
  10496. </li>
  10497. <li><B>getSerial</B><a name="CUL_HMgetSerial"></a><br>
  10498. Auslesen der Seriennummer eines ger&auml;ts und speichern in Attribut serialNr.
  10499. </li>
  10500. <li><B>inhibit [on|off]</B><br>
  10501. Blockieren/Zulassen aller Kanal&auml;nderungen eines Aktors, d.h. Zustand des Aktors ist
  10502. eingefroren bis 'inhibit' wieder deaktiviert wird. 'Inhibit' kann f&uuml;r jeden Aktorkanal
  10503. ausgef&uuml;hrt werden aber nat&uuml;rlich nicht f&uuml;r Sensoren - w&uuml;rde auch keinen Sinn machen.<br>
  10504. Damit ist es praktischerweise m&ouml;glich Nachrichten ebenso wie verkn&uuml;pfte Kanalaktionen
  10505. tempor&auml;r zu unterdr&uuml;cken ohne sie l&ouml;schen zu m&uuml;ssen. <br>
  10506. Beispiele:
  10507. <ul><code>
  10508. # Ausf&uuml;hrung blockieren<br>
  10509. set keymatic inhibit on <br><br>
  10510. </ul></code>
  10511. </li>
  10512. <li><B>pair</B><a name="CUL_HMpair"></a><br>
  10513. Verbinden eines Ger&auml;ts bekannter Seriennummer (z.b. nach einem Reset)
  10514. mit einer FHEM-Zentrale. Diese Zentrale wird normalerweise durch CUL/CUNO,
  10515. HMLAN,... hergestellt.
  10516. Wenn verbunden melden Ger&auml;te ihren Status and FHEM.
  10517. Wenn nicht verbunden wird das Ger&auml;t auf bestimmte Anfragen nicht reagieren
  10518. und auch bestimmte Statusinformationen nicht melden. Pairing geschieht auf
  10519. Ger&auml;teebene. Kan&auml;le k&ouml;nnen nicht unabh&auml;ngig von einem Ger&auml;t mit der Zentrale
  10520. verbunden werden.
  10521. Siehe auch <a href="#CUL_HMgetpair">getPair</a> und
  10522. <a href="#CUL_HMunpair">unpair</a>.<br>
  10523. Nicht das Verbinden (mit einer Zentrale) mit verkn&uuml;pfen (Kanal zu Kanal) oder
  10524. <a href="#CUL_HMpeerChan">peerChan</a> verwechseln.<br>
  10525. </li>
  10526. <li><B>peerBulk</B> &lt;peerch1,peerch2,...&gt; [set|unset]<a name="CUL_HMpeerBulk"></a><br>
  10527. peerBulk f&uuml;gt Peer-Kan&auml;le zu einem Kanal hinzu. Alle Peers einer Liste werden
  10528. dabei hinzugef&uuml;gt.<br>
  10529. Peering setzt die Einstellungen einer Verkn&uuml;pfung auf Standardwerte. Da Peers nicht in Gruppen
  10530. hinzugef&uuml;gt werden werden sie durch HM standardm&auml;ßig als'single' f&uuml;r dieses Ger&auml;t
  10531. angelegt. <br>
  10532. Eine ausgekl&uuml;geltere Funktion wird gegeben durch
  10533. <a href="#CUL_HMpeerChan">peerChan</a>.<br>
  10534. peerBulk l&ouml;scht keine vorhandenen Peers sondern bearbeitet nur die Peerliste.
  10535. Andere bereits angelegt Peers werden nicht ver&auml;ndert.<br>
  10536. peerBulk kann verwendet werden um Peers zu l&ouml;schen indem die <B>unset</B> Option
  10537. mit Standardeinstellungen aufgerufen wird.<br>
  10538. Verwendungszweck dieses Befehls ist haupts&auml;chlich das Wiederherstellen
  10539. von Daten eines Ger&auml;ts.
  10540. Empfehlenswert ist das anschließende Wiederherstellen der Registereinstellung
  10541. mit <a href="#CUL_HMregBulk">regBulk</a>. <br>
  10542. Beispiel:<br>
  10543. <ul><code>
  10544. set myChannel peerBulk 12345601,<br>
  10545. set myChannel peerBulk self01,self02,FB_Btn_04,FB_Btn_03,<br>
  10546. set myChannel peerBulk 12345601 unset # entferne Peer 123456 Kanal 01<br>
  10547. </code></ul>
  10548. </li>
  10549. <li><B>regBulk &lt;reg List&gt;:&lt;peer&gt; &lt;addr1:data1&gt; &lt;addr2:data2&gt;...</B><a name="CUL_HMregBulk"></a><br>
  10550. Dieser Befehl ersetzt das bisherige regRaw. Er erlaubt Register mit Rohdaten zu
  10551. beschreiben. Hauptzweck ist das komplette Wiederherstellen eines zuvor gesicherten
  10552. Registers. <br>
  10553. Werte k&ouml;nnen mit <a href="#CUL_HMgetConfig">getConfig</a> ausgelesen werden. Die
  10554. zur&uuml;ckgegebenen Werte k&ouml;nnen direkt f&uuml;r diesen Befehl verwendet werden.<br>
  10555. &lt;reg List&gt; bezeichnet die Liste in die geschrieben werden soll. M&ouml;gliches Format
  10556. '00', 'RegL_00', '01'...<br>
  10557. &lt;peer&gt; ist eine optionale Angabe falls die Liste ein Peer ben&ouml;tigt.
  10558. Der Peer kann als Kanalname oder als 4-Byte (8 chars) HM-Kanal ID angegeben
  10559. werden.<br>
  10560. &lt;addr1:data1&gt; ist die Liste der Register im Hex-Format.<br>
  10561. Beispiel:<br>
  10562. <ul><code>
  10563. set myChannel regBulk RegL_00. 02:01 0A:17 0B:43 0C:BF 15:FF 00:00<br>
  10564. RegL_03.FB_Btn_07
  10565. 01:00 02:00 03:00 04:32 05:64 06:00 07:FF 08:00 09:FF 0A:01 0B:44 0C:54 0D:93 0E:00 0F:00 11:C8 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 1A:00 1B:00 1C:00 1D:FF 1E:93 1F:00 81:00 82:00 83:00 84:32 85:64 86:00 87:FF 88:00 89:FF 8A:21 8B:44 8C:54 8D:93 8E:00 8F:00 91:C8 92:00 93:00 94:00 95:00 96:00 97:00 98:00 99:00 9A:00 9B:00 9C:00 9D:05 9E:93 9F:00 00:00<br>
  10566. set myblind regBulk 01 0B:10<br>
  10567. set myblind regBulk 01 0C:00<br>
  10568. </code></ul>
  10569. myblind setzt die maximale Zeit f&uuml;r das Hochfahren der Rollos auf 25,6 Sekunden
  10570. </li>
  10571. <li><B>regSet [prep|exec] &lt;regName&gt; &lt;value&gt; &lt;peerChannel&gt;</B><a name="CUL_HMregSet"></a><br>
  10572. F&uuml;r einige Hauptregister gibt es eine lesbarere Version die Registernamen &lt;regName&gt;
  10573. und Wandlung der Werte enth&auml;lt. Nur ein Teil der Register wird davon unterst&uuml;tzt.<br>
  10574. Der optionale Parameter [prep|exec] erlaubt das Packen von Nachrichten und verbessert damit
  10575. deutlich die Daten&uuml;bertragung.
  10576. Benutzung durch senden der Befehle mit Parameter "prep". Daten werden dann f&uuml;r das Senden gesammelt.
  10577. Der letzte Befehl muss den Parameter "exec" habe um die Information zu &uuml;bertragen.<br>
  10578. &lt;value&gt; enth&auml;lt die Daten in menschenlesbarer Form die in das Register geschrieben werden.<br>
  10579. &lt;peerChannel&gt; wird ben&ouml;tigt falls das Register 'peerChan' basiert definiert wird.
  10580. Kann ansonsten auf '0' gesetzt werden. Siehe <a
  10581. href="#CUL_HMgetRegRaw">getRegRaw</a> f&uuml;r komplette Definition.<br>
  10582. Unterst&uuml;tzte Register eines Ger&auml;ts k&ouml;nnen wie folgt bestimmt werden:<br>
  10583. <ul><code>set regSet ? 0 0</code></ul>
  10584. Eine verk&uuml;rzte Beschreibung der Register wird zur&uuml;ckgegeben mit:<br>
  10585. <ul><code>set regSet &lt;regname&gt; ? 0</code></ul>
  10586. </li>
  10587. <li><B>reset</B><a name="CUL_HMreset"></a><br>
  10588. R&uuml;cksetzen des Ger&auml;ts auf Werkseinstellungen. Muss danach erneut verbunden werden um es
  10589. mit FHEM zu nutzen.
  10590. </li>
  10591. <li><B>sign [on|off]</B><a name="CUL_HMsign"></a><br>
  10592. Ein- oder ausschalten der Signierung (auch "AES-Verschl&uuml;sselung" genannt, siehe <a
  10593. href="#HMAES">note</a>). Achtung: Wird das Ger&auml;t &uuml;ber einen CUL eingebunden, ist schalten (oder
  10594. deaktivieren der Signierung) nur m&ouml;glich, wenn das Perl-Modul Crypt::Rijndael installiert ist.
  10595. </li>
  10596. <li><B>statusRequest</B><a name="CUL_HMstatusRequest"></a><br>
  10597. Aktualisieren des Ger&auml;testatus. F&uuml;r mehrkanalige Ger&auml;te sollte dies kanalbasiert
  10598. erfolgen.
  10599. </li>
  10600. <li><B>unpair</B><a name="CUL_HMunpair"></a><br>
  10601. Aufheben des "Pairings", z.B. um das verbinden mit einem anderen Master zu erm&ouml;glichen.
  10602. Siehe <a href="#CUL_HMpair">pair</a> f&uuml;r eine Beschreibung.</li>
  10603. <li><B>virtual &lt;Anzahl an Kn&ouml;pfen&gt;</B><a name="CUL_HMvirtual"></a><br>
  10604. Konfiguriert eine vorhandene Schaltung als virtuelle Fernbedienung. Die Anzahl der anlegbaren
  10605. Kn&ouml;pfe ist 1 - 255. Wird der Befehl f&uuml;r die selbe Instanz erneut aufgerufen werden Kn&ouml;pfe
  10606. hinzugef&uuml;gt. <br>
  10607. Beispiel f&uuml;r die Anwendung:
  10608. <ul><code>
  10609. define vRemote CUL_HM 100000 # die gew&auml;hlte HMid darf nicht in Benutzung sein<br>
  10610. set vRemote virtual 20 # definiere eine Fernbedienung mit 20 Kn&ouml;pfen<br>
  10611. set vRemote_Btn4 peerChan 0 &lt;actorchannel&gt; # verkn&uuml;pft Knopf 4 und 5 mit dem gew&auml;hlten Kanal<br>
  10612. set vRemote_Btn4 press<br>
  10613. set vRemote_Btn5 press long<br>
  10614. </code></ul>
  10615. siehe auch <a href="#CUL_HMpress">press</a>
  10616. </li>
  10617. <li><B>deviceRename &lt;newName&gt;</B><a name="CUL_HMdeviceRename"></a><br>
  10618. benennt das Device und alle seine Kan&auml;le um.
  10619. </li>
  10620. <li><B>fwUpdate [onlyEnterBootLoader] &lt;filename&gt; [&lt;waitTime&gt;]</B><br>
  10621. update Fw des Device. Der User muss das passende FW file bereitstellen.
  10622. waitTime ist optional. Es ist die Wartezeit, um das Device manuell in den FW-update-mode
  10623. zu versetzen.<br>
  10624. "onlyEnterBootLoader" schickt das Device in den Booloader so dass es vom eq3 Firmware Update
  10625. Tool geflashed werden kann. Haupts&auml;chlich f&uuml;r Unterputz-Aktoren in Verbindung mit
  10626. FHEM Installationen die ausschliesslich HM-LANs nutzen interessant.
  10627. </li>
  10628. </ul>
  10629. <br>
  10630. <B>subType abh&auml;ngige Befehle:</B>
  10631. <ul>
  10632. <br>
  10633. <li>switch
  10634. <ul>
  10635. <li><B>on</B> <a name="CUL_HMon"> </a> - setzt Wert auf 100%</li>
  10636. <li><B>off</B><a name="CUL_HMoff"></a> - setzt Wert auf 0%</li>
  10637. <li><B>on-for-timer &lt;sec&gt;</B><a name="CUL_HMonForTimer"></a> -
  10638. Schaltet das Ger&auml;t f&uuml;r die gew&auml;hlte Zeit in Sekunden [0-85825945] an.<br> Hinweis:
  10639. off-for-timer wie bei FS20 wird nicht unterst&uuml;tzt. Kann aber &uuml;ber Kanalregister
  10640. programmiert werden.</li>
  10641. <li><B>on-till &lt;time&gt;</B><a name="CUL_HMonTill"></a> - einschalten bis zum angegebenen Zeitpunkt.<br>
  10642. <ul><code>set &lt;name&gt; on-till 20:32:10<br></code></ul>
  10643. Das momentane Maximum f&uuml;r eine Endzeit liegt bei 24 Stunden.<br>
  10644. </li>
  10645. <li><B>press &lt;[short|long]&gt;&lt;[on|off]&gt;</B><a name="CUL_HMpress"></a><br>
  10646. <B>press &lt;[short|long]&gt;&lt;[noBurst]&gt;</B></a>
  10647. simuliert den Druck auf einen lokalen Knopf oder direkt verbundenen Knopf des Aktors.<br>
  10648. <B>[short|long]</B> w&auml;hlt aus ob ein kurzer oder langer Tastendruck simuliert werden soll.<br>
  10649. <B>[on|off]</B> ist relevant f&uuml;r Ger&auml;te mit direkter Bedienung pro Kanal.
  10650. Verf&uuml;gbar f&uuml;r Dimmer und Rollo-Aktoren, normalerweise nicht f&uuml;r Schalter.<br>
  10651. <B>[noBurst]</B> ist relevant f&uuml;r Peers die bedingte Bursts unterst&uuml;tzen.
  10652. Dies bewirkt das der Befehl der Warteliste des Peers zugef&uuml;gt wird. Ein Burst wird anschließend
  10653. <B>nicht </B> ausgef&uuml;hrt da der Befehl wartet bis der Peer aufgewacht ist. Dies f&uuml;hrt zu einer
  10654. <B>Verz&ouml;gerung des Tastendrucks</B>, reduziert aber &Uuml;bertragungs- und Performanceaufwand. <br>
  10655. </li>
  10656. <li><B>toggle</B><a name="CUL_HMtoggle"></a> - toggled den Aktor. Schaltet vom aktuellen Level auf
  10657. 0% oder von 0% auf 100%</li>
  10658. </ul>
  10659. <li><B>pressL &lt;peer&gt;</B><a name="CUL_HMpressL"></a><br>
  10660. Simuliert einen langen Tastendruck für einen angegebenen peer. Siehe press.
  10661. </li>
  10662. <li><B>pressS &lt;peer&gt;</B><a name="CUL_HMpressS"></a><br>
  10663. Simuliert einen kurzen Tastendruck für einen angegebenen peer. Siehe press.
  10664. </li>
  10665. <br>
  10666. </li>
  10667. <li>dimmer, blindActuator<br>
  10668. Dimmer k&ouml;nnen virtuelle Kan&auml;le unterst&uuml;tzen. Diese werden automatisch angelegt falls vorhanden.
  10669. Normalerweise gibt es 2 virtuelle Kan&auml;le zus&auml;tzlich zum prim&auml;ren Kanal. Virtuelle Dimmerkan&auml;le sind
  10670. standardm&auml;ßig deaktiviert, k&ouml;nnen aber parallel zum ersten Kanal benutzt werden um das Licht zu steuern. <br>
  10671. Die virtuellen Kan&auml;le haben Standardnamen SW&lt;channel&gt;_V&lt;nr&gt; z.B. Dimmer_SW1_V1 and Dimmer_SW1_V2.<br>
  10672. Virtuelle Dimmerkan&auml;le unterscheiden sich komplett von virtuellen Kn&ouml;pfen und Aktoren in FHEM, sind aber
  10673. Teil des HM-Ger&auml;ts. Dokumentation und M&ouml;glichkeiten w&uuml;rde hier aber zu weit f&uuml;hren.<br>
  10674. <ul>
  10675. <li><B>0 - 100 [on-time] [ramp-time]</B><br>
  10676. Setzt den Aktor auf den gegeben Wert (In Prozent)
  10677. mit einer Aufl&ouml;sung von 0.5.<br>
  10678. Bei Dimmern ist optional die Angabe von "on-time" und "ramp-time" m&ouml;glich, beide in Sekunden mit 0.1s Abstufung.<br>
  10679. "On-time" verh&auml;lt sich analog dem "on-for-timer".<br>
  10680. "Ramp-time" betr&auml;gt standardm&auml;ßig 2.5s, 0 bedeutet umgehend.<br>
  10681. </li>
  10682. <li><B><a href="#CUL_HMon">on</a></B></li>
  10683. <li><B><a href="#CUL_HMoff">off</a></B></li>
  10684. <li><B><a href="#CUL_HMpress">press &lt;[short|long]&gt;&lt;[on|off]&gt;</a></B></li>
  10685. <li><B><a href="#CUL_HMtoggle">toggle</a></B></li>
  10686. <li><B>toggleDir</B><a name="CUL_HMtoggleDir"></a> - toggelt die fahrtrichtung des Rollo-Aktors.
  10687. Es wird umgeschaltet zwischen auf/stop/ab/stop</li>
  10688. <li><B><a href="#CUL_HMonForTimer">on-for-timer &lt;sec&gt;</a></B> - Nur Dimmer! <br></li>
  10689. <li><B><a href="#CUL_HMonTill">on-till &lt;time&gt;</a></B> - Nur Dimmer! <br></li>
  10690. <li><B>stop</B> - Stopt Bewegung (Rollo) oder Dimmerrampe</li>
  10691. <li><B>old</B> - schaltet auf den vorigen Wert zurück. Nur dimmer. </li>
  10692. <li><B>pct &lt;level&gt [&lt;ontime&gt] [&lt;ramptime&gt]</B> - setzt Aktor auf gew&uuml;nschten <B>absolut Wert</B>.<br>
  10693. Optional k&ouml;nnen f&uuml;r Dimmer "ontime" und "ramptime" angegeben werden.<br>
  10694. "Ontime" kann dabei in Sekunden angegeben werden. Kann auch als Endzeit angegeben werden im Format hh:mm:ss
  10695. </li>
  10696. <li><B>up [changeValue] [&lt;ontime&gt] [&lt;ramptime&gt]</B> Einen Schritt hochdimmen.</li>
  10697. <li><B>down [changeValue] [&lt;ontime&gt] [&lt;ramptime&gt]</B> Einen Schritt runterdimmen.<br>
  10698. "changeValue" ist optional und gibt den zu &auml;ndernden Wert in Prozent an. M&ouml;gliche Abstufung dabei ist 0.5%, Standard ist 10%. <br>
  10699. "ontime" ist optional und gibt an wielange der Wert gehalten werden soll. '0' bedeutet endlos und ist Standard.<br>
  10700. "ramptime" ist optional und definiert die Zeit bis eine &auml;nderung den neuen Wert erreicht. Hat nur f&uuml;r Dimmer Bedeutung.
  10701. <br></li>
  10702. </ul>
  10703. <br>
  10704. </li>
  10705. <li>remotes, pushButton<a name="CUL_HMremote"></a><br>
  10706. Diese Ger&auml;teart reagiert nicht auf Anfragen, außer sie befinden sich im Lernmodus. FHEM reagiert darauf
  10707. indem alle Anfragen gesammelt werden bis der Lernmodus detektiert wird. Manuelles Eingreifen durch
  10708. den Benutzer ist dazu n&ouml;tig. Ob Befehle auf Ausf&uuml;hrung warten kann auf Ger&auml;teebene mit dem Parameter
  10709. 'protCmdPend' abgefragt werden.
  10710. <ul>
  10711. <li><B>peerChan &lt;btn_no&gt; &lt;actChan&gt; [single|<u>dual</u>|reverse]
  10712. [<u>set</u>|unset] [<u>both</u>|actor|remote]</B><a name="CUL_HMpeerChan"></a><br>
  10713. "peerChan" richtet eine Verbindung zwischen Sender-<B>Kanal</B> und
  10714. Aktor-<B>Kanal</B> ein, bei HM "link" genannt. "Peering" darf dabei nicht
  10715. mit "pairing" verwechselt werden.<br>
  10716. <B>Pairing</B> bezeichnet das Zuordnen eines <B>Ger&auml;ts</B> zu einer Zentrale.<br>
  10717. <B>Peering</B> bezeichnet das faktische Verbinden von <B>Kan&auml;len</B>.<br>
  10718. Peering erlaubt die direkte Interaktion zwischen Sender und Aktor ohne den Einsatz einer CCU<br>
  10719. Peering eines Senderkanals veranlaßt den Sender nach dem Senden eines Triggers auf die
  10720. Best&auml;tigung eines - jeden - Peers zu warten. Positives Feedback (z.B. gr&uuml;ne LED)
  10721. gibt es dabei nur wenn alle Peers den Befehl best&auml;tigt haben.<br>
  10722. Peering eines Aktorkanals richtet dabei einen Satz von Parametern ein welche die auszuf&uuml;hrenden Aktionen
  10723. definieren wenn ein Trigger dieses Peers empfangen wird. Dies bedeutet: <br>
  10724. - nur Trigger von Peers werden ausgef&uuml;hrt<br>
  10725. - die auszuf&uuml;hrende Aktion muss f&uuml;r den zugeh&ouml;rigen Trigger eines Peers definiert werden<br>
  10726. Ein Aktorkanal richtet dabei eine Standardaktion beim Peering ein - diese h&auml;ngt vom Aktor ab.
  10727. Sie kann ebenfalls davon abh&auml;ngen ob ein oder zwei Tasten <B>ein einem Befehl</B> gepeert werden.
  10728. Peert man einen Schalter mit 2 Tasten kann eine Taste f&uuml;r 'on' und eine andere f&uuml;r 'off' angelegt werden.
  10729. Wenn nur eine Taste definiert wird ist die Funktion wahrscheinlich 'toggle'.<br>
  10730. Die Funktion kann durch programmieren des Register (vom Aktor abh&auml;ngig) ge&auml;ndert werden.<br>
  10731. Auch wenn der Befehl von einer Fernbedienung oder einem Taster kommt hat er direkten Effekt auf
  10732. den Aktor. Das Peering beider Seiten ist quasi unabh&auml;ngig und hat unterschiedlich Einfluss auf
  10733. Sender und Empf&auml;nger.<br>
  10734. Peering eines Aktorkanals mit mehreren Senderkan&auml;len ist ebenso m&ouml;glich wie das eines Senderkanals
  10735. mit mehreren Empf&auml;ngerkan&auml;len.<br>
  10736. &lt;actChan&gt; ist der zu verkn&uuml;pfende Aktorkanal.<br>
  10737. &lt;btn_no&gt; ist der zu verkn&uuml;pfende Senderkanal (Knopf). Wird
  10738. 'single' gew&auml;hlt werden die Tasten von 1 an gez&auml;hlt. F&uuml;r 'dual' ist btn_no
  10739. die Nummer des zu verwendenden Tasterpaares. Z.B. ist '3' iim Dualmodus das
  10740. dritte Tasterpaar welches mit Tasten 5 und 6 im Singlemodus &uuml;bereinstimmt.<br>
  10741. Wird der Befehl auf einen Kanal angewendet wird btn_no igroriert.
  10742. Muss gesetzt sein, sollte dabei 0 sein.<br>
  10743. [single|dual]: Dieser Modus bewirkt das Standardverhalten des Aktors bei Benutzung eines Tasters. Ein Dimmer
  10744. kann z.B. an einen einzelnen oder ein Paar von Tastern angelernt werden. <br>
  10745. Standardeinstellung ist "dual".<br>
  10746. 'dual' (default) Schalter verkn&uuml;pft zwei Taster mit einem Aktor. Bei einem Dimmer
  10747. bedeutet das ein Taster f&uuml;r hoch- und einer f&uuml;r runterdimmen. <br>
  10748. 'reverse' identisch zu dual - nur die Reihenfolge der Buttons ist gedreht<br>
  10749. 'single' benutzt nur einen Taster des Senders. Ist z.B. n&uuml;tzlich f&uuml;r einen einfachen Schalter
  10750. der nur zwischen an/aus toggled. Aber auch ein Dimmer kann an nur einen Taster angelernt werden.<br>
  10751. [set|unset]: W&auml;hlt aus ob Peer hinzugef&uuml;gt oder entfernt werden soll.<br>
  10752. Hinzuf&uuml;gen ist Standard.<br>
  10753. 'set' stellt Peers f&uuml;r einen Kanal ein.<br>
  10754. 'unset' entfernt Peer f&uuml;r einen Kanal.<br>
  10755. [actor|remote|both] beschr&auml;nkt die Ausf&uuml;hrung auf Aktor oder Fernbedienung.
  10756. Das erm&ouml;glicht dem Benutzer das entfernen des Peers vom Fernbedienungskanal ohne
  10757. die Einstellungen am Aktor zu entfernen.<br>
  10758. Standardm&auml;ßig gew&auml;hlt ist "both" f&uuml;r beides.<br>
  10759. Example:
  10760. <ul><code>
  10761. set myRemote peerChan 2 mySwActChn single set #Peer zweiten Knopf mit Aktorkanal<br>
  10762. set myRmtBtn peerChan 0 mySwActChn single set #myRmtBtn ist ein Knopf der Fernbedienung. '0' wird hier nicht verarbeitet<br>
  10763. set myRemote peerChan 2 mySwActChn dual set #Verkn&uuml;pfe Kn&ouml;pfe 3 und 4<br>
  10764. set myRemote peerChan 3 mySwActChn dual unset #Entferne Peering f&uuml;r Kn&ouml;pfe 5 und 6<br>
  10765. set myRemote peerChan 3 mySwActChn dual unset aktor #Entferne Peering f&uuml;r Kn&ouml;pfe 5 und 6 nur im Aktor<br>
  10766. set myRemote peerChan 3 mySwActChn dual set remote #Verkn&uuml;pfe Kn&ouml;pfe 5 und 6 nur mit Fernbedienung. Linkeinstellungen mySwActChn werden beibehalten.<br>
  10767. </code></ul>
  10768. </li>
  10769. </ul>
  10770. </li>
  10771. <li>virtual<a name="CUL_HMvirtual"></a><br>
  10772. <ul>
  10773. <li><B><a href="#CUL_HMpeerChan">peerChan</a></B> siehe remote</li>
  10774. <li><B><a name="CUL_HMpress"></a>press [long|short] [&lt;peer&gt;] [&lt;repCount&gt;] [&lt;repDelay&gt;] </B>
  10775. <ul>
  10776. Simuliert den Tastendruck am Aktor eines gepeerted Sensors
  10777. <li>[long|short] soll ein langer oder kurzer Taastendrucl simuliert werden? Default ist kurz. </li>
  10778. <li>[&lt;peer&gt;] legt fest, wessen peer's trigger simuliert werden soll.Default ist self(channelNo).</li>
  10779. <li>[&lt;repCount&gt;] nur gueltig fuer long. wie viele messages sollen gesendet werden? (Laenge des Button press). Default ist 1.</li>
  10780. <li>[&lt;repDelay&gt;] nur gueltig fuer long. definiert die Zeit zwischen den einzelnen Messages. </li>
  10781. </ul>
  10782. </li>
  10783. <li><B>virtTemp &lt;[off -10..50]&gt;<a name="CUL_HMvirtTemp"></a></B>
  10784. Simuliert ein Thermostat. Wenn mit einem Ger&auml;t gepeert wird periodisch eine Temperatur gesendet,
  10785. solange bis "off" gew&auml;hlt wird. Siehe auch <a href="#CUL_HMvirtHum">virtHum</a><br>
  10786. </li>
  10787. <li><B>virtHum &lt;[off -10..50]&gt;<a name="CUL_HMvirtHum"></a></B>
  10788. Simuliert den Feuchtigkeitswert eines Thermostats. Wenn mit einem Ger&auml;t verkn&uuml;pft werden periodisch
  10789. Luftfeuchtigkeit undTemperatur gesendet, solange bis "off" gew&auml;hlt wird. Siehe auch <a href="#CUL_HMvirtTemp">virtTemp</a><br>
  10790. </li>
  10791. <li><B>valvePos &lt;[off 0..100]&gt;<a name="CUL_HMvalvePos"></a></B>
  10792. steuert einen Ventilantrieb<br>
  10793. </li>
  10794. </ul>
  10795. </li>
  10796. <li>smokeDetector<br>
  10797. Hinweis: All diese Befehle funktionieren momentan nur wenn mehr als ein Rauchmelder
  10798. vorhanden ist, und diese gepeert wurden um eine Gruppe zu bilden. Um die Befehle abzusetzen
  10799. muss der Master dieser gruppe verwendet werden, und momentan muss man raten welcher der Master ist.<br>
  10800. smokeDetector kann folgendermaßen in Gruppen eingeteilt werden:
  10801. <a href="#CUL_HMpeerChan">peerChan</a>. Alle Mitglieder m&uuml;ssen mit dem Master verkn&uuml;pft werden. Auch der
  10802. Master muss mit peerChan zur Gruppe zugef&uuml;gt werden - z.B. mit sich selbst verkn&uuml;pft! Dadurch hat man volle
  10803. Kontrolle &uuml;ber die Gruppe und muss nicht raten.<br>
  10804. <ul>
  10805. <li><B>teamCall</B> - f&uuml;hrt einen Netzwerktest unter allen Gruppenmitgliedern aus</li>
  10806. <li><B>teamCallBat</B> - Simuliert einen low-battery alarm</li>
  10807. <li><B>alarmOn</B> - l&ouml;st einen Alarm aus</li>
  10808. <li><B>alarmOff</B> - schaltet den Alarm aus</li>
  10809. </ul>
  10810. </li>
  10811. <li>4Dis (HM-PB-4DIS-WM|HM-PB-4DIS-WM|HM-RC-Dis-H-x-EU|ROTO_ZEL-STG-RM-DWT-10)
  10812. <ul>
  10813. <li><B>text &lt;btn_no&gt; [on|off] &lt;text1&gt; &lt;text2&gt;</B><br>
  10814. Zeigt Text auf dem Display eines Ger&auml;ts an. F&uuml;r diesen Zweck muss zuerst ein set-Befehl
  10815. (oder eine Anzahl davon) abgegeben werden, dann k&ouml;nnen im "teach-in" Men&uuml; des 4Dis mit
  10816. "Central" Daten &uuml;bertragen werden.<br>
  10817. Falls auf einen Kanal angewendet d&uuml;rfen btn_no und on|off nicht verwendet werden, nur
  10818. reiner Text.<br>
  10819. \_ wird durch ein Leerzeichen ersetzt.<br>
  10820. Beispiel:
  10821. <ul>
  10822. <code>
  10823. set 4Dis text 1 on On Lamp<br>
  10824. set 4Dis text 1 off Kitchen Off<br>
  10825. <br>
  10826. set 4Dis_chn4 text Kitchen Off<br>
  10827. </code>
  10828. </ul>
  10829. </li>
  10830. </ul>
  10831. <br>
  10832. </li>
  10833. <li>Climate-Control (HM-CC-TC)
  10834. <ul>
  10835. <li><B>desired-temp &lt;temp&gt;</B><br>
  10836. Setzt verschiedene Temperaturen. &lt;temp&gt; muss zwischen 6°C und 30°C liegen, die Aufl&ouml;sung betr&auml;gt 0.5°C.</li>
  10837. <li><B>tempListSat [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10838. <li><B>tempListSun [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10839. <li><B>tempListMon [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10840. <li><B>tempListTue [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10841. <li><B>tempListThu [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10842. <li><B>tempListWed [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10843. <li><B>tempListFri [prep|exec] HH:MM temp ... 24:00 temp</B><br>
  10844. Gibt eine Liste mit Temperaturintervallen an. Bis zu 24 Intervall k&ouml;nnen pro Wochentag definiert werden, die
  10845. Aufl&ouml;sung dabei sind 10 Minuten. Die letzte Zeitangabe muss 24:00 Uhr sein.<br>
  10846. Beispiel: bis 6:00 soll die Temperatur 19°C sein, dann bis 23:00 Uhr 22.5°C, anschließend
  10847. werden bis Mitternacht 19°C gew&uuml;nscht.<br>
  10848. <code> set th tempListSat 06:00 19 23:00 22.5 24:00 19<br></code>
  10849. </li>
  10850. <li><B>partyMode &lt;HH:MM&gt;&lt;durationDays&gt;</B><br>
  10851. setzt die Steuerung f&uuml;r die angegebene Zeit in den Partymodus. Dazu ist die Endzeit sowie <b>Anzahl an Tagen</b>
  10852. die er dauern soll anzugeben. Falls er am n&auml;chsten Tag enden soll ist '1'
  10853. anzugeben<br></li>
  10854. <li><B>sysTime</B><br>
  10855. setzt Zeit des Klimakanals auf die Systemzeit</li>
  10856. </ul><br>
  10857. </li>
  10858. <li>Climate-Control (HM-CC-RT-DN|HM-CC-RT-DN-BoM)
  10859. <ul>
  10860. <li><B>controlMode &lt;auto|boost|day|night&gt;</B><br></li>
  10861. <li><B>controlManu &lt;temp&gt;</B><br></li>
  10862. <li><B>controlParty &lt;temp&gt;&lt;startDate&gt;&lt;startTime&gt;&lt;endDate&gt;&lt;endTime&gt;</B><br>
  10863. setzt die Steuerung in den Partymodus, definiert Temperatur und Zeitrahmen.<br>
  10864. Beispiel:<br>
  10865. <code>set controlParty 15 03.8.13 20:30 5.8.13 11:30</code></li>
  10866. <li><B>sysTime</B><br>
  10867. setzt Zeit des Klimakanals auf die Systemzeit</li>
  10868. <li><B>desired-temp &lt;temp&gt;</B><br>
  10869. Setzt verschiedene Temperaturen. &lt;temp&gt; muss zwischen 6°C und 30°C liegen, die Aufl&ouml;sung betr&auml;gt 0.5°C.</li>
  10870. <li><B>tempListSat [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10871. <li><B>tempListSun [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10872. <li><B>tempListMon [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10873. <li><B>tempListTue [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10874. <li><B>tempListThu [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10875. <li><B>tempListWed [prep|exec] HH:MM temp ... 24:00 temp</B><br></li>
  10876. <li><B>tempListFri [prep|exec] HH:MM temp ... 24:00 temp</B><br>
  10877. Gibt eine Liste mit Temperaturintervallen an. Bis zu 24 Intervall k&ouml;nnen pro Wochentag definiert werden, die
  10878. Aufl&ouml;sung dabei sind 10 Minuten. Die letzte Zeitangabe muss immer 24:00 Uhr sein.<br>
  10879. Der optionale Parameter [prep|exec] erlaubt das packen der Nachrichten und verbessert damit deutlich
  10880. die Daten&uuml;bertragung. Besonders n&uuml;tzlich wenn das Ger&auml;t im "Wakeup"-modus betrieben wird.
  10881. Benutzung durch senden der Befehle mit Parameter "prep". Daten werden dann f&uuml;r das Senden gesammelt.
  10882. Der letzte Befehl muss den Parameter "exec" habe um die Information zu &uuml;bertragen.<br>
  10883. Beispiel: bis 6:00 soll die Temperatur 19°C sein, dann bis 23:00 Uhr 22.5°C, anschließend
  10884. werden bis Mitternacht 19°C gew&uuml;nscht.<br>
  10885. <code> set th tempListSat 06:00 19 23:00 22.5 24:00 19<br></code>
  10886. <br>
  10887. <code> set th tempListSat prep 06:00 19 23:00 22.5 24:00 19<br>
  10888. set th tempListSun prep 06:00 19 23:00 22.5 24:00 19<br>
  10889. set th tempListMon prep 06:00 19 23:00 22.5 24:00 19<br>
  10890. set th tempListTue exec 06:00 19 23:00 22.5 24:00 19<br></code>
  10891. </li>
  10892. <li><B>tempListTmpl =>"[verify|restore] [[&lt;file&gt;:]templateName] ...</B><br>
  10893. Die Temperaturlisten f&uuml;r ein oder mehrere Devices k&ouml;nnen in einem File hinterlegt
  10894. werden. Es wird ein template f&uuml;r eine Woche hinterlegt. Der User kann dieses
  10895. template in ein Device schreiben lassen (restore). Er kann auch pr&uuml;fen, ob das Device korrekt
  10896. nach dieser Templist programmiert ist (verify).
  10897. Default Opeartion ist verify.<br>
  10898. Default File ist tempList.cfg.<br>
  10899. Default templateName ist der name der Entity<br>
  10900. Default f&uuml;r file und templateName kann mit dem Attribut <B>tempListTmpl</B> gesetzt werden.<br>
  10901. Beispiel f&uuml;r ein templist File. room1 und room2 sind die Namen 2er Tempaltes:<br>
  10902. <code>entities:room1
  10903. tempListSat>08:00 16.0 15:00 18.0 21:30 19.0 24:00 14.0
  10904. tempListSun>08:00 16.0 15:00 18.0 21:30 19.0 24:00 14.0
  10905. tempListMon>07:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  10906. tempListTue>07:00 16.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 15.0
  10907. tempListWed>07:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  10908. tempListThu>07:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  10909. tempListFri>07:00 16.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  10910. entities:room2
  10911. tempListSat>08:00 14.0 15:00 18.0 21:30 19.0 24:00 14.0
  10912. tempListSun>08:00 14.0 15:00 18.0 21:30 19.0 24:00 14.0
  10913. tempListMon>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
  10914. tempListTue>07:00 14.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 15.0
  10915. tempListWed>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
  10916. tempListThu>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
  10917. tempListFri>07:00 14.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
  10918. </code>
  10919. Specials:<br>
  10920. <li>none: das Template wird ignoriert</li>
  10921. <li>defaultWeekplan: Es wird als Default jeden Tag 18.0 Grad eingestellt.
  10922. Sinnvoll nutzbar wenn man einen TC als Kontroller nutzt. Der Wochenplan des TC wird dann imlizit genutzt</li>
  10923. </li>
  10924. <li><B>tempTmplSet =>"[[ &lt;file&gt; :]templateName]</B><br>
  10925. Setzt das Attribut und sendet die Änderungen an das Device.
  10926. </li>
  10927. <li><B>templateDel =>" &lt;template&gt; </B><br>
  10928. Löscht eine Templateeintrag an dieser entity.
  10929. </li>
  10930. </ul><br>
  10931. </li>
  10932. <li>OutputUnit (HM-OU-LED16)
  10933. <ul>
  10934. <li><B>led [off|red|green|yellow]</B><br>
  10935. schaltet die LED des Kanals auf die gew&uuml;nschte Farbe. Wird der Befehl auf ein Ger&auml;t angewandt so
  10936. werden alle LEDs auf diese Farbe gesetzt.<br>
  10937. Experten k&ouml;nnen die LEDs separat durch eine 8-stellige Hex-Zahl ansteuern.<br></li>
  10938. <li><B>ilum &lt;Helligkeit&gt;&lt;Dauer&gt; </B><br>
  10939. &lt;Helligkeit&gt; [0-15] der Beleuchtung.<br>
  10940. &lt;Dauer&gt; [0-127] in Sekunden, 0 bedeutet dauernd an.<br></li>
  10941. </ul><br>
  10942. </li>
  10943. <li>OutputUnit (HM-OU-CFM-PL)
  10944. <ul>
  10945. <li><B>led &lt;color&gt;[,&lt;color&gt;..] [&lt;repeat&gt..]</B><br>
  10946. M&ouml;gliche Farben sind [redL|greenL|yellowL|redS|greenS|yellowS|pause]. Eine Folge von Farben
  10947. kann durch trennen der Farbeintr&auml;ge mit ',' eingestellt werden.
  10948. Leerzeichen d&uuml;rfen in der Liste nicht benutzt werden. 'S' bezeichnet kurze und
  10949. 'L' lange Beleuchtungsdauer. <br>
  10950. <b>repeat</b> definiert wie oft die Sequenz ausgef&uuml;hrt werden soll. Standard ist 1.<br>
  10951. </li>
  10952. <li><B>playTone &lt;MP3No&gt[,&lt;MP3No&gt;..] [&lt;repeat&gt;] [&lt;volume&gt;]</B><br>
  10953. Spielt eine Reihe von T&ouml;nen. Die Liste muss mit ',' getrennt werden. Leerzeichen
  10954. d&uuml;rfen in der Liste nicht benutzt werden.<br>
  10955. <b>replay</b> kann verwendet werden um den zuletzt gespielten Klang zu wiederholen.<br>
  10956. <b>repeat</b> definiert wie oft die Sequenz ausgef&uuml;hrt werden soll. Standard ist 1.<br>
  10957. <b>volume</b> kann im Bereich 0..10 liegen. 0 stoppt jeden aktuell gespielten Sound. Standard ist 10 (100%.<br>
  10958. Beispiel:
  10959. <ul><code>
  10960. set cfm_Mp3 playTone 3 # MP3 Titel 3 einmal<br>
  10961. set cfm_Mp3 playTone 3 3 # MP3 Titel 3 dreimal<br>
  10962. set cfm_Mp3 playTone 3 1 5 # MP3 Titel 3 mit halber Lautst&auml;rke<br>
  10963. set cfm_Mp3 playTone 3,6,8,3,4 # MP3 Titelfolge 3,6,8,3,4 einmal<br>
  10964. set cfm_Mp3 playTone 3,6,8,3,4 255# MP3 Titelfolge 3,6,8,3,4 255 mal<br>
  10965. set cfm_Mp3 playTone replay # Wiederhole letzte Sequenz<br>
  10966. <br>
  10967. set cfm_Led led redL 4 # rote LED dreimal lang blinken<br>
  10968. set cfm_Led led redS,redS,redS,redL,redL,redL,redS,redS,redS 255 # SOS 255 mal<br>
  10969. </ul></code>
  10970. </li>
  10971. </ul><br>
  10972. </li>
  10973. <li>HM-RC-19xxx
  10974. <ul>
  10975. <li><B>alarm &lt;count&gt;</B><br>
  10976. sendet eine Alarmnachricht an die Steuerung<br></li>
  10977. <li><B>service &lt;count&gt;</B><br>
  10978. sendet eine Servicenachricht an die Steuerung<br></li>
  10979. <li><B>symbol &lt;symbol&gt; [set|unset]</B><br>
  10980. aktiviert ein verf&uuml;gbares Symbol auf der Steuerung<br></li>
  10981. <li><B>beep [off|1|2|3]</B><br>
  10982. aktiviert T&ouml;ne<br></li>
  10983. <li><B>backlight [off|on|slow|fast]</B><br>
  10984. aktiviert Hintergrundbeleuchtung<br></li>
  10985. <li><B>display &lt;text&gt; comma unit tone backlight &lt;symbol(s)&gt;
  10986. </B><br>
  10987. Steuert das Display der Steuerung<br>
  10988. &lt;text&gt; : bis zu 5 Zeichen <br>
  10989. comma : 'comma' aktiviert das Komma, 'no' l&auml;ßt es aus <br>
  10990. [unit] : setzt Einheitensymbole.
  10991. [off|Proz|Watt|x3|C|x5|x6|x7|F|x9|x10|x11|x12|x13|x14|x15]. Momentan sind
  10992. x3..x15 nicht getestet. <br>
  10993. tone : aktiviert einen von 3 T&ouml;nen [off|1|2|3]<br>
  10994. backlight: l&auml;ßt die Hintergrundbeleuchtung aufblinken [off|on|slow|fast]<br>
  10995. &lt;symbol(s)&gt; aktiviert die Anzeige von Symbolen. Mehrere Symbole
  10996. k&ouml;nnen zu selben Zeit aktiv sein, Verkn&uuml;pfung erfolgt komma-getrennt. Dabei keine
  10997. Leerzeichen verwenden. M&ouml;gliche Symbole:
  10998. [bulb|switch|window|door|blind|scene|phone|bell|clock|arrowUp|arrowDown]<br><br>
  10999. Beispiel:
  11000. <ul><code>
  11001. # "Hello" auf dem Display, Symbol bulb an, Hintergrundbeleuchtung, Ton ausgeben<br>
  11002. set FB1 display Hello no off 1 on bulb<br>
  11003. # "1234,5" anzeigen mit Einheit 'W'. Symbole scene,phone,bell und
  11004. # clock sind aktiv. Hintergrundbeleuchtung blinikt schnell, Ausgabe von Ton 2<br>
  11005. set FB1 display 12345 comma Watt 2 fast scene,phone,bell,clock
  11006. </ul></code>
  11007. </li>
  11008. </ul><br>
  11009. </li>
  11010. <li>HM-Dis-WM55
  11011. <ul>
  11012. <li><B>displayWM help </B><br>
  11013. <B>displayWM [long|short] &lt;text1&gt; &lt;color1&gt; &lt;icon1&gt; ... &lt;text6&gt; &lt;color6&gt; &lt;icon6&gt;</B><br>
  11014. <B>displayWM [long|short] &lt;lineX&gt; &lt;text&gt; &lt;color&gt; &lt;icon&gt;</B><br>
  11015. es können bis zu 6 Zeilen programmiert werden.<br>
  11016. <B>lineX</B> legt die zu ändernde Zeilennummer fest. Es können die 3 Parameter der Zeile geändert werden.<br>
  11017. <B>textNo</B> ist der anzuzeigende Text. Der Inhalt des Texts wird in den Buttonds definiert.
  11018. txt&lt;BtnNo&gt;_&lt;lineNo&gt; referenziert den Button und dessn jeweiligen Zeile.
  11019. Alternativ kann ein bis zu 12 Zeichen langer Freitext angegeben werden<br>
  11020. <B>color</B> kann sein white, red, orange, yellow, green, blue<br>
  11021. <B>icon</B> kann sein off, on, open, closed, error, ok, noIcon<br>
  11022. Example:
  11023. <ul><code>
  11024. set disp01 displayWM short txt02_2 green noIcon txt10_1 red error txt05_2 yellow closed txt02_2 orange open <br>
  11025. set disp01 displayWM long line3 txt02_2 green noIcon<br>
  11026. set disp01 displayWM long line2 nc yellow noIcon<br>
  11027. set disp01 displayWM long line6 txt02_2<br>
  11028. set disp01 displayWM long line1 nc nc closed<br>
  11029. </ul></code>
  11030. </li>
  11031. </ul><br>
  11032. </li>
  11033. <li>HM-Dis-EP-WM55
  11034. <ul>
  11035. <li><B>displayEP help </B><br>
  11036. <B>displayEP &lt;text1,icon1:text2,icon2:text3,icon3&gt; &lt;sound&gt; &lt;repetition&gt; &lt;pause&gt; &lt;signal&gt;</B><br>
  11037. bis zu 3 Zeilen werden adressiert.<br>
  11038. Wenn help eingegeben wird wird eine <i><B>hilfe</B></i> zum Kommando ausgegeben. Optionen der Parameter werden ausgegeben.<br>
  11039. <B>textx</B> 12 char text für die Zeile.
  11040. Wenn leer wird der Wert gemäß Reading genutzt. Typisch bedeuted es, dass keine Änderung stattfindet.
  11041. text0-9 zeigt den vordefinierten Wert der Kanäle 4 bis 8 an.
  11042. 0xHH erlaubt die anzeige eines hex Zeichens.<br>
  11043. <B>iconx</B> Icon der Zeile.
  11044. Typisch bedeuted es, dass keine Änderung stattfindet.<br>
  11045. <B>sound</B> sound zum Abspielen.<br>
  11046. <B>repetition</B> 0..15 <br>
  11047. <B>pause</B> 1..160<br>
  11048. <B>signal</B> Signalfarbe zum Anzeigen<br>
  11049. <br>
  11050. <B>Note: param reWriteDisplayxx</B> <br>
  11051. <li>
  11052. Beim Druck einer Taste ueberschreibt das Geraet diemittleren 3 Zeilen. Wenn da Attribut <br>
  11053. attr chan param reWriteDisplayxx<br>
  11054. gesetzt ist werden die 3 Zeilen nach xx Sekunden auf den Orginalwert zurück geschrieben.<br>
  11055. </li>
  11056. </li>
  11057. </ul><br>
  11058. </li>
  11059. <li>keyMatic<br><br>
  11060. <ul>Keymatic verwendet eine AES-signierte Kommunikation. Die Steuerung von KeyMatic
  11061. ist mit HMLAN und mit CUL m&ouml;glich.
  11062. Um die Keymatic mit einem CUL zu steuern, muss das Perl-Modul Crypt::Rijndael
  11063. installiert sein.</ul><br>
  11064. <ul>
  11065. <li><B>lock</B><br>
  11066. Schließbolzen f&auml;hrt in Zu-Position<br></li>
  11067. <li><B>unlock [sec]</B><br>
  11068. Schließbolzen f&auml;hrt in Auf-Position.<br>
  11069. [sec]: Stellt die Verz&ouml;gerung ein nach der sich das Schloss automatisch wieder verschließt.<br>
  11070. 0 - 65535 Sekunden</li>
  11071. <li><B>open [sec]</B><br>
  11072. Entriegelt die T&uuml;r sodass diese ge&ouml;ffnet werden kann.<br>
  11073. [sec]: Stellt die Verz&ouml;gerung ein nach der sich das Schloss automatisch wieder
  11074. verschließt.<br>0 - 65535 Sekunden</li>
  11075. </ul>
  11076. </li>
  11077. <li>winMatic <br><br>
  11078. <ul>winMatic arbeitet mit 2 Kan&auml;len, einem f&uuml;r die Fenstersteuerung und einem f&uuml;r den Akku.</ul><br>
  11079. <ul>
  11080. <li><B>level &lt;level&gt; &lt;relockDelay&gt; &lt;speed&gt;</B><br>
  11081. stellt den Wert ein. <br>
  11082. &lt;level&gt;: Bereich ist 0% bis 100%<br>
  11083. &lt;relockDelay&gt;: Spanne reicht von 0 bis 65535 Sekunden. 'ignore' kann verwendet werden um den Wert zu ignorieren.<br>
  11084. &lt;speed&gt;: Bereich ist 0% bis 100%<br>
  11085. </li>
  11086. <li><B>stop</B><br>
  11087. stopt die Bewegung<br>
  11088. </li>
  11089. </ul>
  11090. </li>
  11091. <li>CCU_FHEM<br>
  11092. <ul>
  11093. <li>defIgnUnknown<br>
  11094. Definieren die unbekannten Devices und setze das Attribut ignore.
  11095. Ddann loesche die Readings. <br>
  11096. </li>
  11097. </ul>
  11098. </li>
  11099. <li>HM-Sys-sRP-Pl<br>
  11100. legt Eintr&auml;ge f&uuml;r den Repeater an. Bis zu 36 Eintr&auml;ge k&ouml;nnen angelegt werden.
  11101. <ul>
  11102. <li><B>setRepeat &lt;entry&gt; &lt;sender&gt; &lt;receiver&gt; &lt;broadcast&gt;</B><br>
  11103. &lt;entry&gt; [1..36] Nummer des Eintrags in der Tabelle.<br>
  11104. &lt;sender&gt; Name oder HMid des Senders oder der Quelle die weitergeleitet werden soll<br>
  11105. &lt;receiver&gt; Name oder HMid des Empf&auml;ngers oder Ziels an das weitergeleitet werden soll<br>
  11106. &lt;broadcast&gt; [yes|no] definiert ob Broadcasts von einer ID weitergeleitet werden sollen.<br>
  11107. <br>
  11108. Kurzanwendung: <br>
  11109. <code>setRepeat setAll 0 0 0<br></code>
  11110. schreibt die gesamte Liste der Ger&auml;te neu. Daten kommen vom Attribut repPeers. <br>
  11111. Das Attribut repPeers hat folgendes Format:<br>
  11112. src1:dst1:[y/n],src2:dst2:[y/n],src2:dst2:[y/n],...<br>
  11113. <br>
  11114. Formatierte Werte von repPeer:<br>
  11115. <ul>
  11116. Number src dst broadcast verify<br>
  11117. number: Nummer des Eintrags in der Liste<br>
  11118. src: Ursprungsger&auml;t der Nachricht - aus Repeater ausgelesen<br>
  11119. dst: Zielger&auml;t der Nachricht - aus den Attributen abgeleitet<br>
  11120. broadcast: sollen Broadcasts weitergeleitet werden - aus Repeater ausgelesen<br>
  11121. verify: stimmen Attribute und ausgelesen Werte &uuml;berein?<br>
  11122. </ul>
  11123. </li>
  11124. </ul>
  11125. </li>
  11126. </ul>
  11127. <br>
  11128. Debugging:
  11129. <ul>
  11130. <li><B>raw &lt;data&gt; ...</B><br>
  11131. nur f&uuml;r Experimente ben&ouml;tigt.
  11132. Sendet eine Liste von "Roh"-Befehlen. Der erste Befehl wird unmittelbar gesendet,
  11133. die folgenden sobald der vorherige best&auml;tigt wurde. Die L&auml;nge wird automatisch
  11134. berechnet und der Nachrichtenz&auml;hler wird erh&ouml;ht wenn die ersten beiden Zeichen ++ sind.
  11135. Beispiel (AES aktivieren):
  11136. <pre>
  11137. set hm1 raw ++A001F100001234560105000000001\
  11138. ++A001F10000123456010802010AF10B000C00\
  11139. ++A001F1000012345601080801\
  11140. ++A001F100001234560106
  11141. </pre>
  11142. </li>
  11143. </ul>
  11144. </ul>
  11145. <br>
  11146. <a name="CUL_HMget"></a><b>Get</b><br>
  11147. <ul>
  11148. <li><B>configSave &lt;filename&gt;</B><a name="CUL_HMconfigSave"></a><br>
  11149. Sichert die Einstellungen eines Eintrags in einer Datei. Die Daten werden in
  11150. einem von der FHEM-Befehlszeile ausf&uuml;hrbaren Format gespeichert.<br>
  11151. Die Datei liegt im FHEM Home-Verzeichnis neben der fhem.cfg. Gespeichert wird
  11152. kumulativ- d.h. neue Daten werden an die Datei angeh&auml;ngt. Es liegt am Benutzer das
  11153. doppelte speichern von Eintr&auml;gen zu vermeiden.<br>
  11154. Ziel der Daten ist NUR die Information eines HM-Ger&auml;tes welche IM Ger&auml;t gespeichert ist.
  11155. Im Deteil sind das nur die Peer-Liste sowie die Register.
  11156. Durch die Register wird also das Peering eingeschlossen.<br>
  11157. Die Datei ist vom Benutzer les- und editierbar. Zus&auml;tzlich gespeicherte Zeitstempel
  11158. helfen dem Nutzer bei der Validierung.<br>
  11159. Einschr&auml;nkungen:<br>
  11160. Auch wenn alle Daten eines Eintrags in eine Datei gesichert werden so sichert FHEM nur
  11161. die zum Zeitpunkt des Speicherns verf&uuml;gbaren Daten! Der Nutzer muss also die Daten
  11162. der HM-Hardware auslesen bevor dieser Befehl ausgef&uuml;hrt wird.
  11163. Siehe empfohlenen Ablauf unten.<br>
  11164. Dieser Befehl speichert keine FHEM-Attribute oder Ger&auml;tedefinitionen.
  11165. Diese verbleiben in der fhem.cfg.<br>
  11166. Desweiteren werden gesicherte Daten nicht automatisch zur&uuml;ck auf die HM-Hardware geladen.
  11167. Der Benutzer muss die Wiederherstellung ausl&ouml;sen.<br><br>
  11168. Ebenso wie ander Befehle wird 'configSave' am besten auf ein Ger&auml;t und nicht auf einen
  11169. Kanal ausgef&uuml;hrt. Wenn auf ein Ger&auml;t angewendet werden auch die damit verbundenen Kan&auml;le
  11170. gesichert. <br><br>
  11171. <code>
  11172. Empfohlene Arbeitsfolge f&uuml;r ein Ger&auml;t 'HMdev':<br>
  11173. set HMdev clear msgEvents # alte Events l&ouml;schen um Daten besser kontrollieren zu k&ouml;nnen<br>
  11174. set HMdev getConfig # Ger&auml;te- und Kanalinformation auslesen<br>
  11175. # warten bis Ausf&uuml;hrung abgeschlossen ist<br>
  11176. # "protState" sollte dann "CMDs_done" sein<br>
  11177. # es sollten keine Warnungen zwischen "prot" und den Variablen auftauchen<br>
  11178. get configSave myActorFile<br>
  11179. </code>
  11180. </li>
  11181. <li><B>param &lt;paramName&gt;</B><br>
  11182. Gibt den Inhalt der relevanten Parameter eines Eintrags zur&uuml;ck. <br>
  11183. Hinweis: wird der Befehl auf einen Kanal angewandt und 'model' abgefragt so wird das Model
  11184. des inhalteanbietenden Ger&auml;ts zur&uuml;ckgegeben.
  11185. </li>
  11186. <li><B>reg &lt;addr&gt; &lt;list&gt; &lt;peerID&gt;</B><br>
  11187. liefert den Wert eines Registers zur&uuml;ck. Daten werden aus dem Speicher von FHEM und nicht direkt vom Ger&auml;t geholt.
  11188. Falls der Registerinhalt nicht verf&uuml;gbar ist muss "getConfig" sowie anschließend "getReg" verwendet werden.<br>
  11189. &lt;addr&gt; Adresse des Registers in HEX. Registername kann alternativ verwendet werden falls in FHEM bekannt.
  11190. "all" gibt alle dekodierten Register eines Eintrags in einer Liste zur&uuml;ck.<br>
  11191. &lt;list&gt; Liste aus der das Register gew&auml;hlt wird. Wird der REgistername verwendet wird "list" ignoriert und kann auf '0' gesetzt werden.<br>
  11192. &lt;peerID&gt; identifiziert die Registerb&auml;nke f&uuml;r "list3" und "list4". Kann als Dummy gesetzt werden wenn nicht ben&ouml;tigt.<br>
  11193. </li>
  11194. <li><B>regList</B><br>
  11195. gibt eine Liste der von FHEM f&uuml;r dieses Ger&auml;t dekodierten Register zur&uuml;ck.<br>
  11196. Beachten dass noch mehr Register f&uuml;r ein Ger&auml;t implemetiert sein k&ouml;nnen.<br>
  11197. </li>
  11198. <li><B>saveConfig &lt;file&gt;</B><a name="CUL_HMsaveConfig"></a><br>
  11199. speichert Peers und Register in einer Datei.<br>
  11200. Gespeichert werden die Daten wie sie in FHEM verf&uuml;gbar sind. Es ist daher notwendig vor dem Speichern die Daten auszulesen.<br>
  11201. Der Befehl unterst&uuml;tzt Aktionen auf Ger&auml;teebene. D.h. wird der Befehl auf ein Ger&auml;t angewendet werden auch alle verbundenen Kanaleintr&auml;ge gesichert.<br>
  11202. Das Speichern der Datei erfolgt kumulativ. Wird ein Eintrag mehrfach in der selben Datei gespeichert so werden die Daten an diese angeh&auml;ngt.
  11203. Der Nutzer kann den Zeitpunkt des Speichern bei Bedarf auslesen.<br>
  11204. Der Inhalt der Datei kann verwendet werden um die Ger&auml;teeinstellungen wiederherzustellen. Er stellt alle Peers und Register des Eintrags wieder her.<br>
  11205. Zw&auml;nge/Beschr&auml;nkungen:<br>
  11206. vor dem zur&uuml;ckschreiben der Daten eines Eintrags muss das Ger&auml;t mit FHEM verbunden werden.<br>
  11207. "restore" l&ouml;scht keine verkn&uuml;pften Kan&auml;le, es f&uuml;gt nur neue Peers hinzu.<br>
  11208. </li>
  11209. <li><B>listDevice</B><br>
  11210. <ul>
  11211. <li>bei einer CCU gibt es eine Liste der Devices, welche den ccu service zum zuweisen der IOs zurück<br>
  11212. </li>
  11213. <li>beim ActionDetector wird eine Komma geteilte Liste der Entities zurückgegeben<br>
  11214. get ActionDetector listDevice # returns alle assigned entities<br>
  11215. get ActionDetector listDevice notActive# returns entities ohne status alive<br>
  11216. get ActionDetector listDevice alive # returns entities mit status alive<br>
  11217. get ActionDetector listDevice unknown # returns entities mit status unknown<br>
  11218. get ActionDetector listDevice dead # returns entities mit status dead<br>
  11219. </li>
  11220. </ul>
  11221. </li>
  11222. </ul><br>
  11223. <a name="CUL_HMattr"></a><b>Attribute</b>
  11224. <ul>
  11225. <li><a href="#eventMap">eventMap</a></li>
  11226. <li><a href="#do_not_notify">do_not_notify</a></li>
  11227. <li><a href="#ignore">ignore</a></li>
  11228. <li><a href="#dummy">dummy</a></li>
  11229. <li><a href="#showtime">showtime</a></li>
  11230. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  11231. <li><a name="CUL_HMaesCommReq">aesCommReq</a>
  11232. wenn gesetzt wird HMLAN/USB AES signature anfordern bevor ACK zum Device gesendet wird.<br>
  11233. Die Funktion abeitet aktuell nur mit HMLAN/USB.<br>
  11234. </li>
  11235. <li><a name="#CUL_HMactAutoTry">actAutoTry</a>
  11236. actAutoTry 0_off,1_on<br>
  11237. setzen erlaubt dem ActionDetector ein statusrequest zu senden falls das Device dead markiert werden soll.
  11238. Das Attribut kann fuer Devices nützlich sein, welche sich nicht von selbst zyklisch melden.
  11239. </li>
  11240. <li><a href="#actCycle">actCycle</a>
  11241. actCycle &lt;[hhh:mm]|off&gt;<br>
  11242. Bietet eine 'alive' oder besser 'not alive' Erkennung f&uuml;r Ger&auml;te. [hhh:mm] ist die maximale Zeit ohne Nachricht eines Ger&auml;ts. Wenn innerhalb dieser Zeit keine Nachricht empfangen wird so wird das Event"&lt;device&gt; is dead" generiert.
  11243. Sendet das Ger&auml;t wieder so wird die Nachricht"&lt;device&gt; is alive" ausgegeben. <br>
  11244. Diese Erkennung wird durch 'autocreate' f&uuml;r jedes Ger&auml;t mit zyklischer Statusmeldung angelegt.<br>
  11245. Die Kontrollinstanz ist ein Pseudo-Ger&auml;t "ActionDetector" mit der HMId "000000".<br>
  11246. Aufgrund von Performance&uuml;berlegungen liegt die Antwortverz&ouml;gerung bei 600 Sekunden (10min). Kann &uuml;ber das Attribut "actCycle" des "ActionDetector" kontrolliert werden.<br>
  11247. Sobald die &Uuml;berwachung aktiviert wurde hat das HM-Ger&auml;t 2 Attribute:<br>
  11248. <ul>
  11249. actStatus: Aktivit&auml;tsstatus des Ger&auml;ts<br>
  11250. actCycle: Detektionsspanne [hhh:mm]<br>
  11251. </ul>
  11252. Die gesamte Funktion kann &uuml;ber den "ActionDetector"-Eintrag &uuml;berpr&uuml;ft werden. Der Status aller Instanzen liegt im READING-Bereich.<br>
  11253. Hinweis: Diese Funktion kann ebenfalls f&uuml;r Ger&auml;te ohne zyklische &Uuml;bertragung aktiviert werden. Es obliegt dem Nutzer eine vern&uuml;nftige Zeitspanne festzulegen.
  11254. </li>
  11255. <li><a name="#CUL_HMautoReadReg">autoReadReg</a><br>
  11256. '0' autoReadReg wird ignorert.<br>
  11257. '1' wird automatisch in getConfig ausgef&uuml;hrt f&uuml;r das Device nach jedem reboot von FHEM. <br>
  11258. '2' wie '1' plus nach Power on.<br>
  11259. '3' wie '2' plus update wenn auf das Device geschreiben wird.<br>
  11260. '4' wie '3' plus fordert Status an, wenn es nicht korrekt erscheint<br>
  11261. '5' pr&uuml;ft Registerlisten und peerlisten. Wenn diese nicht komplett sind wird ein update angefordert<br>
  11262. '8_stateOnly' es wird nur der Status gepr&uuml;ft, updates f&uuml;r Register werden nicht gemacht.<br>
  11263. Ausf&uuml;hrung wird verz&ouml;gert ausgef&uuml;hrt. Wenn das IO eine gewisse Last erreicht hat wird
  11264. das Kommando weiter verz&ouml;gert um eine &Uuml;berlast zu vermeiden.<br>
  11265. Empfohlene Zusammenh&auml;nge bei Nutzung:<br>
  11266. <ul>
  11267. Benutze das Attribut f&uuml;r das Device, nicht f&uuml;r jeden einzelnen Kanal<br>
  11268. Das Setzen auf Level 5 wird f&uuml;r alle Devices und Typen empfohlen, auch wakeup Devices.<br>
  11269. </ul>
  11270. </li>
  11271. <li><a name="CUL_HMburstAccess">burstAccess</a><br>
  11272. kann f&uuml;r eine Ger&auml;teinstanz gesetzt werden falls das Model bedingte Bursts erlaubt.
  11273. Das Attribut deaktiviert den Burstbetrieb (0_off) was die Nachrichtenmenge des HMLAN reduziert
  11274. und damit die Wahrscheinlichkeit einer &Uuml;berlast von HMLAN verringert.<br>
  11275. Einschalten (1_auto) erlaubt k&uuml;rzere Reaktionszeiten eines Ger&auml;ts. Der Nutzer muss nicht warten
  11276. bis das Ger&auml;t wach ist. <br>
  11277. Zu beacht ist dass das Register "burstRx" im Ger&auml;t ebenfalls gesetzt werden muss.
  11278. </li>
  11279. <li><a name="CUL_HMexpert">expert</a><br>
  11280. Dieses Attribut steuert die Sichtbarkeit der Register Readngs. Damit wird die Darstellung der Ger&auml;teparameter kontrolliert.<br>
  11281. Es handdelt sich um einen binaer kodierten Wert mit folgenden Empfehlungen:<br>
  11282. <ul>
  11283. 0_defReg : default Register<br>
  11284. 1_allReg : all Register<br>
  11285. 2_defReg+raw : default Register und raw Register<br>
  11286. 3_allReg+raw : alle Register und raw reading<br>
  11287. 4_off : no Register<br>
  11288. 8_templ+default: templates und default Register<br>
  11289. 12_templOnly : nur templates<br>
  11290. 251_anything : alles verfügbare<br>
  11291. </ul>
  11292. Wird 'expert' auf ein Ger&auml;t angewendet so gilt dies auch f&uuml;r alle verkn&uuml;pften Kan&auml;le.
  11293. Kann &uuml;bergangen werden indem das Attribut ' expert' auch f&uuml;r den Ger&auml;tekanal gesetzt wird.<br>
  11294. Das Attribut "showInternalValues" bei den globalen Werten muss ebenfalls &uuml;berpr&uuml;ft werden.
  11295. "expert" macht sich diese Implementierung zu Nutze.
  11296. Gleichwohl setzt "showInternalValues" - bei Definition - 'expert' außer Kraft .
  11297. </li>
  11298. <li><a name="#CUL_HMreadOnly">readOnly</a><br>
  11299. beschränkt kommandos auf Lesen und Beobachten.
  11300. </li>
  11301. <li><a name="#CUL_HMIOgrp">IOgrp</a><br>
  11302. kann an Devices vergeben werden udn zeigt auf eine virtuelle ccu. Danach wird die ccu
  11303. beim Senden das passende IO für das Device auswählen. Es ist notwendig, dass die virtuelle ccu
  11304. definiert und alle erlaubten IOs eingetragen sind. Beim Senden wird die ccu prüfen
  11305. welches IO operational ist und welches den besten rssi-faktor für das Device hat.<br>
  11306. Optional kann ein bevorzugtes IO definiert werden. In diesem Fall wird es, wenn operational,
  11307. genutzt - unabhängig von den rssi Werten.<br>
  11308. wenn kein prefIO verfügbar ist und none erkannt wird wird das IO aus IODev gewählt<br>
  11309. Beispiel:<br>
  11310. <ul><code>
  11311. attr myDevice1 IOgrp vccu<br>
  11312. attr myDevice2 IOgrp vccu:prefIO1,prefIO2,prefIO3<br>
  11313. attr myDevice2 IOgrp vccu:prefIO1,prefIO2,none<br>
  11314. </code></ul>
  11315. </li>
  11316. <li><a name="#CUL_HMlevelRange">levelRange</a><br>
  11317. nur f&uuml;r Dimmer! Der Dimmbereich wird eingeschr&auml;nkt.
  11318. Es ist gedacht um z.B. LED Lichter unterst&uuml;tzen welche mit 10% beginnen und bei 40% bereits das Maximum haben.
  11319. levelrange normalisiert den Bereich entsprechend. D.h. set 100 wird physikalisch den Dimmer auf 40%,
  11320. 1% auf 10% setzen. 0% schaltet physikalisch aus.<br>
  11321. Beeinflusst werdne Kommndos on, up, down, toggle und pct. <b>Nicht</b> beeinflusst werden Kommandos
  11322. die den Wert physikalisch setzen.<br>
  11323. Zu beachten:<br>
  11324. dimmer level von Peers gesetzt wird nicht beeinflusst. Dies wird durch Register konfiguriert.<br>
  11325. Readings level k&ouml;nnte negative werden oder &uuml;ber 100%. Das kommt daher, dass physikalisch der Bereich 0-100%
  11326. ist aber auf den logischen bereicht normiert wird.<br>
  11327. Sind virtuelle Dimmer Kan&auml;le verf&uuml;gbar muss das Attribut f&uuml;r jeden Kanal gesetzt werden<br>
  11328. Beispiel:<br>
  11329. <ul><code>
  11330. attr myChannel levelRange 0,40<br>
  11331. attr myChannel levelRange 10,80<br>
  11332. </code></ul>
  11333. </li>
  11334. <li><a name="#CUL_HMtempListTmpl">tempListTmpl</a><br>
  11335. Setzt das Default f&uuml;r Heizungskontroller. Ist es nicht gesetzt wird der default filename genutzt und der name
  11336. der entity als templatename. Z.B. ./tempList.cfg:RT_Clima<br>
  11337. Um das template nicht zu nutzen kann man es auf '0'setzen.<br>
  11338. Format ist &lt;file&gt;:&lt;templatename&gt;.
  11339. </li>
  11340. <li><a name="CUL_HMmodel">model</a>,
  11341. <a name="subType">subType</a><br>
  11342. Diese Attribute werden bei erfolgreichem Pairing automatisch gesetzt.
  11343. Sie sollten nicht per Hand gesetzt werden und sind notwendig um Ger&auml;tenachrichten
  11344. korrekt interpretieren oder senden zu k&ouml;nnen.</li>
  11345. <li><a name="param">param</a><br>
  11346. 'param' definiert modelspezifische Verhalten oder Funktionen. Siehe "models" f&uuml;r Details.</li>
  11347. <li><a name="CUL_HMmsgRepeat">msgRepeat</a><br>
  11348. Definiert die Nummer an Wiederholungen falls ein Ger&auml;t nicht rechtzeitig antwortet. <br>
  11349. F&uuml;r Ger&auml;te die nur den "Config"-Modus unterst&uuml;tzen sind Wiederholungen nicht erlaubt. <br>
  11350. Bei Ger&auml;te mit wakeup-Modus wartet das Ger&auml;t bis zum n&auml;chsten Aufwachen. Eine l&auml;ngere Verz&ouml;gerung
  11351. sollte in diesem Fall angedacht werden. <br>
  11352. Wiederholen von Bursts hat Auswirkungen auf die HMLAN &Uuml;bertragungskapazit&auml;t.</li>
  11353. <li><a name="rawToReadable">rawToReadable</a><br>
  11354. Wird verwendet um Rohdaten von KFM100 in ein lesbares Fomrat zu bringen, basierend auf
  11355. den gemessenen Werten. Z.B. langsames F&uuml;llen eines Tanks, w&auml;hrend die Werte mit <a href="#inform">inform</a>
  11356. angezeigt werden. Man sieht:
  11357. <ul>
  11358. 10 (bei 0%)<br>
  11359. 50 (bei 20%)<br>
  11360. 79 (bei 40%)<br>
  11361. 270 (bei 100%)<br>
  11362. </ul>
  11363. Anwenden dieser Werte: "attr KFM100 rawToReadable 10:0 50:20 79:40 270:100".
  11364. FHEM f&uuml;r damit eine lineare Interpolation der Werte in den gegebenen Grenzen aus.
  11365. </li>
  11366. <li><a name="unit">unit</a><br>
  11367. setzt die gemeldete Einheit des KFM100 falls 'rawToReadable' aktiviert ist. Z.B.<br>
  11368. attr KFM100 unit Liter
  11369. </li>
  11370. <li><a name="autoReadReg">autoReadReg</a><br>
  11371. '0' autoReadReg wird ignoriert.<br>
  11372. '1' f&uuml;hrt ein "getConfig" f&uuml;r ein Ger&auml;t automatisch nach jedem Neustart von FHEM aus. <br>
  11373. '2' verh&auml;lt sich wie '1',zus&auml;tzlich nach jedem power_on.<br>
  11374. '3' wie '2', zus&auml;tzlich bei jedem Schreiben auf das Ger&auml;t<br>
  11375. '4' wie '3' und versucht außerdem den Status abzufragen falls dieser nicht verf&uuml;gbar erscheint.<br>
  11376. '5' kontrolliert 'reglist' und 'peerlist'. Falls das Auslesen unvollst&auml;ndig ist wird 'getConfig' ausgef&uuml;hrt<br>
  11377. '8_stateOnly' aktualisiert nur Statusinformationen aber keine Konfigurationen wie Daten- oder
  11378. Peerregister.<br>
  11379. Ausf&uuml;hrung wird verz&ouml;gert um eine &Uuml;berlastung beim Start zu vermeiden . Daher werden Aktualisierung und Anzeige
  11380. von Werten abh&auml;ngig von der Gr&ouml;ße der Datenbank verz&ouml;gert geschehen.<br>
  11381. Empfehlungen und Einschr&auml;nkungen bei Benutzung:<br>
  11382. <ul>
  11383. Dieses Attribut nur auf ein Ger&auml;t oder Kanal 01 anwenden. Nicht auf einzelne Kan&auml;le eines mehrkanaligen
  11384. Ger&auml;ts anwenden um eine doppelte Ausf&uuml;hrung zu vermeiden.<br>
  11385. Verwendung bei Ger&auml;ten die nur auf den 'config'-Modus reagieren wird nicht empfohlen da die Ausf&uuml;hrung
  11386. erst starten wird wenn der Nutzer die Konfiguration vornimmt<br>
  11387. Anwenden auf Ger&auml;te mit 'wakeup'-Modus ist n&uuml;tzlich. Zu bedenken ist aber dass die Ausf&uuml;hrung
  11388. bis zm "aufwachen" verz&ouml;gert wird.<br>
  11389. </ul>
  11390. </li>
  11391. </ul> <br>
  11392. <a name="CUL_HMparams"><b>verf&uuml;gbare Parameter f&uuml;r "param"</b></a>
  11393. <ul>
  11394. <li><B>HM-Sen-RD-O</B><br>
  11395. offAtPon: nur Heizkan&auml;le: erzwingt Ausschalten der Heizung nach einem powerOn<br>
  11396. onAtRain: nur Heizkan&auml;le: erzwingt Einschalten der Heizung bei Status 'rain' und Ausschalten bei Status 'dry'<br>
  11397. </li>
  11398. <li><B>virtuals</B><br>
  11399. noOnOff: eine virtuelle Instanz wird den Status nicht &auml;ndern wenn ein Trigger empfangen wird. Ist dieser Paramter
  11400. nicht gegeben so toggled die Instanz ihren Status mit jedem trigger zwischen An und Aus<br>
  11401. msgReduce: falls gesetzt und der Kanal wird f&uuml;r <a ref="CUL_HMvalvePos"></a> genutzt wird jede Nachricht
  11402. außer die der Ventilstellung verworfen um die Nachrichtenmenge zu reduzieren<br>
  11403. </li>
  11404. <li><B>blind</B><br>
  11405. <B>levelInverse</B> w&auml;hrend HM 100% als offen und 0% als geschlossen behandelt ist dies evtl. nicht
  11406. intuitiv f&uuml;r den Nutzer. Defaut f&uuml;r 100% ist offen und wird als 'on'angezeigt.
  11407. Das Setzen des Parameters invertiert die Anzeige - 0% wird also offen und 100% ist geschlossen.<br>
  11408. ACHTUNG: Die Anpassung betrifft nur Readings und Kommandos. <B>Register sind nicht betroffen.</B><br>
  11409. <B>ponRestoreSmart</B> bei powerup des Device fährt das Rollo in die vermeintlich nächstgelegene Endposition und anschliessend in die ursprüngliche Position.<br>
  11410. <B>ponRestoreForce</B> bei powerup des Device fährt das Rollo auf Level 0, dann auf Level 100 und anschliessend in die ursprüngliche Position.<br>
  11411. </li>
  11412. <li><B>sensRain</B><br>
  11413. <B>siren</B><br>
  11414. <B>powerMeter</B><br>
  11415. <B>switch</B><br>
  11416. <B>dimmer</B><br>
  11417. <B>rgb</B><br>
  11418. <B>showTimed</B> wenn timedOn running ist wird -till an state gehängt. Dies führt dazu, dass ggf. on-till im State steht was das stateIcon handling verbessert.<br>
  11419. </li>
  11420. </ul><br>
  11421. <a name="CUL_HMevents"><b>Erzeugte Events:</b></a>
  11422. <ul>
  11423. <li><B>Allgemein</B><br>
  11424. recentStateType:[ack|info] # kann nicht verwendet werden um Nachrichten zu triggern<br>
  11425. <ul>
  11426. <li>ack zeigt an das eine Statusinformation aus einer Best&auml;tigung abgeleitet wurde</li>
  11427. <li>info zeigt eine automatische Nachricht eines Ger&auml;ts an</li>
  11428. <li><a name="CUL_HMsabotageAttackId"><b>sabotageAttackId</b></a><br>
  11429. Alarmiert bei Konfiguration des Ger&auml;ts durch unbekannte Quelle<br></li>
  11430. <li><a name="CUL_HMsabotageAttack"><b>sabotageAttack</b></a><br>
  11431. Alarmiert bei Konfiguration des Ger&auml;ts welche nicht durch das System ausgel&ouml;st wurde<br></li>
  11432. <li><a name="CUL_HMtrigDst"><b>trigDst_&lt;name&gt;: noConfig</b></a><br>
  11433. Ein Sensor triggert ein Device welches nicht in seiner Peerliste steht. Die Peerliste ist nicht akuell<br></li>
  11434. </ul>
  11435. </li>
  11436. <li><B>HM-CC-TC,ROTO_ZEL-STG-RM-FWT</B><br>
  11437. T: $t H: $h<br>
  11438. battery:[low|ok]<br>
  11439. measured-temp $t<br>
  11440. humidity $h<br>
  11441. actuator $vp %<br>
  11442. desired-temp $dTemp<br>
  11443. desired-temp-manu $dTemp #Temperatur falls im manuellen Modus<br>
  11444. desired-temp-cent $dTemp #Temperatur falls im Zentrale-Modus<br>
  11445. windowopen-temp-%d %.1f (sensor:%s)<br>
  11446. tempList$wd hh:mm $t hh:mm $t ...<br>
  11447. displayMode temp-[hum|only]<br>
  11448. displayTemp [setpoint|actual]<br>
  11449. displayTempUnit [fahrenheit|celsius]<br>
  11450. controlMode [auto|manual|central|party]<br>
  11451. tempValveMode [Auto|Closed|Open|unknown]<br>
  11452. param-change offset=$o1, value=$v1<br>
  11453. ValveErrorPosition_for_$dname $vep %<br>
  11454. ValveOffset_for_$dname : $of %<br>
  11455. ValveErrorPosition $vep %<br>
  11456. ValveOffset $of %<br>
  11457. time-request<br>
  11458. trig_&lt;src&gt; &lt;value&gt; #channel was triggered by &lt;src&gt; channel.
  11459. Dieses Event h&auml;ngt vom kompletten Auslesen der Kanalkonfiguration ab, anderenfalls k&ouml;nnen Daten
  11460. unvollst&auml;ndig oder fehlerhaft sein.<br>
  11461. trigLast &lt;channel&gt; #letzter empfangener Trigger<br>
  11462. </li>
  11463. <li><B>HM-CC-RT-DN and HM-CC-RT-DN-BoM</B><br>
  11464. state:T: $actTemp desired: $setTemp valve: $vp %<br>
  11465. motorErr: [ok|ValveTight|adjustRangeTooLarge|adjustRangeTooSmall|communicationERR|unknown|lowBat|ValveErrorPosition]
  11466. measured-temp $actTemp<br>
  11467. desired-temp $setTemp<br>
  11468. ValvePosition $vp %<br>
  11469. mode [auto|manual|party|boost]<br>
  11470. battery [low|ok]<br>
  11471. batteryLevel $bat V<br>
  11472. measured-temp $actTemp<br>
  11473. desired-temp $setTemp<br>
  11474. actuator $vp %<br>
  11475. time-request<br>
  11476. trig_&lt;src&gt; &lt;value&gt; #Kanal wurde durch &lt;src&gt; Kanal ausgel&ouml;ßt.
  11477. </li>
  11478. <li><B>HM-CC-VD,ROTO_ZEL-STG-RM-FSA</B><br>
  11479. $vp %<br>
  11480. battery:[critical|low|ok]<br>
  11481. motorErr:[ok|blocked|loose|adjusting range too small|opening|closing|stop]<br>
  11482. ValvePosition:$vp %<br>
  11483. ValveErrorPosition:$vep %<br>
  11484. ValveOffset:$of %<br>
  11485. ValveDesired:$vp % # durch Temperatursteuerung gesetzt <br>
  11486. operState:[errorTargetNotMet|onTarget|adjusting|changed] # operative Bedingung<br>
  11487. operStateErrCnt:$cnt # Anzahl fehlgeschlagener Einstellungen<br>
  11488. </li>
  11489. <li><B>HM-CC-SCD</B><br>
  11490. [normal|added|addedStrong]<br>
  11491. battery [low|ok]<br>
  11492. </li>
  11493. <li><B>HM-SEC-SFA-SM</B><br>
  11494. powerError [on|off]<br>
  11495. sabotageError [on|off]<br>
  11496. battery: [critical|low|ok]<br>
  11497. </li>
  11498. <li><B>HM-LC-BL1-PB-FM</B><br>
  11499. motor: [opening|closing]<br>
  11500. </li>
  11501. <li><B>HM-LC-SW1-BA-PCB</B><br>
  11502. battery: [low|ok]<br>
  11503. </li>
  11504. <li><B>HM-OU-LED16</B><br>
  11505. color $value # in Hex - nur f&uuml;r Ger&auml;t<br>
  11506. $value # in Hex - nur f&uuml;r Ger&auml;t<br>
  11507. color [off|red|green|orange] # f&uuml;r Kanal <br>
  11508. [off|red|green|orange] # f&uuml;r Kanal <br>
  11509. </li>
  11510. <li><B>HM-OU-CFM-PL</B><br>
  11511. [on|off|$val]<br>
  11512. </li>
  11513. <li><B>HM-Sen-Wa-Od</B><br>
  11514. $level%<br>
  11515. level $level%<br>
  11516. </li>
  11517. <li><B>KFM100</B><br>
  11518. $v<br>
  11519. $cv,$unit<br>
  11520. rawValue:$v<br>
  11521. Sequence:$seq<br>
  11522. content:$cv,$unit<br>
  11523. </li>
  11524. <li><B>KS550/HM-WDS100-C6-O</B><br>
  11525. T: $t H: $h W: $w R: $r IR: $ir WD: $wd WDR: $wdr S: $s B: $b<br>
  11526. temperature $t<br>
  11527. humidity $h<br>
  11528. windSpeed $w<br>
  11529. windDirection $wd<br>
  11530. windDirRange $wdr<br>
  11531. rain $r<br>
  11532. isRaining $ir<br>
  11533. sunshine $s<br>
  11534. brightness $b<br>
  11535. unknown $p<br>
  11536. </li>
  11537. <li><B>HM-Sen-RD-O</B><br>
  11538. lastRain: timestamp # kein Trigger wird erzeugt. Anfang des vorherigen Regen-Zeitstempels
  11539. des Messwerts ist Ende des Regens. <br>
  11540. </li>
  11541. <li><B>THSensor und HM-WDC7000</B><br>
  11542. T: $t H: $h AP: $ap<br>
  11543. temperature $t<br>
  11544. humidity $h<br>
  11545. airpress $ap #nur HM-WDC7000<br>
  11546. </li>
  11547. <li><B>dimmer</B><br>
  11548. overload [on|off]<br>
  11549. overheat [on|off]<br>
  11550. reduced [on|off]<br>
  11551. dim: [up|down|stop]<br>
  11552. </li>
  11553. <li><B>motionDetector</B><br>
  11554. brightness:$b<br>
  11555. alive<br>
  11556. motion on (to $dest)<br>
  11557. motionCount $cnt _next:$nextTr"-"[0x0|0x1|0x2|0x3|15|30|60|120|240|0x9|0xa|0xb|0xc|0xd|0xe|0xf]<br>
  11558. cover [closed|open] # nicht bei HM-Sec-MDIR<br>
  11559. sabotageError [on|off] # nur bei HM-Sec-MDIR<br>
  11560. battery [low|ok]<br>
  11561. devState_raw.$d1 $d2<br>
  11562. </li>
  11563. <li><B>remote/pushButton/outputUnit</B><br>
  11564. <ul> (to $dest) wird hinzugef&uuml;gt wenn der Knopf gepeert ist und keinen Broadcast sendet<br>
  11565. Freigabe ist nur f&uuml;r verkn&uuml;pfte Kan&auml;le verf&uuml;gbar</ul>
  11566. Btn$x onShort<br>
  11567. Btn$x offShort<br>
  11568. Btn$x onLong $counter<br>
  11569. Btn$x offLong $counter<br>
  11570. Btn$x onLongRelease $counter<br>
  11571. Btn$x offLongRelease $counter<br>
  11572. Btn$x onShort (to $dest)<br>
  11573. Btn$x offShort (to $dest)<br>
  11574. Btn$x onLong $counter (to $dest)<br>
  11575. Btn$x offLong $counter (to $dest)<br>
  11576. Btn$x onLongRelease $counter (to $dest)<br>
  11577. Btn$x offLongRelease $counter (to $dest)<br>
  11578. </li>
  11579. <li><B>remote/pushButton</B><br>
  11580. battery [low|ok]<br>
  11581. trigger [Long|Short]_$no trigger event from channel<br>
  11582. </li>
  11583. <li><B>swi</B><br>
  11584. Btn$x Short<br>
  11585. Btn$x Short (to $dest)<br>
  11586. battery: [low|ok]<br>
  11587. </li>
  11588. <li><B>switch/dimmer/blindActuator</B><br>
  11589. $val<br>
  11590. powerOn [on|off|$val]<br>
  11591. [unknown|motor|dim] [up|down|stop]:$val<br>
  11592. timedOn [running|off]<br> # "An" ist tempor&auml;r - z.B. mit dem 'on-for-timer' gestartet
  11593. </li>
  11594. <li><B>sensRain</B><br>
  11595. $val<br>
  11596. powerOn <br>
  11597. level &lt;val&ge;<br>
  11598. timedOn [running|off]<br> # "An" ist tempor&auml;r - z.B. mit dem 'on-for-timer' gestartet
  11599. trigger [Long|Short]_$no trigger event from channel<br>
  11600. </li>
  11601. <li><B>smokeDetector</B><br>
  11602. [off|smoke-Alarm|alive] # f&uuml;r Gruppen-Master<br>
  11603. [off|smoke-forward|smoke-alarm] # f&uuml;r Gruppenmitglieder<br>
  11604. [normal|added|addedStrong] #HM-CC-SCD<br>
  11605. SDteam [add|remove]_$dname<br>
  11606. battery [low|ok]<br>
  11607. smoke_detect [none|&lt;src&gt;]<br>
  11608. teamCall:from $src<br>
  11609. </li>
  11610. <li><B>threeStateSensor</B><br>
  11611. [open|tilted|closed]<br>
  11612. [wet|damp|dry] #nur HM-SEC-WDS<br>
  11613. cover [open|closed] #HM-SEC-WDS und HM-Sec-RHS<br>
  11614. alive yes<br>
  11615. battery [low|ok]<br>
  11616. contact [open|tilted|closed]<br>
  11617. contact [wet|damp|dry] #nur HM-SEC-WDS<br>
  11618. sabotageError [on|off] #nur HM-SEC-SC<br>
  11619. </li>
  11620. <li><B>winMatic</B><br>
  11621. [locked|$value]<br>
  11622. motorErr [ok|TurnError|TiltError]<br>
  11623. direction [no|up|down|undefined]<br>
  11624. charge [trickleCharge|charge|dischange|unknown]<br>
  11625. airing [inactiv|$air]<br>
  11626. course [tilt|close]<br>
  11627. airing [inactiv|$value]<br>
  11628. contact tesed<br>
  11629. </li>
  11630. <li><B>keyMatic</B><br>
  11631. unknown:40<br>
  11632. battery [low|ok]<br>
  11633. uncertain [yes|no]<br>
  11634. error [unknown|motor aborted|clutch failure|none']<br>
  11635. lock [unlocked|locked]<br>
  11636. [unlocked|locked|uncertain]<br>
  11637. </li>
  11638. </ul>
  11639. <a name="CUL_HMinternals"><b>Internals</b></a>
  11640. <ul>
  11641. <li><B>aesCommToDev</B><br>
  11642. Information über Erfolg und Fehler der AES Kommunikation zwischen IO-device und HM-Device<br>
  11643. </li>
  11644. </ul><br>
  11645. <br>
  11646. </ul>
  11647. =end html_DE
  11648. =cut