Skip to content

Commit 695e34b

Browse files
committed
- Changed: All Energy sensors have been transfered to General kWh sensors (more accurate)
1 parent b7be07e commit 695e34b

16 files changed

+70
-201
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Version 2.xxx (xxxx 2015)
111111
- Changed: OpenZWave, Fibaro Wall Plug, now using multisensor for power reading
112112
- Fixed: Display correct energy graph in devices view (spline instead of bars for short log)
113113
- Implemented: MySensors, some more default naming of sensors if they where presented with a name
114+
- Changed: All Energy sensors have been transfered to General kWh sensors (more accurate)
114115

115116
Version 2.2563 (June 14th 2015)
116117
- Implemented: WebServer, native SSL and keep-alive, big thanks to chimit!!!!

hardware/DomoticzHardware.cpp

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -473,64 +473,14 @@ void CDomoticzHardwareBase::SendWattMeter(const int NodeID, const int ChildID, c
473473
}
474474
}
475475

476-
void CDomoticzHardwareBase::SendKwhMeter(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname)
476+
//Obsolete, we should not call this anymore
477+
//when all calls are removed, we should delete this function
478+
void CDomoticzHardwareBase::SendKwhMeterOldWay(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname)
477479
{
478-
int Idx = (NodeID * 256) + ChildID;
479-
bool bDeviceExits = true;
480-
std::vector<std::vector<std::string> > result;
481-
result = m_sql.safe_query("SELECT Name FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
482-
m_HwdID, int(Idx), int(pTypeENERGY), int(sTypeELEC2));
483-
if (result.size() < 1)
484-
{
485-
bDeviceExits = false;
486-
}
487-
488-
RBUF tsen;
489-
memset(&tsen, 0, sizeof(RBUF));
490-
491-
tsen.ENERGY.packettype = pTypeENERGY;
492-
tsen.ENERGY.subtype = sTypeELEC2;
493-
tsen.ENERGY.packetlength = sizeof(tsen.ENERGY) - 1;
494-
tsen.ENERGY.id1 = NodeID;
495-
tsen.ENERGY.id2 = ChildID;
496-
tsen.ENERGY.count = 1;
497-
tsen.ENERGY.rssi = 12;
498-
499-
tsen.ENERGY.battery_level = BatteryLevel;
500-
501-
unsigned long long instant = (unsigned long long)(musage*1000.0);
502-
tsen.ENERGY.instant1 = (unsigned char)(instant / 0x1000000);
503-
instant -= tsen.ENERGY.instant1 * 0x1000000;
504-
tsen.ENERGY.instant2 = (unsigned char)(instant / 0x10000);
505-
instant -= tsen.ENERGY.instant2 * 0x10000;
506-
tsen.ENERGY.instant3 = (unsigned char)(instant / 0x100);
507-
instant -= tsen.ENERGY.instant3 * 0x100;
508-
tsen.ENERGY.instant4 = (unsigned char)(instant);
509-
510-
double total = (mtotal*1000.0)*223.666;
511-
tsen.ENERGY.total1 = (unsigned char)(total / 0x10000000000ULL);
512-
total -= tsen.ENERGY.total1 * 0x10000000000ULL;
513-
tsen.ENERGY.total2 = (unsigned char)(total / 0x100000000ULL);
514-
total -= tsen.ENERGY.total2 * 0x100000000ULL;
515-
tsen.ENERGY.total3 = (unsigned char)(total / 0x1000000);
516-
total -= tsen.ENERGY.total3 * 0x1000000;
517-
tsen.ENERGY.total4 = (unsigned char)(total / 0x10000);
518-
total -= tsen.ENERGY.total4 * 0x10000;
519-
tsen.ENERGY.total5 = (unsigned char)(total / 0x100);
520-
total -= tsen.ENERGY.total5 * 0x100;
521-
tsen.ENERGY.total6 = (unsigned char)(total);
522-
523-
sDecodeRXMessage(this, (const unsigned char *)&tsen.ENERGY);
524-
525-
if (!bDeviceExits)
526-
{
527-
//Assign default name for device
528-
m_sql.safe_query("UPDATE DeviceStatus SET Name='%q' WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
529-
defaultname.c_str(), m_HwdID, int(Idx), int(pTypeENERGY), int(sTypeELEC2));
530-
}
480+
SendKwhMeter(NodeID, ChildID, BatteryLevel, musage * 1000, mtotal, defaultname);
531481
}
532482

