@@ -146,6 +146,14 @@ void CNotificationHelper::LoadConfig()
146146 _log.Log (LOG_NORM, std::string (logline.str ()).c_str ());
147147}
148148
149+ std::string CNotificationHelper::ParseCustomMessage (const std::string &cMessage, const std::string &sName , const std::string &sValue )
150+ {
151+ std::string ret = cMessage;
152+ stdreplace (ret, " $name" , sName );
153+ stdreplace (ret, " $value" , sValue );
154+ return ret;
155+ }
156+
149157bool CNotificationHelper::CheckAndHandleTempHumidityNotification (
150158 const unsigned long long Idx,
151159 const std::string &devicename,
@@ -159,6 +167,7 @@ bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
159167 return false ;
160168
161169 char szTmp[600 ];
170+ std::string notValue;
162171
163172 std::string szExtraData = " |Name=" + devicename + " |" ;
164173
@@ -221,10 +230,15 @@ bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
221230 msg = szTmp;
222231 }
223232 }
233+ if (bSendNotification)
234+ {
235+ sprintf (szTmp, " %.1f" , temp);
236+ notValue = szTmp;
237+ }
224238 }
225239 else if ((ntype == signhum) && (bHaveHumidity))
226240 {
227- // humanity
241+ // humidity
228242 szExtraData += " Image=moisture48|" ;
229243 if (bWhenIsGreater)
230244 {
@@ -244,11 +258,16 @@ bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
244258 msg = szTmp;
245259 }
246260 }
261+ if (bSendNotification)
262+ {
263+ sprintf (szTmp, " %d" , humidity);
264+ notValue = szTmp;
265+ }
247266 }
248267 if (bSendNotification)
249268 {
250269 if (!itt->CustomMessage .empty ())
251- msg = itt->CustomMessage ;
270+ msg = ParseCustomMessage ( itt->CustomMessage , devicename, notValue) ;
252271 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
253272 TouchNotification (itt->ID );
254273 }
@@ -269,6 +288,7 @@ bool CNotificationHelper::CheckAndHandleDewPointNotification(
269288
270289 char szTmp[600 ];
271290 std::string szExtraData = " |Name=" + devicename + " |Image=temp-0-5|" ;
291+ std::string notValue;
272292
273293 time_t atime = mytime (NULL );
274294
@@ -301,12 +321,14 @@ bool CNotificationHelper::CheckAndHandleDewPointNotification(
301321 bSendNotification = true ;
302322 sprintf (szTmp, " %s Dew Point reached (%.1f degrees)" , devicename.c_str (), temp);
303323 msg = szTmp;
324+ sprintf (szTmp, " %.1f" , temp);
325+ notValue = szTmp;
304326 }
305327 }
306328 if (bSendNotification)
307329 {
308330 if (!itt->CustomMessage .empty ())
309- msg = itt->CustomMessage ;
331+ msg = ParseCustomMessage ( itt->CustomMessage , devicename, notValue) ;
310332 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
311333 TouchNotification (itt->ID );
312334 }
@@ -336,6 +358,7 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
336358 atime -= m_NotificationSensorInterval;
337359
338360 std::string msg = " " ;
361+ std::string notValue;
339362
340363 std::string signamp1 = Notification_Type_Desc (NTYPE_AMPERE1, 1 );
341364 std::string signamp2 = Notification_Type_Desc (NTYPE_AMPERE2, 2 );
@@ -377,6 +400,11 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
377400 msg = szTmp;
378401 }
379402 }
403+ if (bSendNotification)
404+ {
405+ sprintf (szTmp, " %.1f" , Ampere1);
406+ notValue = szTmp;
407+ }
380408 }
381409 else if (ntype == signamp2)
382410 {
@@ -399,6 +427,11 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
399427 msg = szTmp;
400428 }
401429 }
430+ if (bSendNotification)
431+ {
432+ sprintf (szTmp, " %.1f" , Ampere2);
433+ notValue = szTmp;
434+ }
402435 }
403436 else if (ntype == signamp3)
404437 {
@@ -421,11 +454,16 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
421454 msg = szTmp;
422455 }
423456 }
457+ if (bSendNotification)
458+ {
459+ sprintf (szTmp, " %.1f" , Ampere3);
460+ notValue = szTmp;
461+ }
424462 }
425463 if (bSendNotification)
426464 {
427465 if (!itt->CustomMessage .empty ())
428- msg = itt->CustomMessage ;
466+ msg = ParseCustomMessage ( itt->CustomMessage , devicename, notValue) ;
429467 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
430468 TouchNotification (itt->ID );
431469 }
@@ -448,7 +486,9 @@ bool CNotificationHelper::CheckAndHandleNotification(
448486 result = m_sql.safe_query (" SELECT SwitchType, CustomImage FROM DeviceStatus WHERE (ID=%llu)" , Idx);
449487 if (result.size () == 0 )
450488 return false ;
489+
451490 std::string szExtraData = " |Name=" + devicename + " |SwitchType=" + result[0 ][0 ] + " |CustomImage=" + result[0 ][1 ] + " |" ;
491+ std::string notValue;
452492
453493 time_t atime = mytime (NULL );
454494
@@ -470,7 +510,7 @@ bool CNotificationHelper::CheckAndHandleNotification(
470510 {
471511 std::string msg = message;
472512 if (!itt->CustomMessage .empty ())
473- msg = itt->CustomMessage ;
513+ msg = ParseCustomMessage ( itt->CustomMessage , devicename, notValue) ;
474514 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
475515 TouchNotification (itt->ID );
476516 }
@@ -567,7 +607,12 @@ bool CNotificationHelper::CheckAndHandleNotification(
567607 if (bSendNotification)
568608 {
569609 if (!itt->CustomMessage .empty ())
570- msg = itt->CustomMessage ;
610+ {
611+ std::string notValue;
612+ sprintf (szTmp, " %.1f" , mvalue);
613+ notValue = szTmp;
614+ msg = ParseCustomMessage (itt->CustomMessage , devicename, notValue);
615+ }
571616 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
572617 TouchNotification (itt->ID );
573618 }
@@ -613,6 +658,7 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
613658 std::string atype = splitresults[0 ];
614659
615660 bool bSendNotification = false ;
661+ std::string notValue;
616662
617663 if (atype == ltype)
618664 {
@@ -624,46 +670,46 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
624670 switch (switchtype)
625671 {
626672 case STYPE_Doorbell:
627- msg + = " pressed" ;
673+ notValue = " pressed" ;
628674 break ;
629675 case STYPE_Contact:
630- msg + = " Open" ;
676+ notValue = " Open" ;
631677 szExtraData += " Image=contact48_open|" ;
632678 break ;
633679 case STYPE_DoorLock:
634- msg + = " Open" ;
680+ notValue = " Open" ;
635681 szExtraData += " Image=door48open|" ;
636682 break ;
637683 case STYPE_Motion:
638- msg + = " movement detected" ;
684+ notValue = " movement detected" ;
639685 break ;
640686 case STYPE_SMOKEDETECTOR:
641- msg + = " ALARM/FIRE !" ;
687+ notValue = " ALARM/FIRE !" ;
642688 break ;
643689 default :
644- msg + = " >> ON" ;
690+ notValue = " >> ON" ;
645691 break ;
646692 }
647-
648693 }
649694 else {
650695 szExtraData += " Status=Off|" ;
651696 switch (switchtype)
652697 {
653698 case STYPE_DoorLock:
654699 case STYPE_Contact:
655- msg + = " Closed" ;
700+ notValue = " Closed" ;
656701 break ;
657702 default :
658- msg + = " >> OFF" ;
703+ notValue = " >> OFF" ;
659704 break ;
660705 }
661706 }
707+ msg += " " + notValue;
662708 }
663709 if (bSendNotification)
664710 {
665711 if (!itt->CustomMessage .empty ())
666- msg = itt->CustomMessage ;
712+ msg = ParseCustomMessage ( itt->CustomMessage , devicename, notValue) ;
667713 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
668714 TouchNotification (itt->ID );
669715 }
@@ -710,6 +756,7 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
710756 std::string atype = splitresults[0 ];
711757
712758 bool bSendNotification = false ;
759+ std::string notValue;
713760
714761 if (atype == ltype)
715762 {
@@ -736,22 +783,27 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
736783 std::vector<std::string> splitresults;
737784 StringSplit (levelNames, " |" , splitresults);
738785 msg += " >> " + splitresults[(llevel / 10 )];
786+ notValue = " >> " + splitresults[(llevel / 10 )];
739787 }
740788 else
789+ {
741790 msg += " >> LEVEL " + sLevel ;
791+ notValue = " >> LEVEL " + sLevel ;
792+ }
742793 }
743794 }
744795 else
745796 {
746797 bSendNotification = true ;
747798 szExtraData += " Status=Off|" ;
748799 msg += " >> OFF" ;
800+ notValue = " >> OFF" ;
749801 }
750802 }
751803 if (bSendNotification)
752804 {
753805 if (!itt->CustomMessage .empty ())
754- msg = itt->CustomMessage ;
806+ msg = ParseCustomMessage ( itt->CustomMessage , devicename, notValue) ;
755807 SendMessageEx (itt->ActiveSystems , msg, msg, szExtraData, itt->Priority , std::string (" " ), true );
756808 TouchNotification (itt->ID );
757809 }
0 commit comments