Converting group items into non-group items

I have multiple group items which average out temperatures across all the sensors in every room like so:

Group:Number:AVG HKTKitchen_Average_Temp "Avg. temp [%.1f °C]" <temperature> (Kitchen, Smart_Thermostat, Sensors)

This works very well and lets me easily add items to the average when I put them in the room’s appropriate average temperature group (in this case, HKTKitchen_Average_Temp). These averages should also be stored in influxDB persistence (group Sensors* is in influxdb.persist).

Unfortunately, I can’t graph them with Graphana or the “chart” widget in HabPanel. Now, a bit of searching reveals that inability to graph group items is a known issue (in graphana at least) and one of the suggested solutions is to have the group item save it’s state into a non-group item every time it is updated.

Now, I could imagine the code for this would look something like this:

rule "do conversion"
when
   group_average_item changed
then
   non_group_average_item.postUpdate(group_average_item.state)
end

The problem is that I’m too lazy I’d rather not to write this 30+ times (I have a lot of zones) and even with copy/paste and find/replace, this strikes me as something that should be able to be efficiently handled. What would be the quickest and least effort way of doing this?

Almost the right answer. You can get the group state into the influxDB, but you must specify it in the Influxdb.persist file and without the *.

example:

Strategies {
	default = everyChange
}

Items {
Sensors* : 
HKTKitchen_Average_Temp :

}

Now it will persist the HKTKitchen_Average_Temp state and not the group-members, but as a group.

1 Like

Not necessary. Just put HKTKitchen_Average_Temp in your influxdb.persist file (no *). Then the state of the Group will be saved just like any other Item.

You never need to write identical Rules 30+ times. That’s what the Member of rule trigger, triggeringItem implicit variable and Design Pattern: Associated Items is for. You can handle all 30+ Items with one six or so line Rule (only one line of actual code).

rule "do conversion"
when
    Member of AverageGroups changed
then
    postUpdate(triggeringItem.name+"_PersistItem", triggeringItem.state.toString)
end
1 Like