GasDeci1Min.vb +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Public Sub Main(ByVal Parms As Object) 'Increments device values as you cant do it in an event. Dim GasPulsesPerMinute As Double = hs.DeviceValue(254) Dim GasDeciLitre As Double = hs.DeviceValue(259) Dim GasDeciL24Hrs As Double = hs.DeviceValue(255) GasPulsesPerMinute = GasPulsesPerMinute + 1 GasDeciLitre = GasDeciLitre + 1 GasDeciL24Hrs = GasDeciL24Hrs + 1 hs.SetDeviceValueByRef(254, GasPulsesPerMinute, True) 'Update Gaspulses Per Minute hs.SetDeviceString(254, CStr(GasPulsesPerMinute), True) hs.SetDeviceValueByRef(259, GasDeciLitre, True) 'Update Decilitre counter hs.SetDeviceValueByRef(255, GasDeciL24Hrs, True) 'Update Decilitre in 24 Hrs End Sub GasHS3.vb +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Public Sub Main(ByVal param As String) Dim calorificvalue Dim CubicMetersUsed Dim cost Dim kWhUsed Dim pricekWh Dim standingcharge Dim verboselog As Integer Dim vat Dim currentDate As DateTime = DateTime.Now Dim DailyAverageCuM Dim MonthlyPredictioncubicmeters Dim MonthlyPredictionCost Dim AverageDailyCost 'rounded figure rather than actual days in month Dim DaysInMonth = 30.436875 verboselog = 1 'Set to 1 for logging. '----------------------------------------------------------------------------- 'January 2015 figures fixed for 1 year. 'All this data is on your gas bill 'Value added tax - gas is 5% vat = 1.05 'Calorific value take from gas bill - this changes nearly every month. calorificvalue = 39.5 'Standing charge in pounds per day (so this is 24.66 pence) standingcharge = 0.2466 'Price of gas in pence per KWh pricekWh = 0.0283 '----------------------------------------------------------------------------- 'Calculate running costs CubicMetersUsed = hs.DeviceValue(256) 'Get Cubic Meters of Gas used this month kWhUsed = ((CubicMetersUsed * 1.02264) * calorificvalue) / 3.6 cost = ((kWhUsed * pricekWh) * vat) If verboselog Then hs.WriteLog("Cost before standing charge", cost) End If 'add the standing charge which is day of month times standing charge cost = cost + (currentDate.Day * standingcharge) 'Calculate averages and predicted costs DailyAverageCuM = CubicMetersUsed / currentDate.Day AverageDailyCost = cost / currentDate.Day MonthlyPredictioncubicmeters = (DailyAverageCuM * DaysInMonth) MonthlyPredictionCost = AverageDailyCost * DaysInMonth 'Set daily average hs.SetDeviceValueByRef(262, DailyAverageCuM * 100, True) 'Set Gas Daily Averaga hs.SetDeviceString(262, Math.Round(AverageDailyCost, 2), True) 'Set Monthly predictions hs.SetDeviceValueByRef(258, MonthlyPredictioncubicmeters, True) 'Set Gas MonthlyPrediction hs.SetDeviceString(258, Math.Round(MonthlyPredictionCost, 2), True) 'Update the text of the Monthly figure with the cost cost = Math.Round(cost, 2) hs.SetDeviceString(256, cost, True) 'Update accumlated cost so far this month If verboselog Then hs.WriteLog("Standing Charge pence per day", standingcharge) hs.WriteLog("Cubic Meters Used", CubicMetersUsed) hs.WriteLog("Cost after standing charge", cost) hs.WriteLog("day of month", currentDate.Day) hs.WriteLog("Daily Average Cubic Meters", DailyAverageCuM) hs.WriteLog("Daily Average cost", AverageDailyCost) hs.WriteLog("Monthly Predicted Cubic Meters", MonthlyPredictioncubicmeters) hs.WriteLog("Monthly Predicted Cost", MonthlyPredictionCost) End If '----------------------------------------------------------------------------- 'Retrieve todays usage - which is decimeters cubed (100dm3 = 1m3) and update the text string of same device. CubicMetersUsed = hs.DeviceValue(255) / 100 'Gas24H kWhUsed = ((CubicMetersUsed * 1.02264) * calorificvalue) / 3.6 cost = ((kWhUsed * pricekWh) * vat) + standingcharge cost = Math.Round(cost, 2) hs.SetDeviceString(255, cost, True) If verboselog Then hs.WriteLog("Decimeter cost was", cost) End If '----------------------------------------------------------------------------- 'Calculate cost of realtime flow rate CubicMetersUsed = hs.DeviceValue(252) / 100 'Gas FlowRate kWhUsed = ((CubicMetersUsed * 1.02264) * calorificvalue) / 3.6 cost = ((kWhUsed * pricekWh) * vat) * 100 cost = Math.Round(cost, 1) hs.SetDeviceString(252, cost, True) If verboselog Then hs.WriteLog("Flowrate cost in pence was", cost) End If End Sub