[SOLVED] Avg items in sitemap

Hi guys,

I’m using avg group item for room temps and I’d like to show the avg temp item in my sitemap but can’t figure it out?

items

Group:Number:AVG LB_avgTemp 

Number LB_Temperature         "Lilly's Bedroom Temperature 	[%.1f °C]"	<temperature> (gTemperature, LB_avgTemp, gChart) 	["CurrentTemperature"] { channel="mqtt:topic:mosquitto:lillythermostat:temperature" }
Number LB1_Temperature         "Lilly's Bedroom1 Temperature 	[%.1f °C]"	<temperature> (gTemperature, LB_avgTemp) 	["CurrentTemperature"] { alexa="TemperatureSensor.temperature" [scale="Celsius"], channel="mqtt:topic:mosquitto:lilylamp:temperature" }

sitemap

	Frame label="Lilys Bedroom" {
			Text item=LB_Temperature label="Temperature"
			Switch item=LB_Heating_Actuator label="Heating"
			Setpoint item=LB_Heating_TargetTemp label="Set Point [%.1f °C]" minValue=12.0 maxValue=30.0 step=1
	}

If i use my group item in my sitemap it will obviously display both items in that group but id just like to display the avg value from both items.

cheers

Use a rule and proxy item to display the avg of both sensors.

Here’s an example rule:

rule “Rule_Temp”
when
    Item ThermoSoggiorno_T changed
or
    Item ThermoBagnoPT_T changed
then
    if(!(ThermoSoggiorno_T.state instanceof Number )) return; // check if ThermoSoggiorno_T.state is of type number
    if(!(ThermoBagnoPT_T.state instanceof Number )) return; // check if ThermoBagnoPT_T.state is of type number
    // both items have a number value, so calculate...
    var t = (ThermoSoggiorno_T.state as Number) + (ThermoBagnoPT_T.state as Number) // beware the brackets!
    TemperaturaPianoTerra.postUpdate(t)
end

You can try this rule with your items just change the names.

You could also try changing the items config and add (LB_avgTemp) to Group and post that in your sitemap. Not really sure about exact item config as I like rules.:upside_down_face: See this post [SOLVED] Average room temperature - indoor and outdoor separation

1 Like

thanks for the help.

I’m trying your rule

rule “RuleTemp”
when
    Item LB_Temperature changed
or
    Item LB1_Temperature changed
then
    if(!(LB_Temperature.state instance of Number )) return; // check if LB_Temperature.state is of type number
    if(!(LB1_Temperature.state instance of Number )) return; // check if LB1_Temperature.state is of type number
    // both items have a number value, so calculate...
    var t = (LB_Temperature.state as Number) + (LB1_Temperature.state as Number) // beware the brackets!
    LilysBedroom.postUpdate(t)
end

and have created a new item

Number LilysBedroom         "Lilly's Bedroom Temperature 	[%.1f °C]"

but i’m getting this error?

2019-12-27 16:57:06.627 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'temp.rules' has errors, therefore ignoring it: [1,6]: no viable alternative at input '?'

@matt_shepherd: Since we know the value is a number, remove the items from a group and try just this:

rule "RuleTemp"
when
    Item LB_Temperature changed
or
    Item LB1_Temperature changed
then
    var t = ((LB_Temperature.state as Number) + (LB1_Temperature.state as Number)) / 2
    LilysBedroom.postUpdate(t)
end

Edit I added the divide by 2 at the end for average as I overlooked that at first.:grimacing:

And changed quotes. thanks Vincent

Line 1 column 6
rule “RuleTemp”
It’s the wrong type of quotes

1 Like

I should have noticed that.:upside_down_face: but I also need to add the divide by 2 at the end.

as simple as that :slight_smile:

Please tick the solution, thanks

Yep but don’t forget to add the / 2 to end. I edited the rule above to be correct. Quotes included.

1 Like

I’m not getting the correct reading?

2019-12-27 18:35:15.976 [vent.ItemStateChangedEvent] - LB1_Temperature changed from 20.7 to 20.6

2019-12-27 18:35:16.380 [vent.ItemStateChangedEvent] - LilysBedroom changed from NULL to 32.00000000

2019-12-27 18:35:39.767 [vent.ItemStateChangedEvent] - LB_Temperature changed from 21.7 to 21.8

2019-12-27 18:35:39.798 [vent.ItemStateChangedEvent] - LilysBedroom changed from 32.00000000 to 32.10000000

You need to divide the sum by 2 not just the last one

    var t = ((LB_Temperature.state as Number) + (LB1_Temperature.state as Number)) / 2

Your original plan would work fine, if you just asked the sitemap to display your avg group’s state

Text item=LB_avgTemp label="Temperature [%.1f °C]"

or you might want to click on it to see members (only)

Group item=LB_avgTemp label="Temperature [%.1f °C]"

or you might want to click on it to see items of your choosing

Text item=LB_avgTemp label="Temperature [%.1f °C]" {
   Text item=LB_Temperature label="Temperature"
   Switch item=LB_Heating_Actuator label="Heating"
   Setpoint item=LB_Heating_TargetTemp label="Set Point [%.1f °C]" minValue=12.0 maxValue=30.0 step=1
}
2 Likes