Skip to content

Commit

Permalink
Adjust ei6500 for proper duration tariff support.
Browse files Browse the repository at this point in the history
  • Loading branch information
weetmuts committed May 21, 2022
1 parent 005a605 commit b200f62
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

ATTENTION! Counter suffix _int is changed to _counter.
New fields are added to lansendw, lansenpu, qsmoke drivers.
Eventually the old fields will go away in drivers.
Duration tariff added properly this causes a change in the
ei6500 driver json.

ATTENTION! When a field is not optional in the driver description,
but alas, no data has arrived in the telegram, then the json now
contains a null for the value! Previousy 0 was used, which is misleading.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ wmbusmeters --format=json 234433300602010014007a8e0000002f2f0efd3a1147000000008e
which will output:

```
{"media":"other","meter":"lansenpu","name":"MyCounter","id":"00010206","counter_a_int":4711,"counter_b_int":1234,"timestamp":"2021-09-12T08:45:52Z"}
{"media":"other","meter":"lansenpu","name":"MyCounter","id":"00010206","a_counter":4711,"b_counter":1234,"timestamp":"2021-09-12T08:45:52Z"}
```

You can also pipe the hex into wmbusmeters like this:
Expand Down
2 changes: 1 addition & 1 deletion simulations/simulation_c1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ telegram=|27442D2C5768663230028D20E900C91C2011BA79138CCCFB_1A0300000000000003000

# Test EI Electronics smoke detector
telegram=|5E442515112801000C1A7A370050252F2F_0BFD0F060101046D300CAB2202FD17000082206CAB22426C01018440FF2C000F11008250FD61000082506C01018260FD6100008360FD3100000082606C01018270FD61010082706CAB222F2F2F2F|
{"media":"smoke detector","meter":"ei6500","name":"Smokey","id":"00012811","software_version":"1.1.6","message_datetime":"2021-02-11 12:48","last_alarm_date":"2000-01-01","smoke_alarm_counter":"0","total_remove_duration":"0 minutes","last_remove_date":"2000-01-01","removed_counter":"0","test_button_last_date":"2021-02-11","test_button_counter":"1","status":"NOT_INSTALLED","timestamp":"1111-11-11T11:11:11Z"}
{"media":"smoke detector","meter":"ei6500","name":"Smokey","id":"00012811","software_version":"010106","message_datetime":"2021-02-11 12:48","last_alarm_date":"2000-01-01","smoke_alarm_counter":0,"duration_removed_h":0,"last_remove_date":"2000-01-01","removed_counter":0,"test_button_last_date":"2021-02-11","test_button_counter":1,"status":"NOT_INSTALLED","timestamp":"1111-11-11T11:11:11Z"}

# Test Techem radio convert + Wehrle water meter combo.
telegram=|494468509494949495377286868686A85CFE07A90030052F2F_0413100000000F52FCF6A52A90A8D83CA8F7FEAE86990502323D0C70EFF49833C7C1696F75BCABC1E52E6305308D0F31FB|
Expand Down
12 changes: 6 additions & 6 deletions simulations/simulation_t1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ telegram=|2e44333003020100071b7a634820252f2f0265840842658308820165950802fb1aae01
# Test Lansen door window telegram

telegram=|2e44333005020100071d7ab54800002f2f02fd1b110002fd971d01000efd3a2200000000008e40fd3a000000000000|
{"media":"reserved","meter":"lansendw","name":"Dooro","id":"00010205","status":"CLOSED","counter_a_int":22,"counter_b_int":0,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"reserved","meter":"lansendw","name":"Dooro","id":"00010205","status":"CLOSED","a_counter":22,"b_counter":0,"timestamp":"1111-11-11T11:11:11Z"}
|Dooro;00010205;CLOSED;1111-11-11 11:11.11

telegram=|2e44333005020100071d7ab66800002f2f02fd1b550002fd971d01000efd3a2300000000008e40fd3a000000000000|
{"media":"reserved","meter":"lansendw","name":"Dooro","id":"00010205","status":"OPEN","counter_a_int":23,"counter_b_int":0,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"reserved","meter":"lansendw","name":"Dooro","id":"00010205","status":"OPEN","a_counter":23,"b_counter":0,"timestamp":"1111-11-11T11:11:11Z"}
|Dooro;00010205;OPEN;1111-11-11 11:11.11

# Test Lansen pulse counter

telegram=|234433300602010014007a8e0000002f2f0efd3a1147000000008e40fd3a341200000000|
{"media":"other","meter":"lansenpu","name":"Countero","id":"00010206","counter_a_int":4711,"counter_b_int":1234,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"other","meter":"lansenpu","name":"Countero","id":"00010206","a_counter":4711,"b_counter":1234,"timestamp":"1111-11-11T11:11:11Z"}
|Countero;00010206;4711.000000;1234.000000;1111-11-11 11:11.11

