Displaying a dynamic battery charge graphic

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Post Reply
talisman
Starting Member
Starting Member
Posts: 33
Joined: Tue Oct 06, 2009 9:04 pm
Location: Netherlands

Displaying a dynamic battery charge graphic

Post by talisman »

Hi,

I am trying to get a graphic showing the battery charge of a device.
I tried this directly:
Image_[$SCRIPT=Math.Round(&hs.DeviceValue("V1")/25)*25].png

But this does not work, so I used $hs.regex to run a little script which does this indirectly, I am just having problems returning a (correct) result. How does this work?

The script is simple and currently looks like this:

Sub Main (parm as object)
Dim Charge as Integer = parm
Charge = Math.Round(Charge / 25)*25
hs.writelog("Battery", "Rounded Batterylife comes to: " & Charge)
End Sub

Where the log returns the expected value, but in HSTouch I get 0?

Any ideas?

Cheers,
Elco
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Displaying a dynamic battery charge graphic

Post by AshaiRey »

I don't know what values you get but here's my grain of salt.
If the variable is an integer then every value below 1 will be zero. Try to multiply the value by 100.
e.g. 0.89 will become 0 but 0.89 * 100 will give a value of 89
Bram
talisman
Starting Member
Starting Member
Posts: 33
Joined: Tue Oct 06, 2009 9:04 pm
Location: Netherlands

Re: Displaying a dynamic battery charge graphic

Post by talisman »

The values are in the range of 0 - 100 like any other device - The problem was that I do not want to make an image for every charge value (1, 2, 3, 4, etc), but only for empty and every 25% up to full.

I did find the solution - it needed to be a function (my VB isn't great) :

Function Main (parm as object)
Dim Charge as Integer = parm
Charge = Math.Round(Charge / 25)*25
hs.writelog("Battery", "Rounded Batterylife comes to: " & Charge)
Main = Charge
End Function

Cheers,
Elco
Post Reply

Return to “Homeseer Scripts Forum”