-- Work out amount of power actually being consumed when solar is generating. -- Upload a Value of 0 if power is being exported to the grid module(...,package.seeall) require("xap") require("xap.bsc") require("string") info={ version="1.0", description="Power Consumed ADM" } solarpower=0 housepower=0 houseusing=0 nhc=201 genminusnhc = 0 addload = 0 function init() bscConsumedW = bsc.Endpoint{source="dbzoo.livebox.plugboard:ConsumedW", direction=bsc.INPUT, type=bsc.STREAM} local f = xap.Filter() f:add("xap-header", "source", "dbzoo.livebox.CurrentCost:ch.1") f:add("xap-header","class","xAPBSC.event") f:callback(solarwatt) local f = xap.Filter() f:add("xap-header", "source", "dbzoo.livebox.CurrentCost:ch.2") f:add("xap-header","class","xAPBSC.event") f:callback(housewatt) xap.Timer(powersave, 15):start() end function solarwatt(frame) solarpower = tonumber(frame:getValue("input.state","text")) if solarpower < 50 then solarpower=0 end end function housewatt(frame) housepower = tonumber(frame:getValue("input.state","text")) end function powersave(self) if solarpower > nhc then genminusnhc = solarpower - nhc addload=housepower - genminusnhc if addload > 0 then --print("Imorting "..housepower) else --print("Exporting "..housepower) housepower = 0 end else --print("Not enough Solar. Importing "..housepower) end ConsumedW= math.ceil(tonumber(housepower)) bscConsumedW:setText( tostring(ConsumedW) ) bscConsumedW:sendEvent() CumulativeDataPost() self:reset() end function CumulativeDataPost() CumulativeData = string.format([[xap-header { class=pachube.update target=dbzoo.livebox.pachube } datastream { id=4 tag=Consumed W Value=%s }]], ConsumedW) xap.sendShort(CumulativeData) end