533-
void CDomoticzHardwareBase::SendKwhMeterEx(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname)
483+
void CDomoticzHardwareBase::SendKwhMeter(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname)
534484
{
535485
int Idx = (NodeID * 256) + ChildID;
536486
bool bDeviceExits = true;
@@ -563,7 +513,7 @@ double CDomoticzHardwareBase::GetKwhMeter(const int NodeID, const int ChildID, b
563513
double ret = 0;
564514
std::vector<std::vector<std::string> > result;
565515
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
566-
m_HwdID, int(Idx), int(pTypeENERGY), int(sTypeELEC2));
516+
m_HwdID, int(Idx), int(pTypeGeneral), int(sTypeKwh));
567517
if (result.size() < 1)
568518
{
569519
bExists = false;

hardware/DomoticzHardware.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class CDomoticzHardwareBase
117117
void SendTempHumBaroSensor(const int NodeID, const int BatteryLevel, const float temperature, const int humidity, const float pressure, int forecast);
118118
void SendTempHumBaroSensorFloat(const int NodeID, const int BatteryLevel, const float temperature, const int humidity, const float pressure, int forecast, const std::string &defaultname);
119119
void SendSetPointSensor(const int NodeID, const int ChildID, const unsigned char SensorID, const float Temp, const std::string &defaultname);
120+
void SendKwhMeterOldWay(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname);
120121
void SendKwhMeter(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname);
121-
void SendKwhMeterEx(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname);
122122
void SendWattMeter(const int NodeID, const int ChildID, const int BatteryLevel, const float musage, const std::string &defaultname);
123123
double GetKwhMeter(const int NodeID, const int ChildID, bool &bExists);
124124
void SendLuxSensor(const int NodeID, const int ChildID, const int BatteryLevel, const float Lux, const std::string &defaultname);

hardware/Dummy.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,61 +219,64 @@ namespace http {
219219
bCreated = true;
220220
}
221221
break;
222+
case 18:
223+
//kWh
224+
{
225+
std::string rID = std::string(ID);
226+
padLeft(rID, 8, '0');
227+
m_sql.UpdateValue(HwdID, rID.c_str(), 1, pTypeGeneral, sTypeKwh, 12, 255, 0, "0;0.0", devname);
228+
bCreated = true;
229+
}
230+
break;
222231
case pTypeLimitlessLights:
223232
//RGB switch
224233
m_sql.UpdateValue(HwdID, ID, 1, pTypeLimitlessLights, sTypeLimitlessRGB, 12, 255, 1, devname);
225234
bCreated = true;
226235
break;
227236
case pTypeTEMP:
228-
m_sql.UpdateValue(HwdID, ID, 1, pTypeTEMP, sTypeTEMP1, 10, 255, 0, "0.0", devname);
237+
m_sql.UpdateValue(HwdID, ID, 1, pTypeTEMP, sTypeTEMP1, 12, 255, 0, "0.0", devname);
229238
bCreated = true;
230239
break;
231240
case pTypeHUM:
232-
m_sql.UpdateValue(HwdID, ID, 1, pTypeHUM, sTypeTEMP1, 10, 255, 50, "1", devname);
241+
m_sql.UpdateValue(HwdID, ID, 1, pTypeHUM, sTypeTEMP1, 12, 255, 50, "1", devname);
233242
bCreated = true;
234243
break;
235244
case pTypeTEMP_HUM:
236-
m_sql.UpdateValue(HwdID, ID, 1, pTypeTEMP_HUM, sTypeTH1, 10, 255, 0, "0.0;50;1", devname);
245+
m_sql.UpdateValue(HwdID, ID, 1, pTypeTEMP_HUM, sTypeTH1, 12, 255, 0, "0.0;50;1", devname);
237246
bCreated = true;
238247
break;
239248
case pTypeTEMP_HUM_BARO:
240-
m_sql.UpdateValue(HwdID, ID, 1, pTypeTEMP_HUM_BARO, sTypeTHB1, 10, 255, 0, "0.0;50;1;1010;1", devname);
249+
m_sql.UpdateValue(HwdID, ID, 1, pTypeTEMP_HUM_BARO, sTypeTHB1, 12, 255, 0, "0.0;50;1;1010;1", devname);
241250
bCreated = true;
242251
break;
243252
case pTypeWIND:
244-
m_sql.UpdateValue(HwdID, ID, 1, pTypeWIND, sTypeWIND1, 10, 255, 0, "0;N;0;0;0;0", devname);
253+
m_sql.UpdateValue(HwdID, ID, 1, pTypeWIND, sTypeWIND1, 12, 255, 0, "0;N;0;0;0;0", devname);
245254
bCreated = true;
246255
break;
247256
case pTypeRAIN:
248-
m_sql.UpdateValue(HwdID, ID, 1, pTypeRAIN, sTypeRAIN3, 10, 255, 0, "0;0", devname);
257+
m_sql.UpdateValue(HwdID, ID, 1, pTypeRAIN, sTypeRAIN3, 12, 255, 0, "0;0", devname);
249258
bCreated = true;
250259
break;
251260
case pTypeUV:
252-
m_sql.UpdateValue(HwdID, ID, 1, pTypeUV, sTypeUV1, 10, 255, 0, "0;0", devname);
253-
bCreated = true;
254-
break;
255-
case pTypeENERGY:
256-
m_sql.UpdateValue(HwdID, ID, 1, pTypeENERGY, sTypeELEC2, 10, 255, 0, "0;0.0", devname);
261+
m_sql.UpdateValue(HwdID, ID, 1, pTypeUV, sTypeUV1, 12, 255, 0, "0;0", devname);
257262
bCreated = true;
258263
break;
259264
case pTypeRFXMeter:
260-
m_sql.UpdateValue(HwdID, ID, 1, pTypeRFXMeter, sTypeRFXMeterCount, 10, 255, 0, "0", devname);
261-
bCreated = true;
262265
break;
263266
case pTypeAirQuality:
264-
m_sql.UpdateValue(HwdID, ID, 1, pTypeAirQuality, sTypeVoltcraft, 10, 255, 0, devname);
267+
m_sql.UpdateValue(HwdID, ID, 1, pTypeAirQuality, sTypeVoltcraft, 12, 255, 0, devname);
265268
bCreated = true;
266269
break;
267270
case pTypeUsage:
268-
m_sql.UpdateValue(HwdID, ID, 1, pTypeUsage, sTypeElectric, 10, 255, 0, "0", devname);
271+
m_sql.UpdateValue(HwdID, ID, 1, pTypeUsage, sTypeElectric, 12, 255, 0, "0", devname);
269272
bCreated = true;
270273
break;
271274
case pTypeLux:
272-
m_sql.UpdateValue(HwdID, ID, 1, pTypeLux, sTypeLux, 10, 255, 0, "0", devname);
275+
m_sql.UpdateValue(HwdID, ID, 1, pTypeLux, sTypeLux, 12, 255, 0, "0", devname);
273276
bCreated = true;
274277
break;
275278
case pTypeP1Power:
276-
m_sql.UpdateValue(HwdID, ID, 1, pTypeP1Power, sTypeP1Power, 10, 255, 0, "0;0;0;0;0;0", devname);
279+
m_sql.UpdateValue(HwdID, ID, 1, pTypeP1Power, sTypeP1Power, 12, 255, 0, "0;0;0;0;0;0", devname);
277280
bCreated = true;
278281
break;
279282
}

