diff --git a/HMI/README.md b/HMI/README.md index 6be70ec0..91a51ce1 100644 --- a/HMI/README.md +++ b/HMI/README.md @@ -71,13 +71,11 @@ change the page type: `pageType,popupNotify` +`pageType,screensaver` + ### screensaver page -`weatherUpdate,? tMainIcon? tMainText? tMRIcon? tMR? tForecast1? tF1Icon? tForecast1Val? tForecast2? tF2Icon? tForecast2Val` - -`weatherUpdate,?0?2,3 C?0?0 mm?Mi?0?9,3 C?Do?0?11,5 C` - -`page,0` +`weatherUpdate,? tMainIcon? tMainText? tMRIcon? tMR? tForecast1? tF1Icon? tForecast1Val? tForecast2? tF2Icon? tForecast2Val?tForecast3? tF3Icon? tForecast3Val?tForecast4? tF4Icon? tForecast4Val` ### cardEntities Page @@ -117,7 +115,7 @@ The following message can be used to update the content on the cardEntities Page `entityUpdateDetail,*internalName*,*tHeading*,*tHeadingColor*,*b1*,*tB1Color*,*b2*,*tB2Color*,*tText*,*tTextColor*,*sleepTimeout*` -`popupExit` +`exitPopup` ### cardThermo Page @@ -127,29 +125,36 @@ The following message can be used to update the content on the cardEntities Page ### cardMedia Page -`entityUpd,|*internalNameEntiy*|*heading*|*icon*|*title*|*author*|*volume*|*playpauseicon*` +`entityUpd,|*internalNameEntiy*|*heading*|*icon*|*title*|*author*|*volume*|*playpauseicon*|currentSpeaker|speakerList-seperated-by-?` ### cardAlarm Page -`entityUpd,*internalNameEntity*,*arm1*,*arm1ActionName*,*arm2*,*arm2ActionName*,*arm3*,*arm3ActionName*,*arm4*,*arm4ActionName*,*icon*,*numpadStatus*` +`entityUpd,*internalNameEntity*,*arm1*,*arm1ActionName*,*arm2*,*arm2ActionName*,*arm3*,*arm3ActionName*,*arm4*,*arm4ActionName*,*icon*,*iconcolor*,*numpadStatus*,*flashing*` ## Messages from Nextion Display +`event,buttonPress2,pageName,bNext` + +`event,buttonPress2,pageName,bPrev` + +`event,buttonPress2,pageName,bExit,number_of_taps` + ### startup page `event,startup,version` ### screensaver page -`event,screensaverOpen` +`event,buttonPress2,screensaver,exit` - Touch Event on Screensaver + +`event,screensaverOpen` - Screensaver has opened + ### cardEntities Page `event,*eventName*,*entityName*,*actionName*,*optionalValue*` -`event,pageOpen,0` - `event,buttonPress2,internalNameEntity,up` `event,buttonPress2,internalNameEntity,down` @@ -186,8 +191,6 @@ The following message can be used to update the content on the cardEntities Page ### cardThermo Page -`event,pageOpen,0` - `event,buttonPress2,*entityName*,tempUpd,*temperature*` `event,buttonPress2,*entityName*,hvac_action,*hvac_action*` diff --git a/HMI/code_gen/icons/icons.py b/HMI/code_gen/icons/icons.py index 66b58967..9cec3704 100644 --- a/HMI/code_gen/icons/icons.py +++ b/HMI/code_gen/icons/icons.py @@ -40,7 +40,12 @@ icons = [ "shield-home", "door-open", "door-closed", - "window-closed" + "window-closed", + "shield-off", + "shield", + "shield-lock", + "shield-airplane", + "bell-ring" ] @@ -66,7 +71,7 @@ for icon_name in icons: icon_name_list.append(icon_name) # write mapping lib for python -with open(os.path.join(__location__, "../../../apps/nspanel-lovelace-ui", "icon_mapping.py"), 'w') as f: +with open(os.path.join(__location__, "../../../apps/nspanel-lovelace-ui/luibackend", "icon_mapping.py"), 'w') as f: f.write("icons = {\n") for idx, val in enumerate(icon_name_list): f.write(f" '{val}': {idx},\n") diff --git a/HMI/icons.md b/HMI/icons.md index 6fd39e90..9e6aacd3 100644 --- a/HMI/icons.md +++ b/HMI/icons.md @@ -43,3 +43,8 @@ ID | MD Icon Name | Icon 36 | door-open | ![door-open](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/door-open.svg) 37 | door-closed | ![door-closed](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/door-closed.svg) 38 | window-closed | ![window-closed](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/window-closed.svg) +39 | shield-off | ![shield-off](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield-off.svg) +40 | shield | ![shield](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield.svg) +41 | shield-lock | ![shield-lock](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield-lock.svg) +42 | shield-airplane | ![shield-airplane](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield-airplane.svg) +43 | bell-ring | ![bell-ring](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/bell-ring.svg) diff --git a/HMI/n2t-out/Program.s.txt b/HMI/n2t-out/Program.s.txt index 36907784..0ea4a9f5 100644 --- a/HMI/n2t-out/Program.s.txt +++ b/HMI/n2t-out/Program.s.txt @@ -5,24 +5,11 @@ Program.s int recvCrc=0 int payloadLength=0 int par0=0,par1=0 - // landsspace orientation x has 480px and y has 320px xy limits todo: adjust xy values to something that fit's resulution - //Maximum values in directional change for Swipes beeing detected as swipe (diagonal swipes are invalid) (for one axis at a time) - int xLimit=125,yLimit=125 - int ixLimit=-125,iyLimit=-125 - //Minimum values for swipes, directional changes below theese values are ignored, because they could be unintended swipes - int xLimitMin=80,yLimitMin=80 - int ixLimitMin=-80,iyLimitMin=-80 - // Swipe Result Vars - int ycR=0,xcR=0 - // Start End Swipe Touch Locations - int yc1=0,xc1=0,yc2=0,xc2=0 // sleep timeout in s int sleepTimeout=20 int sleepValue=0 // dim value int dimValue=40 - // current page - int nPage=0 // fix touch offset lcd_dev fffb 0002 0000 0020 page pageStartup diff --git a/HMI/n2t-out/cardAlarm.txt b/HMI/n2t-out/cardAlarm.txt index e1557b88..e44c02a3 100644 --- a/HMI/n2t-out/cardAlarm.txt +++ b/HMI/n2t-out/cardAlarm.txt @@ -222,7 +222,7 @@ Text tCode Send Component ID : disabled Opacity : 127 x coordinate : 92 - y coordinate : 12 + y coordinate : 16 Width : 192 Height : 49 Effect : load @@ -252,7 +252,7 @@ Text tIcon Send Component ID : disabled Opacity : 127 x coordinate : 300 - y coordinate : 12 + y coordinate : 16 Width : 64 Height : 49 Effect : load @@ -267,7 +267,7 @@ Text tIcon Horizontal Alignment : center Vertical Alignment : center Input Type : character - Text :  + Text : Max. Text Size : 10 Word wrap : disabled Horizontal Spacing : 0 @@ -324,14 +324,7 @@ Button bNext Events Touch Press Event - nPage=nPage+1 - nPageDisp.val=nPage - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardAlarm,bNext" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -378,14 +371,7 @@ Button bPrev Events Touch Press Event - nPage=nPage-1 - nPageDisp.val=nPage - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardAlarm,bPrev" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -406,8 +392,8 @@ Button b0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 52 - y coordinate : 146 + x coordinate : 25 + y coordinate : 94 Width : 75 Height : 50 Effect : load @@ -444,8 +430,8 @@ Button b1 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 144 - y coordinate : 146 + x coordinate : 117 + y coordinate : 94 Width : 75 Height : 50 Effect : load @@ -482,8 +468,8 @@ Button b2 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 236 - y coordinate : 145 + x coordinate : 209 + y coordinate : 93 Width : 75 Height : 50 Effect : load @@ -520,8 +506,8 @@ Button b3 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 52 - y coordinate : 204 + x coordinate : 25 + y coordinate : 152 Width : 75 Height : 50 Effect : load @@ -558,8 +544,8 @@ Button b4 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 144 - y coordinate : 204 + x coordinate : 117 + y coordinate : 152 Width : 75 Height : 50 Effect : load @@ -596,8 +582,8 @@ Button b5 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 236 - y coordinate : 204 + x coordinate : 209 + y coordinate : 152 Width : 75 Height : 50 Effect : load @@ -634,8 +620,8 @@ Button b6 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 52 - y coordinate : 262 + x coordinate : 25 + y coordinate : 210 Width : 75 Height : 50 Effect : load @@ -672,8 +658,8 @@ Button b7 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 144 - y coordinate : 262 + x coordinate : 117 + y coordinate : 210 Width : 75 Height : 50 Effect : load @@ -710,8 +696,8 @@ Button b8 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 236 - y coordinate : 262 + x coordinate : 209 + y coordinate : 210 Width : 75 Height : 50 Effect : load @@ -748,8 +734,8 @@ Button b9 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 328 - y coordinate : 204 + x coordinate : 116 + y coordinate : 266 Width : 75 Height : 50 Effect : load @@ -786,8 +772,8 @@ Button b10 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 328 - y coordinate : 262 + x coordinate : 209 + y coordinate : 266 Width : 75 Height : 50 Effect : load @@ -806,7 +792,7 @@ Button b10 Horizontal Alignment : center Vertical Alignment : center State : unpressed - Text : CLEAR + Text : CLR Max. Text Size : 10 Word wrap : disabled Horizontal Spacing : 0 @@ -824,10 +810,10 @@ Button arm1 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 59 - y coordinate : 72 - Width : 64 - Height : 64 + x coordinate : 300 + y coordinate : 91 + Width : 141 + Height : 50 Effect : load Effect Priority : 0 Effect Time : 300 @@ -845,7 +831,7 @@ Button arm1 Vertical Alignment : center State : unpressed Text : - Max. Text Size : 10 + Max. Text Size : 40 Word wrap : enabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -868,6 +854,7 @@ Button arm1 prints sys0,2 prints tSend.txt,0 prints crcval,2 + tCode.txt="" Button arm3 Attributes @@ -877,10 +864,10 @@ Button arm3 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 239 - y coordinate : 72 - Width : 64 - Height : 64 + x coordinate : 300 + y coordinate : 210 + Width : 140 + Height : 50 Effect : load Effect Priority : 0 Effect Time : 300 @@ -898,7 +885,7 @@ Button arm3 Vertical Alignment : center State : unpressed Text : - Max. Text Size : 10 + Max. Text Size : 40 Word wrap : enabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -921,6 +908,7 @@ Button arm3 prints sys0,2 prints tSend.txt,0 prints crcval,2 + tCode.txt="" Button arm2 Attributes @@ -930,10 +918,10 @@ Button arm2 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 149 - y coordinate : 72 - Width : 64 - Height : 64 + x coordinate : 300 + y coordinate : 152 + Width : 141 + Height : 50 Effect : load Effect Priority : 0 Effect Time : 300 @@ -951,7 +939,7 @@ Button arm2 Vertical Alignment : center State : unpressed Text : - Max. Text Size : 10 + Max. Text Size : 40 Word wrap : enabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -974,6 +962,7 @@ Button arm2 prints sys0,2 prints tSend.txt,0 prints crcval,2 + tCode.txt="" Button arm4 Attributes @@ -983,10 +972,10 @@ Button arm4 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 329 - y coordinate : 72 - Width : 64 - Height : 64 + x coordinate : 300 + y coordinate : 266 + Width : 141 + Height : 50 Effect : load Effect Priority : 0 Effect Time : 300 @@ -1004,7 +993,7 @@ Button arm4 Vertical Alignment : center State : unpressed Text : - Max. Text Size : 10 + Max. Text Size : 40 Word wrap : enabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -1027,6 +1016,7 @@ Button arm4 prints sys0,2 prints tSend.txt,0 prints crcval,2 + tCode.txt="" Timer tmSerial Attributes @@ -1120,8 +1110,12 @@ Timer tmSerial spstr strCommand.txt,tTmp.txt,",",10 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tIcon.txt,sys0,1 - //numpad status + //icon color spstr strCommand.txt,tTmp.txt,",",11 + covx tTmp.txt,sys0,0,0 + tIcon.pco=sys0 + //numpad status + spstr strCommand.txt,tTmp.txt,",",12 if(tTmp.txt!="disable") { vis b0,1 @@ -1137,6 +1131,15 @@ Timer tmSerial vis b10,1 vis tCode,1 } + //flashing status + spstr strCommand.txt,tTmp.txt,",",13 + if(tTmp.txt=="enable") + { + tmFlash.en=1 + }else + { + tmFlash.en=0 + } } if(tInstruction.txt=="time") { @@ -1235,6 +1238,25 @@ Timer tmSleep } } +Timer tmFlash + Attributes + ID : 35 + Scope : local + Period (ms): 600 + Enabled : no + + Events + Timer Event + if(tIcon.isbr==1) + { + tIcon.isbr=0 + vis tIcon,0 + }else + { + tIcon.isbr=1 + vis tIcon,1 + } + TouchCap tc0 Attributes ID : 12 diff --git a/HMI/n2t-out/cardEntities.txt b/HMI/n2t-out/cardEntities.txt index 11928259..ac510f63 100644 --- a/HMI/n2t-out/cardEntities.txt +++ b/HMI/n2t-out/cardEntities.txt @@ -38,6 +38,7 @@ Page cardEntities vis tIcon1,0 vis tEntity1,0 vis bText1,0 + vis hSlider1,0 //ui e2 vis btOnOff2,0 vis bUp2,0 @@ -46,6 +47,7 @@ Page cardEntities vis tIcon2,0 vis tEntity2,0 vis bText2,0 + vis hSlider2,0 //ui e3 vis btOnOff3,0 vis bUp3,0 @@ -54,6 +56,7 @@ Page cardEntities vis tIcon3,0 vis tEntity3,0 vis bText3,0 + vis hSlider3,0 //ui e4 vis btOnOff4,0 vis bUp4,0 @@ -62,6 +65,7 @@ Page cardEntities vis tIcon4,0 vis tEntity4,0 vis bText4,0 + vis hSlider4,0 Variable (string) strCommand Attributes @@ -103,28 +107,28 @@ Variable (string) entn1 ID : 49 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) entn2 Attributes ID : 50 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) entn3 Attributes ID : 51 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) entn4 Attributes ID : 52 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Text tHeading Attributes @@ -533,6 +537,106 @@ Picture p0 Effect Time : 300 Picture ID : 0 +Slider hSlider1 + Attributes + ID : 54 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 275 + y coordinate : 77 + Width : 150 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Direction : horizontal + Fill : image + Cursor width : auto + Cursor height : 255 + Back. Picture ID : 5 + Slided Back. Picture ID : 4 + Position : 50 + Upper range limit : 100 + Lower range limit : 0 + +Slider hSlider2 + Attributes + ID : 55 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 276 + y coordinate : 133 + Width : 150 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Direction : horizontal + Fill : image + Cursor width : auto + Cursor height : 255 + Back. Picture ID : 5 + Slided Back. Picture ID : 4 + Position : 50 + Upper range limit : 100 + Lower range limit : 0 + +Slider hSlider3 + Attributes + ID : 56 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 276 + y coordinate : 187 + Width : 150 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Direction : horizontal + Fill : image + Cursor width : auto + Cursor height : 255 + Back. Picture ID : 5 + Slided Back. Picture ID : 4 + Position : 50 + Upper range limit : 100 + Lower range limit : 0 + +Slider hSlider4 + Attributes + ID : 57 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 275 + y coordinate : 243 + Width : 150 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Direction : horizontal + Fill : image + Cursor width : auto + Cursor height : 255 + Back. Picture ID : 5 + Slided Back. Picture ID : 4 + Position : 50 + Upper range limit : 100 + Lower range limit : 0 + Button bDown1 Attributes ID : 11 @@ -1131,13 +1235,14 @@ Button bPrev Events Touch Press Event - nPage=nPage-1 - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardEntities," + if(bPrev.isbr==1) + { + tSend.txt+="bBack" + }else + { + tSend.txt+="bPrev" + } //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -1184,13 +1289,7 @@ Button bNext Events Touch Press Event - nPage=nPage+1 - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardEntities,bNext" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -1776,6 +1875,27 @@ Timer tmSerial if(tInstruction.txt=="entityUpdHeading") { spstr strCommand.txt,tHeading.txt,",",1 + spstr strCommand.txt,tTmp.txt,",",2 + if(tTmp.txt=="0") + { + vis bPrev,0 + }else + { + vis bPrev,1 + if(tTmp.txt=="2") + { + bPrev.txt="" + bPrev.isbr=1 + } + } + spstr strCommand.txt,tTmp.txt,",",3 + if(tTmp.txt=="0") + { + vis bNext,0 + }else + { + vis bNext,1 + } } if(tInstruction.txt=="entityUpd") { @@ -1784,7 +1904,7 @@ Timer tmSerial spstr strCommand.txt,type1.txt,",",1 // get internal name spstr strCommand.txt,entn1.txt,",",2 - if(type1.txt=="delete") + if(type1.txt=="delete"||type1.txt=="") { vis bUp1,0 vis bStop1,0 @@ -1793,6 +1913,7 @@ Timer tmSerial vis tEntity1,0 vis tIcon1,0 vis bText1,0 + vis hSlider1,0 }else { // change icon @@ -1815,6 +1936,7 @@ Timer tmSerial vis bDown1,1 vis btOnOff1,0 vis bText1,0 + vis hSlider1,0 } if(type1.txt=="light") { @@ -1823,6 +1945,7 @@ Timer tmSerial vis bDown1,0 vis btOnOff1,1 vis bText1,0 + vis hSlider1,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",6 covx tTmp.txt,sys0,0,0 @@ -1835,6 +1958,7 @@ Timer tmSerial vis bDown1,0 vis btOnOff1,1 vis bText1,0 + vis hSlider1,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",6 covx tTmp.txt,sys0,0,0 @@ -1848,6 +1972,7 @@ Timer tmSerial vis btOnOff1,0 vis bText1,1 tsw bText1,0 + vis hSlider1,0 bText1.pco=65535 bText1.pco2=65535 // get Text (optional Value) @@ -1861,17 +1986,29 @@ Timer tmSerial vis btOnOff1,0 vis bText1,1 tsw bText1,1 + vis hSlider1,0 bText1.pco=1374 bText1.pco2=1374 // get Text (optional Value) spstr strCommand.txt,bText1.txt,",",6 } - // id2 + if(type1.txt=="number") + { + vis bUp1,0 + vis bStop1,0 + vis bDown1,0 + vis btOnOff1,0 + vis bText1,0 + tsw bText1,0 + vis hSlider1,1 + // get Text (optional Value) + spstr strCommand.txt,bText1.txt,",",6 + } // get Type spstr strCommand.txt,type2.txt,",",7 // get internal name spstr strCommand.txt,entn2.txt,",",8 - if(type2.txt=="delete") + if(type2.txt=="delete"||type2.txt=="") { vis bUp2,0 vis bStop2,0 @@ -1880,9 +2017,10 @@ Timer tmSerial vis tEntity2,0 vis tIcon2,0 vis bText2,0 + vis hSlider2,0 }else { - //change icon + // change icon spstr strCommand.txt,tTmp.txt,",",9 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tIcon2.txt,sys0,1 @@ -1902,6 +2040,7 @@ Timer tmSerial vis bDown2,1 vis btOnOff2,0 vis bText2,0 + vis hSlider2,0 } if(type2.txt=="light") { @@ -1910,6 +2049,7 @@ Timer tmSerial vis bDown2,0 vis btOnOff2,1 vis bText2,0 + vis hSlider2,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",12 covx tTmp.txt,sys0,0,0 @@ -1922,6 +2062,7 @@ Timer tmSerial vis bDown2,0 vis btOnOff2,1 vis bText2,0 + vis hSlider2,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",12 covx tTmp.txt,sys0,0,0 @@ -1935,6 +2076,7 @@ Timer tmSerial vis btOnOff2,0 vis bText2,1 tsw bText2,0 + vis hSlider2,0 bText2.pco=65535 bText2.pco2=65535 // get Text (optional Value) @@ -1948,17 +2090,29 @@ Timer tmSerial vis btOnOff2,0 vis bText2,1 tsw bText2,1 + vis hSlider2,0 bText2.pco=1374 bText2.pco2=1374 // get Text (optional Value) spstr strCommand.txt,bText2.txt,",",12 } - // id3 + if(type2.txt=="number") + { + vis bUp2,0 + vis bStop2,0 + vis bDown2,0 + vis btOnOff2,0 + vis bText2,0 + tsw bText2,0 + vis hSlider2,1 + // get Text (optional Value) + spstr strCommand.txt,bText2.txt,",",12 + } // get Type spstr strCommand.txt,type3.txt,",",13 // get internal name spstr strCommand.txt,entn3.txt,",",14 - if(type3.txt=="delete") + if(type3.txt=="delete"||type3.txt=="") { vis bUp3,0 vis bStop3,0 @@ -1967,9 +2121,10 @@ Timer tmSerial vis tEntity3,0 vis tIcon3,0 vis bText3,0 + vis hSlider3,0 }else { - //change icon + // change icon spstr strCommand.txt,tTmp.txt,",",15 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tIcon3.txt,sys0,1 @@ -1989,14 +2144,16 @@ Timer tmSerial vis bDown3,1 vis btOnOff3,0 vis bText3,0 + vis hSlider3,0 } if(type3.txt=="light") { vis bUp3,0 vis bStop3,0 vis bDown3,0 - vis bText3,0 vis btOnOff3,1 + vis bText3,0 + vis hSlider3,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",18 covx tTmp.txt,sys0,0,0 @@ -2007,8 +2164,9 @@ Timer tmSerial vis bUp3,0 vis bStop3,0 vis bDown3,0 - vis bText3,0 vis btOnOff3,1 + vis bText3,0 + vis hSlider3,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",18 covx tTmp.txt,sys0,0,0 @@ -2022,6 +2180,7 @@ Timer tmSerial vis btOnOff3,0 vis bText3,1 tsw bText3,0 + vis hSlider3,0 bText3.pco=65535 bText3.pco2=65535 // get Text (optional Value) @@ -2035,17 +2194,29 @@ Timer tmSerial vis btOnOff3,0 vis bText3,1 tsw bText3,1 + vis hSlider3,0 bText3.pco=1374 bText3.pco2=1374 // get Text (optional Value) spstr strCommand.txt,bText3.txt,",",18 } - // id4 + if(type3.txt=="number") + { + vis bUp3,0 + vis bStop3,0 + vis bDown3,0 + vis btOnOff3,0 + vis bText3,0 + tsw bText3,0 + vis hSlider3,1 + // get Text (optional Value) + spstr strCommand.txt,bText3.txt,",",18 + } // get Type spstr strCommand.txt,type4.txt,",",19 // get internal name spstr strCommand.txt,entn4.txt,",",20 - if(type4.txt=="delete") + if(type4.txt=="delete"||type4.txt=="") { vis bUp4,0 vis bStop4,0 @@ -2054,9 +2225,10 @@ Timer tmSerial vis tEntity4,0 vis tIcon4,0 vis bText4,0 + vis hSlider4,0 }else { - //change icon + // change icon spstr strCommand.txt,tTmp.txt,",",21 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tIcon4.txt,sys0,1 @@ -2076,14 +2248,16 @@ Timer tmSerial vis bDown4,1 vis btOnOff4,0 vis bText4,0 + vis hSlider4,0 } if(type4.txt=="light") { vis bUp4,0 vis bStop4,0 vis bDown4,0 - vis bText4,0 vis btOnOff4,1 + vis bText4,0 + vis hSlider4,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",24 covx tTmp.txt,sys0,0,0 @@ -2094,8 +2268,9 @@ Timer tmSerial vis bUp4,0 vis bStop4,0 vis bDown4,0 - vis bText4,0 vis btOnOff4,1 + vis bText4,0 + vis hSlider4,0 // get Button State (optional Value) spstr strCommand.txt,tTmp.txt,",",24 covx tTmp.txt,sys0,0,0 @@ -2109,6 +2284,7 @@ Timer tmSerial vis btOnOff4,0 vis bText4,1 tsw bText4,0 + vis hSlider4,0 bText4.pco=65535 bText4.pco2=65535 // get Text (optional Value) @@ -2122,11 +2298,24 @@ Timer tmSerial vis btOnOff4,0 vis bText4,1 tsw bText4,1 + vis hSlider4,0 bText4.pco=1374 bText4.pco2=1374 // get Text (optional Value) spstr strCommand.txt,bText4.txt,",",24 } + if(type4.txt=="number") + { + vis bUp4,0 + vis bStop4,0 + vis bDown4,0 + vis btOnOff4,0 + vis bText4,0 + tsw bText4,0 + vis hSlider4,1 + // get Text (optional Value) + spstr strCommand.txt,bText4.txt,",",24 + } } if(tInstruction.txt=="pageType") { diff --git a/HMI/n2t-out/cardGrid.txt b/HMI/n2t-out/cardGrid.txt index ba246587..e53a3017 100644 --- a/HMI/n2t-out/cardGrid.txt +++ b/HMI/n2t-out/cardGrid.txt @@ -83,28 +83,28 @@ Variable (string) entn1 ID : 18 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) entn2 Attributes ID : 19 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) entn3 Attributes ID : 20 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) entn4 Attributes ID : 21 Scope : local Text : - Max. Text Size: 50 + Max. Text Size: 70 Variable (string) type5 Attributes @@ -515,13 +515,7 @@ Button bPrev Events Touch Press Event - nPage=nPage-1 - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardGrid,bPrev" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -568,13 +562,7 @@ Button bNext Events Touch Press Event - nPage=nPage+1 - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardGrid,bNext" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC diff --git a/HMI/n2t-out/cardMedia.txt b/HMI/n2t-out/cardMedia.txt index e03c53d4..3adb82bc 100644 --- a/HMI/n2t-out/cardMedia.txt +++ b/HMI/n2t-out/cardMedia.txt @@ -23,54 +23,36 @@ Page cardMedia vis p0,0 vis tSend,0 vis tInstruction,0 - vis nPageDisp,0 vis tTmp,0 vis tId,0 //vis nPageDisp,0 Variable (string) strCommand Attributes - ID : 8 + ID : 7 Scope : local Text : - Max. Text Size: 200 + Max. Text Size: 500 Variable (string) entn Attributes - ID : 19 + ID : 18 Scope : local Text : Max. Text Size: 50 -Number nPageDisp +Variable (string) vaSpeakerList Attributes - ID : 6 - Scope : local - Dragging : 0 - Disable release event after dragging: 0 - Send Component ID : disabled - Opacity : 127 - x coordinate : 426 - y coordinate : 0 - Width : 42 - Height : 24 - Effect : load - Effect Priority : 0 - Effect Time : 300 - Fill : solid color - Style : flat - Associated Keyboard : none - Font ID : 0 - Back. Color : 65535 - Font Color : 0 - Horizontal Alignment : center - Vertical Alignment : center - Value : 0 - Significant digits shown : all - Format : decimal - Word wrap : enabled - Horizontal Spacing : 0 - Vertical Spacing : 0 + ID : 27 + Scope : local + Text : + Max. Text Size: 200 + +Variable (int32) vaSpeakerPos + Attributes + ID : 28 + Scope: local + Value: 0 Text tSend Attributes @@ -83,7 +65,7 @@ Text tSend x coordinate : 0 y coordinate : 0 Width : 230 - Height : 23 + Height : 15 Effect : load Effect Priority : 0 Effect Time : 300 @@ -96,8 +78,8 @@ Text tSend Horizontal Alignment : center Vertical Alignment : center Input Type : character - Text : newtxt - Max. Text Size : 100 + Text : + Max. Text Size : 200 Word wrap : disabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -110,9 +92,9 @@ Text tTmp Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 406 - y coordinate : 277 - Width : 34 + x coordinate : 450 + y coordinate : 145 + Width : 27 Height : 30 Effect : load Effect Priority : 0 @@ -134,16 +116,16 @@ Text tTmp Text tInstruction Attributes - ID : 9 + ID : 8 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 0 - y coordinate : 290 + x coordinate : 296 + y coordinate : 0 Width : 100 - Height : 30 + Height : 20 Effect : load Effect Priority : 0 Effect Time : 300 @@ -164,15 +146,15 @@ Text tInstruction Text tId Attributes - ID : 10 + ID : 9 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 99 - y coordinate : 290 - Width : 39 + x coordinate : 449 + y coordinate : 187 + Width : 30 Height : 30 Effect : load Effect Priority : 0 @@ -194,7 +176,7 @@ Text tId Text tHeading Attributes - ID : 11 + ID : 10 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -224,7 +206,7 @@ Text tHeading Text tTitle Attributes - ID : 12 + ID : 11 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -254,7 +236,7 @@ Text tTitle Text tAuthor Attributes - ID : 13 + ID : 12 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -284,14 +266,14 @@ Text tAuthor Text t2 Attributes - ID : 14 + ID : 13 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 x coordinate : 314 - y coordinate : 159 + y coordinate : 145 Width : 50 Height : 50 Effect : load @@ -333,14 +315,14 @@ Text t2 Text tPlayPause Attributes - ID : 15 + ID : 14 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 x coordinate : 203 - y coordinate : 159 + y coordinate : 145 Width : 50 Height : 50 Effect : load @@ -382,14 +364,14 @@ Text tPlayPause Text t0 Attributes - ID : 16 + ID : 15 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 x coordinate : 92 - y coordinate : 159 + y coordinate : 145 Width : 50 Height : 50 Effect : load @@ -431,7 +413,7 @@ Text t0 Text tIcon Attributes - ID : 18 + ID : 17 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -459,6 +441,227 @@ Text tIcon Horizontal Spacing : 0 Vertical Spacing : 0 +Text t1 + Attributes + ID : 22 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 5 + y coordinate : 201 + Width : 50 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 2 + Back. Color : 6371 + Font Color : 50712 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text :  + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + + Events + Touch Press Event + hVolume.val=hVolume.val-5 + // event,buttonPress2,internalNameEntity,volumeSlider,50 + //craft command + tSend.txt="event,buttonPress2,"+entn.txt+",volumeSlider," + covx hVolume.val,tTmp.txt,0,0 + tSend.txt+=tTmp.txt + //send calc crc + btlen tSend.txt,sys0 + crcrest 1,0xffff // reset CRC + crcputh 55 bb + crcputs sys0,1 + crcputs tSend.txt,0 + //send cmd + printh 55 bb + prints sys0,2 + prints tSend.txt,0 + prints crcval,2 + +Text t3 + Attributes + ID : 23 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 397 + y coordinate : 201 + Width : 50 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 2 + Back. Color : 6371 + Font Color : 50712 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text :  + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + + Events + Touch Press Event + hVolume.val=hVolume.val+5 + // event,buttonPress2,internalNameEntity,volumeSlider,50 + //craft command + tSend.txt="event,buttonPress2,"+entn.txt+",volumeSlider," + covx hVolume.val,tTmp.txt,0,0 + tSend.txt+=tTmp.txt + //send calc crc + btlen tSend.txt,sys0 + crcrest 1,0xffff // reset CRC + crcputh 55 bb + crcputs sys0,1 + crcputs tSend.txt,0 + //send cmd + printh 55 bb + prints sys0,2 + prints tSend.txt,0 + prints crcval,2 + +Text t4 + Attributes + ID : 24 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 21 + y coordinate : 262 + Width : 50 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 2 + Back. Color : 6371 + Font Color : 50712 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text :  + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tSpeaker + Attributes + ID : 25 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 90 + y coordinate : 260 + Width : 267 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 0 + Back. Color : 6371 + Font Color : 65535 + Horizontal Alignment : left + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 50 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + + Events + Touch Press Event + // event,buttonPress2,entn,media-next + //craft command + tSend.txt="event,buttonPress2," + tSend.txt+=entn.txt+"," + tSend.txt+="speaker-sel,"+tSpeaker.txt + //send calc crc + btlen tSend.txt,sys0 + crcrest 1,0xffff // reset CRC + crcputh 55 bb + crcputs sys0,1 + crcputs tSend.txt,0 + //send cmd + printh 55 bb + prints sys0,2 + prints tSend.txt,0 + prints crcval,2 + +Text t6 + Attributes + ID : 26 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 381 + y coordinate : 262 + Width : 50 + Height : 50 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 2 + Back. Color : 6371 + Font Color : 50712 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text :  + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + + Events + Touch Press Event + //speaker + tSpeaker.pco=65535 + spstr vaSpeakerList.txt,tSpeaker.txt,"?",vaSpeakerPos.val + vaSpeakerPos.val+=1 + if(tSpeaker.txt=="") + { + vaSpeakerPos.val=0 + spstr vaSpeakerList.txt,tSpeaker.txt,"?",vaSpeakerPos.val + } + Picture p0 Attributes ID : 1 @@ -478,14 +681,14 @@ Picture p0 Slider hVolume Attributes - ID : 17 + ID : 16 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 61 - y coordinate : 227 + x coordinate : 59 + y coordinate : 206 Width : 335 Height : 43 Effect : load @@ -503,6 +706,8 @@ Slider hVolume Events Touch Release Event + tmCooldown.en=1 + tmCooldown.tim=800 // event,buttonPress2,internalNameEntity,volumeSlider,50 //craft command tSend.txt="event,buttonPress2,"+entn.txt+",volumeSlider," @@ -554,14 +759,7 @@ Button bNext Events Touch Press Event - nPage=nPage+1 - nPageDisp.val=nPage - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardMedia,bNext" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -608,14 +806,7 @@ Button bPrev Events Touch Press Event - nPage=nPage-1 - nPageDisp.val=nPage - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardMedia,bPrev" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -630,7 +821,7 @@ Button bPrev Timer tmSerial Attributes - ID : 7 + ID : 6 Scope : local Period (ms): 50 Enabled : yes @@ -702,6 +893,22 @@ Timer tmSerial spstr strCommand.txt,tTmp.txt,"|",7 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tPlayPause.txt,sys0,1 + //speaker current + spstr strCommand.txt,tSpeaker.txt,"|",8 + if(tSpeaker.txt!="") + { + tSpeaker.pco=1374 + }else + { + tSpeaker.pco=65535 + } + //speaker list + spstr strCommand.txt,vaSpeakerList.txt,"|",9 + if(vaSpeakerList.txt=="") + { + vis t6,0 + } + vaSpeakerPos.val=0 } if(tInstruction.txt=="time") { @@ -791,7 +998,7 @@ Timer tmSerial Timer tmSleep Attributes - ID : 20 + ID : 19 Scope : local Period (ms): 1000 Enabled : yes @@ -809,9 +1016,20 @@ Timer tmSleep } } +Timer tmCooldown + Attributes + ID : 21 + Scope : local + Period (ms): 100 + Enabled : no + + Events + Timer Event + tmCooldown.en=0 + TouchCap tc0 Attributes - ID : 21 + ID : 20 Scope: local Value: 0 diff --git a/HMI/n2t-out/cardThermo.txt b/HMI/n2t-out/cardThermo.txt index 15c24aa6..45818e84 100644 --- a/HMI/n2t-out/cardThermo.txt +++ b/HMI/n2t-out/cardThermo.txt @@ -559,14 +559,7 @@ Button bNext Events Touch Press Event - nPage=nPage+1 - nPageDisp.val=nPage - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardThermo,bNext" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -721,14 +714,7 @@ Button bPrev Events Touch Press Event - nPage=nPage-1 - nPageDisp.val=nPage - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,cardThermo,bPrev" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC diff --git a/HMI/n2t-out/nspanel_Stats.txt b/HMI/n2t-out/nspanel_Stats.txt index 98785905..e46ebdff 100644 --- a/HMI/n2t-out/nspanel_Stats.txt +++ b/HMI/n2t-out/nspanel_Stats.txt @@ -1,66 +1,62 @@ Program.s 0 Component(s) - 17 Line(s) of event code - 17 Unique line(s) of event code + 10 Line(s) of event code + 10 Unique line(s) of event code pageIcons 6 Component(s) 0 Line(s) of event code 0 Unique line(s) of event code +pageTest + 13 Component(s) + 13 Line(s) of event code + 13 Unique line(s) of event code pageSerialTest 13 Component(s) 48 Line(s) of event code 43 Unique line(s) of event code -popupNotify - 17 Component(s) - 180 Line(s) of event code - 119 Unique line(s) of event code -pageStartup - 19 Component(s) - 146 Line(s) of event code - 111 Unique line(s) of event code -cardMedia - 22 Component(s) - 200 Line(s) of event code - 115 Unique line(s) of event code -pageSwipeTest - 18 Component(s) - 62 Line(s) of event code - 44 Unique line(s) of event code popupShutter 19 Component(s) - 180 Line(s) of event code - 103 Unique line(s) of event code -pageTest - 14 Component(s) - 14 Line(s) of event code - 14 Unique line(s) of event code -screensaver - 25 Component(s) - 173 Line(s) of event code - 124 Unique line(s) of event code -popupLight - 26 Component(s) - 307 Line(s) of event code - 168 Unique line(s) of event code + 179 Line(s) of event code + 102 Unique line(s) of event code +popupNotify + 17 Component(s) + 179 Line(s) of event code + 118 Unique line(s) of event code +cardEntities + 58 Component(s) + 824 Line(s) of event code + 346 Unique line(s) of event code +cardMedia + 29 Component(s) + 256 Line(s) of event code + 132 Unique line(s) of event code cardThermo 42 Component(s) - 412 Line(s) of event code - 221 Unique line(s) of event code + 406 Line(s) of event code + 218 Unique line(s) of event code +pageStartup + 19 Component(s) + 150 Line(s) of event code + 113 Unique line(s) of event code cardGrid 39 Component(s) - 382 Line(s) of event code - 221 Unique line(s) of event code -cardEntities - 54 Component(s) - 728 Line(s) of event code - 317 Unique line(s) of event code + 378 Line(s) of event code + 219 Unique line(s) of event code +popupLight + 27 Component(s) + 323 Line(s) of event code + 174 Unique line(s) of event code +screensaver + 31 Component(s) + 183 Line(s) of event code + 133 Unique line(s) of event code cardAlarm - 35 Component(s) - 259 Line(s) of event code - 163 Unique line(s) of event code + 36 Component(s) + 277 Line(s) of event code + 173 Unique line(s) of event code Total - 14 Page(s) + 13 Page(s) 349 Component(s) - 3108 Line(s) of event code - 828 Unique line(s) of event code + 3226 Line(s) of event code + 864 Unique line(s) of event code diff --git a/HMI/n2t-out/pageIcons.txt b/HMI/n2t-out/pageIcons.txt index c4d13be6..901db106 100644 --- a/HMI/n2t-out/pageIcons.txt +++ b/HMI/n2t-out/pageIcons.txt @@ -72,8 +72,8 @@ Text tIcons Horizontal Alignment : left Vertical Alignment : top Input Type : character - Text :  - Max. Text Size : 120 + Text :  + Max. Text Size : 150 Word wrap : enabled Horizontal Spacing : 0 Vertical Spacing : 0 diff --git a/HMI/n2t-out/pageStartup.txt b/HMI/n2t-out/pageStartup.txt index 38919eb7..aee5187b 100644 --- a/HMI/n2t-out/pageStartup.txt +++ b/HMI/n2t-out/pageStartup.txt @@ -402,7 +402,7 @@ Text tVersion Horizontal Alignment : center Vertical Alignment : center Input Type : character - Text : 16 + Text : 20 Max. Text Size : 10 Word wrap : disabled Horizontal Spacing : 0 @@ -592,6 +592,10 @@ Timer tmSerial { page cardThermo } + if(tId.txt=="screensaver") + { + page screensaver + } if(tId.txt=="popupLight") { pageIcons.tTmp1.txt=tTmp.txt diff --git a/HMI/n2t-out/pageTest.txt b/HMI/n2t-out/pageTest.txt index 1c0cc58d..54098892 100644 --- a/HMI/n2t-out/pageTest.txt +++ b/HMI/n2t-out/pageTest.txt @@ -111,45 +111,9 @@ Button b1 Touch Press Event page pageSerialTest -Button b2 - Attributes - ID : 4 - Scope : local - Dragging : 0 - Disable release event after dragging: 0 - Send Component ID : disabled - Opacity : 127 - x coordinate : 7 - y coordinate : 265 - Width : 100 - Height : 50 - Effect : load - Effect Priority : 0 - Effect Time : 300 - Fill : solid color - Style : 3D auto - Font ID : 4 - Back. Color : 50712 - Back. Picture ID (Pressed) : 65535 - Back. Color (Pressed) : 1024 - Font Color (Unpressed) : 0 - Font Color (Pressed) : 65535 - Horizontal Alignment : center - Vertical Alignment : center - State : unpressed - Text : swipe - Max. Text Size : 10 - Word wrap : disabled - Horizontal Spacing : 0 - Vertical Spacing : 0 - - Events - Touch Press Event - page pageSwipeTest - Button b3 Attributes - ID : 5 + ID : 4 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -185,7 +149,7 @@ Button b3 Button b6 Attributes - ID : 6 + ID : 5 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -221,7 +185,7 @@ Button b6 Button b4 Attributes - ID : 7 + ID : 6 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -257,7 +221,7 @@ Button b4 Button b5 Attributes - ID : 8 + ID : 7 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -293,7 +257,7 @@ Button b5 Button b7 Attributes - ID : 9 + ID : 8 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -329,7 +293,7 @@ Button b7 Button b8 Attributes - ID : 10 + ID : 9 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -366,7 +330,7 @@ Button b8 Button b9 Attributes - ID : 11 + ID : 10 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -402,7 +366,7 @@ Button b9 Button b10 Attributes - ID : 12 + ID : 11 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -438,7 +402,7 @@ Button b10 Button b11 Attributes - ID : 13 + ID : 12 Scope : local Dragging : 0 Disable release event after dragging: 0 diff --git a/HMI/n2t-out/popupLight.txt b/HMI/n2t-out/popupLight.txt index 785f154b..6c5d50f6 100644 --- a/HMI/n2t-out/popupLight.txt +++ b/HMI/n2t-out/popupLight.txt @@ -500,6 +500,8 @@ Slider hBrightness Events Touch Release Event + tmCooldown.en=1 + tmCooldown.tim=2500 //craft command tSend.txt="event,buttonPress2,"+entn.txt+",brightnessSlider," covx hBrightness.val,tTmp.txt,0,0 @@ -543,6 +545,8 @@ Slider hTempSlider Events Touch Release Event + tmCooldown.en=1 + tmCooldown.tim=2500 //craft command tSend.txt="event,buttonPress2,"+entn.txt+",colorTempSlider," covx hTempSlider.val,tTmp.txt,0,0 @@ -593,12 +597,7 @@ Button b0 Events Touch Press Event - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,popupLight,bExit" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC @@ -815,7 +814,10 @@ Timer tmSerial vis t2,1 vis hBrightness,1 covx tTmp.txt,sys0,0,0 - hBrightness.val=sys0 + if(tmCooldown.en==0) + { + hBrightness.val=sys0 + } } // get ColorTemp value spstr strCommand.txt,tTmp.txt,",",5 @@ -848,6 +850,11 @@ Timer tmSerial vis hTempSlider,1 vis t3,1 vis t4,1 + if(tmCooldown.en==0) + { + covx tTmp.txt,sys0,0,0 + hTempSlider.val=sys0 + } // mode == 0 is rgb controls currently shown if(mode.val==0) { @@ -949,6 +956,17 @@ Timer tmSerial } } +Timer tmCooldown + Attributes + ID : 26 + Scope : local + Period (ms): 100 + Enabled : no + + Events + Timer Event + tmCooldown.en=0 + TouchCap tc0 Attributes ID : 14 diff --git a/HMI/n2t-out/popupNotify.txt b/HMI/n2t-out/popupNotify.txt index 092fb756..462cb337 100644 --- a/HMI/n2t-out/popupNotify.txt +++ b/HMI/n2t-out/popupNotify.txt @@ -278,12 +278,7 @@ Button b0 Events Touch Press Event sleepTimeout=vaOldSleepT.val - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,popupNotify,bExit" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC diff --git a/HMI/n2t-out/popupShutter.txt b/HMI/n2t-out/popupShutter.txt index 84352b87..e832b2ee 100644 --- a/HMI/n2t-out/popupShutter.txt +++ b/HMI/n2t-out/popupShutter.txt @@ -364,12 +364,7 @@ Button b0 Events Touch Press Event - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + tSend.txt="event,buttonPress2,popupShutter,bExit" //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC diff --git a/HMI/n2t-out/screensaver.txt b/HMI/n2t-out/screensaver.txt index 15120f9f..bd02e6a1 100644 --- a/HMI/n2t-out/screensaver.txt +++ b/HMI/n2t-out/screensaver.txt @@ -27,12 +27,26 @@ Page screensaver vis tTmp,0 vis p0,0 //load gloabl time string from pageIcons - tTime.txt=vaTime.txt + //tTime.txt=vaTime.txt + spstr vaTime.txt,tTime.txt,"?",0 + spstr vaTime.txt,tAMPM.txt,"?",1 + if(tAMPM.txt=="") + { + vis tAMPM,0 + } tDate.txt=vaDate.txt dim=dimValue vis tSend,0 //page open event - // craft command + // clear weather elements, to keep example content in HMI + tMainIcon.txt="" + tMainText.txt="" + tForecast1.txt="" + tF1Icon.txt="" + tForecast1Val.txt="" + tForecast2.txt="" + tF2Icon.txt="" + tForecast2Val.txt="" tSend.txt="event,screensaverOpen" //send calc crc btlen tSend.txt,sys0 @@ -45,31 +59,20 @@ Page screensaver prints sys0,2 prints tSend.txt,0 prints crcval,2 - // clear weather elements, to keep example content in HMI - tMainIcon.txt="" - tMainText.txt="" - tMRIcon.txt="" - tMR.txt="" - tForecast1.txt="" - tF1Icon.txt="" - tForecast1Val.txt="" - tForecast2.txt="" - tF2Icon.txt="" - tForecast2Val.txt="" Variable (string) strCommand Attributes ID : 5 Scope : local Text : - Max. Text Size: 100 + Max. Text Size: 200 Variable (string) vaTime Attributes ID : 10 Scope : global Text : - Max. Text Size: 10 + Max. Text Size: 15 Variable (string) vaDate Attributes @@ -80,11 +83,17 @@ Variable (string) vaDate Variable (string) tId Attributes - ID : 24 + ID : 22 Scope : local Text : Max. Text Size: 25 +Variable (int32) vaTap + Attributes + ID : 30 + Scope: local + Value: 0 + Number originPage Attributes ID : 3 @@ -140,7 +149,7 @@ Text tInstruction Vertical Alignment : center Input Type : character Text : - Max. Text Size : 20 + Max. Text Size : 50 Word wrap : disabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -170,7 +179,7 @@ Text tTmp Vertical Alignment : center Input Type : character Text : - Max. Text Size : 20 + Max. Text Size : 50 Word wrap : disabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -199,8 +208,8 @@ Text tTime Horizontal Alignment : center Vertical Alignment : center Input Type : character - Text : 21:32 - Max. Text Size : 10 + Text : 21:32 + Max. Text Size : 15 Word wrap : disabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -260,7 +269,7 @@ Text tSend Vertical Alignment : center Input Type : character Text : - Max. Text Size : 25 + Max. Text Size : 50 Word wrap : disabled Horizontal Spacing : 0 Vertical Spacing : 0 @@ -273,9 +282,9 @@ Text tMainIcon Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 6 - y coordinate : 223 - Width : 100 + x coordinate : 26 + y coordinate : 202 + Width : 70 Height : 66 Effect : load Effect Priority : 0 @@ -303,8 +312,8 @@ Text tMainText Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 114 - y coordinate : 214 + x coordinate : 7 + y coordinate : 267 Width : 110 Height : 43 Effect : load @@ -325,7 +334,7 @@ Text tMainText Horizontal Spacing : 0 Vertical Spacing : 0 -Text tMRIcon +Text tForecast1 Attributes ID : 15 Scope : local @@ -333,69 +342,9 @@ Text tMRIcon Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 115 - y coordinate : 268 - Width : 40 - Height : 35 - Effect : load - Effect Priority : 0 - Effect Time : 300 - Fill : solid color - Style : flat - Associated Keyboard : none - Font ID : 1 - Back. Color : 0 - Font Color : 65535 - Horizontal Alignment : center - Vertical Alignment : center - Input Type : character - Text :  - Max. Text Size : 10 - Word wrap : disabled - Horizontal Spacing : 0 - Vertical Spacing : 0 - -Text tMR - Attributes - ID : 16 - Scope : local - Dragging : 0 - Disable release event after dragging: 0 - Send Component ID : disabled - Opacity : 127 - x coordinate : 157 - y coordinate : 275 - Width : 67 - Height : 22 - Effect : load - Effect Priority : 0 - Effect Time : 300 - Fill : solid color - Style : flat - Associated Keyboard : none - Font ID : 0 - Back. Color : 0 - Font Color : 65535 - Horizontal Alignment : center - Vertical Alignment : center - Input Type : character - Text : 0 mm - Max. Text Size : 10 - Word wrap : disabled - Horizontal Spacing : 0 - Vertical Spacing : 0 - -Text tForecast1 - Attributes - ID : 17 - Scope : local - Dragging : 0 - Disable release event after dragging: 0 - Send Component ID : disabled - Opacity : 127 - x coordinate : 228 + x coordinate : 128 y coordinate : 210 - Width : 108 + Width : 72 Height : 26 Effect : load Effect Priority : 0 @@ -417,15 +366,15 @@ Text tForecast1 Text tForecast1Val Attributes - ID : 18 + ID : 16 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 228 + x coordinate : 126 y coordinate : 277 - Width : 108 + Width : 72 Height : 26 Effect : load Effect Priority : 0 @@ -447,13 +396,13 @@ Text tForecast1Val Text tF1Icon Attributes - ID : 19 + ID : 17 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 262 + x coordinate : 146 y coordinate : 239 Width : 40 Height : 35 @@ -477,15 +426,15 @@ Text tF1Icon Text tForecast2 Attributes - ID : 20 + ID : 18 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 341 + x coordinate : 212 y coordinate : 210 - Width : 107 + Width : 72 Height : 25 Effect : load Effect Priority : 0 @@ -507,16 +456,16 @@ Text tForecast2 Text tF2Icon Attributes - ID : 21 + ID : 19 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 375 - y coordinate : 238 + x coordinate : 228 + y coordinate : 239 Width : 40 - Height : 33 + Height : 35 Effect : load Effect Priority : 0 Effect Time : 300 @@ -537,15 +486,15 @@ Text tF2Icon Text tForecast2Val Attributes - ID : 22 + ID : 20 Scope : local Dragging : 0 Disable release event after dragging: 0 Send Component ID : disabled Opacity : 127 - x coordinate : 341 + x coordinate : 212 y coordinate : 277 - Width : 107 + Width : 72 Height : 25 Effect : load Effect Priority : 0 @@ -567,7 +516,7 @@ Text tForecast2Val Text t10 Attributes - ID : 23 + ID : 21 Scope : local Dragging : 0 Disable release event after dragging: 0 @@ -595,6 +544,216 @@ Text t10 Horizontal Spacing : 0 Vertical Spacing : 0 +Text tAMPM + Attributes + ID : 23 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 343 + y coordinate : 48 + Width : 104 + Height : 57 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 3 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : PM + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tForecast3Val + Attributes + ID : 24 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 292 + y coordinate : 277 + Width : 71 + Height : 25 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 0 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tF3Icon + Attributes + ID : 25 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 309 + y coordinate : 239 + Width : 40 + Height : 35 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 1 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tForecast3 + Attributes + ID : 26 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 293 + y coordinate : 210 + Width : 72 + Height : 25 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 0 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tForecast4 + Attributes + ID : 27 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 374 + y coordinate : 210 + Width : 72 + Height : 25 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 0 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tF4Icon + Attributes + ID : 28 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 390 + y coordinate : 239 + Width : 40 + Height : 35 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 1 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + +Text tForecast4Val + Attributes + ID : 29 + Scope : local + Dragging : 0 + Disable release event after dragging: 0 + Send Component ID : disabled + Opacity : 127 + x coordinate : 374 + y coordinate : 277 + Width : 72 + Height : 25 + Effect : load + Effect Priority : 0 + Effect Time : 300 + Fill : solid color + Style : flat + Associated Keyboard : none + Font ID : 0 + Back. Color : 0 + Font Color : 65535 + Horizontal Alignment : center + Vertical Alignment : center + Input Type : character + Text : + Max. Text Size : 10 + Word wrap : disabled + Horizontal Spacing : 0 + Vertical Spacing : 0 + Picture p0 Attributes ID : 1 @@ -680,7 +839,12 @@ Timer tmSerial { //get set time to global variable spstr strCommand.txt,vaTime.txt,",",1 - tTime.txt=vaTime.txt + spstr vaTime.txt,tTime.txt,"?",0 + spstr vaTime.txt,tAMPM.txt,"?",1 + if(tAMPM.txt=="") + { + vis tAMPM,0 + } } if(tInstruction.txt=="date") { @@ -702,36 +866,38 @@ Timer tmSerial substr pageIcons.tIcons.txt,tMainIcon.txt,sys0,1 //tMainText spstr strCommand.txt,tMainText.txt,"?",2 - //tMRIcon - spstr strCommand.txt,tTmp.txt,"?",3 - covx tTmp.txt,sys0,0,0 - substr pageIcons.tIcons.txt,tMRIcon.txt,sys0,1 - //tMR - spstr strCommand.txt,tMR.txt,"?",4 //tForecast1 - spstr strCommand.txt,tForecast1.txt,"?",5 + spstr strCommand.txt,tForecast1.txt,"?",3 //tF1Icon - spstr strCommand.txt,tTmp.txt,"?",6 + spstr strCommand.txt,tTmp.txt,"?",4 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tF1Icon.txt,sys0,1 //tForecast1Val - spstr strCommand.txt,tForecast1Val.txt,"?",7 + spstr strCommand.txt,tForecast1Val.txt,"?",5 //tForecast2 - spstr strCommand.txt,tForecast2.txt,"?",8 + spstr strCommand.txt,tForecast2.txt,"?",6 //tF2Icon - spstr strCommand.txt,tTmp.txt,"?",9 + spstr strCommand.txt,tTmp.txt,"?",7 covx tTmp.txt,sys0,0,0 substr pageIcons.tIcons.txt,tF2Icon.txt,sys0,1 //tForecast2Val - spstr strCommand.txt,tForecast2Val.txt,"?",10 - } - if(tInstruction.txt=="page") - { - //pagenumber - spstr strCommand.txt,tTmp.txt,",",1 + spstr strCommand.txt,tForecast2Val.txt,"?",8 + //tForecast3 + spstr strCommand.txt,tForecast3.txt,"?",9 + //tF3Icon + spstr strCommand.txt,tTmp.txt,"?",10 covx tTmp.txt,sys0,0,0 - nPage=sys0 - //don't send current page number, wake will do + substr pageIcons.tIcons.txt,tF3Icon.txt,sys0,1 + //tForecast3Val + spstr strCommand.txt,tForecast3Val.txt,"?",11 + //tForecast4 + spstr strCommand.txt,tForecast4.txt,"?",12 + //tF4Icon + spstr strCommand.txt,tTmp.txt,"?",13 + covx tTmp.txt,sys0,0,0 + substr pageIcons.tIcons.txt,tF4Icon.txt,sys0,1 + //tForecast4Val + spstr strCommand.txt,tForecast4Val.txt,"?",14 } if(tInstruction.txt=="pageType") { @@ -804,12 +970,10 @@ TouchCap tc0 Events Touch Press Event - //page open event - // event,pageOpen,cardEntities,pageNumber - // craft command - // convert pageNumber and write to tTmp - covx nPage,tTmp.txt,0,0 - tSend.txt="event,pageOpen,"+tTmp.txt + dim=100 + vaTap.val+=1 + covx vaTap.val,tTmp.txt,0,0 + tSend.txt="event,buttonPress2,screensaver,bExit,"+tTmp.txt //send calc crc btlen tSend.txt,sys0 crcrest 1,0xffff // reset CRC diff --git a/HMI/nspanel.HMI b/HMI/nspanel.HMI index 054fa6ab..dccf2c32 100644 Binary files a/HMI/nspanel.HMI and b/HMI/nspanel.HMI differ diff --git a/HMI/nspanel.tft b/HMI/nspanel.tft index e02f397a..55fc5132 100644 Binary files a/HMI/nspanel.tft and b/HMI/nspanel.tft differ diff --git a/README.md b/README.md index 6942c5f6..6d11ce63 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Due the limitations of Berry, it's not possible to download the tft file directl The following Link has always the latest version from this repository, just execute the following Command in Tasmota: -`FlashNextion http://nspanel.pky.eu/lui.tft` +`FlashNextion http://nspanel.pky.eu/lui-release.tft` ## Configuration @@ -244,26 +244,25 @@ Confiure your NSPanel as you like, you need to edit the `apps.yaml` inside of yo You can have multiple nspanel sections. ```yaml +--- nspanel-1: module: nspanel-lovelace-ui class: NsPanelLovelaceUIManager config: panelRecvTopic: "tele/tasmota_your_mqtt_topic/RESULT" panelSendTopic: "cmnd/tasmota_your_mqtt_topic/CustomSend" - updateMode: auto-notify # possible values are auto, auto-notify and manual - timeoutScreensaver: 15 #in seconds + timeoutScreensaver: 20 #brightnessScreensaver: 10 brightnessScreensaver: - time: "7:00:00" value: 10 - time: "23:00:00" value: 0 - locale: "de_DE" # only used if babel python package is installed - dateFormatBabel: "full" # only used if babel python package is installed - # formatting options on https://babel.pocoo.org/en/latest/dates.html?highlight=name%20of%20day#date-fields + locale: "de_DE" + dateFormatBabel: "full" timeFormat: "%H:%M" dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed - weatherEntity: weather.example + weather: weather.example pages: - type: cardEntities heading: Example Page 1 @@ -309,9 +308,42 @@ key | optional | type | default | description `class` | False | string | | The name of the Class. `config` | False | complex | | Config/Mapping between Homeassistant and your NsPanel -### Override Icons +Possible configuration values for config key: -To override Icons of entities you can configure an icon name in your configuration, please see the following example. +key | optional | type | default | description +-- | -- | -- | -- | -- +`panelRecvTopic` | False | string | `tele/tasmota_your_mqtt_topic/RESULT` | The mqtt topic used to receive messages. +`panelSendTopic` | False | string | `cmnd/tasmota_your_mqtt_topic/CustomSend` | The mqtt topic used to send messages. +`timeoutScreensaver` | True | integer | `20` | Timeout for the screen to enter screensaver, to disable screensaver use 0 +`brightnessScreensaver` | True | integer/complex | `20` | Brightness for the screen to enter screensaver, see example below for complex/scheduled config. +`brightnessScreensaverTracking` | True | string | None | Forces screensaver brightness to 0 in case entity state is not_home, can be a group, person or device_tracker entity. +`locale` | True | string | `en_US` | Used by babel to determinante Date format on screensaver, also used for localization. +`dateFormatBabel` | True | string | `full` | formatting options on https://babel.pocoo.org/en/latest/dates.html?highlight=name%20of%20day#date-fields +`timeFormat` | True | string | `%H:%M` | Time Format on screensaver. Substring after `?` is displayed in a seperate smaller textbox. Useful for 12h time format with AM/PM `"%I:%M ?%p"` +`dateFormat` | True | string | `%A, %d. %B %Y` | date format used if babel is not installed +`weather` | True | string | `weather.example` | weather entity from homeassistant +`weatherOverrideForecast1` | True | string | `None` | sensor entity from home assistant here to override the first weather forecast item on the screensaver +`weatherOverrideForecast2` | True | string | `None` | sensor entity from home assistant here to override the second weather forecast item on the screensaver +`weatherOverrideForecast3` | True | string | `None` | sensor entity from home assistant here to override the third weather forecast item on the screensaver +`weatherOverrideForecast4` | True | string | `None` | sensor entity from home assistant here to override the forth weather forecast item on the screensaver +`doubleTapToUnlock` | True | boolean | `False` | requires to tap screensaver two times +`pages` | False | complex | | configuration for pages on panel + +#### Schedule screensaver brightness + +It is possible to schedule a brightness change for the screen at specific times. + +```yaml + brightnessScreensaver: + - time: "7:00:00" + value: 10 + - time: "23:00:00" + value: 0 +``` + +#### Override Icons or Names + +To override Icons or Names of entities you can configure an icon and/or name in your configuration, please see the following example. Only the icons listed in the [Icon Table](HMI#icons-ids) are useable. ```yaml @@ -322,6 +354,7 @@ Only the icons listed in the [Icon Table](HMI#icons-ids) are useable. - light.schreibtischlampe - switch.deckenbeleuchtung_hinten: icon: lightbulb + name: Lampe - delete - delete - type: cardMedia @@ -342,13 +375,9 @@ HACS will show you that there is an update avalible and ask you to update. ### Update Display Firmware -Use the following command to update or use your own webserver. FlashNextionFast will use Nextion Upload Protocol 1.2 and try to skip unchanged parts of the firmware. +Use the following command to update or use your own webserver. -`FlashNextionFast http://nspanel.pky.eu/lui.tft` - -In case this Update failes, reboot tasmota and use the following command: - -`FlashNextion http://nspanel.pky.eu/lui.tft` +`FlashNextion http://nspanel.pky.eu/lui-release.tft` ### Update Tasmota Berry Driver @@ -377,4 +406,23 @@ Reboot Tasmota and try to flash it a second time. Please check your MQTT Topics in your apps.yaml and your mqtt configuration on tasmota. +### How to upgrade from a release to the current development version + +1. Update App in HACS to main + +Click redownload in the menu of the app in HACS. + +Select main version. + +![hacs-main](doc-pics/hacs-main.png) + +**Wait for it to load, dropdown needs to be selectable again** + +Click download. + +2. Restart AppDaemon + +3. Flash current Development Firmware in Tasmota Console. + +`FlashNextion http://nspanel.pky.eu/lui.tft` diff --git a/appdaemon/apps.yaml b/appdaemon/apps.yaml index 629e2f8a..e6e67e18 100644 --- a/appdaemon/apps.yaml +++ b/appdaemon/apps.yaml @@ -1,12 +1,12 @@ --- -nspanel: +nspanel-1: module: nspanel-lovelace-ui class: NsPanelLovelaceUIManager config: panelRecvTopic: "tele/tasmota_your_mqtt_topic/RESULT" panelSendTopic: "cmnd/tasmota_your_mqtt_topic/CustomSend" - updateMode: auto-notify # possible values are auto, auto-notify and manual - timeoutScreensaver: 15 #in seconds + updateMode: "auto-notify" + timeoutScreensaver: 20 #brightnessScreensaver: 10 brightnessScreensaver: - time: "7:00:00" @@ -18,7 +18,7 @@ nspanel: # formatting options on https://babel.pocoo.org/en/latest/dates.html?highlight=name%20of%20day#date-fields timeFormat: "%H:%M" dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed - weatherEntity: weather.example + weather: weather.example pages: - type: cardEntities heading: Example Page 1 @@ -55,5 +55,4 @@ nspanel: item: climate.example_climate - type: cardMedia heading: Exampe Media - item: media_player.spotify_user - + item: media_player.spotify_user \ No newline at end of file diff --git a/apps/nspanel-lovelace-ui/luibackend/config.py b/apps/nspanel-lovelace-ui/luibackend/config.py new file mode 100644 index 00000000..51ab35d0 --- /dev/null +++ b/apps/nspanel-lovelace-ui/luibackend/config.py @@ -0,0 +1,160 @@ +import logging + +LOGGER = logging.getLogger(__name__) + +class PageNode(object): + def __init__(self, data, parent=None): + self.data = data + self.name = None + self.childs = [] + self.parent = parent + self.pos = None + + if "items" in data: + childs = data.pop("items") + for page in childs: + self.add_child(PageNode(page, self)) + + name = self.data.get("heading", "unkown") if type(self.data) is dict else self.data + ptype = self.data.get("type", "unkown") if type(self.data) is dict else "leaf" + + self.name = f"{ptype}.{name}" if type(self.data) is dict else self.data + self.name = self.name.replace(".","_") + self.name = self.name.replace(",","_") + self.name = self.name.replace(" ","_") + + def add_child(self, obj): + obj.pos = len(self.childs) + self.childs.append(obj) + + def next(self): + if self.parent is not None: + pos = self.pos + length = len(self.parent.childs) + return self.parent.childs[(pos+1)%length] + else: + return self + def prev(self): + if self.parent is not None: + pos = self.pos + length = len(self.parent.childs) + return self.parent.childs[(pos-1)%length] + else: + return self + + def search_page_by_name(self, name): + name = name.replace("navigate.", "") + pages = [] + for i in self.childs: + # compare name of current page + if i.name == name: + pages.append(i) + # current pages has also childs + if len(i.childs) > 0: + pages.extend(i.search_page_by_name(name)) + return pages + + return items + + def dump(self, indent=0): + """dump tree to string""" + tab = ' '*(indent-1) + ' |- ' if indent > 0 else '' + name = self.name + parent = self.parent.name if self.parent is not None else "root" + dumpstring = f"{tab}{self.pos}:{name} -> {parent} \n" + for obj in self.childs: + dumpstring += obj.dump(indent + 1) + return dumpstring + + def get_items(self): + items = [] + for i in self.childs: + if len(i.childs) > 0: + items.append(f"navigate.{i.name}") + else: + items.append(i.data) + return items + + def get_all_item_names(self, recursive=True): + items = [] + # current page + if type(self.data) is dict: + items.append(self.data.get("item", next(iter(self.data)))) + else: + items.append(self.data) + # childs of page + for i in self.childs: + if len(i.childs) > 0: + if recursive: + items.extend(i.get_all_item_names()) + else: + if type(i.data) is dict: + items.append(i.data.get("item", next(iter(i.data)))) + else: + items.append(i.data) + return items + +class LuiBackendConfig(object): + + _DEFAULT_CONFIG = { + 'panelRecvTopic': "tele/tasmota_your_mqtt_topic/RESULT", + 'panelSendTopic': "cmnd/tasmota_your_mqtt_topic/CustomSend", + 'updateMode': "auto-notify", + 'timeoutScreensaver': 20, + 'brightnessScreensaver': 20, + 'brightnessScreensaverTracking': None, + 'locale': "en_US", + 'timeFormat': "%H:%M", + 'dateFormatBabel': "full", + 'dateFormat': "%A, %d. %B %Y", + 'weather': 'weather.example', + 'weatherOverrideForecast1': None, + 'weatherOverrideForecast2': None, + 'weatherOverrideForecast3': None, + 'weatherOverrideForecast4': None, + 'doubleTapToUnlock': False, + 'pages': [{ + 'type': 'cardEntities', + 'heading': 'Test Entities 1', + 'items': ['switch.test_item', 'switch.test_item', 'switch.test_item'] + }, { + 'type': 'cardGrid', + 'heading': 'Test Grid 1', + 'items': ['switch.test_item', 'switch.test_item', 'switch.test_item'] + } + ] + } + + def __init__(self, args=None, check=True): + self._config = {} + self._page_config = None + + if args: + self.load(args) + + if check: + self.check() + + def load(self, args): + for k, v in args.items(): + if k in self._DEFAULT_CONFIG: + self._config[k] = v + LOGGER.info(f"Loaded config: {self._config}") + + root_page = {"items": self.get("pages"), "type": "internal", "heading": "root"} + self._page_config = PageNode(root_page) + + LOGGER.info(f"Parsed Page config to the following Tree: \n {self._page_config.dump()}") + + def check(self): + return + + def get(self, name): + value = self._config.get(name) + if value is None: + value = self._DEFAULT_CONFIG.get(name) + return value + + def get_root_page(self): + return self._page_config + diff --git a/apps/nspanel-lovelace-ui/luibackend/controller.py b/apps/nspanel-lovelace-ui/luibackend/controller.py new file mode 100644 index 00000000..82b2ed65 --- /dev/null +++ b/apps/nspanel-lovelace-ui/luibackend/controller.py @@ -0,0 +1,222 @@ +import logging +import datetime +from helper import scale, pos_to_color + +from pages import LuiPagesGen + +LOGGER = logging.getLogger(__name__) + +class LuiController(object): + + def __init__(self, ha_api, config, send_mqtt_msg): + self._ha_api = ha_api + self._config = config + self._send_mqtt_msg = send_mqtt_msg + + # first child of root page (default, after startup) + self._current_page = self._config._page_config.childs[0] + + self._pages_gen = LuiPagesGen(ha_api, config, send_mqtt_msg) + + # send panel back to startup page on restart of this script + self._pages_gen.page_type("pageStartup") + + # time update callback + time = datetime.time(0, 0, 0) + ha_api.run_minutely(self._pages_gen.update_time, time) + + # weather callback + weather_interval = 15 * 60 # 15 minutes + ha_api.run_every(self.weather_update, "now", weather_interval) + + # register callbacks + self.register_callbacks() + + # register callbacks for each time + if type(self._config.get("brightnessScreensaver")) == list: + for index, timeset in enumerate(self._config.get("brightnessScreensaver")): + self._ha_api.run_daily(self.update_screensaver_brightness, timeset["time"], value=timeset["value"]) + + # calculate current brightness + self.current_screensaver_brightness = self.calc_current_screensaver_brightness() + + # call update_screensaver_brightness on changes of entity configured in brightnessScreensaverTracking + bst = self._config.get("brightnessScreensaverTracking") + if bst is not None and self._ha_api.entity_exists(bst): + self._ha_api.listen_state(self.update_screensaver_brightness, entity_id=bst, value=self.current_screensaver_brightness) + + def startup(self): + LOGGER.info(f"Startup Event") + # send time and date on startup + self._pages_gen.update_time("") + self._pages_gen.update_date("") + + # set screensaver timeout + timeout = self._config.get("timeoutScreensaver") + self._send_mqtt_msg(f"timeout,{timeout}") + + # set current screensaver brightness + self.update_screensaver_brightness(kwargs={"value": self.current_screensaver_brightness}) + + # send panel to screensaver + self._pages_gen.page_type("screensaver") + self.weather_update("") + + def update_screensaver_brightness(self, kwargs): + bst = self._config.get("brightnessScreensaverTracking") + if bst is not None and self._ha_api.entity_exists(bst) and self._ha_api.get_entity(bst).state == "not_home": + self.current_screensaver_brightness = 0 + else: + self.current_screensaver_brightness = kwargs['value'] + self._send_mqtt_msg(f"dimmode,{self.current_screensaver_brightness}") + + def calc_current_screensaver_brightness(self): + current_screensaver_brightness = 20 + # set brightness of screensaver + if type(self._config.get("brightnessScreensaver")) == int: + current_screensaver_brightness = self._config.get("brightnessScreensaver") + elif type(self._config.get("brightnessScreensaver")) == list: + sorted_timesets = sorted(self._config.get("brightnessScreensaver"), key=lambda d: self._ha_api.parse_time(d['time'])) + # calc current screensaver brightness + found_current_dim_value = False + for index, timeset in enumerate(sorted_timesets): + LOGGER.info("Current time %s", self._ha_api.get_now().time()) + if self._ha_api.parse_time(timeset["time"]) > self._ha_api.get_now().time() and not found_current_dim_value: + # first time after current time, set dim value + current_screensaver_brightness = sorted_timesets[index-1]["value"] + LOGGER.info("Setting dim value to %s", sorted_timesets[index-1]) + found_current_dim_value = True + # still no dim value + if not found_current_dim_value: + self.current_screensaver_brightness = sorted_timesets[-1]["value"] + return current_screensaver_brightness + + def weather_update(self, kwargs): + we_name = self._config.get("weather") + unit = "°C" + self._pages_gen.update_screensaver_weather(kwargs={"weather": we_name, "unit": unit}) + + def register_callbacks(self): + items = self._config.get_root_page().get_all_item_names() + LOGGER.debug(f"Registering callbacks for the following items: {items}") + for item in items: + if self._ha_api.entity_exists(item): + self._ha_api.listen_state(self.state_change_callback, entity_id=item, attribute="all") + + def state_change_callback(self, entity, attribute, old, new, kwargs): + LOGGER.debug(f"Got callback for: {entity}") + LOGGER.debug(f"Current page has the following items: {self._current_page.get_items()}") + if entity in self._current_page.get_all_item_names(recursive=False): + LOGGER.debug(f"Callback Entity is on current page: {entity}") + self._pages_gen.render_page(self._current_page, send_page_type=False) + # send detail page update, just in case + if self._current_page.data.get("type", "unknown") in ["cardGrid", "cardEntities"]: + if entity.startswith("light"): + self._pages_gen.generate_light_detail_page(entity) + if entity.startswith("cover"): + self._pages_gen.generate_shutter_detail_page(entity) + + + def detail_open(self, detail_type, entity_id): + if detail_type == "popupShutter": + self._pages_gen.generate_shutter_detail_page(entity_id) + if detail_type == "popupLight": + self._pages_gen.generate_light_detail_page(entity_id) + + def button_press(self, entity_id, button_type, value): + LOGGER.info(f"Button Press Event; entity_id: {entity_id}; button_type: {button_type}; value: {value} ") + # internal buttons + if entity_id == "screensaver" and button_type == "bExit": + if self._config.get("doubleTapToUnlock") and int(value) >= 2: + self._pages_gen.render_page(self._current_page) + elif not self._config.get("doubleTapToUnlock"): + self._pages_gen.render_page(self._current_page) + return + if button_type == "bExit": + self._pages_gen.render_page(self._current_page) + + if button_type == "bNext": + self._current_page = self._current_page.next() + self._pages_gen.render_page(self._current_page) + if button_type == "bPrev": + self._current_page = self._current_page.prev() + self._pages_gen.render_page(self._current_page) + + elif entity_id == "updateDisplayNoYes" and value == "no": + self._pages_gen.render_page(self._current_page) + + # buttons with actions on HA + if button_type == "OnOff": + if value == "1": + self._ha_api.turn_on(entity_id) + else: + self._ha_api.turn_off(entity_id) + + # for shutter / covers + if button_type == "up": + self._ha_api.get_entity(entity_id).call_service("open_cover") + if button_type == "stop": + self._ha_api.get_entity(entity_id).call_service("stop_cover") + if button_type == "down": + self._ha_api.get_entity(entity_id).call_service("close_cover") + if button_type == "positionSlider": + pos = int(value) + self._ha_api.get_entity(entity_id).call_service("set_cover_position", position=pos) + + if button_type == "button": + if entity_id.startswith('navigate'): + # internal for navigation to nested pages + self._current_page = self._config.get_root_page().search_page_by_name(entity_id)[0] + self._pages_gen.render_page(self._current_page) + elif entity_id.startswith('scene'): + self._ha_api.get_entity(entity_id).call_service("turn_on") + elif entity_id.startswith('light') or entity_id.startswith('switch') or entity_id.startswith('input_boolean'): + self._ha_api.get_entity(entity_id).call_service("toggle") + else: + self._ha_api.get_entity(entity_id).call_service("press") + + # for media page + if button_type == "media-next": + self._ha_api.get_entity(entity_id).call_service("media_next_track") + if button_type == "media-back": + self._ha_api.get_entity(entity_id).call_service("media_previous_track") + if button_type == "media-pause": + player = self._ha_api.get_entity(entity_id) + if player.state == "off": + player.call_service("turn_on") + player.call_service("media_play_pause") + if button_type == "volumeSlider": + pos = int(value) + # HA wants this value between 0 and 1 as float + pos = pos/100 + self._ha_api.get_entity(entity_id).call_service("volume_set", volume_level=pos) + if button_type == "speaker-sel": + self._ha_api.get_entity(entity_id).call_service("select_source", source=value) + + # for light detail page + if button_type == "brightnessSlider": + # scale 0-100 to ha brightness range + brightness = int(scale(int(value),(0,100),(0,255))) + self._ha_api.get_entity(entity_id).call_service("turn_on", brightness=brightness) + if button_type == "colorTempSlider": + entity = self._ha_api.get_entity(entity_id) + #scale 0-100 from slider to color range of lamp + color_val = scale(int(value), (0, 100), (entity.attributes.min_mireds, entity.attributes.max_mireds)) + self._ha_api.get_entity(entity_id).call_service("turn_on", color_temp=color_val) + if button_type == "colorWheel": + self._ha_api.log(value) + value = value.split('|') + color = pos_to_color(int(value[0]), int(value[1])) + self._ha_api.log(color) + self._ha_api.get_entity(entity_id).call_service("turn_on", rgb_color=color) + + # for climate page + if button_type == "tempUpd": + temp = int(value)/10 + self._ha_api.get_entity(entity_id).call_service("set_temperature", temperature=temp) + if button_type == "hvac_action": + self._ha_api.get_entity(entity_id).call_service("set_hvac_mode", hvac_mode=value) + + # for alarm page + if button_type in ["disarm", "arm_home", "arm_away", "arm_night", "arm_vacation"]: + self._ha_api.get_entity(entity_id).call_service(f"alarm_{button_type}", code=value) \ No newline at end of file diff --git a/apps/nspanel-lovelace-ui/helper.py b/apps/nspanel-lovelace-ui/luibackend/helper.py similarity index 73% rename from apps/nspanel-lovelace-ui/helper.py rename to apps/nspanel-lovelace-ui/luibackend/helper.py index 92cfe5b6..a6e6a885 100644 --- a/apps/nspanel-lovelace-ui/helper.py +++ b/apps/nspanel-lovelace-ui/luibackend/helper.py @@ -10,6 +10,7 @@ def scale(val, src, dst): def hsv2rgb(h, s, v): hsv = colorsys.hsv_to_rgb(h,s,v) return tuple(round(i * 255) for i in hsv) + def pos_to_color(x, y): r = 160/2 x = round((x - r) / r * 100) / 100 @@ -26,10 +27,13 @@ def pos_to_color(x, y): return rgb def rgb_brightness(rgb_color, brightness): + # brightness values are in range 0-255 + # to make sure that the color is not completly lost we need to rescale this to 70-255 + brightness = int(scale(brightness,(0,255),(70,255))) red = rgb_color[0]/255*brightness green = rgb_color[1]/255*brightness blue = rgb_color[2]/255*brightness - return [red, green, blue] + return [int(red), int(green), int(blue)] def rgb_dec565(rgb_color): red = rgb_color[0] @@ -37,4 +41,8 @@ def rgb_dec565(rgb_color): blue = rgb_color[2] # take in the red, green and blue values (0-255) as 8 bit values and then combine # and shift them to make them a 16 bit dec value in 565 format. - return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31))) \ No newline at end of file + return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31))) + +def get_attr_safe(entity, attr, default): + res = entity.attributes.get(attr, default) if not None else default + return res \ No newline at end of file diff --git a/apps/nspanel-lovelace-ui/icon_mapping.py b/apps/nspanel-lovelace-ui/luibackend/icon_mapping.py similarity index 90% rename from apps/nspanel-lovelace-ui/icon_mapping.py rename to apps/nspanel-lovelace-ui/luibackend/icon_mapping.py index 808ea06e..2078fe69 100644 --- a/apps/nspanel-lovelace-ui/icon_mapping.py +++ b/apps/nspanel-lovelace-ui/luibackend/icon_mapping.py @@ -38,6 +38,11 @@ icons = { 'door-open': 36, 'door-closed': 37, 'window-closed': 38, + 'shield-off': 39, + 'shield': 40, + 'shield-lock': 41, + 'shield-airplane': 42, + 'bell-ring': 43, } def get_icon_id(ma_name): diff --git a/apps/nspanel-lovelace-ui/icons.py b/apps/nspanel-lovelace-ui/luibackend/icons.py similarity index 100% rename from apps/nspanel-lovelace-ui/icons.py rename to apps/nspanel-lovelace-ui/luibackend/icons.py diff --git a/apps/nspanel-lovelace-ui/luibackend/localization.py b/apps/nspanel-lovelace-ui/luibackend/localization.py new file mode 100644 index 00000000..cac1c3fe --- /dev/null +++ b/apps/nspanel-lovelace-ui/luibackend/localization.py @@ -0,0 +1,349 @@ +translations = { + 'af_ZA': { + 'ACTIVATE': "Aktiveer", + 'aux_heat': "Aanvullende hitte", + 'cooling': "Koel Af", + 'drying': "Droog Uit", + 'fan': "Waaier", + 'idle': "Onaktief", + 'off': "Af", + 'arm_away': "Bewapen weg", + 'arm_custom_bypass': "Pasgemaakte omseil", + 'arm_home': "Bewapen Huis", + 'arm_night': "Nag alarm", + 'clear_code': "Maak skoon", + 'code': "Kode", + 'disarm': "Skakel Af", + }, + 'ca_ES': { + 'PRESS': "Prem", + 'ACTIVATE': "Activar", + 'aux_heat': "Calefactor auxiliar", + 'cooling': "Refredant", + 'drying': "Assecant", + 'fan': "Ventilació", + 'idle': "Inactiu", + 'off': "OFF", + 'arm_away': "Activar, fora", + 'arm_custom_bypass': "Bypass personalitzat", + 'arm_home': "Activar, a casa", + 'arm_night': "Activar, nocturn", + 'arm_vacation': "Activa en mode vacances", + 'clear_code': "Borrar", + 'code': "Codi", + 'disarm': "Desactivar", + }, + 'cs_CZ': { + 'PRESS': "Stisknutí", + 'ACTIVATE': "Aktivovat", + 'aux_heat': "Pomocné teplo", + 'cooling': "Chlazení", + 'drying': "Sušení", + 'fan': "Ventilátor", + 'idle': "Nečinný", + 'off': "Vypnuto", + 'arm_away': "Aktivovat režim nepřítomnost", + 'arm_custom_bypass': "Vlastní obejítí", + 'arm_home': "Aktivovat režim domov", + 'arm_night': "Aktivovat noční režim", + 'arm_vacation': "Aktivovat režim dovolená", + 'clear_code': "Zrušit", + 'code': "Kód", + 'disarm': "Odbezpečit", + }, + 'cy_GB': { + 'ACTIVATE': "Actifadu", + 'off': "I ffwrdd", + 'arm_custom_bypass': "Ffordd osgoi personol", + 'arm_night': "Larwm nos", + 'code': "Cod dilysu dwy-ffactor", + }, + 'da_DK': { + 'PRESS': "Tryk", + 'ACTIVATE': "Aktiver", + 'aux_heat': "Støtte-varme", + 'cooling': "Køling", + 'drying': "Tørring", + 'fan': "Blæser", + 'idle': "Inaktiv", + 'off': "Fra", + 'arm_away': "Tilkobl ude", + 'arm_custom_bypass': "Brugerdefineret bypass", + 'arm_home': "Tilkobl hjemme", + 'arm_night': "Tilkoblet nat", + 'arm_vacation': "Tilkobl ferie", + 'clear_code': "Ryd", + 'code': "Kode", + 'disarm': "Frakobl", + }, + 'de_DE': { + 'PRESS': "Drücken", + 'ACTIVATE': "Aktivieren", + 'aux_heat': "Hilfswärme", + 'cooling': "Kühlung", + 'drying': "Trocknen", + 'fan': "Ventilator", + 'idle': "Leerlauf", + 'off': "Aus", + 'arm_away': "Aktivieren - Unterwegs", + 'arm_custom_bypass': "Benutzerdefinierter Bypass", + 'arm_home': "Aktivieren - Zuhause", + 'arm_night': "Aktivieren - Nacht", + 'arm_vacation': "Aktiviere Urlaub", + 'clear_code': "Löschen", + 'code': "Code", + 'disarm': "Deaktivieren", + }, + 'en_US': { + 'PRESS': "Press", + 'ACTIVATE': "Activate", + 'aux_heat': "Aux heat", + 'cooling': "Cooling", + 'drying': "Drying", + 'fan': "Fan", + 'idle': "Idle", + 'off': "Off", + 'arm_away': "Arm away", + 'arm_custom_bypass': "Custom bypass", + 'arm_home': "Arm home", + 'arm_night': "Arm night", + 'arm_vacation': "Arm vacation", + 'clear_code': "Clear", + 'code': "Code", + 'disarm': "Disarm", + }, + 'es_ES': { + 'PRESS': "Pulsa", + 'ACTIVATE': "Activar", + 'aux_heat': "Calor auxiliar", + 'cooling': "Enfriando", + 'drying': "Secando", + 'fan': "Ventilador", + 'idle': "Inactivo", + 'off': "Apagado", + 'arm_away': "Armar ausente", + 'arm_custom_bypass': "Bypass personalizada", + 'arm_home': "Armar en casa", + 'arm_night': "Armar noche", + 'arm_vacation': "Armar por vacaciones", + 'clear_code': "Limpiar", + 'code': "Código", + 'disarm': "Desarmar", + }, + 'et_EE': { + 'PRESS': "Vajuta nuppu", + 'ACTIVATE': "Aktiveeri", + 'aux_heat': "Abiküte", + 'cooling': "Jahutamine", + 'drying': "Kuivatamine", + 'fan': "Ventilaator", + 'idle': "Ootel", + 'off': "Väljas", + 'arm_away': "Valvesta eemal", + 'arm_custom_bypass': "Eranditega", + 'arm_home': "Valvesta kodus", + 'arm_night': "Valvesta öine", + 'arm_vacation': "Valvesta puhkuse režiimis", + 'clear_code': "Puhasta", + 'code': "Kood", + 'disarm': "Valvest maha", + }, + 'eu_ES': { + 'ACTIVATE': "Aktibatu", + 'off': "Itzalita", + 'clear_code': "Garbitu", + 'code': "Kodea", + }, + 'fi_FI': { + 'PRESS': "Paina", + 'ACTIVATE': "Aktivoi", + 'aux_heat': "Lisälämpö", + 'cooling': "Jäähdytys", + 'drying': "Kuivaus", + 'fan': "Tuuletin", + 'idle': "Lepotilassa", + 'off': "Pois", + 'arm_away': "Viritä (poissa)", + 'arm_custom_bypass': "Mukautettu ohitus", + 'arm_home': "Viritä (kotona)", + 'arm_night': "Viritä yöksi", + 'arm_vacation': "Aktivoi lomatila", + 'clear_code': "Tyhjennä", + 'code': "Koodi", + 'disarm': "Poista hälytys", + }, + 'fr_FR': { + 'PRESS': "Appui", + 'ACTIVATE': "Activer", + 'aux_heat': "Chauffage d'appoint", + 'cooling': "Refroidissement", + 'drying': "Séchage", + 'fan': "Ventilateur", + 'idle': "Inactif", + 'off': "Off", + 'arm_away': "Armer (absent)", + 'arm_custom_bypass': "Bypass personnalisé", + 'arm_home': "Armer (présent)", + 'arm_night': "Armer nuit", + 'arm_vacation': "Armer vacances", + 'clear_code': "Effacer", + 'code': "Code", + 'disarm': "Désarmer", + }, + 'fy_DE': { + 'off': "Út", + }, + 'gl_ES': { + 'off': "Apagado", + }, + 'hr_HR': { + 'ACTIVATE': "Aktivirati", + 'aux_heat': "Pomoćno grijanje", + 'cooling': "Hlađenje", + 'drying': "Sušenje", + 'fan': "Ventilator", + 'idle': "Neaktivan", + 'off': "Isključen", + 'arm_away': "Aktiviran odsutno", + 'arm_custom_bypass': "Prilagođena premosnica", + 'arm_home': "Aktiviran doma", + 'arm_night': "Aktiviran nočni", + 'clear_code': "Vedro", + 'code': "Kod", + 'disarm': "Deaktiviraj", + }, + 'id_ID': { + 'PRESS': "Tekan", + 'ACTIVATE': "Aktifkan", + 'aux_heat': "Pemanasan tambahan", + 'cooling': "Mendinginkan", + 'drying': "Mengeringkan", + 'fan': "Kipas", + 'idle': "Diam", + 'off': "Mati", + 'arm_away': "Aktifkan utk keluar", + 'arm_custom_bypass': "Diaktifkan khusus", + 'arm_home': "Aktifkan utk di rumah", + 'arm_night': "Aktifkan utk malam", + 'arm_vacation': "Aktifkan utk liburan", + 'clear_code': "Hapus", + 'code': "Kode", + 'disarm': "Nonaktifkan", + }, + 'is_IS': { + 'PRESS': "Ýttu á", + 'ACTIVATE': "Virkja", + 'cooling': "Kæling", + 'drying': "Þurrkun", + 'fan': "Vifta", + 'idle': "Aðgerðalaus", + 'off': "Slökkt", + 'arm_away': "Vörður úti", + 'arm_custom_bypass': "Sérsniðin hjáleið", + 'arm_home': "Vörður heima", + 'arm_night': "Vörður nótt", + 'arm_vacation': "Vörður frí", + 'clear_code': "Hreinsa", + 'code': "Kóði", + 'disarm': "Taka af verði", + }, + 'it_IT': { + 'PRESS': "Premi", + 'ACTIVATE': "Attiva", + 'aux_heat': "Riscaldamento ausiliario", + 'cooling': "Raffreddamento", + 'drying': "Deumidificazione", + 'fan': "Ventilatore", + 'idle': "Inattivo", + 'off': "Spento", + 'arm_away': "Attiva fuori casa", + 'arm_custom_bypass': "Bypass personalizzato", + 'arm_home': "Attiva in casa", + 'arm_night': "Attiva notte", + 'arm_vacation': "Attiva in vacanza", + 'clear_code': "Canc", + 'code': "Codice", + 'disarm': "Disattiva", + }, + 'nl_NL': { + 'PRESS': "Klik", + 'ACTIVATE': "Activeren", + 'aux_heat': "Extra warmte", + 'cooling': "Koelen", + 'drying': "Ontvochtigen", + 'fan': "Ventilator", + 'idle': "Inactief", + 'off': "Uit", + 'arm_away': "Inschakelen voor vertrek", + 'arm_custom_bypass': "Inschakelen met overbrugging", + 'arm_home': "Inschakelen voor thuis", + 'arm_night': "Inschakelen voor 's nachts", + 'arm_vacation': "Inschakelen voor vakantie", + 'clear_code': "Wis", + 'code': "Code", + 'disarm': "Uitschakelen", + }, + 'nn_NO': { + 'ACTIVATE': "Aktiver", + 'aux_heat': "Aux-varme", + 'cooling': "Nedkjøling", + 'drying': "Tørkar", + 'fan': "Vifte", + 'idle': "Tomgang", + 'off': "Av", + 'arm_away': "Bortemodus", + 'arm_custom_bypass': "Tilpassa bypass", + 'arm_home': "Heimemodus", + 'arm_night': "Aktiver natt", + 'arm_vacation': "Armert feriemodus", + 'clear_code': "Slett alt", + 'code': "Kode", + 'disarm': "Skru av", + }, + 'pt_PT': { + 'PRESS': "Pressione", + 'ACTIVATE': "Ativar", + 'aux_heat': "Calor auxiliar", + 'cooling': "Resfriar", + 'drying': "Secagem", + 'fan': "Ventoinha", + 'idle': "Em espera", + 'off': "Desligado", + 'arm_away': "Armado ausente", + 'arm_custom_bypass': "Desvio personalizado", + 'arm_home': "Armado casa", + 'arm_night': "Armado noite", + 'clear_code': "Apagar", + 'code': "Código", + 'disarm': "Desarmar", + }, + 'sr_RS': { + 'PRESS': "Pritisnite taster", + 'ACTIVATE': "Aktiviraj", + 'off': "Isključen", + }, + 'sv_SE': { + 'PRESS': "Tryck", + 'ACTIVATE': "Aktivera", + 'aux_heat': "Underhållsvärme", + 'cooling': "Kyler", + 'drying': "Avfuktar", + 'fan': "Fläkt", + 'idle': "Inaktiv", + 'off': "Av", + 'arm_away': "Larma bortaläge", + 'arm_custom_bypass': "Larm förbikopplat", + 'arm_home': "Larma hemmaläge", + 'arm_night': "Larma nattläge", + 'arm_vacation': "Larma semesterläge", + 'clear_code': "Rensa", + 'code': "Kod", + 'disarm': "Larma från", + }, +} + +def get_translation(locale, input): + if locale in translations: + return translations.get(locale).get(input, input) + else: + return translations.get("en_US").get(input, input) \ No newline at end of file diff --git a/apps/nspanel-lovelace-ui/luibackend/mqttListener.py b/apps/nspanel-lovelace-ui/luibackend/mqttListener.py new file mode 100644 index 00000000..457597bc --- /dev/null +++ b/apps/nspanel-lovelace-ui/luibackend/mqttListener.py @@ -0,0 +1,54 @@ +import json + +import logging + +LOGGER = logging.getLogger(__name__) + +class LuiMqttListener(object): + + def __init__(self, mqtt_api, topic, controller, updater): + self._controller = controller + self._updater = updater + # Setup, mqtt subscription and callback + mqtt_api.mqtt_subscribe(topic=topic) + mqtt_api.listen_event(self.mqtt_event_callback, "MQTT_MESSAGE", topic=topic, namespace='mqtt') + + + def mqtt_event_callback(self, event_name, data, kwargs): + LOGGER.debug(f'MQTT callback for: {data}') + # Parse Json Message from Tasmota and strip out message from nextion display + data = json.loads(data["payload"]) + if("nlui_driver_version" in data): + msg = data["nlui_driver_version"] + self._updater.set_tasmota_driver_version(int(msg)) + self._updater.check_updates() + if("CustomRecv" not in data): + return + msg = data["CustomRecv"] + LOGGER.info(f"Received Message from Screen: {msg}") + # Split message into parts seperated by "," + msg = msg.split(",") + # run action based on received command + if msg[0] == "event": + if msg[1] == "startup": + display_firmware_version = int(msg[2]) + self._updater.set_current_display_firmware_version(display_firmware_version) + # check for updates + msg_send = self._updater.check_updates() + # send messages for current page + if not msg_send: + self._controller.startup() + if msg[1] == "screensaverOpen": + self._controller.weather_update("") + if msg[1] == "buttonPress2": + entity_id = msg[2] + btype = msg[3] + value = msg[4] if len(msg) > 4 else None + + if entity_id == "updateDisplayNoYes" and value == "yes": + self._updater.update_panel_driver() + + self._controller.button_press(entity_id, btype, value) + if msg[1] == "pageOpenDetail": + self._controller.detail_open(msg[2], msg[3]) + diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py new file mode 100644 index 00000000..4f4f08cf --- /dev/null +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -0,0 +1,367 @@ +import logging +import datetime + +from icon_mapping import get_icon_id +from icons import get_icon_id_ha +from helper import scale, rgb_dec565, rgb_brightness, get_attr_safe +from localization import get_translation + +# check Babel +import importlib +babel_spec = importlib.util.find_spec("babel") +if babel_spec is not None: + import babel.dates + +LOGGER = logging.getLogger(__name__) + +class LuiPagesGen(object): + + def __init__(self, ha_api, config, send_mqtt_msg): + self._ha_api = ha_api + self._config = config + self._locale = config.get("locale") + self._send_mqtt_msg = send_mqtt_msg + + def get_entity_color(self, entity): + attr = entity.attributes + default_color_on = rgb_dec565([253, 216, 53]) + default_color_off = rgb_dec565([68, 115, 158]) + icon_color = default_color_on if entity.state == "on" else default_color_off + + if "rgb_color" in attr: + color = attr.rgb_color + if "brightness" in attr: + color = rgb_brightness(color, attr.brightness) + icon_color = rgb_dec565(color) + elif "brightness" in attr: + color = rgb_brightness([253, 216, 53], attr.brightness) + icon_color = rgb_dec565(color) + return icon_color + + def update_time(self, kwargs): + time = datetime.datetime.now().strftime(self._config.get("timeFormat")) + self._send_mqtt_msg(f"time,{time}") + + def update_date(self, kwargs): + global babel_spec + if babel_spec is not None: + dateformat = self._config.get("dateFormatBabel") + date = babel.dates.format_date(datetime.datetime.now(), dateformat, locale=self._locale) + else: + dateformat = self._config.get("dateFormat") + date = datetime.datetime.now().strftime(dateformat) + self._send_mqtt_msg(f"date,?{date}") + + def page_type(self, target_page): + self._send_mqtt_msg(f"pageType,{target_page}") + + def update_screensaver_weather(self, kwargs): + global babel_spec + we_name = kwargs['weather'] + unit = kwargs['unit'] + + if self._ha_api.entity_exists(we_name): + we = self._ha_api.get_entity(we_name) + else: + LOGGER.error("Skipping Weather Update, entitiy not found") + return + + icon_cur = get_icon_id_ha("weather", state=we.state) + text_cur = f"{we.attributes.temperature}{unit}" + + weather_res = "" + for i in range(1,5): + wOF = self._config.get(f"weatherOverrideForecast{i}") + if wOF is None: + up = we.attributes.forecast[i-1]['datetime'] + up = datetime.datetime.fromisoformat(up) + if babel_spec is not None: + up = babel.dates.format_date(up, "E", locale=self._locale) + else: + up = up.strftime("%a") + icon = get_icon_id_ha("weather", state=we.attributes.forecast[i-1]['condition']) + down = f"{we.attributes.forecast[i-1]['temperature']} {unit}" + else: + LOGGER.info(f"Forecast 1 is overrriden with {wOF}") + icon = None + name = None + if type(wOF) is dict: + icon = next(iter(wOF.items()))[1].get('icon') + name = next(iter(wOF.items()))[1].get('name') + wOF = next(iter(wOF.items()))[0] + entity = self._ha_api.get_entity(wOF) + up = name if name is not None else entity.attributes.friendly_name + icon = get_icon_id_ha("sensor", state=entity.state, device_class=entity.attributes.get("device_class", ""), overwrite=icon) + unit_of_measurement = entity.attributes.get("unit_of_measurement", "") + down = f"{entity.state} {unit_of_measurement}" + weather_res+=f"?{up}?{icon}?{down}" + + self._send_mqtt_msg(f"weatherUpdate,?{icon_cur}?{text_cur}{weather_res}") + + def generate_entities_item(self, item): + icon = None + name = None + if type(item) is dict: + icon = next(iter(item.items()))[1].get('icon') + name = next(iter(item.items()))[1].get('name') + item = next(iter(item.items()))[0] + # type of the item is the string before the "." in the item name + item_type = item.split(".")[0] + LOGGER.debug(f"Generating item command for {item} with type {item_type}",) + # Internal Entities + if item_type == "delete": + return f",{item_type},,,,," + if item_type == "navigate": + page_search = self._config.get_root_page().search_page_by_name(item) + if len(page_search) > 0: + page_data = page_search[0].data + if name is None: + name = page_data.get("heading") + text = get_translation(self._locale,"PRESS") + icon_id = get_icon_id(icon) if icon is not None else get_icon_id(page_data.get("icon", "gesture-tap-button")) + return f",button,{item},{icon_id},17299,{name},{text}" + else: + return f",text,{item},{get_icon_id('alert-circle-outline')},17299,page not found," + if not self._ha_api.entity_exists(item): + return f",text,{item},{get_icon_id('alert-circle-outline')},17299,Not found check, apps.yaml" + + # HA Entities + entity = self._ha_api.get_entity(item) + name = name if name is not None else entity.attributes.friendly_name + if item_type == "cover": + icon_id = get_icon_id_ha("cover", state=entity.state, overwrite=icon) + return f",shutter,{item},{icon_id},17299,{name}," + if item_type in "light": + switch_val = 1 if entity.state == "on" else 0 + icon_color = self.get_entity_color(entity) + icon_id = get_icon_id_ha("light", overwrite=icon) + return f",{item_type},{item},{icon_id},{icon_color},{name},{switch_val}" + if item_type in ["switch", "input_boolean"]: + switch_val = 1 if entity.state == "on" else 0 + icon_color = self.get_entity_color(entity) + icon_id = get_icon_id_ha(item_type, state=entity.state, overwrite=icon) + return f",switch,{item},{icon_id},{icon_color},{name},{switch_val}" + if item_type in ["sensor", "binary_sensor"]: + device_class = entity.attributes.get("device_class", "") + icon_id = get_icon_id_ha("sensor", state=entity.state, device_class=device_class, overwrite=icon) + unit_of_measurement = entity.attributes.get("unit_of_measurement", "") + value = entity.state + " " + unit_of_measurement + icon_color = self.get_entity_color(entity) + return f",text,{item},{icon_id},{icon_color},{name},{value}" + if item_type in ["button", "input_button"]: + icon_id = get_icon_id_ha("button", overwrite=icon) + text = get_translation(self._locale,"PRESS") + return f",button,{item},{icon_id},17299,{name},{text}" + if item_type == "scene": + icon_id = get_icon_id_ha("scene", overwrite=icon) + text = get_translation(self._locale,"ACTIVATE") + return f",button,{item},{icon_id},17299,{name},{text}" + + + def generate_entities_page(self, heading, items): + # Set Heading of Page + self._send_mqtt_msg(f"entityUpdHeading,{heading}") + # Get items and construct cmd string + command = "entityUpd" + for item in items: + command += self.generate_entities_item(item) + self._send_mqtt_msg(command) + + + + def generate_thermo_page(self, item): + if not self._ha_api.entity_exists(item): + command = f"entityUpd,{item},Not found,220,220,Not found,150,300,5" + else: + entity = self._ha_api.get_entity(item) + heading = entity.attributes.friendly_name + current_temp = int(get_attr_safe(entity, "current_temperature", 0)*10) + dest_temp = int(get_attr_safe(entity, "temperature", 0)*10) + status = get_attr_safe(entity, "hvac_action", "") + status = get_translation(self._locale,status) + min_temp = int(get_attr_safe(entity, "min_temp", 0)*10) + max_temp = int(get_attr_safe(entity, "max_temp", 0)*10) + step_temp = int(get_attr_safe(entity, "target_temp_step", 0.5)*10) + icon_res = "" + hvac_modes = get_attr_safe(entity, "hvac_modes", []) + for mode in hvac_modes: + icon_id = get_icon_id('alert-circle-outline') + color_on = 64512 + if mode == "auto": + icon_id = get_icon_id("calendar-sync") + color_on = 1024 + if mode == "heat": + icon_id = get_icon_id("fire") + color_on = 64512 + if mode == "off": + icon_id = get_icon_id("power") + color_on = 35921 + if mode == "cool": + icon_id = get_icon_id("snowflake") + color_on = 11487 + if mode == "dry": + icon_id = get_icon_id("water-percent") + color_on = 60897 + if mode == "fan_only": + icon_id = get_icon_id("fan") + color_on = 35921 + state = 0 + if(mode == entity.state): + state = 1 + icon_res += f",{icon_id},{color_on},{state},{mode}" + + len_hvac_modes = len(hvac_modes) + if len_hvac_modes%2 == 0: + # even + padding_len = int((4-len_hvac_modes)/2) + icon_res = ","*4*padding_len + icon_res + ","*4*padding_len + # use last 4 icons + icon_res = ","*4*5 + icon_res + else: + # uneven + padding_len = int((5-len_hvac_modes)/2) + icon_res = ","*4*padding_len + icon_res + ","*4*padding_len + # use first 5 icons + icon_res = icon_res + ","*4*4 + command = f"entityUpd,{item},{heading},{current_temp},{dest_temp},{status},{min_temp},{max_temp},{step_temp}{icon_res}" + self._send_mqtt_msg(command) + + def generate_media_page(self, item): + if not self._ha_api.entity_exists(item): + command = f"entityUpd,|{item}|Not found|{get_icon_id('alert-circle-outline')}|Please check your|apps.yaml in AppDaemon|50|{get_icon_id('alert-circle-outline')}" + else: + entity = self._ha_api.get_entity(item) + heading = entity.attributes.friendly_name + icon = 0 + title = get_attr_safe(entity, "media_title", "") + author = get_attr_safe(entity, "media_artist", "") + volume = int(get_attr_safe(entity, "volume_level", 0)*100) + iconplaypause = get_icon_id("pause") if entity.state == "playing" else get_icon_id("play") + if "media_content_type" in entity.attributes: + if entity.attributes.media_content_type == "music": + icon = get_icon_id("music") + source = get_attr_safe(entity, "source", "") + speakerlist = get_attr_safe(entity, "source_list",[]) + if source in speakerlist: + # move current source to the end of the list + speakerlist.remove(source) + speakerlist.append(source) + if len(speakerlist) == 1: + speakerlist = [] + speakerlist = "?".join(speakerlist) + command = f"entityUpd,|{item}|{heading}|{icon}|{title}|{author}|{volume}|{iconplaypause}|{source}|{speakerlist}" + self._send_mqtt_msg(command) + + def generate_alarm_page(self, item): + if not self._ha_api.entity_exists(item): + command = f"entityUpd,{item},Not found,Not found,Check your,Check your,apps.,apps.,yaml,yaml,0,,0" + else: + entity = self._ha_api.get_entity(item) + icon = get_icon_id("shield-off") + color = rgb_dec565([255,255,255]) + supported_modes = [] + numpad = "enable" + if entity.state == "disarmed": + color = rgb_dec565([13,160,53]) + icon = get_icon_id("shield-off") + test = entity.attributes.get("code_arm_required", "false") + if not entity.attributes.get("code_arm_required", False): + numpad = "disable" + bits = entity.attributes.supported_features + if bits & 0b000001: + supported_modes.append("arm_home") + if bits & 0b000010: + supported_modes.append("arm_away") + if bits & 0b000100: + supported_modes.append("arm_night") + if bits & 0b100000: + supported_modes.append("arm_vacation") + else: + supported_modes.append("disarm") + + if entity.state == "armed_home": + color = rgb_dec565([223,76,30]) + icon = get_icon_id("shield-home") + if entity.state == "armed_away": + color = rgb_dec565([223,76,30]) + icon = get_icon_id("shield-lock") + if entity.state == "armed_night": + color = rgb_dec565([223,76,30]) + icon = get_icon_id("weather-night") + if entity.state == "armed_vacation": + color = rgb_dec565([223,76,30]) + icon = get_icon_id("shield-airplane") + + flashing = "disable" + if entity.state in ["arming", "pending"]: + color = rgb_dec565([243,179,0]) + icon = get_icon_id("shield") + flashing = "enable" + if entity.state == "triggered": + color = rgb_dec565([223,76,30]) + icon = get_icon_id("bell-ring") + flashing = "enable" + + # add padding to arm buttons + arm_buttons = "" + for b in supported_modes: + arm_buttons += f",{get_translation(self._locale, b)},{b}" + if len(supported_modes) < 4: + arm_buttons += ","*((4-len(supported_modes))*2) + command = f"entityUpd,{item}{arm_buttons},{icon},{color},{numpad},{flashing}" + self._send_mqtt_msg(command) + + def render_page(self, page, send_page_type=True): + config = page.data + page_type = config["type"] + LOGGER.info(f"Started rendering of page {page.pos} with type {page_type}") + # Switch to page + if send_page_type: + self.page_type(page_type) + if page_type in ["cardEntities", "cardGrid"]: + heading = config.get("heading", "unknown") + self.generate_entities_page(heading, page.get_items()) + return + if page_type == "cardThermo": + self.generate_thermo_page(page.data.get("item")) + if page_type == "cardMedia": + self.generate_media_page(page.data.get("item")) + if page_type == "cardAlarm": + self.generate_alarm_page(page.data.get("item")) + + + def generate_light_detail_page(self, entity): + entity = self._ha_api.get_entity(entity) + switch_val = 1 if entity.state == "on" else 0 + icon_color = self.get_entity_color(entity) + brightness = "disable" + color_temp = "disable" + color = "disable" + if entity.state == "on": + if "brightness" in entity.attributes: + # scale 0-255 brightness from ha to 0-100 + brightness = int(scale(entity.attributes.brightness,(0,255),(0,100))) + else: + brightness = "disable" + if "color_temp" in entity.attributes.supported_color_modes: + if "color_temp" in entity.attributes: + # scale ha color temp range to 0-100 + color_temp = int(scale(entity.attributes.color_temp,(entity.attributes.min_mireds, entity.attributes.max_mireds),(0,100))) + else: + color_temp = "unknown" + else: + color_temp = "disable" + list_color_modes = ["xy", "rgb", "rgbw", "hs"] + if any(item in list_color_modes for item in entity.attributes.supported_color_modes): + color = "enable" + else: + color = "disable" + self._send_mqtt_msg(f"entityUpdateDetail,{get_icon_id('lightbulb')},{icon_color},{switch_val},{brightness},{color_temp},{color}") + + def generate_shutter_detail_page(self, entity): + pos = 100-int(entity.attributes.get("current_position", 50)) + self._send_mqtt_msg(f"entityUpdateDetail,{pos}") + + def send_message_page(self, id, heading, msg, b1, b2): + self._send_mqtt_msg(f"pageType,popupNotify") + self._send_mqtt_msg(f"entityUpdateDetail,|{id}|{heading}|65535|{b1}|65535|{b2}|65535|{msg}|65535|0") diff --git a/apps/nspanel-lovelace-ui/luibackend/updater.py b/apps/nspanel-lovelace-ui/luibackend/updater.py new file mode 100644 index 00000000..83db2b79 --- /dev/null +++ b/apps/nspanel-lovelace-ui/luibackend/updater.py @@ -0,0 +1,77 @@ +import logging + +LOGGER = logging.getLogger(__name__) + +class Updater: + def __init__(self, send_mqtt_msg, topic_send, mode, desired_display_firmware_version, desired_display_firmware_url, desired_tasmota_driver_version, desired_tasmota_driver_url): + self.desired_display_firmware_version = desired_display_firmware_version + self.desired_display_firmware_url = desired_display_firmware_url + self.desired_tasmota_driver_version = desired_tasmota_driver_version + self.desired_tasmota_driver_url = desired_tasmota_driver_url + + self.mode = mode + self._send_mqtt_msg = send_mqtt_msg + self.topic_send = topic_send + self.current_tasmota_driver_version = None + self.current_display_firmware_version = None + + def set_tasmota_driver_version(self, driver_version): + self.current_tasmota_driver_version = driver_version + def set_current_display_firmware_version(self, panel_version): + self.current_display_firmware_version = panel_version + + def check_pre_req(self): + # we need to know both versions to continue + if self.current_tasmota_driver_version is not None and self.current_display_firmware_version is not None: + # tasmota driver has to be at least version 2 for Update command + # and panel has to be at version 11 for notify commands + # version 16 for new button cmd format + if self.current_tasmota_driver_version >= 2 and self.current_display_firmware_version >= 16: + return True + return False + + def send_message_page(self, id, heading, msg, b1, b2): + self._send_mqtt_msg(f"pageType,popupNotify") + self._send_mqtt_msg(f"entityUpdateDetail,|{id}|{heading}|65535|{b1}|65535|{b2}|65535|{msg}|65535|0") + + def check_updates(self): + # return's true if a notification was send to the panel + # run pre req check + if self.check_pre_req(): + LOGGER.info("Update Pre-Check sucessful Tasmota Driver Version: %s Panel Version: %s", self.current_tasmota_driver_version, self.current_display_firmware_version) + # check if tasmota driver needs update + if self.current_tasmota_driver_version < self.desired_tasmota_driver_version: + LOGGER.info("Update of Tasmota Driver needed") + # in auto mode just do the update + if self.mode == "auto": + self.update_berry_driver() + return False + # send notification about the update + if self.mode == "auto-notify": + update_msg = "There's an update available for the Tasmota Berry driver, do you want to start the update now? If you encounter issues after the update or this message appears frequently, please check the manual and repeat the installation steps for the Tasmota Berry driver. " + self.send_message_page("updateBerryNoYes", "Driver Update available!", update_msg, "Dismiss", "Yes") + return True + return False + # check if display firmware needs an update + if self.current_display_firmware_version < self.desired_display_firmware_version: + LOGGER.info("Update of Display Firmware needed") + # in auto mode just do the update + if self.mode == "auto": + self.update_panel_driver() + return False + # send notification about the update + if self.mode == "auto-notify": + update_msg = "There's a firmware update available for the Nextion screen of the NSPanel. Do you want tostart the update now? If the update fails check the installation manual and flash again over the Tasmota console. Be patient, the update will take a while." + self.send_message_page("updateDisplayNoYes", "Display Update available!", update_msg, "Dismiss", "Yes") + return True + return False + else: + LOGGER.info("Update Pre-Check failed Tasmota Driver Version: %s Panel Version: %s", self.current_tasmota_driver_version, self.current_display_firmware_version) + return False + + def update_berry_driver(self): + topic = self.topic_send.replace("CustomSend", "UpdateDriverVersion") + self._send_mqtt_msg(self.desired_tasmota_driver_url, topic=topic) + def update_panel_driver(self): + topic = self.topic_send.replace("CustomSend", "FlashNextion") + self._send_mqtt_msg(self.desired_display_firmware_url, topic=topic) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index 93f24efb..0483fd3a 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -1,627 +1,79 @@ -import json -import datetime +import logging +import traceback + import hassapi as hass -from helper import scale, pos_to_color, rgb_dec565, rgb_brightness -from icon_mapping import get_icon_id -from icons import get_icon_id_ha -# check Babel -import importlib -babel_spec = importlib.util.find_spec("babel") -if babel_spec is not None: - import babel.dates + +from luibackend.config import LuiBackendConfig +from luibackend.controller import LuiController +from luibackend.mqttListener import LuiMqttListener +from luibackend.updater import Updater + +LOGGER = logging.getLogger(__name__) + + +class AppDaemonLoggingHandler(logging.Handler): + def __init__(self, app): + super().__init__() + self._app = app + + def emit(self, record): + message = record.getMessage() + if record.exc_info: + message += '\nTraceback (most recent call last):\n' + message += '\n'.join(traceback.format_tb(record.exc_info[2])) + message += f'{record.exc_info[0].__name__}: {record.exc_info[1]}' + self._app.log(message, level=record.levelname) + class NsPanelLovelaceUIManager(hass.Hass): - def initialize(self): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._redirect_logging() - data = self.args["config"] - LovelaceUIPanel(self, data) + def _redirect_logging(self): + # Add a handler for the logging module that will convert the + # calls to AppDaemon's logger with the self instance, so that + # we can simply use logging in the rest of the application + rlogger = logging.getLogger() + rlogger.handlers = [ + h for h in rlogger.handlers + if type(h).__name__ != AppDaemonLoggingHandler.__name__ + ] + rlogger.addHandler(AppDaemonLoggingHandler(self)) -class Updater: - def __init__(self, nsplui, mode): - self.desired_display_firmware_version = 16 - self.desired_display_firmware_url = "http://nspanel.pky.eu/lovelace-ui/github/nspanel-v1.7.0.tft" - self.desired_tasmota_driver_version = 3 - self.desired_tasmota_driver_url = "https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/tasmota/autoexec.be" + # We want to grab all the logs, AppDaemon will + # then care about filtering those we asked for + rlogger.setLevel(logging.DEBUG) - self.mode = mode - self.nsplui = nsplui - self.current_tasmota_driver_version = None - self.current_display_firmware_version = None - def set_tasmota_driver_version(self, driver_version): - self.current_tasmota_driver_version = driver_version - def set_current_display_firmware_version(self, panel_version): - self.current_display_firmware_version = panel_version - def check_pre_req(self): - # we need to know both versions to continue - if self.current_tasmota_driver_version is not None and self.current_display_firmware_version is not None: - # tasmota driver has to be at least version 2 for Update command and panel has to be at version 11 for notify commands - if self.current_tasmota_driver_version >= 2 and self.current_display_firmware_version >= 11: - return True - return False - def check_updates(self): - # return's true if a notification was send to the panel - # run pre req check - if self.check_pre_req(): - self.nsplui.api.log("Update Pre-Check sucessful Tasmota Driver Version: %s Panel Version: %s", self.current_tasmota_driver_version, self.current_display_firmware_version, level="DEBUG") - # check if tasmota driver needs update - if self.current_tasmota_driver_version < self.desired_tasmota_driver_version: - self.nsplui.api.log("Update of Tasmota Driver needed") - # in auto mode just do the update - if self.mode == "auto": - self.update_berry_driver() - return False - # send notification about the update - if self.mode == "auto-notify": - update_msg = "There's an update avalible for the tasmota berry driver, do you want to start the update now? If you encounter issues after the update or this message appears frequently, please checkthe manual and repeat the installation steps for the tasmota berry driver. " - self.nsplui.send_message_page("updateBerryNoYes", "Driver Update available!", update_msg, "Dismiss", "Yes") - return True - return False - # check if display firmware needs an update - if self.current_display_firmware_version < self.desired_display_firmware_version: - self.nsplui.api.log("Update of Display Firmware needed") - # in auto mode just do the update - if self.mode == "auto": - self.update_panel_driver() - return False - # send notification about the update - if self.mode == "auto-notify": - update_msg = "There's a firmware update avalible for the nextion sceen inside of nspanel, do you want to start the update now? If the update fails check the installation manual and flash again over the tasmota console. Be pationed the update will take a while." - self.nsplui.send_message_page("updateDisplayNoYes", "Display Update available!", update_msg, "Dismiss", "Yes") - return True - return False - else: - self.nsplui.api.log("Update Pre-Check failed Tasmota Driver Version: %s Panel Version: %s", self.current_tasmota_driver_version, self.current_display_firmware_version) - return False - def update_berry_driver(self): - self.nsplui.mqtt.mqtt_publish(self.nsplui.config["panelSendTopic"].replace("CustomSend", "UpdateDriverVersion"), self.desired_tasmota_driver_url) - def update_panel_driver(self): - self.nsplui.mqtt.mqtt_publish(self.nsplui.config["panelSendTopic"].replace("CustomSend", "FlashNextion"), self.desired_display_firmware_url) -class LovelaceUIPanel: - def __init__(self, api, config): - self.api = api - self.config = config - self.current_page_nr = 0 - self.current_screensaver_brightness = 10 - - # check configured items - self.check_items() - - # Setup, mqtt subscription and callback - self.mqtt = self.api.get_plugin_api("MQTT") - self.mqtt.mqtt_subscribe(topic=self.config["panelRecvTopic"]) - self.mqtt.listen_event(self.handle_mqtt_incoming_message, "MQTT_MESSAGE", topic=self.config["panelRecvTopic"], namespace='mqtt') - - # Read updateMode and use "auto-notify" as default - update_mode = self.config["updateMode"] if "updateMode" in self.config else "auto-notify" - self.updater = Updater(self, update_mode) - - # Request Tasmota Driver Version - self.mqtt.mqtt_publish(self.config["panelSendTopic"].replace("CustomSend", "GetDriverVersion"), "x") - - # send panel back to startup page on restart of this script - self.send_mqtt_msg("pageType,pageStartup") - - # Setup time callback - time = datetime.time(0, 0, 0) - self.api.run_minutely(self.update_time, time) - - # Setup date callback - time = datetime.time(0, 0, 0) - self.api.run_daily(self.update_date, time) - # send date update in case config has been changed - self.update_date("") - - # Setup weather callback - weather_interval = 15 * 60 # 15 minutes - self.api.run_every(self.update_screensaver_weather, "now", weather_interval) - - # set brightness of screensaver - if type(self.config["brightnessScreensaver"]) == int: - self.current_screensaver_brightness = self.config["brightnessScreensaver"] - elif type(self.config["brightnessScreensaver"]) == list: - sorted_timesets = sorted(self.config["brightnessScreensaver"], key=lambda d: self.api.parse_time(d['time'])) - found_current_dim_value = False - for index, timeset in enumerate(sorted_timesets): - self.api.run_daily(self.update_screensaver_brightness, timeset["time"], value=timeset["value"]) - self.api.log("Current time %s", self.api.get_now().time(), level="DEBUG") - if self.api.parse_time(timeset["time"]) > self.api.get_now().time() and not found_current_dim_value: - # first time after current time, set dim value - self.current_screensaver_brightness = sorted_timesets[index-1]["value"] - self.api.log("Setting dim value to %s", sorted_timesets[index-1]) #level="DEBUG" - found_current_dim_value = True - # still no dim value - if not found_current_dim_value: - self.current_screensaver_brightness = sorted_timesets[-1]["value"] - # send screensaver brightness in case config has changed - self.update_screensaver_brightness(kwargs={"value": self.current_screensaver_brightness}) - - # register callbacks - self.register_callbacks() - - def filter_dict_from_item_list(self, items): - # remove all dicts from list - cleaned_list = [] - for item in items: - # in case item is a dict, grab the item name - if type(item) is dict: - cleaned_list.append(next(iter(item))) - else: - cleaned_list.append(item) - return cleaned_list - - def get_all_configured_items(self): - items = [] - for page in self.config["pages"]: - if "item" in page: - items.append(page["item"]) - if "items" in page: - items.extend(page["items"]) - return self.filter_dict_from_item_list(items) - - def check_items(self): - items = self.get_all_configured_items() - for item in items: - if self.api.entity_exists(item) or item == "delete": - self.api.log("Found configured item in Home Assistant %s", item, level="DEBUG") - else: - self.api.error("The following item does not exist in Home Assistant, configuration error: %s", item) - - def register_callbacks(self): - items = self.get_all_configured_items() - for item in items: - self.api.log("Enable state callback for %s", item, level="DEBUG") - self.api.handle = self.api.listen_state(self.state_change_callback, entity_id=item, attribute="all") - - def state_change_callback(self, entity, attribute, old, new, kwargs): - current_page_config = self.config["pages"][self.current_page_nr] - page_type = current_page_config["type"] - self.api.log(f"Got state_callback from {entity}", level="DEBUG") - - if page_type in ["cardEntities", "cardGrid"]: - items = current_page_config["items"] - items_filtered = self.filter_dict_from_item_list(items) - if entity in items_filtered: - self.api.log(f"State change on current page for {entity}", level="DEBUG") - # send update of the page - self.generate_entities_page(items) - # send detail pages in case they are open - if(entity.startswith("cover")): - self.generate_shutter_detail_page(entity) - if(entity.startswith("light")): - self.generate_light_detail_page(entity) - return - - if page_type in ["cardThermo", "cardMedia"]: - if entity == current_page_config["item"]: - self.api.log(f"State change on current page for {entity}", level="DEBUG") - # send update of the whole page - if page_type == "cardThermo": - self.generate_thermo_page(entity) - return - if page_type == "cardMedia": - self.generate_media_page(entity) - return - return - - def send_mqtt_msg(self,msg): - self.api.log("Send Message to Tasmota: %s", msg) #, level="DEBUG" - self.mqtt.mqtt_publish(self.config["panelSendTopic"], msg) - - def handle_mqtt_incoming_message(self, event_name, data, kwargs): - # Parse Json Message from Tasmota and strip out message from nextion display - data = json.loads(data["payload"]) - # pass tasmota driver version to updater class - if("nlui_driver_version" in data): - msg = data["nlui_driver_version"] - self.api.log("Received Driver Version from Tasmota: %s", int(msg), level="DEBUG") - self.updater.set_tasmota_driver_version(int(msg)) - return - if("CustomRecv" not in data): - self.api.log("Received Message from Tasmota, but not from nextion screen: %s", data, level="DEBUG") - return - msg = data["CustomRecv"] - self.api.log("Received Message from Tasmota: %s", msg) #, level="DEBUG" - - # Split message into parts seperated by "," - msg = msg.split(",") - - # run action based on received command - if msg[0] == "event": - if msg[1] == "startup": - self.api.log("Handling startup event", level="DEBUG") - # grab version from screen and pass to updater class - self.updater.set_current_display_firmware_version(int(msg[2])) - # send date and time - self.update_time("") - self.update_date("") - # set screensaver timeout - timeout = self.config["timeoutScreensaver"] - self.send_mqtt_msg(f"timeout,{timeout}") - # send screensaver brightness - self.update_screensaver_brightness(kwargs={"value": self.current_screensaver_brightness}) - # check for updates - msg_send = self.updater.check_updates() - # send messages for current page - if not msg_send: - self.generate_page(self.current_page_nr) - - if msg[1] == "pageOpen": - # Calculate current page - recv_page = int(msg[2]) - self.current_page_nr = recv_page % len(self.config["pages"]) - self.api.log("Received pageOpen command, raw page: %i, calc page: %i", recv_page, self.current_page_nr, level="DEBUG") - # generate commands for current page - self.generate_page(self.current_page_nr) + def initialize(self): + LOGGER.info('Starting') + mqtt_api = self._mqtt_api = self.get_plugin_api("MQTT") + cfg = self._cfg = LuiBackendConfig(self.args["config"]) - if msg[1] == "buttonPress": - entity_id = msg[4] - btype = msg[6] - if len(msg) > 7: - value = msg[7] - else: - value = None - self.handle_button_press(entity_id, btype, value) + topic_send = cfg.get("panelSendTopic") + def send_mqtt_msg(msg, topic=None): + if topic is None: + topic = topic_send + LOGGER.info(f"Sending MQTT Message: {msg}") + mqtt_api.mqtt_publish(topic, msg) + + # Request Tasmota Driver Version + mqtt_api.mqtt_publish(topic_send.replace("CustomSend", "GetDriverVersion"), "x") + + controller = LuiController(self, cfg, send_mqtt_msg) + + desired_display_firmware_version = 20 + desired_display_firmware_url = "http://nspanel.pky.eu/lovelace-ui/github/nspanel-v1.9.0.tft" + desired_tasmota_driver_version = 3 + desired_tasmota_driver_url = "https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/tasmota/autoexec.be" - if msg[1] == "buttonPress2": - entity_id = msg[2] - btype = msg[3] - if len(msg) > 4: - value = msg[4] - else: - value = None - self.handle_button_press(entity_id, btype, value) + mode = cfg.get("updateMode") + topic_send = cfg.get("panelSendTopic") + updater = Updater(send_mqtt_msg, topic_send, mode, desired_display_firmware_version, desired_display_firmware_url, desired_tasmota_driver_version, desired_tasmota_driver_url) - if msg[1] == "pageOpenDetail": - self.api.log("Received pageOpenDetail command", level="DEBUG") - if msg[2] == "popupShutter": - self.generate_shutter_detail_page(msg[3]) - if msg[2] == "popupLight": - self.generate_light_detail_page(msg[3]) + topic_recv = cfg.get("panelRecvTopic") + LuiMqttListener(mqtt_api, topic_recv, controller, updater) - if msg[1] == "screensaverOpen": - self.update_screensaver_weather("") - - def update_time(self, kwargs): - time = datetime.datetime.now().strftime(self.config["timeFormat"]) - self.send_mqtt_msg(f"time,{time}") - - def update_date(self, kwargs): - global babel_spec - if babel_spec is not None: - self.api.log("Babel package found", level="DEBUG") - if "dateFormatBabel" in self.config: - dateformat = self.config["dateFormatBabel"] - else: - dateformat = "full" - date = babel.dates.format_date(datetime.datetime.now(), dateformat, locale=self.config["locale"]) - self.send_mqtt_msg(f"date,?{date}") - else: - self.api.log("Babel package not found", level="DEBUG") - date = datetime.datetime.now().strftime(self.config["dateFormat"]) - self.send_mqtt_msg(f"date,?{date}") - - def update_screensaver_brightness(self, kwargs): - self.current_screensaver_brightness = kwargs['value'] - self.send_mqtt_msg(f"dimmode,{self.current_screensaver_brightness}") - - def update_screensaver_weather(self, kwargs): - if not ("weatherEntity" in self.config and self.api.entity_exists(self.config["weatherEntity"])): - return - we = self.api.get_entity(self.config["weatherEntity"]) - unit = "°C" - - icon_cur = get_icon_id_ha("weather", state=we.state) - text_cur = f"{we.attributes.temperature}{unit}" - icon_cur_detail = get_icon_id("water-percent") - text_cur_detail = f"{we.attributes.humidity} %" - - up1 = we.attributes.forecast[0]['datetime'] - up1 = datetime.datetime.fromisoformat(up1) - icon1 = get_icon_id_ha("weather", state=we.attributes.forecast[0]['condition']) - down1 = we.attributes.forecast[0]['temperature'] - - up2 = we.attributes.forecast[1]['datetime'] - up2 = datetime.datetime.fromisoformat(up2) - icon2 = get_icon_id_ha("weather", state=we.attributes.forecast[1]['condition']) - down2 = we.attributes.forecast[1]['temperature'] - - global babel_spec - if babel_spec is not None: - up1 = babel.dates.format_date(up1, "E", locale=self.config["locale"]) - up2 = babel.dates.format_date(up2, "E", locale=self.config["locale"]) - else: - up1 = up1.strftime("%a") - up2 = up2.strftime("%a") - - self.send_mqtt_msg(f"weatherUpdate,?{icon_cur}?{text_cur}?{icon_cur_detail}?{text_cur_detail}?{up1}?{icon1}?{down1}?{up2}?{icon2}?{down2}") - - - def handle_button_press(self, entity_id, btype, optVal=None): - if entity_id == "updateBerryNoYes" and optVal == "yes": - # go back to main page before starting the update - self.generate_page(self.current_page_nr) - self.updater.update_berry_driver() - elif entity_id == "updateBerryNoYes" and optVal == "no": - self.generate_page(self.current_page_nr) - - if entity_id == "updateDisplayNoYes" and optVal == "yes": - self.updater.update_panel_driver() - elif entity_id == "updateDisplayNoYes" and optVal == "no": - self.generate_page(self.current_page_nr) - - if btype == "OnOff": - if optVal == "1": - self.api.turn_on(entity_id) - else: - self.api.turn_off(entity_id) - if btype == "up": - self.api.get_entity(entity_id).call_service("open_cover") - if btype == "stop": - self.api.get_entity(entity_id).call_service("stop_cover") - if btype == "down": - self.api.get_entity(entity_id).call_service("close_cover") - - if btype == "button": - if entity_id.startswith('scene'): - self.api.get_entity(entity_id).call_service("turn_on") - elif entity_id.startswith('light') or entity_id.startswith('switch') or entity_id.startswith('input_boolean'): - self.api.get_entity(entity_id).call_service("toggle") - else: - self.api.get_entity(entity_id).call_service("press") - - if btype == "media-next": - self.api.get_entity(entity_id).call_service("media_next_track") - if btype == "media-back": - self.api.get_entity(entity_id).call_service("media_previous_track") - if btype == "media-pause": - self.api.get_entity(entity_id).call_service("media_play_pause") - - if btype == "hvac_action": - self.api.get_entity(entity_id).call_service("set_hvac_mode", hvac_mode=optVal) - - - if btype == "brightnessSlider": - # scale 0-100 to ha brightness range - brightness = int(scale(int(optVal),(0,100),(0,255))) - self.api.get_entity(entity_id).call_service("turn_on", brightness=brightness) - - if btype == "colorTempSlider": - entity = self.api.get_entity(entity_id) - #scale 0-100 from slider to color range of lamp - color_val = scale(int(optVal), (0, 100), (entity.attributes.min_mireds, entity.attributes.max_mireds)) - self.api.get_entity(entity_id).call_service("turn_on", color_temp=color_val) - - if btype == "colorWheel": - self.api.log(optVal) - optVal = optVal.split('|') - color = pos_to_color(int(optVal[0]), int(optVal[1])) - self.api.log(color) - self.api.get_entity(entity_id).call_service("turn_on", rgb_color=color) - - if btype == "positionSlider": - pos = int(optVal) - self.api.get_entity(entity_id).call_service("set_cover_position", position=pos) - - if btype == "volumeSlider": - pos = int(optVal) - # HA wants this value between 0 and 1 as float - pos = pos/100 - self.api.get_entity(entity_id).call_service("volume_set", volume_level=pos) - - if btype == "tempUpd": - temp = int(optVal)/10 - self.api.get_entity(msg[3]).call_service("set_temperature", temperature=temp) - - def generate_page(self, page_number): - # get type of page - page_type = self.config["pages"][self.current_page_nr]["type"] - self.api.log("Generating page commands for page %i with type %s", self.current_page_nr, page_type, level="DEBUG") - - # Send page type - self.send_mqtt_msg(f"pageType,{page_type}") - - if page_type in ["cardEntities", "cardGrid"]: - self.generate_entities_page(self.config["pages"][self.current_page_nr]["items"]) - - if page_type == "cardThermo": - self.generate_thermo_page(self.config["pages"][self.current_page_nr]["item"]) - - if page_type == "cardMedia": - self.generate_media_page(self.config["pages"][self.current_page_nr]["item"]) - - def generate_entities_item(self, item): - icon = None - if type(item) is dict: - icon = next(iter(item.items()))[1]['icon'] - item = next(iter(item.items()))[0] - - # type of the item is the string before the "." in the item name - item_type = item.split(".")[0] - - self.api.log("Generating item command for %s with type %s", item, item_type, level="DEBUG") - - if item_type == "delete": - return f",{item_type},,,,," - - if not self.api.entity_exists(item): - return f",text,{item},{get_icon_id('alert-circle-outline')},17299,Not found check, apps.yaml" - - entity = self.api.get_entity(item) - name = entity.attributes.friendly_name - - if item_type == "cover": - icon_id = get_icon_id_ha("cover", state=entity.state, overwrite=icon) - return f",shutter,{item},{icon_id},17299,{name}," - - if item_type == "light": - switch_val = 1 if entity.state == "on" else 0 - icon_color = self.getEntityColor(entity) - icon_id = get_icon_id_ha("light", overwrite=icon) - return f",{item_type},{item},{icon_id},{icon_color},{name},{switch_val}" - - if item_type == "switch" or item_type == "input_boolean": - icon_id = get_icon_id_ha(item_type, state=entity.state, overwrite=icon) - switch_val = 1 if entity.state == "on" else 0 - icon_color = self.getEntityColor(entity) - return f",switch,{item},{icon_id},{icon_color},{name},{switch_val}" - - if item_type in ["sensor", "binary_sensor"]: - device_class = self.get_safe_ha_attribute(entity.attributes, "device_class", "") - icon_id = get_icon_id_ha("sensor", state=entity.state, device_class=device_class, overwrite=icon) - unit_of_measurement = self.get_safe_ha_attribute(entity.attributes, "unit_of_measurement", "") - value = entity.state + " " + unit_of_measurement - return f",text,{item},{icon_id},17299,{name},{value}" - - if item_type in ["button", "input_button"]: - icon_id = get_icon_id_ha("button", overwrite=icon) - return f",button,{item},{icon_id},17299,{name},PRESS" - - if item_type == "scene": - icon_id = get_icon_id_ha("scene", overwrite=icon) - return f",button,{item},{icon_id},17299,{name},ACTIVATE" - - def generate_entities_page(self, items): - # Set Heading of Page - self.send_mqtt_msg(f"entityUpdHeading,{self.config['pages'][self.current_page_nr]['heading']}") - # Get items and construct cmd string - command = "entityUpd" - for item in items: - command += self.generate_entities_item(item) - self.send_mqtt_msg(command) - - def get_safe_ha_attribute(self, eattr, attr, default): - return eattr[attr] if attr in eattr else default - - def generate_thermo_page(self, item): - if not self.api.entity_exists(item): - command = f"entityUpd,{item},Not found,220,220,Not found,150,300,5" - else: - entity = self.api.get_entity(item) - heading = entity.attributes.friendly_name - current_temp = int(self.get_safe_ha_attribute(entity.attributes, "current_temperature", 0)*10) - dest_temp = int(self.get_safe_ha_attribute(entity.attributes, "temperature", 0)*10) - status = self.get_safe_ha_attribute(entity.attributes, "hvac_action", "") - min_temp = int(self.get_safe_ha_attribute(entity.attributes, "min_temp", 0)*10) - max_temp = int(self.get_safe_ha_attribute(entity.attributes, "max_temp", 0)*10) - step_temp = int(self.get_safe_ha_attribute(entity.attributes, "target_temp_step", 0.5)*10) - - icon_res = "" - hvac_modes = self.get_safe_ha_attribute(entity.attributes, "hvac_modes", []) - for mode in hvac_modes: - icon_id = get_icon_id('alert-circle-outline') - color_on = 64512 - if mode == "auto": - icon_id = get_icon_id("calendar-sync") - color_on = 1024 - if mode == "heat": - icon_id = get_icon_id("fire") - color_on = 64512 - if mode == "off": - icon_id = get_icon_id("power") - color_on = 35921 - if mode == "cool": - icon_id = get_icon_id("snowflake") - color_on = 11487 - if mode == "dry": - icon_id = get_icon_id("water-percent") - color_on = 60897 - if mode == "fan_only": - icon_id = get_icon_id("fan") - color_on = 35921 - state = 0 - if(mode == entity.state): - state = 1 - icon_res += f",{icon_id},{color_on},{state},{mode}" - - len_hvac_modes = len(hvac_modes) - if len_hvac_modes%2 == 0: - # even - padding_len = int((4-len_hvac_modes)/2) - icon_res = ","*4*padding_len + icon_res + ","*4*padding_len - # use last 4 icons - icon_res = ","*4*5 + icon_res - else: - # uneven - padding_len = int((5-len_hvac_modes)/2) - icon_res = ","*4*padding_len + icon_res + ","*4*padding_len - # use first 5 icons - icon_res = icon_res + ","*4*4 - command = f"entityUpd,{item},{heading},{current_temp},{dest_temp},{status},{min_temp},{max_temp},{step_temp}{icon_res}" - self.send_mqtt_msg(command) - - def generate_media_page(self, item): - - if not self.api.entity_exists(item): - command = f"entityUpd,|{item}|Not found|{get_icon_id('alert-circle-outline')}|Please check your|apps.yaml in AppDaemon|50|11" - else: - entity = self.api.get_entity(item) - heading = entity.attributes.friendly_name - icon = 0 - title = self.get_safe_ha_attribute(entity.attributes, "media_title", "") - author = self.get_safe_ha_attribute(entity.attributes, "media_artist", "") - volume = int(self.get_safe_ha_attribute(entity.attributes, "volume_level", 0)*100) - iconplaypause = get_icon_id("pause") if entity.state == "playing" else get_icon_id("play") - if "media_content_type" in entity.attributes: - if entity.attributes.media_content_type == "music": - icon = get_icon_id("music") - command = f"entityUpd,|{item}|{heading}|{icon}|{title}|{author}|{volume}|{iconplaypause}" - - self.send_mqtt_msg(command) - - def getEntityColor(self, entity): - attr = entity.attributes - default_color_on = rgb_dec565([253, 216, 53]) - default_color_off = rgb_dec565([68, 115, 158]) - icon_color = default_color_on if entity.state == "on" else default_color_off - - if "rgb_color" in attr: - color = attr.rgb_color - if "brightness" in attr: - color = rgb_brightness(color, attr.brightness) - icon_color = rgb_dec565(color) - elif "brightness" in attr: - color = rgb_brightness([253, 216, 53], attr.brightness) - icon_color = rgb_dec565(color) - return icon_color - - def generate_light_detail_page(self, entity): - entity = self.api.get_entity(entity) - switch_val = 1 if entity.state == "on" else 0 - icon_color = self.getEntityColor(entity) - brightness = "disable" - color_temp = "disable" - color = "disable" - # scale 0-255 brightness from ha to 0-100 - if entity.state == "on": - if "brightness" in entity.attributes: - brightness = int(scale(entity.attributes.brightness,(0,255),(0,100))) - else: - brightness = "disable" - if "color_temp" in entity.attributes.supported_color_modes: - if "color_temp" in entity.attributes: - # scale ha color temp range to 0-100 - color_temp = int(scale(entity.attributes.color_temp,(entity.attributes.min_mireds, entity.attributes.max_mireds),(0,100))) - else: - color_temp = "unknown" - else: - color_temp = "disable" - - list_color_modes = ["xy", "rgb", "rgbw", "hs"] - if any(item in list_color_modes for item in entity.attributes.supported_color_modes): - color = "enable" - else: - color = "disable" - self.send_mqtt_msg(f"entityUpdateDetail,{get_icon_id('lightbulb')},{icon_color},{switch_val},{brightness},{color_temp},{color}") - - def generate_shutter_detail_page(self, entity): - pos = int(self.get_safe_ha_attribute(entity.attributes, "current_position", 50)) - # reverse position for slider - pos = 100-pos - self.send_mqtt_msg(f"entityUpdateDetail,{pos}") - - def send_message_page(self, id, heading, msg, b1, b2): - self.send_mqtt_msg(f"pageType,popupNotify") - self.send_mqtt_msg(f"entityUpdateDetail,|{id}|{heading}|65535|{b1}|65535|{b2}|65535|{msg}|65535|0") - + LOGGER.info('Started') diff --git a/doc-pics/hacs-main.png b/doc-pics/hacs-main.png new file mode 100644 index 00000000..d92d6928 Binary files /dev/null and b/doc-pics/hacs-main.png differ diff --git a/doc-pics/screens.png b/doc-pics/screens.png index da3ee02b..1b4ff66d 100644 Binary files a/doc-pics/screens.png and b/doc-pics/screens.png differ diff --git a/info.md b/info.md index c2a79230..7372571e 100644 --- a/info.md +++ b/info.md @@ -5,14 +5,15 @@ Checkout [README](https://github.com/joBr99/nspanel-lovelace-ui/blob/main/README ### App Configuration ```yaml +--- nspanel-1: module: nspanel-lovelace-ui class: NsPanelLovelaceUIManager config: panelRecvTopic: "tele/tasmota_your_mqtt_topic/RESULT" panelSendTopic: "cmnd/tasmota_your_mqtt_topic/CustomSend" - updateMode: auto-notify # possible values are auto, auto-notify and manual - timeoutScreensaver: 15 #in seconds + updateMode: "auto-notify" + timeoutScreensaver: 20 #brightnessScreensaver: 10 brightnessScreensaver: - time: "7:00:00" @@ -24,7 +25,7 @@ nspanel-1: # formatting options on https://babel.pocoo.org/en/latest/dates.html?highlight=name%20of%20day#date-fields timeFormat: "%H:%M" dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed - weatherEntity: weather.example + weather: weather.example pages: - type: cardEntities heading: Example Page 1