// Copyright (C) 2022 Fredrik Öhrström (gpl-3.0-or-later)
driver {
    name           = vario451mid
    meter_type     = HeatMeter
    default_fields = name,id,total_energy_consumption_kwh,energy_at_old_date_kwh,energy_at_set_date_kwh,timestamp
    detect {
        mvt = TCH,17,04
    }
    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           = energy_at_old_date
            quantity       = Energy
            info           = 'The total energy consumption recorded when?'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = AnyEnergyVIF
                storage_nr       = 1
            }
        }
        field {
            name           = old
            quantity       = PointInTime
            info           = 'The last billing old date?'
            vif_scaling    = Auto
            dif_signedness = Signed
            display_unit   = DateLT
            match {
                measurement_type = Instantaneous
                vif_range        = Date
                storage_nr       = 1
            }
        }
        field {
            name           = energy_at_set_date
            quantity       = Energy
            info           = 'The total energy consumption recorded by this meter at the due date.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = AnyEnergyVIF
                storage_nr       = 8
            }
        }
        field {
            name         = set
            quantity     = PointInTime
            info         = 'The last billing set date.'
            display_unit = DateLT
            match {
                measurement_type = Instantaneous
                vif_range        = Date
                storage_nr       = 8
            }
        }
    }
    tests {
        test {
            args     = 'Heato vario451mid 94430412 NOKEY'
            telegram = 734468501204439417048c0084900f002c2536700000B767B64527c50ac67a33005007102f2f8404062846000082046c9f2c8d04861f1e72fe00000000000000000000000000000000000000000000000000000000440600000000426cffff0406c94700002f2f2f2f2f2f2f2f2f2f2f2f2f2f2f
            json     = '{"_":"telegram","media":"heat","meter":"vario451mid","name":"Heato","id":"94430412","total_energy_consumption_kwh":18377,"energy_at_old_date_kwh":0,"old_date":"2128-03-31","energy_at_set_date_kwh":17960,"set_date":"2020-12-31","timestamp":"1111-11-11T11:11:11Z"}'
            fields   = 'Heato;94430412;18377;0;17960;1111-11-11 11:11.11'
        }
    }
}