Sub Main(params as Object)
Dim devRefNow as Integer = 680
Dim devRefPrev as Integer = 684
Dim devRefWatts as Integer = 685
Dim devRefWattsDayHi as Integer = 686
Dim devRefWattsDayLo as Integer = 687
Dim dateNow As Date = hs.DeviceLastChangeRef(devRefNow)
Dim datePrev As Date = hs.DeviceLastChangeRef(devRefPrev)
Dim kWhNow as Double = hs.DeviceValueEx(devRefNow)
Dim kWhPrev As Double = hs.DeviceValueEx(devrefPrev)
Dim wattsDayHi As Integer = hs.DeviceValueEx(devRefWattsDayHi)
Dim wattsDayLo As Integer = hs.DeviceValueEx(devRefWattsDayLo)
Dim watts As Integer = Math.Round(1000 * (kWhNow - kWhPrev) / dateNow.Subtract(datePrev).TotalHours, 0)
hs.writelog("NorthQ","NorthQ VP - Current kWh: " & kWhNow & " Previous kWh: " & kWhPrev & " Current W: " & watts)
hs.SetDeviceValueByRef(devRefWatts, watts, True)
hs.SetDeviceString(devRefWatts, watts & " W", False)
hs.SetDeviceValueByRef(devRefPrev, kWhNow, True)
hs.SetDeviceString(devRefPrev, kWhPrev & " kWh", False)
if wattsDayHi < watts then
hs.SetDeviceValueByRef(devRefWattsDayHi, watts, True)
hs.SetDeviceString(devRefWattsDayHi, watts & " W", False)
End if
if wattsDayLo > watts then
hs.SetDeviceValueByRef(devRefWattsDayLo, watts, True)
hs.SetDeviceString(devRefWattsDayLo, watts & " W", False)
End if
End Sub
Se øverst i scriptet her, du har ikke alt med deg i ditt eksempel tror jeg. Erstatt numrene her med dine egne.