# Test BMEters RFM-AMB Temperature Hygrometer telegram
Expand Down Expand Up @@ -294,7 +294,7 @@ telegram=76442104710007612507727100076121042507B5006005E2E95A3C2A1279A5415E67326

# Test Unismart Gas Meter
telegram=|6044B8059430040001037A1D005085E2B670BCF1A5C87E0C1A51DA18924EF984613DA2A9CD39D8F4C7208326C76D42DBEADF80D574192B71BD7C4F56A7F1513151768A9DB804883B28CB085CA2D0F7438C361CB9E2734712ED9BFBB2A14EF55208|
{"media":"gas","meter":"unismart","name":"GasMeter","id":"00043094","fabrication_no":"3162296","total_date_time":"2021-09-15 13:18","total_m3":917,"target_date_time":"2021-09-01 06:00","target_m3":911.32,"version":"UGG4","device_date_time":"2021-09-15 13:18","suppler_info":"00","status":"F00C","parameter_set":"02","other_int":20,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"gas","meter":"unismart","name":"GasMeter","id":"00043094","fabrication_no":"3162296","total_date_time":"2021-09-15 13:18","total_m3":917,"target_date_time":"2021-09-01 06:00","target_m3":911.32,"version":"UGG4","device_date_time":"2021-09-15 13:18","suppler_info":"00","status":"F00C","parameter_set":"02","other_counter":20,"timestamp":"1111-11-11T11:11:11Z"}
|GasMeter;00043094;917.000000;911.320000;1111-11-11 11:11.11

# Test Hydrocal M3 heat/cooling meter
Expand All @@ -314,10 +314,10 @@ telegram=|3C449344957002372337725880226793442304DC0000200C05043900004C0500000000

# Test QSmoke smoke detector this one is not yet understood.
telegram=|3E44934486707945211A7801FD08F081027C034955230082026CFFFF81037C034C41230082036CFFFF03FD17000000326CFFFF046D0F0ABC2B02FDAC7E1100|
{"media":"smoke detector","meter":"qsmoke","name":"QSmokeo","id":"45797086","status":"WOOT","counter_int":0,"device_date_time":"2021-11-28 10:15","timestamp":"1111-11-11T11:11:11Z"}
{"media":"smoke detector","meter":"qsmoke","name":"QSmokeo","id":"45797086","status":"WOOT","counter_counter":0,"device_date_time":"2021-11-28 10:15","timestamp":"1111-11-11T11:11:11Z"}
|QSmokeo;45797086;WOOT;1111-11-11 11:11.11

