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
Are you still using the rule above?
Im using openhab 3.3.0, and I simply cant get it to work… Nothing seems to happen.
This is my rules:
rule "Convert Inverter negative Power to Positive"
when
Item Grid_Power 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(Grid_Power.state < 0){
val Number fromgrid = (Grid_Power.state as Number).floatValue * -1
Energy_FromGrid.postUpdate(fromgrid/1000)
} else {
if(Grid_Power.state > 0)
Energy_FromGrid.postUpdate(fromgrid/1000)
}
end
My original item is: Grid_Power
I Made an proxy item to work with which is: Energy_FromGrid
Grid_Power is udating just fine every 5 sec. But Energy_FromGrid never gets updated…
Any idea of what am I missing?
Nope, cant get it to work. I think there are issue in the original rules, and I´m havnt got the knowlegde to correct it. Spend a few hours trying now getting nothing but either obvious errors or no result
I get no logging inside the if at all.
First loginfo returns fine. Second loginfo (within the if) do not show in the log at all
rule "Convert Inverter Power to the Grid to Positive"
when
Item Grid_Power changed
then
logInfo("Grid Power","Grid power is {} ", Grid_Power.state)
// If its a negative value, we are feeding to the grid so update the item and change negative to positive for display purposes
if(Grid_Power.state < 0){
val Number fromgrid = (Grid_Power.state as Number).floatValue * -1
logInfo("From Grid","Grid power is {} and fromgrid is {} ", Grid_Power.state,fromgrid.state)
Energy_FromGrid.postUpdate(fromgrid/1000)
} else {
if(Grid_Power.state > 0)
Energy_FromGrid.postUpdate(fromgrid/1000)
}
end
2023-05-07 18:00:04.745 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Grid_Power' changed from -1993.9 W to -1993.3 W
==> /var/log/openhab/openhab.log <==
2023-05-07 18:00:04.746 [INFO ] [openhab.core.model.script.Grid Power] - Grid power is -1993.3 W
==> /var/log/openhab/events.log <==