Announcement

Collapse
No announcement yet.

Script to Add/Subtract values from devices to other devices...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • manaesh
    replied
    Think i need a ,true after the setdevicevalueby ref... Working now!

    Again - thanks for your help in this!

    Cheers

    Mike

    Leave a comment:


  • manaesh
    replied
    Thanks very much for your help Jon

    I have a made the changes - but get the following error in the log :
    Sep-14 16:26:47 Error 1 Running script C:\Program Files (x86)\HomeSeer HS3\scripts\addtotalkwh.vb :Exception has been thrown by the target of an invocation.Overload resolution failed because no accessible 'setdevicevaluebyref' accepts this number of arguments.

    Anything else I need to do to get it to work?

    Many thanks

    Mike

    Leave a comment:


  • jon00
    replied
    For your first script, you need to use the following:

    Code:
    Sub Main(Byval Parms As Object)
    Dim diff As Double = hs.devicevalueEx(1409) + hs.devicevalueEx(1036)
    hs.setdevicevaluebyref(1409, diff, True)
    End Sub

    Leave a comment:


  • manaesh
    started a topic Script to Add/Subtract values from devices to other devices...

    Script to Add/Subtract values from devices to other devices...

    HI All

    I need to get a script to add or subract a rolling value to another value.

    I am trying to get my power consumption worked out on a 30 min timescale, and then added to another value to work out the usage.

    I am doing this in mind of doing a comparison with Octopus Agile. Thanks to Jon00 i now have the current rate in Pence in a device.


    I have a KWH counter that will give me the amount of KWH used in 30 mins (i will reset after that)

    I wish to take this devices value (1036) and add it to my daily cumlative KWH consumed (1409)

    Looking though my past questions - Mokus provided an answer for a similar requirement over 10 years ago (probably for HS2 or even 1) :-

    "'Adds current KWH reading for last 30 mins onto cumlative KWH for the day
    Sub Main(Byval Parms As Object)
    Dim diff As Double = hs.devicevalue(1409) + hs.devicevalue(1036)
    hs.setdevicevalue(1409, diff)
    End Sub"

    This does not seem to work - there are no errors in the log, but device 1409 does not increase from 0.



    My next script (when i have the above working) would calculate the cost of the KWH used so far at a flat rate (0.15) by taking device 1409 and mutilply by 0.15 and place this value in a further device 1410 - which would give my my cost so far to plot using Device History.

    My next script (when i have the above working) would calculate the cost of the KWH used so far at the agile rate and i would take the current value of the 30 minute KWH consumption (1036), multiply this by my Agile rate (Device 1407) and place this result into further device 1408 - which would give my my cost so far to plot using Device History.

    I then could see the cost using different tarrifs, using the live Octopus rates.

    Does anyone know if the script above should work, or if there is a better way to go around adding or subtracting values from different devices a setting other devices?

    Many thanks for any help provided!

    Cheers

    Mike

Working...
X