# Test another QSmoke detector, not understood either.
telegram=|3744934450881248231A7A5C00002081027C034955230082026CFFFF81037C034C41230082036CFFFF02FD170000326CFFFF046D2514BC2B|
{"media":"smoke detector","meter":"qsmoke","name":"QSmokep","id":"48128850","status":"WOOT","counter_int":0,"device_date_time":"2021-11-28 20:37","timestamp":"1111-11-11T11:11:11Z"}
{"media":"smoke detector","meter":"qsmoke","name":"QSmokep","id":"48128850","status":"WOOT","counter_counter":0,"device_date_time":"2021-11-28 20:37","timestamp":"1111-11-11T11:11:11Z"}
|QSmokep;48128850;WOOT;1111-11-11 11:11.11
4 changes: 2 additions & 2 deletions src/driver_lansendw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ MeterLansenDW::MeterLansenDW(MeterInfo &mi, DriverInfo &di) :
"The current status: OPEN or CLOSED.",
PrintProperty::FIELD | PrintProperty::JSON);
*/
addPrint("counter_a", Quantity::Counter,
addPrint("a", Quantity::Counter,
[&](Unit u) { assertQuantity(u, Quantity::Counter); return pulse_counter_a_; },
"How many times the door/window has been opened or closed.",
PrintProperty::JSON);

addPrint("counter_b", Quantity::Counter,
addPrint("b", Quantity::Counter,
[&](Unit u) { assertQuantity(u, Quantity::Counter); return pulse_counter_b_; },
"The current number of counted pulses from counter b.",
PrintProperty::JSON);
Expand Down
17 changes: 15 additions & 2 deletions src/dvparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@ bool findKeyWithNr(MeasurementType mit, VIFRange vif_range, StorageNr storagenr,
return false;
}

void extractDV(DifVifKey &dvk, uchar *dif, uchar *vif, bool *has_difes, bool *has_vifes)
void extractDV(DifVifKey &dvk, uchar *dif, int *vif, bool *has_difes, bool *has_vifes)
{
string tmp = dvk.str();
extractDV(tmp, dif, vif, has_difes, has_vifes);
}

void extractDV(string &s, uchar *dif, uchar *vif, bool *has_difes, bool *has_vifes)
void extractDV(string &s, uchar *dif, int *vif, bool *has_difes, bool *has_vifes)
{
vector<uchar> bytes;
hex2bin(s, &bytes);
Expand Down Expand Up @@ -528,6 +528,19 @@ void extractDV(string &s, uchar *dif, uchar *vif, bool *has_difes, bool *has_vif
}

*vif = bytes[i];
if (*vif == 0xfb || // first extension
*vif == 0xfd || // second extensio
*vif == 0xef || // third extension
*vif == 0xff) // vendor extension
{
if (i+1 < bytes.size())
{
// Create an extended vif, like 0xfd31 for example.
*vif = bytes[i] << 8 | bytes[i+1];
i++;
}
}

while (i < bytes.size() && (bytes[i] & 0x80))
{
i++;
Expand Down
10 changes: 5 additions & 5 deletions src/dvparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
X(SoftwareVersion,0x7D0F,0x7D0F, Quantity::Text, Unit::TXT) \
X(ErrorFlags,0x7D17,0x7D17, Quantity::Text, Unit::TXT) \
X(DurationOfTariff,0x7D31,0x7D33, Quantity::Time, Unit::Hour) \
X(CumulationCounter,0x7D61,0x7D61, Quantity::Counter, Unit::INT) \
X(CumulationCounter,0x7D61,0x7D61, Quantity::Counter, Unit::COUNTER) \
X(AnyVolumeVIF,0x00,0x00, Quantity::Volume, Unit::Unknown) \
X(AnyEnergyVIF,0x00,0x00, Quantity::Energy, Unit::Unknown) \
X(AnyPowerVIF,0x00,0x00, Quantity::Power, Unit::Unknown) \
Expand Down Expand Up @@ -182,7 +182,7 @@ enum class MeasurementType

const char *toString(MeasurementType mt);

void extractDV(std::string &s, uchar *dif, uchar *vif, bool *has_difes, bool *has_vifes);
void extractDV(std::string &s, uchar *dif, int *vif, bool *has_difes, bool *has_vifes);

struct DifVifKey
{
Expand All @@ -192,20 +192,20 @@ struct DifVifKey
std::string str() { return key_; }
bool operator==(DifVifKey &dvk) { return key_ == dvk.key_; }
uchar dif() { return dif_; }
uchar vif() { return vif_; }
int vif() { return vif_; }
bool hasDifes() { return has_difes_; }
bool hasVifes() { return has_vifes_; }

private:

std::string key_;
uchar dif_;
uchar vif_;
int vif_;
bool has_difes_;
bool has_vifes_;
};

void extractDV(DifVifKey &s, uchar *dif, uchar *vif, bool *has_difes, bool *has_vifes);
void extractDV(DifVifKey &s, uchar *dif, int *vif, bool *has_difes, bool *has_vifes);

static DifVifKey NoDifVifKey = DifVifKey("");

Expand Down
4 changes: 2 additions & 2 deletions src/meter_lansenpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ MeterLansenPU::MeterLansenPU(MeterInfo &mi) :
// other version 0x0b reported, but we lack telegram
addLinkMode(LinkMode::T1);

addPrint("counter_a", Quantity::Counter,
addPrint("a", Quantity::Counter,
[&](Unit u) { assertQuantity(u, Quantity::Counter); return counterA(); },
"The current number of counted pulses from counter a.",
PrintProperty::FIELD | PrintProperty::JSON);

addPrint("counter_b", Quantity::Counter,
addPrint("b", Quantity::Counter,
[&](Unit u) { assertQuantity(u, Quantity::Counter); return counterB(); },
"The current number of counted pulses from counter b.",
PrintProperty::FIELD | PrintProperty::JSON);
Expand Down
4 changes: 2 additions & 2 deletions src/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
X(RelativeHumidity,RH) \
X(HCA,HCA) \
X(Text,TXT) \
X(Counter,INT) \
X(Counter,COUNTER) \
X(Time,Hour) \
X(PointInTime,DateTimeLT) \
X(Voltage,Volt) \
Expand All @@ -56,7 +56,7 @@
X(RH,rh,"RH",RelativeHumidity,"relative humidity") \
X(HCA,hca,"hca",HCA,"heat cost allocation") \
X(TXT,txt,"txt",Text,"text") \
X(INT,int,"int",Counter,"int") \
X(COUNTER,counter,"counter",Counter,"counter") \
X(Second,s,"s",Time,"second") \
X(Minute,m,"m",Time,"minute") \
X(Hour,h,"h",Time,"hour") \
Expand Down
13 changes: 10 additions & 3 deletions src/wmbus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2608,9 +2608,10 @@ string vifType(int vif)

double vifScale(int vif)
{
int t = vif & 0x7f;
// Remove any remaining 0x80 top bits.
vif &= 0x7f7f;

switch (t) {
switch (vif) {
// wmbusmeters always returns enery as kwh
case 0x00: return 1000000.0; // Energy mWh
case 0x01: return 100000.0; // Energy 10⁻² Wh
Expand Down Expand Up @@ -2765,6 +2766,7 @@ double vifScale(int vif)
case 0x72: return 1.0; // Averaging duration hours
case 0x73: return (1.0/24.0); // Averaging duration days

// wmbusmeters always returns time in hours
case 0x74: return 3600.0; // Actuality duration seconds
case 0x75: return 60.0; // Actuality duration minutes
case 0x76: return 1.0; // Actuality duration hours
Expand All @@ -2778,7 +2780,12 @@ double vifScale(int vif)
case 0x7E: // Any VIF
case 0x7F: // Manufacturer specific

default: warning("(wmbus) warning: type %d cannot be scaled!\n", t);
// wmbusmeters always returns time in hours
case 0x7d31: return 60.0; // Duration tariff minutes
case 0x7d32: return 1.0; // Duration tariff hours
case 0x7d33: return (1.0/24.0); // Duration tariff days

default: warning("(wmbus) warning: type 0x%x cannot be scaled!\n", vif);
return -1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_hex_cmdline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ fi
TESTNAME="Test hex on stdin"

cat > $TEST/test_expected.txt <<EOF
{"media":"other","meter":"lansenpu","name":"MyCounter","id":"00010206","counter_a_int":4711,"counter_b_int":1234,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"other","meter":"lansenpu","name":"MyCounter","id":"00010206","a_counter":4711,"b_counter":1234,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"cold water","meter":"multical21","name":"MyWater","id":"76348799","total_m3":6.408,"target_m3":6.408,"max_flow_m3h":0,"flow_temperature_c":127,"external_temperature_c":19,"current_status":"DRY","time_dry":"22-31 days","time_reversed":"","time_leaking":"","time_bursting":"","timestamp":"1111-11-11T11:11:11Z"}
{"media":"other","meter":"lansenpu","name":"MyCounter","id":"00010206","counter_a_int":4711,"counter_b_int":1234,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"other","meter":"lansenpu","name":"MyCounter","id":"00010206","a_counter":4711,"b_counter":1234,"timestamp":"1111-11-11T11:11:11Z"}
EOF

echo 234433300602010014007a8e0000002f2f0efd3a1147000000008e40fd3a3412000000002A442D2C998734761B168D2091D37CAC21E1D68CDAFFCD3DC452BD802913FF7B1706CA9E355D6C2701CC24234433300602010014007a8e0000002f2f0efd3a1147000000008e40fd3a341200000000999 | \
Expand Down
4 changes: 2 additions & 2 deletions tests/test_unknown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ cat > $TEST/test_expected.txt <<EOF
(meter) Not printing this warning again for id: 00010205 mfct: (LAS) Lansen Systems, Sweden (0x3033) type: Unknown (0xff) ver: 0x07
(meter) please consider opening an issue at https://github.com/weetmuts/wmbusmeters/
(meter) to add support for this unknown mfct,media,version combination
{"media":"Unknown","meter":"lansendw","name":"Dorren","id":"00010205","status":"OPEN","counter_a_int":23,"counter_b_int":0,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"Unknown","meter":"lansendw","name":"Dorren","id":"00010205","status":"OPEN","a_counter":23,"b_counter":0,"timestamp":"1111-11-11T11:11:11Z"}
(meter) Forren: meter detection did not match the selected driver lansensm! correct driver is: lansendw
(meter) Not printing this warning again for id: 00010206 mfct: (LAS) Lansen Systems, Sweden (0x3033) type: Reserved for sensors (0x1d) ver: 0x07
{"media":"reserved","meter":"lansensm","name":"Forren","id":"00010206","status":"OK","timestamp":"1111-11-11T11:11:11Z"}
{"media":"Unknown","meter":"lansendw","name":"Dorren","id":"00010205","status":"OPEN","counter_a_int":23,"counter_b_int":0,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"Unknown","meter":"lansendw","name":"Dorren","id":"00010205","status":"OPEN","a_counter":23,"b_counter":0,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"reserved","meter":"lansensm","name":"Forren","id":"00010206","status":"OK","timestamp":"1111-11-11T11:11:11Z"}
EOF

Expand Down

0 comments on commit b200f62

Please sign in to comment.