// Copyright (C) 2020-2022 Fredrik Öhrström (gpl-3.0-or-later)
driver {
    name           = ebzwmbe
    meter_type     = ElectricityMeter
    default_fields = name,id,total_energy_consumption_kwh,current_power_consumption_kw,current_power_consumption_phase1_kw,current_power_consumption_phase2_kw,current_power_consumption_phase3_kw,timestamp
    detect {
        mvt = EBZ,01,02
    }
    fields {
        field {
            name           = total_energy_consumption
            quantity       = Energy
            info           = 'The total energy consumption recorded by this meter.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = AnyEnergyVIF
            }
        }
        field {
            name           = current_power_consumption_phase1
            quantity       = Power
            info           = 'Current power consumption at phase 1.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                difvifkey = 04A9FF01
            }
        }
        field {
            name           = current_power_consumption_phase2
            quantity       = Power
            info           = 'Current power consumption at phase 2.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                difvifkey = 04A9FF02
            }
        }
        field {
            name           = current_power_consumption_phase3
            quantity       = Power
            info           = 'Current power consumption at phase 3.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                difvifkey = 04A9FF03
            }
        }
        field {
            name     = customer
            quantity = Text
            info     = 'Customer name.'
            match {
                measurement_type = Instantaneous
                vif_range        = Customer
            }
        }
        field {
            name      = current_power_consumption
            quantity  = Power
            info      = 'Calculated sum of power consumption of all phases.'
            calculate = current_power_consumption_phase1_kw+current_power_consumption_phase2_kw+current_power_consumption_phase3_kw
        }
    }
    tests {
        test {
            args     = 'Elen1 ebzwmbe 22992299 NOKEY'
            telegram = 5B445A149922992202378C20F6900F002C25BC9E0000BF48954821BC508D72992299225A140102F6003007102F2F040330F92A0004A9FF01FF24000004A9FF026A29000004A9FF03460600000DFD11063132333435362F2F2F2F2F2F
            json     = '{"_":"telegram","media":"electricity","meter":"ebzwmbe","name":"Elen1","id":"22992299","total_energy_consumption_kwh":2816.304,"current_power_consumption_phase1_kw":0.09471,"current_power_consumption_phase2_kw":0.10602,"current_power_consumption_phase3_kw":0.01606,"customer":"654321","current_power_consumption_kw":0.21679,"timestamp":"1111-11-11T11:11:11Z"}'
            fields   = 'Elen1;22992299;2816.304;0.21679;0.09471;0.10602;0.01606;1111-11-11 11:11.11'
        }
        test {
            args     = 'MyEl ebzwmbe 01135263 NOKEY'
            comment  = 'This is eBZ DD3 meter with a wMB-E01 wmbus radio converter module.'
            telegram = 4B445A146450000002378C20F3900F002C25F38B00006CBB07CEB215901172635213015A140102F3002007102F2F_04039D3E03000429E82201000DFD110E333632353331313031305A424531
            json     = '{"_":"telegram","media":"electricity","meter":"ebzwmbe","name":"MyEl","id":"01135263","total_energy_consumption_kwh":212.637,"customer":"1EBZ0101135263","current_power_consumption_kw":null,"timestamp":"1111-11-11T11:11:11Z"}'
            fields   = 'MyEl;01135263;212.637;null;null;null;null;1111-11-11 11:11.11'
        }
    }
}