Adding multiple items together in a rule

hey guys. I must be missing something simple. I’m trying to add two items together. here’s the items file and rule file.

the rule is firing but its not adding the two items together and updating the combined item with the combined value. any help would be awesome

Number Inverter_1_Generation 		"INV 1 Gen"		{ channel="fronius:powerinverter:89b7524c:inverterdatachannelpac" }
Number Inverter_1_Grid 			"INV 1 Grid"		{ channel="fronius:powerinverter:89b7524c:powerflowchannelpgrid" }
Number Inverter_1_Load 			"INV 1 Load"		{ channel="fronius:powerinverter:89b7524c:powerflowchannelpload" }

Number Inverter_2_Generation 		"INV 2 Gen"		{ channel="fronius:powerinverter:008407eb:inverterdatachannelpac" }
Number Inverter_Generation_Combined 	"INV Gen"		
rule "Add Inverter Generation" 

when
	Item Inverter_1_Generation changed or
	Item Inverter_2_Generation changed
then
	logInfo("Add Inverter Generation", "Rule triggered")
	Thread::sleep(200)
 	Inverter_Generation_Combined.postUpdate((Inverter_1_Generation.state as DecimalType) + (Inverter_2_Generation.state as DecimalType))
	logInfo("Add Inverter Generation", "Rule sent command")
end

What do you get instead?

Break it down, step by step.
I would use as Number only because it’s generally more in line with how DSL rules natively handles decimals.

logInfo("Add Inverter Generation", "inv1 " + Inverter_1_Generation.state.toString)
var xx = Inverter_1_Generation.state as Number
logInfo("Add Inverter Generation", "inv2 " + Inverter_2_Generation.state.toString)
var xx = xx + (Inverter_1_Generation.state as Number)
logInfo("Add Inverter Generation", "sum " + xx.toString)

Your rule will blow up if either Item has state NULL or UNDEF, you could catch that condition if likely and decide what to do with your sum.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.