hardware/MySensorsBase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void MySensorsBase::SendSensor2Domoticz(_tMySensorNode *pNode, _tMySensorChild *
561561
if (pSensorKwh) {
562562
float Kwh;
563563
if (pSensorKwh->GetValue(V_KWH, Kwh))
564-
SendKwhMeter(pSensorKwh->nodeID, pSensorKwh->childID, pSensorKwh->batValue, floatValue / 1000.0f, Kwh, (!pChild->childName.empty()) ? pChild->childName : "Meter");
564+
SendKwhMeterOldWay(pSensorKwh->nodeID, pSensorKwh->childID, pSensorKwh->batValue, floatValue / 1000.0f, Kwh, (!pChild->childName.empty()) ? pChild->childName : "Meter");
565565
}
566566
else {
567567
SendWattMeter(pChild->nodeID, pChild->childID, pChild->batValue, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Usage");
@@ -576,10 +576,10 @@ void MySensorsBase::SendSensor2Domoticz(_tMySensorNode *pNode, _tMySensorChild *
576576
if (pSensorWatt) {
577577
float Watt;
578578
if (pSensorWatt->GetValue(V_WATT, Watt))
579-
SendKwhMeter(pChild->nodeID, pChild->childID, pChild->batValue, Watt / 1000.0f, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Meter");
579+
SendKwhMeterOldWay(pChild->nodeID, pChild->childID, pChild->batValue, Watt / 1000.0f, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Meter");
580580
}
581581
else {
582-
SendKwhMeter(pChild->nodeID, pChild->childID, pChild->batValue, 0, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Meter");
582+
SendKwhMeterOldWay(pChild->nodeID, pChild->childID, pChild->batValue, 0, floatValue, (!pChild->childName.empty()) ? pChild->childName : "Meter");
583583
}
584584
}
585585
break;

hardware/RFLink.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,11 @@ bool CRFLink::ParseLine(const std::string &sLine)
815815

816816
if (bHaveKWatt)
817817
{
818-
SendKwhMeter(Node_ID, Child_ID, BatteryLevel, kwatt / 1000.0f, kwatt, "Meter");
818+
SendKwhMeterOldWay(Node_ID, Child_ID, BatteryLevel, kwatt / 1000.0f, kwatt, "Meter");
819819
}
820820
if (bHaveWatt)
821821
{
822-
SendKwhMeter(Node_ID, Child_ID, BatteryLevel, 0, watt, "Meter");
822+
SendKwhMeterOldWay(Node_ID, Child_ID, BatteryLevel, 0, watt, "Meter");
823823
}
824824
if (bHaveDistance)
825825
{

hardware/SolarEdgeBase.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -230,26 +230,6 @@ int SolarEdgeBase::ParsePacket(const unsigned char *pData, int len)
230230
return orgdlen;
231231
}
232232

233-
bool SolarEdgeBase::GetMeter(const unsigned char ID1,const unsigned char ID2, double &musage, double &mtotal)
234-
{
235-
int Idx=(ID1 * 256) + ID2;
236-
bool bDeviceExits=true;
237-
std::vector<std::vector<std::string> > result;
238-
result=m_sql.safe_query("SELECT Name, sValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
239-
m_HwdID, int(Idx), int(pTypeENERGY), int(sTypeELEC2));
240-
if (result.size()<1)
241-
{
242-
return false;
243-
}
244-
std::vector<std::string> splitresult;
245-
StringSplit(result[0][1],";",splitresult);
246-
if (splitresult.size()!=2)
247-
return false;
248-
musage=atof(splitresult[0].c_str());
249-
mtotal=atof(splitresult[1].c_str());
250-
return true;
251-
}
252-
253233
void SolarEdgeBase::SendMeter(const unsigned char ID1,const unsigned char ID2, const double musage, const double mtotal, const std::string &defaultname)
254234
{
255235
int Idx=(ID1 * 256) + ID2;
@@ -469,14 +449,6 @@ int SolarEdgeBase::ParsePacket0x0280(const unsigned char *pData, int dlen)
469449
unsigned long *pUL=(unsigned long*)b;
470450
b+=4;
471451
dlen-=4;
472-
/*
473-
double musage,mtotal;
474-
if (GetMeter(0,1,musage,mtotal))
475-
{
476-
SendMeter(0,1, Watt/100.0f, mtotal/1000.0f, "SolarMain");
477-
UpdateTempSensor(1,temp,"SolarMain");
478-
}
479-
*/
480452
return (b-pData);
481453
}
482454

@@ -496,13 +468,6 @@ int SolarEdgeBase::ParsePacket0x0281(const unsigned char *pData, int dlen)
496468
//Watt P-Out
497469
float Watt=GetFloat(b);
498470
b+=4;
499-
/*
500-
double musage,mtotal;
501-
if (GetMeter(0,1,musage,mtotal))
502-
{
503-
SendMeter(0,1, Watt/100.0f, mtotal/1000.0f, "SolarMain");
504-
}
505-
*/
506471
//skip the rest
507472
return dlen-2;
508473
}
@@ -579,15 +544,6 @@ int SolarEdgeBase::ParsePacket0x0283(const unsigned char *pData, int dlen)
579544
float temp=GetFloat(b);
580545
b+=4;
581546

582-
/*
583-
double musage,mtotal;
584-
if (GetMeter(0,1,musage,mtotal))
585-
{
586-
SendMeter(0,1, Watt/100.0f, mtotal/1000.0f, "SolarMain");
587-
UpdateTempSensor(1,temp,"SolarMain");
588-
}
589-
*/
590-
591547
//skip the rest
592548
return dlen-2;
593549
}

hardware/SolarEdgeBase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class SolarEdgeBase : public CDomoticzHardwareBase
1818
void ParseData(const unsigned char *pData, int Len);
1919
int ParsePacket(const unsigned char *pData, int len);
2020
//
21-
bool GetMeter(const unsigned char ID1,const unsigned char ID2, double &musage, double &mtotal);
2221
void SendMeter(const unsigned char ID1,const unsigned char ID2, const double musage, const double mtotal, const std::string &defaultname);
2322
void SendTempSensor(const unsigned char Idx, const float Temp, const std::string &defaultname);
2423
void SendVoltage(const unsigned long Idx, const float Volt, const std::string &defaultname);

hardware/SolarMaxTCP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void SolarMaxTCP::ParseLine()
405405
}
406406
if (kwhCounter != 0)
407407
{
408-
SendKwhMeter(1, 1, 255, ActUsage/1000.0f, kwhCounter, "kWh Meter");
408+
SendKwhMeterOldWay(1, 1, 255, ActUsage/1000.0f, kwhCounter, "kWh Meter");
409409
}
410410

411411
}

hardware/ToonThermostat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ double CToonThermostat::GetElectricOffset(const int idx, const double currentKwh
575575
{
576576
//First time, lets add it
577577
bool bExists = false;
578-
m_OffsetElectricUsage[idx] = GetKwhMeter(idx, 1, bExists)/100.0;
578+
m_OffsetElectricUsage[idx] = GetKwhMeter(idx, 1, bExists);
579579
m_LastElectricCounter[idx] = currentKwh;
580580
}
581581
return m_OffsetElectricUsage[idx];
@@ -679,7 +679,7 @@ void CToonThermostat::GetMeterDetails()
679679
m_OffsetElectricUsage[Idx] += OldDayCounter;
680680
}
681681
m_LastElectricCounter[Idx] = DayCounter;
682-
SendKwhMeter(Idx, 1, 255, currentUsage/1000.0, (m_OffsetElectricUsage[Idx] + m_LastElectricCounter[Idx])/1000.0, deviceName);
682+
SendKwhMeterOldWay(Idx, 1, 255, currentUsage/1000.0, (m_OffsetElectricUsage[Idx] + m_LastElectricCounter[Idx])/1000.0, deviceName);
683683
}
684684
}
685685
}

0 commit comments

Comments
 (0)