Habpanel template access units of items

Hoi zäme,

I currently try to get the units from my items into a table in a template in HabPanel:

<h4>
Wetter Daten
</h4>
<table class="table table-condensed">
  <tr ng-repeat="item in itemsInGroup('gHPWU')">
   <td class ="text-left">{{item.label}}</td>
   <td class="text-left" ng-style="{color:'lightblue'}">{{itemState(item.name)}}</td>
   <td class="text-left" ng-style="{color:'lightblue'}">{{itemState(item.unit)}}</td>
 	</tr>
</table>

with this item for instance:

Weather_RainTodayTotalforecast "Rain Today forecast [%.2f mm]"    (gWeatherUnderground, gHPWU)	{channel="weatherunderground:weather:local:forecastToday#precipitationDay"}

could anyone tell me how I can call up the unit in the table I try to produce above?

Thanks in advance, Cheers
Klim

See: Split Item Result in Temp

1 Like

Hey vzorglub, thanks for the hint, but I still cannot get to it. How would I need to split it to get to the unit? :confused:
Thanks so much for your help!!!

@hr3
Can you help, here, please?

You can use for instance

<td class="text-left">{{item | json)}}</td>

to inspect the structure.

In your case the unit is probably going to be in stateDescription.pattern

so you would get to the unit (the part after the space) with something like:

<td class="text-left" ng-style="{color:'lightblue'}"
ng-if="item.stateDescription.pattern && item.stateDescription.pattern.split(' ').length == 2">
  {{item.stateDescription.pattern.split(' ')[1]}}
</td>
1 Like

hey @ysc it works!!! thanks so much! :wink: hopefully helping future requests with this :wink:

1 Like