// Copyright (C) 2020-2022 Fredrik Öhrström (gpl-3.0-or-later)
driver {
    name           = sontex868
    meter_type     = HeatCostAllocationMeter
    default_fields = name,id,current_consumption_hca,set_date,consumption_at_set_date_hca,timestamp
    detect {
        mvt = SON,16,08
    }
    fields {
        field {
            name           = current_consumption
            quantity       = HCA
            info           = 'The current heat cost allocation for this meter.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = HeatCostAllocation
            }
        }
        field {
            name     = set_date
            quantity = Text
            info     = 'The most recent billing period date.'
            match {
                measurement_type = Instantaneous
                vif_range        = Date
                storage_nr       = 1
            }
        }
        field {
            name           = consumption_at_set_date
            quantity       = HCA
            info           = 'Heat cost allocation at the most recent billing period date.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = HeatCostAllocation
                storage_nr       = 1
            }
        }
        field {
            name           = current_temp
            quantity       = Temperature
            info           = 'The current temperature of the heating element.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = FlowTemperature
            }
        }
        field {
            name           = current_room_temp
            quantity       = Temperature
            info           = 'The current room temperature.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Instantaneous
                vif_range        = ExternalTemperature
            }
        }
        field {
            name           = max_temp
            quantity       = Temperature
            info           = 'The maximum temperature so far during this billing period.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Maximum
                vif_range        = FlowTemperature
            }
        }
        field {
            name           = max_temp_previous_period
            quantity       = Temperature
            info           = 'The maximum temperature during the previous billing period.'
            vif_scaling    = Auto
            dif_signedness = Signed
            match {
                measurement_type = Maximum
                vif_range        = FlowTemperature
                storage_nr       = 1
            }
        }
        field {
            name         = device
            quantity     = PointInTime
            info         = 'Date and time when the meter sent the telegram.'
            display_unit = datetime
            match {
                measurement_type = Instantaneous
                vif_range        = DateTime
            }
        }
    }
    tests {
        test {
            args     = 'MyHeatCoster sontex868 27282728 NOKEY'
            telegram = AF46EE4D2827282716087A80000000_046D040A9F2A036E770000426CE1F7436E660000525900008288016C61258388016E0000008D8801EE1E3533FE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005FF2D0000803F8520FF2D0000803F0259AD0A0265D8041259AD0A8310FD3100000082106C01018110FD610082206C9F2A0BFD0F01030102FF2C000002FD66AC08
            json     = '{"_":"telegram","media":"heat cost allocation","meter":"sontex868","name":"MyHeatCoster","id":"27282728","current_consumption_hca":119,"set_date":"2127-07-01","consumption_at_set_date_hca":102,"current_temp_c":27.33,"current_room_temp_c":12.4,"max_temp_c":27.33,"max_temp_previous_period_c":0,"device_datetime":"2020-10-31 10:04","timestamp":"1111-11-11T11:11:11Z"}'
            fields   = 'MyHeatCoster;27282728;119;2127-07-01;102;1111-11-11 11:11.11'
        }
    }
}