Map battery level to %

Grrrr. I thought that the JavaScript would return an integer but it is returning a float.

return(Math.round(i*20));

Then use label="Netatmo Bedroom Battery status [JS(netatmo_battery.js):%s %%]"

That will fix the icon problem.

Or not. The Icon is based on the actual state of the Item, not just its transformed label. You will either need to make new battery icons that go from 0 to 5 or you will need to use the Rule.

inch pincher! NA != NaN :joy:
Or was this on purpose?

(function(i) {
    if( isNaN(i) ) return "NaN";
    return( Math.round(i*20) );
})(input)

I was hoping it was possible to do transform directly on the item…

It was on purpose. For the sitemap, I usually try to use something a little more human meaningful. Only a programmer would know that “NaN” means “Not a Number”, but “NA” is pretty universally understood (in English at least) as “Not Applicable.” I suppose for consistency I should return “-” so the Item looks like it is NULL, but that could cause other confusion.

Thanks for the clarification. As non native english speaker i just thought this must be an obvious error.

Most of the users on this forum are so proficient in English I sometimes let slip in too many idioms.

Hi, how can I leave battery voltage showing so battery icon to show correct level? Let’s say battery voltage is 56 volts and it is 100% battery icon, battery level 41 volts - 0%

So far I have used JS transformation:

(function(i) {
return (((parseFloat(i)/10) - 40)*100)/16 ;
})(input)

but I need voltage showing instead of percentage with correct battery icon showings…((

Transformation won’t help, icon selections are derived from real Item state before transformation.

Maybe you should adjust your icons to fit your displayed voltage.

Make a set of custom icons where
yourIcon-42.png is the 0% image
yourIcon-55.png is the 100% image
etc.

Yes, that is good idea, for now I have used JS transformation on the title to show percentage, that is fine and when I go to details I have generated another binding with voltage showings. That is perfect for now.
Thanks for support bud!

Hello,

I’m also turning around…
I want to closely monitor my thermal cranes (thermostats) batteries.
They range from 3v (new) to 2.2v (empty…would require an alarm).

So my range goes from 2.2 to 3…and I would like to display it at the levels:

  • 2.2v = empty
  • 2.4v
  • 2.6v
  • 2.8v
  • 3.0v= full

As a perfect newbie I really don’t understand all the proposals about transform/proxy/others… :frowning:
Would anyone have a real life example to share ?

Tx!

What actual state do your Items take up? This influences paths available to you.

The battery level is fetched per 0.1 volt.

What actual state do your Items take up?
Perhaps show us an events.log entry.

Or use a 2nd item with range 0-100, standard icons and a rule to trigger upon changes of your original value and to convert it instead of using a transformation. That rule can also issue a warning right away.

Here you go:

2020-11-01 16:41:46.519 [vent.ItemStateChangedEvent] - VanneSalleDeJeu_4_BatteryState changed from NULL to 2.80 V

2020-11-01 17:24:32.551 [vent.ItemStateChangedEvent] - VanneCouloir1erTage_4_BatteryState changed from NULL to 2.30 V

Okay, your Items are quantity types - they have units. You need to know that for your rules and transformations.

The constraint is that dynamic icons only work for 0-100 and only in integer steps, i.e. you get the same icon for 2.1 as 2.9.
So you will have to use a dummy Item with scaled value, as @mstormi suggests.

Optionally, you can add a transformation to un-scale the dummy state for a display text.

Tx.

Could you guide me in setting up that “dummy item with scaled value” ?

see

Not as evident as you think it is :slight_smile:

I keepthinking…
in my sitemap: Text item=ThermostatSalon_2_BatteryState icon=“batterie”

Where ThermostatSalon_2_BatteryState givesthe value used by the dynamic icon “batterie”.

I’m an absolute noob when it comes to put my ideas in a “script” … I keep searching

What we’re saying is that Item is no use in your sitemap. You’ve decided you want icons to work a certain way, and that cannot happen using the values that Item takes.

So you need to make another Item that can have a range of values that you can use with icons, and you put that Item on your sitemap instead.

A rule can listen for changes in your original Item, and do some maths on the value and place the scales value into your new dummy Item.