Announcement

Collapse
No announcement yet.

Converting my battery voltage to percentage in a virtual device.

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

    Converting my battery voltage to percentage in a virtual device.

    Hi All. Is this possible.

    I can't seem to get my head around it. I have 105 KWH of Lithium batteries on my off-grid solar system. The voltage range from empty to full on the batteries is from 50 to 54.4 Volt, with some buffer in both ends.

    Now I would like to have an immediate script to set a virtual device to do the calculation to percentage. Ranging from 0 - 100 %, equal 50 volt is 0 % and 54.4 volt is 100 %

    Is this possible and is it just my mathematic that is so rusty that I can't find my way through it, or will I have to go for a bigger script.

    Help will be greatly appreciate.

    Stones


    #2
    Try: ((voltage-50) / (54.4-50)) * 100

    Comment


      #3
      Easy way to remember, First minus the 2nd divided by the 1st = decimal percent Times 100 = integer percent

      Comment


        #4
        Thanks aa6vh and George, yes way to rusty to reach that.
        But now I have to ask for the actual string of script where 2595 is the voltage device and 2924 is the target virtual device. I tried a difference of my own using the formulas from aa6vh but both failed.

        To be honest, I can't script at all. When I have to do these things I use bits and pieces and copy/paste and try as good as I can, and I have to say, often with good result from all the quality posts and good people here.

        Comment


          #5
          &nhs.SetDeviceValueByRef(2924, ((hs.DeviceValueEx(2595)/(54.4-50))*100) True)

          This is one of my attempt, I tried but I don't get it right. Try and learn

          Comment


            #6
            Originally posted by Stones View Post
            &nhs.SetDeviceValueByRef(2924, ((hs.DeviceValueEx(2595)/(54.4-50))*100) True)

            This is one of my attempt, I tried but I don't get it right. Try and learn
            You forgot to subtract the starting point from your active voltage. Syntax is a little wrong to. Try:

            &nhs.SetDeviceValueByRef(2924, ((hs.DeviceValueEx(2595)-50)/(54.4-50))*100, True)

            Comment


              #7
              Thanks a lot, it worked in first go 🙏😁 and I learned in the process.

              Comment


                #8
                (Voltage - 50) * 22.727 can be easier to work with nearly the same results.

                Roger D

                Comment

                Working...
                X