Ive created some rules which so far give me the production (from solar) , consumption (from grid) and therefore I can work out the overall consumption. This works fine however, the inverter channels display positive or negative values for when its feeding in to the grid, or drawing down.
Is there a way I can just reference the actual number, without the - or + ?
Or a way to populate an item based off those states, ie if value is -, then TO the grid (feeding in) so populate Item:Number Feed_In
and if the value is 0 or more, populate Item:Number Grid_In
My rules so far really just changing things from watts to kilowatts and dont remove the negative value, despite saying so
rule "Convert Inverter Power to the Grid to Positive"
when
Item Solar_HouseGrid_Power changed
then
val Number fromgrid = (Solar_HouseGrid_Power.state as Number).floatValue
Energy_FromGrid.postUpdate(fromgrid/1000)
end
rule "Real Time Overall Consumption - Solar & Grid"
when
Item Solar_HouseGrid_Power changed
then
var Number gridconsumption = (Solar_HouseGrid_Power.state as Number).floatValue / 1000
logInfo("energy", "Grid Consumption is " + gridconsumption)
var Number solarproduction = (Solar_ACPower.state as Number).floatValue
logInfo("energy", "Solar production is " + solarproduction)
var Number totalconsumption = gridconsumption + solarproduction
Energy_Used.postUpdate(totalconsumption)
end
When its a negative value, I want to convert it to positive and update the item (Its feeding in). When its a positive value, dont convert it but update the item (its drawing from the grid)
rule "Convert Inverter Power to the Grid to Positive"
when
Item Solar_HouseGrid_Power changed or
Item Solar_ACPower changed
then
// If its a negative value, we are feeding to the grid so update the item and change negative to positive for display purposes
if(Solar_HouseGrid_Power.state < 0){
val Number fromgrid = (Solar_HouseGrid_Power.state as Number).floatValue * -1
Energy_FromGrid.postUpdate(fromgrid/1000)
} else {
if(Solar_HouseGrid_Power.state > 0)
Energy_FromGrid.postUpdate(fromgrid/1000)
}
end