Hide units from QuantityType items in HABPanel widget


with the newly added QuantityType for items I was searching for a way to remove the units when showing the value in a HABPanel widget.

Lets say you have a item with QuantityType temperature

<div ng-init="plain_WU_ForecastToday_MaximumTemperatur = itemValue('WU_ForecastToday_MaximumTemperature').replace(' ℃', '');">

you can then access the item without units by using {{plain_WU_ForecastToday_MaximumTemperatur}} in your widget

If anyone know a better way to do this, please don’t be shy and tell us. Took me some serious time to find this, but i’m also a beginner to HABPanel widget creation


the downside to use ng-init is that the values will only be updated when the page is reloaded
if you want to see the dynamic changes of the values without reloading the page, you need to add a dummy item and rule with js

example js:

(function(i) {
    i = i.replace(' ℃', '');
    i = i.replace(' °C', '');
    i = i.replace(' %', '');
    i = i.replace(' kPa', '');
    return parseFloat(i);

the rule would look like:

rule "habpanel max temperature without unit"
   Item WU_ForecastToday_MaximumTemperature received update
   var habpanel_WU_ForecastToday_MaximumTemperature = transform("JS", "replace.js", WU_ForecastToday_MaximumTemperature.state.toString)

still hoping to find a way to hide the units directly in HABpanel with something like a pipe command

This probably works too :slight_smile:
{{itemValue('WU_ForecastToday_MaximumTemperature').split(' ')[0]}}

@ysc thank you this tip, it is working and reduce the needed rules and dummy items so much :slight_smile:
i marked as a solution for this problem