Announcement

Collapse
No announcement yet.

Display battery status in %

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

    Display battery status in %

    Hello!

    I am using the script from here: https://forums.homeseer.com/forum/ho...ck?postcount=6
    I find this script quite handy because it shows the % on each battery in my system. However this isnt workin with the Netatmo3 batteries because they have value from 1-10000, instead of 1-100 like many other battery devices. Is there a way to divide the value by 100 to get the correct %value or is this something that has to be done from the creator of the plugin?
    This could maybe be a feature in the plugin that we could check if we wanted?


    Note: Since the script checks if battery > 100 it will automaticly print out error on Netatmo device batteries since they have a valuerange 100x normal batteries.(See pic below) Click image for larger version

Name:	6.PNG
Views:	93
Size:	34.7 KB
ID:	1289835

    #2
    Zheep-

    Until the author updates the plugin, you will have to work around the issue. Here are a few ideas:

    1. Create a separate virtual device that will have the corrected value. Here is an excerpt from this post.

    Originally posted by mrhappy View Post
    If you create a new virtual device then set up a range value/status pair (end tab labelled status-graphics) that accepts a decimal value wide enough. Set the suffix to if you so wish, set it to status rather than both/control.

    Create an event and the trigger of the event is whenever your Neatatmo batteryvalue changes to anything, in the action add a single line scripting command which should be like this;

    &hs.setdevicevaluebyref(1234, (hs.devicevalueex(508) / 100), True)

    And see what it does, 1234 is the reference of your new virtual device and 508 is the reference of your Neatatmo input device.
    Note that I modified mrhappy's original quote to better suit your situation. I've highlighted my changes in purple italics. I have not tested this but it should at least get you started.


    2. You can modify the code of your script to handle the error differently...

    On lines 34-38 you have this IF statement:
    Code:
       If dv.devValue(Nothing) > 100 Then ' if battery value is larger than 100(%), battery is invalid state
          myArray(UBound(myArray) - 1).devValue = "  ERROR"
       Else
          myArray(UBound(myArray) - 1).devValue = (dv.devValue(Nothing).ToString & "%").PadLeft(7)
       End If
    If you wrap that with an IF statement looking for your device reference ID, you can do the math there...

    Code:
       If [ref id is 508]
          [save value as original value/100]
       Else
          If dv.devValue(Nothing) > 100 Then ' if battery value is larger than 100(%), battery is invalid state
             myArray(UBound(myArray) - 1).devValue = "  ERROR"
          Else
             myArray(UBound(myArray) - 1).devValue = (dv.devValue(Nothing).ToString & "%").PadLeft(7)
          End If
       End If
    Note... I can't be sure without testing what the correct code lines would be... but your basis is already in the original code. mwaite would be a good person to ask how to modify his code, but maybe this will get you going in the right direction:

    Code:
       If dv.Ref(Nothing).ToString = 508
          myArray(UBound(myArray) - 1).devValue = ((dv.devValue(Nothing) / 100).ToString & "%").PadLeft(7)
       Else
          If dv.devValue(Nothing) > 100 Then ' if battery value is larger than 100(%), battery is invalid state
             myArray(UBound(myArray) - 1).devValue = "  ERROR"
          Else
             myArray(UBound(myArray) - 1).devValue = (dv.devValue(Nothing).ToString & "%").PadLeft(7)
          End If
       End If
    The biggest thing I'm not sure about is doing math with the .ToString function. I hope some of this helps...

    Comment


      #3
      B1Trash

      Thanks for your quick reply!
      What i have done is almost what u said in suggestion 1. But instead of creating a virtual device, i just updated the value on the device itself.
      The reason for not using a virtual device is that i would have to change so many things to make it fit into the script mentioned.

      However by using this code &hs.setdevicevaluebyref(508, (hs.devicevalueex(508) / 100), True) in a script i was able to change the value until next change. To avoid looping(which happend when i first tried it) i have added a new then setting and added a delay for when it can run again. Look on the pic under for my event setup.

      Click image for larger version

Name:	prosent.PNG
Views:	66
Size:	54.0 KB
ID:	1289903
      This is how it looks in the advanced tab now, previously it was 6144. So the only thing left to do now is create a new statusgraphics acordingly to the changes, i.e Range value from 0-100 and graphics that correspond.
      Click image for larger version

Name:	prosent2.PNG
Views:	57
Size:	16.0 KB
ID:	1289904



      When i think about it now it probably should work with only the cannot re-run for timer set to 10 secs. This should be within the limit of the refresh rate of the sensor aswell which by the plug-ins standards cant be less than 5 minutes.

      Comment


        #4
        I never thought of resetting its own value. That's brilliant!

        Comment


          #5
          That's a great function; should be built-into HS.

          But, I coped the file into the HS3 scripts folder (running HS4) and added it to a manually executed event (for testing). I did edit the Email TO address.
          BUT, when I execute the event I get:

          HomeSeer Event Error Event (Low Battery, Send Email) action Run Script could not be completed - action does not have a valid script file or immediate command"

          I have a feeling I haven't done something fundamental correctly -- any ideas?

          Comment


            #6
            Jeff492
            If it is the script from the post i mentioned that is not working, you should probably try to ask in that thread.
            I currently dont have anything from HS running, as the reason why i used HS was for my bachelor thesis. So sadly I can't help you with this problem right now..

            I have no idea if anything major has changed from HS3 to HS4, and if that is the reason why it doesnt work.

            I hope you can figure it out, so you get the script up and running, because it is indeed a great function to have!

            Comment

            Working...
            X