Page 1 of 1

Calculate the revenue of your Solar Hotwater Boiler

Posted: Saturday 10 March 2018 15:49
by McMelloW
This topic LUA – Virtual Solar Battery: simulate the presence of a battery for storing harvested solar energy by jake gives me idea to do more or less the same for my Solar Hotwater Boiler.

Not because it has to, but just because it is possible.
Therefore I want to see how much revenue I get from my Hotwater Solar Boiler. The picture below shows how my hotwater boiler works.

Image

When the collector temperatur is at least 6 degrees above the boiler temperature, then pump starts and the glycol is circulating and heating the boiler. When this temperature difference is smaller then 6 degrees or even negative (Boiler hotter then the collector) the pump stops circulating.

At the moment the pump is on, I measure the temperature increase in the boiler. The temperature increase is converted to kWh. The kWh is a unit to see the revenue of my Solar Hotwater Boiler.
And the dzVents code of my script

Code: Select all

-- dzVents script Heat-Counter - Created and run in Domoticz events
--
-- Time based Script to see how much revenue I get from my Solar Hotwater Boiler
-- The temperature increase is calculated and converted to kWh to make it comparable with Solar generated energy
-- The energy is counted by an Energy counter device
-- The increase of the temperature is stored in a user variable HeatBattery 

--Manually create and/or define below (newly created virtual) devices and 'User Variables' by user given names
local Btemp = 62                            -- Temperature of the Solar Hotwater Boiler
local Bpump = 64                            -- Boiler pump activity

-- To be created virtual devices in the hardware section of Domoticz:
local idxvsec = 82                           -- (1) Custom Sensor name for the 'Virtual Solarheat Energy Counter'

-- User Variables:
local battery = 'HeatBattery'                -- User Variable name for the 'Heat Battery Capacity' increase  °K                      
local VarHeat = 'Temp_Heat'                  -- User Variable to store temporary temperature                          

-- Define variables, used in this script. Don't change!!!
local new_temp
local old_temp
local delta_temp
local boiler_gain
local boiler_usage
local old_bat_value
local new_bat_value



local ScriptVersion = '0.0.1'

return {
	active = true,
	logging = {
	    level = domoticz.LOG_DEBUG,    -- Uncomment this line to override the dzVents global logging setting
		marker = 'VSEB '.. ScriptVersion
	},
	on = {
		timer = { 'every minute' },
		devices = { Bpump }
	},
	
	execute = function(domoticz, triggerItem)
	    -- Execute every minute, but only when the boiler pump is running.
	    if (triggerItem.isTimer and domoticz.devices(Bpump).percentage > 0) then
        domoticz.log('Script is running.', domoticz.LOG_DEBUG)

        -- Get actual temperature of the Solar Hotwater Boiler
	    local temp = domoticz.devices(Btemp).rawData
	    
        new_temp = tonumber(temp[1])
        old_temp = tonumber(domoticz.variables(VarHeat).value) 
        domoticz.log('New Boiler temperatuur = '.. new_temp, domoticz.LOG_DEBUG)
        domoticz.variables(VarHeat).set(new_temp)
        
        -- Check the temperature change since last update.
            -- A positive number means an increase of the Boiler temperature and negative number means a decrease of the Boiler temperature
        delta_temp = (new_temp - old_temp)
        domoticz.log('Temperature change = '.. delta_temp ..' °K', domoticz.LOG_DEBUG)
        if delta_temp <= 0 then
            local boiler_usage = delta_temp     
            domoticz.log('Decrease of the Boiler temperature with '.. boiler_usage ..' °K', domoticz.LOG_DEBUG)
        else             
            -- An increase of the Boiler temperatur. Get the last value from the HeatBattery
            local boiler_gain = delta_temp
            old_bat_value = tonumber(domoticz.variables(battery).value)
            domoticz.log('Increase of the Boiler temperature with '.. boiler_gain ..' °K', domoticz.LOG_DEBUG)

            -- Calculate the new battery value by adding the delta_temp to the previous battery value. (only increase of the battery)
            new_bat_value = (old_bat_value + boiler_gain)
            domoticz.variables(battery).set(new_bat_value)
            -- Convert temperature increase to kWh ==>  1 °K increase = (200 L * 4.186 J * 1 °K ) / 3600 = 0.23256 kWh
            local count_val = tonumber(domoticz.utils.round((new_bat_value * 0.23256),3))
            domoticz.log('New counter value =  '.. count_val ..' kWh', domoticz.LOG_DEBUG)
            -- Energy valaue is added to the Virtual Solarheat Energy Counter
            domoticz.devices(idxvsec).updateCustomSensor(count_val)
        end -- delta_temp
        
        end -- triggerItem
    
    end -- execute 
}
Feel free to use it.
Comments and improvements are more then welcome