What are the available functions and methods for items and groups?

I want to use “item in itemsInGroup(groupname)” and would like to do an ng-if on the item.name if it contains a certain string.

How can I do this?

Is there a reference to all the functions and methods available in the Widget coding?
For example:

  • itemsInGroup
  • item.name
  • etc…

This thread is a great start’‘Design Pattern: Working with Groups in Rules’’

I have read it and am using it for items and rules.

But I need the functions/methods that can be used in Widget.

Other functions I came across in the examples:

  • itemState
  • itemValue
  • itemValue.split
  • sendCmd

I also read this:

OK, so I have used the split to find the right item in the group and have created a button as needed.

My complete code is:

<div>{{config.groupitem}}</div>
<div>&nbsp</div>
<div ng-init="data = {Temperature: '0', HeatCool: '1', FanSpeed: '2'};"></div>
<div ng-repeat="item in itemsInGroup(config.groupitem)">
  <div ng-hide="true" ng-if="item.name.split('_')[2]=='Temperature'">{{data.Temperature = itemState(item.name)}}</div>
  <div ng-hide="true" ng-if="item.name.split('_')[2]=='HeatCool'">{{data.HeatCool = itemState(item.name)}}</div>
  <div ng-hide="true" ng-if="item.name.split('_')[2]=='FanSpeed'">{{data.FanSpeed = itemState(item.name)}}</div>
  <!--<div>{{item.name.split("_")[2]}} --- {{itemState(item.name)}}</div>-->
</div>
<div ng-repeat="item in itemsInGroup(config.groupitem)">
  <div ng-if="item.name.split('_')[2]=='Set'">
    <button class="btn btn-success"  ng-click="sendCmd(item, 'ON')"><span>ON: {{data.Temperature}},{{data.HeatCool}},{{data.FanSpeed}}</span></button>
  </div>
</div>
<div>&nbsp</div>
<div ng-repeat="item in itemsInGroup(config.groupitem)">
  <div ng-if="item.name.split('_')[2]=='Off'">
    <button class="btn btn-danger"  ng-click="sendCmd(item, 'ON')"><span>OFF</span></button>
  </div>
</div>

The Widget looks like this:

image

though, when I press either button, the ON command is not send to the item/rule (I have a log in the rule that checks for ON for these 2 specific items).

Am I missing something?

item in your ng-repeat has the complete structure (use {{item | json}} inside a div to show it as JSON).

=> ng-click="sendCmd(item.name, 'ON')"

1 Like

Thanks it works.
I though I was supposed to pass an item object to the SendCmd function and not a string of the item name.