Public Sub Main(ByVal Parms As Object) 'waterpulse.vb '(C) Eliot Mansfield 2015 'Free to use/distribute as long as you retain credit to Eliot Mansfield - www.mez.co.uk 'Homeseer VB sctipt to increment device values as you cant do it in an event. 'You need to define multiple virtual devices to hold the calculated values - 'then update the device ID's in my script for the device ID's of your virtual devices. Dim WaterLitresPerMinute As Double = hs.DeviceValue(286) 'Litres per Minute Dim WaterLitresPer10Minutes As Double = hs.DeviceValue(287) 'Litres Flowed in a 10 Mins Dim WaterLitres As Double = hs.DeviceValue(285) 'Total litres flowed counter Dim WaterLitreToday As Double = hs.DeviceValue(288) 'Litres used today Dim WaterLitreSinceLastRegen As Double = hs.DeviceValue(332) 'Litres since last softener regen Dim WaterCubicMeters As Double = hs.DeviceValue(289) 'Cubic Meters of water Dim WaterDailyAverage As Double = hs.DeviceValue(291) 'Average Daily Use Dim WaterPredictedThisMonth As Double = hs.DeviceValue(290) 'What we are predicting for the month Dim currentDate As DateTime = DateTime.Now 'Get current day of the month 'Anglian 2015-16 rates. 'Standing charge is £29 for water and £86 for sewerage per year. So Daily cost is found by adding together and divide by 365 Dim standingcharge As Double = (29 + 86) / 365 'Water is £1.4608 per cubic meter of water and £1.5775 for sewerage. Sewerage is charged at 90% of water used, so we multiply it by .90 Dim watercost As Double = (1.4608 + (1.5775 * 0.9)) 'Price for a cubic meter of water and 90% sewerage Dim cost As Double Dim AverageDailyCost As Double Dim daysinmonth As Single daysinmonth = 30 'Increment counters WaterLitresPerMinute = WaterLitresPerMinute + 1 WaterLitresPer10Minutes = WaterLitresPer10Minutes + 1 WaterLitres = WaterLitres + 1 WaterLitreToday = WaterLitreToday + 1 'I have a whole house water softener, so i count the litres used between regens and when a regen is expected I ignore overnight water consumption alerts WaterLitreSinceLastRegen = WaterLitreSinceLastRegen +1 'Update the incremented counters hs.SetDeviceValueByRef(286, WaterLitresPerMinute, True) 'Update Litres Per minute Flow Rate hs.SetDeviceValueByRef(287, WaterLitresPer10Minutes, True) 'Update Litres per 10 minutes flow rate hs.SetDeviceValueByRef(285, WaterLitres, True) 'Update total litres flowed counter hs.SetDeviceValueByRef(288, WaterLitreToday, True) 'Update Litres used today hs.SetDeviceValueByRef(289, WaterCubicMeters, True) 'Update Cubic Meters of water hs.SetDeviceValueByRef(332, WaterLitreSinceLastRegen , True) 'Update regen litres 'Work out the comercials and stats WaterCubicMeters = Math.Round((WaterLitres / 1000), 1) 'Cubic meters is just litres used since begining of month hs.SetDeviceValueByRef(289, WaterCubicMeters, True) 'Update Cubic Meters of water cost = (((watercost / 1000) * WaterLitreToday)) + standingcharge 'Cost of Today's water hs.SetDeviceString(288, Math.Round(cost, 2), True) cost = (((watercost / 1000) * WaterLitres)) + (standingcharge * currentDate.Day) 'Cost of all water so far, plus standing charge hs.SetDeviceString(285, Math.Round(cost, 2), True) AverageDailyCost = Math.Round(cost / currentDate.Day, 2) 'Calculate average cost of all water this month divided by the day of the month WaterDailyAverage = Math.Round(WaterLitres / currentDate.Day, 0) 'Calc average usage hs.SetDeviceString(291, AverageDailyCost, True) 'Update the device hs.SetDeviceValueByRef(291, WaterDailyAverage, True) hs.SetDeviceString(290, AverageDailyCost * daysinmonth, True) 'Update monthly predictions by multiplying daily average by days in month hs.SetDeviceValueByRef(290, WaterDailyAverage * daysinmonth, True) End Sub