dzVents script for heating control  [SOLVED]

Moderator: leecollings

alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: dzVents script for heating control

Post by alarm_guy1 »

Cheers
renerene
Posts: 316
Joined: Wednesday 03 August 2016 11:36
Target OS: -
Domoticz version:
Contact:

Re: dzVents script for heating control

Post by renerene »

Does the scrtipt calculate the heating start point in order to reach the setpoint as soon as the required time zone starts?
Or is it just working during the selected time zone?

in other words: Does this script 'think ahead'?
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: dzVents script for heating control

Post by Eoreh »

renerene wrote: Sunday 23 September 2018 12:02 Does the scrtipt calculate the heating start point in order to reach the setpoint as soon as the required time zone starts?
Or is it just working during the selected time zone?

in other words: Does this script 'think ahead'?
It does not think ahead. Depending on the time zone set and setpoint it tries to keep the temperature in the hysteresis range.

Code: Select all

      -- switching the boiler on or off if the set temperature has been reached
        local temp_to_compare = domoticz.devices(devHEAT).state 
		local switchOnTemp = temp_set - HISTERESIS
		local switchOffTemp = temp_set + HISTERESIS
funnybu
Posts: 10
Joined: Monday 07 May 2018 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9272
Location: Russia, Novosibirsk
Contact:

Re: dzVents script for heating control

Post by funnybu »

What is happen (with mode switched) if i just click on "Fire icon" on "Workin mode" device?
uzturre
Posts: 14
Joined: Wednesday 13 June 2018 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Basque Country
Contact:

Re: dzVents script for heating control

Post by uzturre »

hello:
thank you very much for this good script, with all my respect towards the author, I have translated it into my usual language.
But the object of this message is the error that appears to me and that I have highlighted it in red.
What can be the cause?

2018-10-31 16:10:00.659 Status: dzVents: Info: ------ Start internal script: BEROGAILU dzvents:, trigger: every 2 minutes
2018-10-31 16:10:00.659 Status: dzVents: !Info:
2018-10-31 16:10:00.660 Status: dzVents: !Info: **************************************************************************
2018-10-31 16:10:00.660 Status: dzVents: !Info: 1. Control de calefacción - iniciar la depuración versión -> 2.3
2018-10-31 16:10:00.660 Status: dzVents: !Info: **************************************************************************
2018-10-31 16:10:00.660 Status: dzVents: !Info: En el momento de inicio del script:
2018-10-31 16:10:00.660 Status: dzVents: !Info: --------------------------------------------------------------------------
2018-10-31 16:10:00.760 Status: dzVents: !Info: > RELE -1- -> Off
2018-10-31 16:10:00.769 Status: dzVents: !Info: > TEMPERATURA SALA -> 20.1
2018-10-31 16:10:00.772 Status: dzVents: !Info: > Current working status CO -> >AUTO< Heating temp.: 19.5 dg.
2018-10-31 16:10:00.787 Status: dzVents: !Info: > Temperatura Confort -> 19.50
2018-10-31 16:10:00.790 Status: dzVents: !Info: > Temperatura Económica -> 18.70
2018-10-31 16:10:00.793 Status: dzVents: !Info: > Temperatura Modo Manual -> 20.00
2018-10-31 16:10:00.807 Status: dzVents: !Info: > Temperatura FESTIVOS -> 19.50
2018-10-31 16:10:00.810 Status: dzVents: !Info: > CALEFACCION -dias laborables -> 10-13/14.30-22.30
2018-10-31 16:10:00.819 Status: dzVents: !Info: > CALEFACCION -festivos -> 10-13/14.30-22.30
2018-10-31 16:10:00.819 Status: dzVents: !Info: > HISTERESIS -> 0.3
2018-10-31 16:10:00.819 Status: dzVents: !Info: --------------------------------------------------------------------------
2018-10-31 16:10:00.823 Status: dzVents: !Info: Ajustes de funcionamiento de la caldera para el modo. AUTO:
2018-10-31 16:10:00.823 Status: dzVents: !Info: --------------------------------------------------------------------------
2018-10-31 16:10:00.823 Status: dzVents: !Info: > 13. Franja horaria de calefacción: días laborables - calefacción desde 10:00-13:00
2018-10-31 16:10:00.824 Status: dzVents: !Info: > 14. Franja horaria de calefacción: días laborables - calefacción desde 14:30-22:30
2018-10-31 16:10:00.824 Status: dzVents: !Info: > 15. Franja horaria de calefacción: Fines de semana - calefacción. 10:00-13:00
2018-10-31 16:10:00.837 Status: dzVents: !Info: > 20. Modo de funcionamiento actual de la caldera: Día de calefacción.
2018-10-31 16:10:00.837 Status: dzVents: !Info: > 22. Enciendo la caldera para una temperatura uniforme o más baja: 19.2 Temperatura actual: 20.1
2018-10-31 16:10:00.838 Status: dzVents: !Info: > 23. Apago la caldera para una temperatura uniforme o más alta: 19.8 Temperatura actual: 20.1
2018-10-31 16:10:00.838 Status: dzVents: !Info: --------------------------------------------------------------------------
2018-10-31 16:10:00.838 Status: dzVents: Error (2.4.6): There is no uservariable with that name or id: HeatWorkCondition
2018-10-31 16:10:00.838 Status: dzVents: Error (2.4.6): An error occured when calling event handler BEROGAILU dzvents
2018-10-31 16:10:00.838 Status: dzVents: Error (2.4.6): .../scripts/dzVents/generated_scripts/BEROGAILU dzvents.lua:96: attempt to index a nil value
2018-10-31 16:10:00.839 Status: dzVents: Info: ------ Finished BEROGAILU dzvents
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: dzVents script for heating control

Post by Eoreh »

uzturre wrote: Wednesday 31 October 2018 16:15 2018-10-31 16:10:00.838 Status: dzVents: !Info: --------------------------------------------------------------------------
2018-10-31 16:10:00.838 Status: dzVents: Error (2.4.6): There is no uservariable with that name or id: HeatWorkCondition
2018-10-31 16:10:00.838 Status: dzVents: Error (2.4.6): An error occured when calling event handler BEROGAILU dzvents
2018-10-31 16:10:00.838 Status: dzVents: Error (2.4.6): .../scripts/dzVents/generated_scripts/BEROGAILU dzvents.lua:96: attempt to index a nil value
2018-10-31 16:10:00.839 Status: dzVents: Info: ------ Finished BEROGAILU dzvents
Script from line 38 start like this.

Code: Select all

 --=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz ( Setup > More options > User variables). 
 --=======================================================
	local usrStateWorkHEAT     = 'HeatWorkCondition'           -- helper variable to work script 
	local usrLastStatement      = 'HeatStatement'                 -- helper variable last statemen 
"HeatWorkCondition" is the name of the variable you must manually create in "Domoticz". As You see above is also second variable "HeatStatement" which of course You also have to create.

Of course You can change name of variable according to your own needs in this line of script and domoticz's "user variables".
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: dzVents script for heating control

Post by Eoreh »

By the way, a slightly newer version of the Polish-language objects names.

Code: Select all

--
--      Heat control 
--
        ------------------------------------------------------------------------
        local version = '2.5'                   -- current version of script 
        ------------------------------------------------------------------------
        local LOGGING =  false                   -- true or false LOGGING info to domoticz log. 
        --=======================================================
        -- DEVICES // name of devices in Domoticz  
        --=======================================================
		-- HEAT  
		local devHEAT = 'Kocioł C.O.'     -- switch that will be turned OFF and ON
		local devAUTO = 'Automatyka'      -- switch that will be turned OFF and ON autmatic of scrpt 

		-- thermometers
		local devThermometer_main   = 'Temperatura Babcia'       -- main thermometer to control switch
		local devThermometer_second = 'Temperatura Jacek'           -- backup thermometer to control switch  when main thermometer dont work  (lastUpdate > max_time_last_seen) 
        
        --=======================================================
        -- DUMMY DEVICES  // your name of devices create in Domoticz  for this script
        --=======================================================
        -- setpoints  
		local devSetpoint_comfort = 'Temperatura komfortowa'        -- setpoint: comfort temperature
        local devSetpoint_night = 'Temperatura na noc'              -- setpoint: eco temperature for night 
        local devSetpoint_custom = 'Temperatura dla trybu ręcznego' -- setpoint: temperature for manual mode
        local devSetpoint_holidays = 'Temperatura WYJAZD'           -- setpoint: eco temperature for holidays mode
        -- selectors 
		local devSelector_heat_work_day = 'Grzanie - dni robocze'   -- heat work day  with buttons for zone of hours exp: [5-22] or [5,30-22,30] or [5,30-7 i 14,00-22]
		local devSelector_heat_weekend = 'Grzanie - weekendy'       -- heat weekend with buttons for zone of hours exp: [5-22] or [5,30-22,30] or [5,30-7 i 14,00-22]
		local devSelector_mode = 'Wybierz tryb pracy'               -- work mode with 4 buttons as below: 
		        local devSelector_mode_auto = 'AUTO'
		        local devSelector_mode_manual = 'RĘCZNY'
				local devSelector_mode_holidays = 'WYJAZD'
		        local devSelector_mode_off  = 'OFF'
   
        -- text 
		local devText_work_state      = 'DODATKOWO - CO'   -- text device witch displayed current status 
		local devText_temp_state      = 'DODATKOWO - T'  

        --=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz ( Setup > More options > User variables). 
        --=======================================================
		local usrStateWorkHEAT      = 'StanPracyCO'                 -- helper variable to work script 
		local usrLastStatement      = 'komunikatCO'                 -- helper variable last statemen 

        --=======================================================
        -- OTHER 
        --=======================================================
        -- conditions of TIME ZONE 
        local NOTIFY_TIME    = 'at 07:00-22:00'                                  -- matchesRule when notify will be send.  (default - PUSHOVER)
		local BACK_TO_AUTO   = 'at 23:30-23:40 on mon,tue,wed,thu,fri,sat,sun'   -- matchesRule to back to 'AUTO' mode from 'MANUAL' mode. 
        --=======================================================
		-- auxiliary variables
		local HISTERESIS = 0.1             -- deviation from the set temperature
		local max_time_last_seen = 60       -- the maximum time in minutes when main thermometer have to report  (lastUpdate) or we change on backup 
		local min_time_to_change = 30        -- the minimum time in minutes to do change  of state devHEAT
		local min_time_to_notify = 60       -- the minimum time in minutes to repeat the unchanged notifycation. 
		local temp_default  = 20            -- default temperature when both  termometers dont work. 

		local description_heat ='Grzanie '        -- label "HEAT" to info for text device 
		local description_break ='Przerwa '       -- label "BREAK" to info for text device 
		local descriptionPrefix = ' Ust. temp.: '     -- label "PREFIX" to info for text device  
		local descriptionSufix  = ' st.'          -- label "SUFIX" to info for text device   

        --=======================================================
        -- FUNCTION: helpers
        --=======================================================

function notify(domoticz, text1, text2)
    if domoticz.variables(usrLastStatement).value ~= text2 or domoticz.variables(usrLastStatement).lastUpdate.minutesAgo > min_time_to_notify then 
        domoticz.variables(usrLastStatement).set(text2) 
 	    if domoticz.time.matchesRule(NOTIFY_TIME) then 
            domoticz.notify(text1,text2, domoticz.PRIORITY_HIGH, domoticz.SOUND_PUSHOVER, '', domoticz.NSS_PUSHOVER)    -- notify system default - PUSHOVER
        end  
    end 
end     

function log(domoticz, text, lvlError)
     local lvlLog = domoticz.LOG_FORCE
     if lvlError ~= nil and lvlError == true then lvlLog = domoticz.LOG_ERROR end 
     if LOGGING then  domoticz.log(text , lvlLog) end 
end      

function round(num, numDecimalPlaces)
  local mult = 10^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
end

function rtrim(s)
  local n = #s
  while n > 0 and s:find("^%s", n) do n = n - 1 end
  return s:sub(1, n)
end

function updateTextInfoDevice(domoticz, text_content)
        if domoticz.devices(devText_work_state).state ~= text_content then domoticz.devices(devText_work_state).updateText(text_content) end
        if domoticz.variables(usrStateWorkHEAT).value ~= text_content then
            domoticz.variables(usrStateWorkHEAT).set(text_content) 
 		    notify(domoticz,'Sterowanie CO - zmiana trybu pracy', 'Zmiana trybu: '..text_content) 
        --  domoticz.log(text_content, domoticz.LOG_FORCE);
        --  domoticz.log(domoticz.variables(usrStateWorkHEAT).value, domoticz.LOG_FORCE);
        end
end 

function getHourFromSelector(state,nZone)
	-- separators in buttons with hours exp: [5-22] or [5.30-22.15] or [5.30-7/14.20-22]
    local hourSplit = '-'     
    local minSplit = '.'
    local zoneSplit = '/'
    ---
    
    local ret = ''
    local hour1 =''
    local hour2 =''
    if  minSplit == '.' then minSplit = '%.' end 
    local nZoneSplit= string.find(state, zoneSplit)    
    if nZone == 1 then nFrom = 0 end 
    nLenZoneSplit=string.len(zoneSplit)
    if nZone == 2 and nZoneSplit ~= nil then  
        nFrom = nZoneSplit + nLenZoneSplit
    else 
       if nZone == 2 then  return nil end 
    end 
    if nFrom == nil then return nil end 
    local nHourSplit= string.find(state, hourSplit, nFrom,true)     
    if nHourSplit > 0 then  
        local hour1 = string.sub(state,nFrom,nHourSplit-1)  
        if string.len(hour1) == 0 then hour1='00' end 
        if string.len(hour1) == 1 then hour1='0'..hour1 end  
        local nMin=string.find(hour1,minSplit,1)      

        if nMin == nil then 
            hour1 = hour1..':00' 
        else
            hour1 = string.gsub(hour1,minSplit,':')
        end 

        local nZoneSplit2 = string.find(state, zoneSplit, nHourSplit+1)           

        if nZoneSplit2 == nil then  hour2 = string.sub(state,nHourSplit+1) else  
            hour2 = string.sub(state,nHourSplit+1,nZoneSplit2-1)  
        end 
        hour2=rtrim(hour2)

        if string.len(hour2) == 0 then hour2='00' end 
        if string.len(hour2) == 1 then hour2='0'..hour2 end  
        nMin=string.find(hour2,minSplit,1)      

        if nMin == nil then 
            hour2 = hour2..':00'
        else 
            hour2 = string.gsub(hour2,minSplit,':')
        end 

        ret = hour1..'-'..hour2
    end 
    return ret 
    
end     

--=======================================================
 -- MAIN dzVent's SCRIPT  
--=======================================================

return {
    active = true,
    on = { 
	       devices = {devSetpoint_comfort, devSetpoint_night, devSetpoint_custom, devSetpoint_holidays, devSelector_heat_work_day, devSelector_heat_weekend, devSelector_mode, devThermometer_main },
		   timer = {'every 2 minutes'},
		   },
 		
    execute = function(domoticz,device,triggerInfo)
	    
	    --==========================================    
        -- BLOCK INFO TO DEBUG
        --==========================================
        log(domoticz,'')
        log(domoticz,' **************************************************************************')
        log(domoticz,'1. STEROWANIE CO - rozpoczynam debugowanie ver -> '.. version)
        -------------- STATE ON BEGIN RUN OF SCRIPT 
        log(domoticz,' **************************************************************************')
        log(domoticz,' Stany na wejściu do skryptu:')
        log(domoticz,' --------------------------------------------------------------------------')
        log(domoticz,' > '..domoticz.devices(devHEAT).name .. ' -> '.. domoticz.devices(devHEAT).state)
        log(domoticz,' > '..domoticz.devices(devThermometer_main).name .. ' -> '.. round(domoticz.devices(devThermometer_main).temperature,1))
        log(domoticz,' > '..domoticz.devices(devText_work_state).name .. ' -> '.. domoticz.devices(devText_work_state).state)
        log(domoticz,' > '..domoticz.devices(devSetpoint_comfort).name .. ' -> '.. domoticz.devices(devSetpoint_comfort).state)
        log(domoticz,' > '..domoticz.devices(devSetpoint_night).name .. ' -> '.. domoticz.devices(devSetpoint_night).state)
        log(domoticz,' > '..domoticz.devices(devSetpoint_custom).name .. ' -> '.. domoticz.devices(devSetpoint_custom).state)
        log(domoticz,' > '..domoticz.devices(devSetpoint_holidays).name .. ' -> '.. domoticz.devices(devSetpoint_holidays).state)
        log(domoticz,' > '..domoticz.devices(devSelector_heat_work_day).name .. ' -> '.. domoticz.devices(devSelector_heat_work_day).state)
        log(domoticz,' > '..domoticz.devices(devSelector_heat_weekend).name .. ' -> '.. domoticz.devices(devSelector_heat_weekend).state)
        log(domoticz,' > HISTERESIS' .. ' -> '.. HISTERESIS)
        log(domoticz,' --------------------------------------------------------------------------')

        --=======================================================
        --  variables
        --=======================================================
            local Time = require('Time')
            local stateworkHEAT = ''
            local stateworkMODE = ''
    	    local temp_current = 0
            local temp_set = 0
            local temp_night = 0
            local temp_comfort = 0

        --=======================================================
        --  BLOCK OF selectors 
        --=======================================================

       if ((domoticz.devices(devSelector_mode).changed) and (domoticz.devices(devSelector_mode).state == devSelector_mode_off)) then 
			local text_content = 'SYSTEM OFF'
            updateTextInfoDevice(domoticz, text_content)                   
			domoticz.devices(devHEAT).switchOff()		
			log(domoticz,' > 3. USTAWIONY TRYB PRACY: [' .. text_content .. ']',true)
            log(domoticz,' --------------------------------------------------------------------------')
			return
		end						

        if domoticz.devices(devSelector_mode).state == devSelector_mode_holidays then stateworkMODE = '>'..devSelector_mode_holidays..'<' end			
		if domoticz.devices(devSelector_mode).state == devSelector_mode_auto then  stateworkMODE = '>'..devSelector_mode_auto..'<' end	
		if domoticz.devices(devSelector_mode).state == devSelector_mode_manual then stateworkMODE = '>'..devSelector_mode_manual..'<' end				
		if domoticz.devices(devSelector_mode).state == devSelector_mode_off then  return  end		  --- because system is OFF. 
        
        
        --==========================================    
        -- BLOCK return from MANUAL to AUTO 
        --==========================================
        -- automatic return to AUTO mode when the time condition described in the parameters is met, the event is triggered by a thermometer (ie automatically and not manually)
        if domoticz.time.matchesRule(BACK_TO_AUTO) and domoticz.devices(devSelector_mode).state == devSelector_mode_manual then  
	        domoticz.devices(devSelector_mode).dimTo(10)
		    notify(domoticz,'Sterowanie CO - powrót do trybu '..devSelector_mode_auto, 'Jest spełniony warunek dla przełączenia automatycznego w tryb '..devSelector_mode_auto) 
    	    log(domoticz,' > 2. Automatyczny powrót do trybu '..devSelector_mode_auto..' -> Włączam tryb '..devSelector_mode_auto..' -> '..BACK_TO_AUTO)         
            log(domoticz,' **************************************************************************')
            log(domoticz,'')
            return  --exit from the script, because it will trigger a second event which will enter the new service for auto mode.
        end 

        --=======================================================
        --  BLOCK OF setpoints
        --=======================================================

        -- notifications of changes in the status of important control parameters
        local llnotify=false
		if (domoticz.devices(devSetpoint_comfort).changed) then
		    notify(domoticz,'Sterowanie CO - zmiana parametru', 'Zmieniono ustawienie temp. dla strefy komfortu na wart.: '..domoticz.devices(devSetpoint_comfort).state) 
		    log(domoticz,' > 4. Wysłano powiadomienie ->'..' Zmieniono ustawienie temp. dla strefy komfortu na wart.: '..domoticz.devices(devSetpoint_comfort).state)
		    llnotify = true
		end
		if (domoticz.devices(devSetpoint_night).changed) then
    		notify(domoticz,'Sterowanie CO - zmiana parametru', 'Zmieniono ustawienie temp. nocnej na wart.: '..domoticz.devices(devSetpoint_night).state) 
		    log(domoticz,' > 5. Wysłano powiadomienie ->'..' Zmieniono ustawienie temp. nocnej na wart.: '..domoticz.devices(devSetpoint_night).state)
		    llnotify = true
		end
		if (domoticz.devices(devSetpoint_custom).changed) then
		    notify(domoticz,'Sterowanie CO - zmiana parametru', 'Zmieniono ustawienie temp. użytkownika na wart.: '..domoticz.devices(devSetpoint_custom).state) 
		    log(domoticz,' > 6. Wysłano powiadomienie ->'..'Zmieniono ustawienie temp. użytkownika na wart.: '..domoticz.devices(devSetpoint_custom).state)
		    llnotify = true
		end
		if (domoticz.devices(devSetpoint_holidays).changed) then
		    notify(domoticz,'Sterowanie CO - zmiana parametru', 'Zmieniono ustawienie temp. dla trybu '..devSelector_mode_holidays..' na wart.: '..domoticz.devices(devSetpoint_holidays).state) 
		    log(domoticz,' > 7. Wysłano powiadomienie ->'..'Zmieniono ustawienie temp. dla trybu '..devSelector_mode_holidays..' na wart.: '..domoticz.devices(devSetpoint_holidays).state) 
		    llnotify = true
		end
		if (domoticz.devices(devSelector_heat_work_day).changed) then
		    notify(domoticz,'Sterowanie CO - zmiana parametru', 'Zmieniono ustawienie stref grzania w dni rob. na wart: '..domoticz.devices(devSelector_heat_work_day).state) 
		    log(domoticz,' > 8. Wysłano powiadomienie ->'..' Zmieniono ustawienie stref grzania w dni rob. na wart: '..domoticz.devices(devSelector_heat_work_day).state)
		    llnotify = true
		end
		if (domoticz.devices(devSelector_heat_weekend).changed) then
		    notify(domoticz,'Sterowanie CO - zmiana parametru', 'Zmieniono ustawienie stref grzania w weekendy. na wart: '..domoticz.devices(devSelector_heat_weekend).state) 
		    log(domoticz,' > 9. Wysłano powiadomienie ->'..'Zmieniono ustawienie stref grzania w weekendy. na wart: '..domoticz.devices(devSelector_heat_weekend).state)
		    llnotify = true
		end
        if llnotify  then log(domoticz,' ------------------------------------------------------------------------') end 


        --==========================================    
        -- BLOCK OF CHECKS termometers :
        --==========================================
        local devHeatMinAgo = domoticz.devices(devHEAT).lastUpdate.minutesAgo
        --- its time event so user dont click any push button, below we check condition to not offen change state of devHEAT. 
        if (triggerInfo.type ==  domoticz.EVENT_TYPE_TIMER or device.name == devThermometer_main)  and devHeatMinAgo <  min_time_to_change  then 
    	    log(domoticz,' > 10. Nic do zmiany bo ostatnia była -> '.. tostring(devHeatMinAgo) .. '  minut temu. WYCHODZĘ')
            log(domoticz,' **************************************************************************')
            log(domoticz,'')
            return  --exit from the script, because it will trigger a second event which will enter the new service for auto mode.
        end 

        -- Determining the current temperature in the living room [this is a reference point for heating control] but if the thermometer does not work, we assume the temperature of the spare thermometer
        if domoticz.devices(devThermometer_main).lastUpdate.minutesAgo < max_time_last_seen then temp_current = round(domoticz.devices(devThermometer_main).temperature,2) end 

        if (domoticz.devices(devThermometer_main).lastUpdate.minutesAgo >= max_time_last_seen) then
            notify(domoticz,'Sterowanie CO - ALERT!!!', 'Termometr nie zgłasza się od 60min, system pobiera temp. z alternatywnego termometru!')
            log(domoticz,'10a. Termometr nie zgłasza się od 60min, system pobiera temp. z alternatywnego termometru!') 
            if (domoticz.devices(devThermometer_second).lastUpdate.minutesAgo < max_time_last_seen) then
                temp_current = round(domoticz.devices(devThermometer_second).temperature,2)
            else
                temp_current =  temp_default
		        notify(domoticz,'Sterowanie CO - ALERT!!!', 'Alternatywny termometr też nie działa, przyjmuję jako temp_current 20 st.') 
		        log(domoticz,'10b. Alternatywny termometr też nie działa, przyjmuję jako temp_current 20 st.!') 
            end
        end

        --==========================================
        -- BLOCK CONTROL:  <holidays> i <MANUAL>
        --==========================================
        if ((domoticz.devices(devSelector_mode).state == devSelector_mode_holidays) or (domoticz.devices(devSelector_mode).state == devSelector_mode_manual)) then 
            if domoticz.devices(devSelector_mode).state == devSelector_mode_holidays  then 
                temp_set =  tonumber(domoticz.devices(devSetpoint_holidays).state) 
                log(domoticz,' > Wybrano tryb pracy >'..devSelector_mode_holidays..'<, sprawdzanie czy praca kotła jest potrzebna ')
                end
            if domoticz.devices(devSelector_mode).state == devSelector_mode_manual then 
                temp_set =  tonumber(domoticz.devices(devSetpoint_custom).state) 
                log(domoticz,' > Wybrano tryb pracy >'..devSelector_mode_manual..'<, sprawdzanie czy praca kotła jest potrzebna ')
                end
            log(domoticz,' --------------------------------------------------------------------------')
            log(domoticz,' Reakcja kotła na nowe ustawienia: ')
            log(domoticz,' --------------------------------------------------------------------------')
            if temp_set > temp_current then
                domoticz.devices(devHEAT).switchOn()
                log(domoticz,' >11. ' .. devHEAT .. ' Włączony bo aktualna temperatura '.. tostring(temp_current)..' niższa niż wymagana '..tostring(temp_set),true)
            else
                domoticz.devices(devHEAT).switchOff()
                log(domoticz,' > 11a. '.. devHEAT .. ' Wyłączony bo aktualna temperatura '..tostring(temp_current)..' nie jest niższa niż wymagana '..tostring(temp_set),true)
            end 
             -- contentet of text info 
            local text_content = stateworkMODE ..' '..stateworkHEAT..' Ust.temp: '..temp_set..' st.'
            updateTextInfoDevice(domoticz, text_content)     
            log(domoticz,' > 11b. Ustawiam info o stanie pracy na: [' .. text_content .. ']')
            log(domoticz,' **************************************************************************')
            log(domoticz,'')
            return 
        end   

        --==========================================
        -- BLOCK CONTROL: <AUTO>
        --==========================================
        --  determination of heating zones: on what days in which times the comfort temperature should be maintained, and when it should be lowered
        --- WORK DAY 
        
        log(domoticz,' Ustawienia pracy kotła dla trybu '..devSelector_mode_auto..': ')
        log(domoticz,' --------------------------------------------------------------------------')

    	local HEAT_MORNING   = ''      
		local HEAT_AFTERNOON = '' 
		local HEAT_WEEKEND   = '' 

        if domoticz.devices(devAUTO).state=='Off' then 
            if domoticz.devices(devHEAT).state=='On'  then 
                -- contentet of text info 
                local text_content = ' AUTO SYSTEM OFF !!!'
                updateTextInfoDevice(domoticz, text_content)                     
			    domoticz.devices(devHEAT).switchOff()		
                log(domoticz,text_content,true);
                log(domoticz,' > 11c. Ustawiam info o stanie pracy na: AUTO OFF ')
            end 
            log(domoticz,' **************************************************************************')
            log(domoticz,'')
            return 
        end     
        -- devSelector_heat_work_day
        stateDevSelector_heat_work_day=domoticz.devices(devSelector_heat_work_day).state
        strHEAT_morning = getHourFromSelector(stateDevSelector_heat_work_day, 1)
        if strHEAT_morning ~= nil then 
            HEAT_MORNING = 'at '..  strHEAT_morning  ..' on mon,tue,wed,thu,fri'
            log(domoticz,' > 13. Ustawiam strefę grzania: Dni robocze - grzanie od '.. strHEAT_morning)
        else 
             -- contentet of text info 
            local text_content = ' SYSTEM OFF !!!'
            updateTextInfoDevice(domoticz, text_content)                     
			domoticz.devices(devHEAT).switchOff()		
            log(domoticz,text_content,true);
            log(domoticz,' **************************************************************************')
            log(domoticz,'')
            return 
        end    

        strHEAT_afternoon = getHourFromSelector(stateDevSelector_heat_work_day, 2)
        if strHEAT_afternoon ~= nil then 
            HEAT_AFTERNOON = 'at '..  strHEAT_afternoon  ..' on mon,tue,wed,thu,fri'
            log(domoticz,' > 14. Ustawiam strefę grzania: Dni robocze - grzanie od '.. strHEAT_afternoon)
        else 
            HEAT_AFTERNOON = HEAT_MORNING
        end    
       
        --- WEEKEND; 
        stateDevSelector_heat_work_weekend=domoticz.devices(devSelector_heat_weekend).state
        strHEAT_weekend = getHourFromSelector(stateDevSelector_heat_work_weekend, 1)
        if strHEAT_weekend ~= nil then 
           HEAT_WEEKEND = 'at ' .. strHEAT_weekend .. ' on sat, sun'
           log(domoticz,' > 15. Ustawiam strefę grzania: Weekendy - grzanie '..strHEAT_weekend)
        else 
            local text_content = ' SYSTEM OFF !!!'
            updateTextInfoDevice(domoticz, text_content)                     

			domoticz.devices(devHEAT).switchOff()		
            log(domoticz,text_content,true);
            log(domoticz,' **************************************************************************')
            log(domoticz,'')
            return 
        end
        
       -- log(domoticz,' > 16. Aktualne reguły : ')
       -- log(domoticz,' > 17. ...HEAT_MORNING   -> '.. HEAT_MORNING )
       -- log(domoticz,' > 18. ...HEAT_AFTERNOON -> '.. HEAT_AFTERNOON )
       -- log(domoticz,' > 19. ...HEAT_WEEKEND   -> '.. HEAT_WEEKEND )

        -- determination of comfortable and overnight temperature
        if (domoticz.time.matchesRule(HEAT_MORNING) or domoticz.time.matchesRule(HEAT_AFTERNOON) or domoticz.time.matchesRule(HEAT_WEEKEND)) then 
              temp_comfort =  tonumber(domoticz.devices(devSetpoint_comfort).state)
	          temp_set = temp_comfort
	          stateworkHEAT = description_heat
              log(domoticz,' > 20. Aktualny tryb pracy kotła: Grzanie dzień')
        else
              temp_night = domoticz.devices(devSetpoint_night).state
              temp_set = tonumber(temp_night)
              stateworkHEAT = description_break
              log(domoticz,' > 21. Aktualny tryb pracy kotła: Strefa chłodna')
	    end
            -- switching the boiler on or off if the set temperature has been reached
        local temp_to_compare = domoticz.devices(devHEAT).state 
		local switchOnTemp = temp_set - HISTERESIS
		local switchOffTemp = temp_set + HISTERESIS

        log(domoticz,' > 22. Wlaczam piec dla temperatury równej lub mniejszej: ' .. switchOnTemp ..'  Akt temp: '..tostring(temp_current))
        log(domoticz,' > 23. Wylaczam piec dla temperatury równej lub większej: ' .. switchOffTemp ..'  Akt temp: '..tostring(temp_current))
        
        log(domoticz,' --------------------------------------------------------------------------')
    	if (temp_current >= switchOffTemp and domoticz.devices(devHEAT).state == 'On') then
            log(domoticz,' Reakcja kotła na nowe ustawienia (lub wywołanie skrytpu przez czujnik temp.): ')
            log(domoticz,' --------------------------------------------------------------------------')
			log(domoticz,' > 24. Docelowa temperature osiagnieta, Piec-Status => off',true)
	    	domoticz.devices(devHEAT).switchOff()
		end
		if (temp_current <= switchOnTemp and  domoticz.devices(devHEAT).state == 'Off') then
            log(domoticz,' Reakcja kotła na nowe ustawienia (lub wywołanie skrytpu przez czujnik temp.): ')
            log(domoticz,' --------------------------------------------------------------------------')
		    domoticz.devices(devHEAT).switchOn()
			log(domoticz,' > 25. Ogrzewanie jest potrzebne, Piec-Status => on',true) 
		end

       -- contentet of text info 
        local text_content = stateworkMODE ..' '..stateworkHEAT..descriptionPrefix..temp_set..descriptionSufix
        updateTextInfoDevice(domoticz, text_content)
        local text_content2 = tostring(temp_current)..' on: '..switchOnTemp..' off: '..switchOffTemp
        if domoticz.devices(devText_temp_state).state ~= text_content2 then
            domoticz.devices(devText_temp_state).updateText(text_content2) 
            log(domoticz,' > 26. Temperatura przełączania kotła: [' .. text_content .. ']')
        end 
        log(domoticz,' > 27. Ustawiam info o stanie pracy na: [' .. text_content .. ']')
        log(domoticz,' ************************************************************************** ')
        log(domoticz,'')
    end
}
 --=======================================================
 -- end of script 
--========================================================
uzturre
Posts: 14
Joined: Wednesday 13 June 2018 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Basque Country
Contact:

Re: dzVents script for heating control

Post by uzturre »

Eoreh wrote: Wednesday 31 October 2018 19:11
uzturre wrote: Wednesday 31 October 2018 16:15

Code: Select all

 --=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz ( Setup > More options > User variables). 
 --=======================================================
	local usrStateWorkHEAT     = 'HeatWorkCondition'           -- helper variable to work script 
	local usrLastStatement      = 'HeatStatement'                 -- helper variable last statemen 
"HeatWorkCondition" is the name of the variable you must manually create in "Domoticz". As You see above is also second variable "HeatStatement" which of course You also have to create.

Of course You can change name of variable according to your own needs in this line of script and domoticz's "user variables".
***************************************************
***************************************************
This is the code on line 38..

Code: Select all

 --=======================================================
        -- VARIABLES DE USUARIO // nombre de las variables de usuario en Domoticz (Configuración> Más opciones> Variables de usuario). 
        --=======================================================
		local usrStateWorkHEAT      = 'HeatWorkCondition'                 -- Variable auxiliar para trabajar script 
		local usrLastStatement      = 'HeatStatement'                 -- variable de ayuda último estado
		
***************************************************
***************************************************
the log tells me the following:

Code: Select all

2018-11-01 12:46:00.405 Status: dzVents: Error (2.4.6): There is no uservariable with that name or id: HeatWorkCondition
2018-11-01 12:46:00.405 Status: dzVents: Error (2.4.6): An error occured when calling event handler BEROGAILU dzvents
2018-11-01 12:46:00.405 Status: dzVents: Error (2.4.6): .../scripts/dzVents/generated_scripts/BEROGAILU dzvents.lua:96: attempt to index a nil value


I continue with the same error detailed above, but the script is working correctly. I do not know why the log gives me that error. The error in line 96 calls my attention.
Thank you very much for your answer.
Last edited by uzturre on Thursday 01 November 2018 12:51, edited 3 times in total.
uzturre
Posts: 14
Joined: Wednesday 13 June 2018 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Basque Country
Contact:

Re: dzVents script for heating control

Post by uzturre »

I tell you my installation, I have two pi zero w, one pi zero for the temperature probe installed in the room and the other pi zero with the relay modules next to the boiler, in this pi zero I have a module with 2 relays (relay 1 and relay 3) when the relay 1 is activated its contact closes to give way to the current and activate the relay 3. The relay 3 is subject to the start of the relay 1. This I did because it used blockly and in this way I could do the boiler operated at certain times activating relay 1 (relay 1 with time condition) and this way activate relay 3 which in turn had to meet the temperature condition of the room probe.

As you see in your script, I have changed line 12 and it works for me that way, but only relay 1 remains OFF, relay 3 always remains activated, I do not know how to do it in the correct way.
If you read line 13, if I put it in active mode, the script does not work.

Thank you.

Code: Select all

   CONTROL DE CALEFACCION 
--
        ------------------------------------------------------------------------
        local version = '2.3'                   -- current version of script 
        ------------------------------------------------------------------------
        local LOGGING =  true                   -- true or false LOGGING info to domoticz log. 
        --=======================================================
        -- DEVICES // name of devices in Domoticz  
        --=======================================================
		-- HEAT  
		local devHEAT = 'RELE -3-' and 'RELE -1-'     -- switch that will be turned OFF and ON
		--- local devHEAT = 'RELE -1-'     -- interruptor OFF - ON
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: dzVents script for heating control

Post by Eoreh »

uzturre wrote: Thursday 01 November 2018 12:19 I tell you my installation, I have two pi zero w, one pi zero for the temperature probe installed in the room and the other pi zero with the relay modules next to the boiler, in this pi zero I have a module with 2 relays (relay 1 and relay 3) when the relay 1 is activated its contact closes to give way to the current and activate the relay 3. The relay 3 is subject to the start of the relay 1. This I did because it used blockly and in this way I could do the boiler operated at certain times activating relay 1 (relay 1 with time condition) and this way activate relay 3 which in turn had to meet the temperature condition of the room probe.

As you see in your script, I have changed line 12 and it works for me that way, but only relay 1 remains OFF, relay 3 always remains activated, I do not know how to do it in the correct way.
If you read line 13, if I put it in active mode, the script does not work.

Thank you.

Code: Select all

   CONTROL DE CALEFACCION 
--
        ------------------------------------------------------------------------
        local version = '2.3'                   -- current version of script 
        ------------------------------------------------------------------------
        local LOGGING =  true                   -- true or false LOGGING info to domoticz log. 
        --=======================================================
        -- DEVICES // name of devices in Domoticz  
        --=======================================================
		-- HEAT  
		local devHEAT = 'RELE -3-' and 'RELE -1-'     -- switch that will be turned OFF and ON
		--- local devHEAT = 'RELE -1-'     -- interruptor OFF - ON
This script cant be used with 2 relays. A lot of line used syntex like egz. " domoticz.devices(devHEAT).switchOff()"
so

Code: Select all

local devHEAT = 'RELE -3-' and 'RELE -1-'     -- switch that will be turned OFF and ON 
is not correct.

If you want still use this script and you have 2 relays, you can use it with one relay and in another script "dzVents" or even blockly do action depending on the condition second and link the actions of these relays.
uzturre
Posts: 14
Joined: Wednesday 13 June 2018 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Basque Country
Contact:

Re: dzVents script for heating control

Post by uzturre »

Thank you very much, the problem is that I do not know how to write code... :roll: :roll:
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: dzVents script for heating control

Post by Eoreh »

uzturre wrote: Thursday 01 November 2018 23:08 Thank you very much, the problem is that I do not know how to write code... :roll: :roll:
So You can do this in blockly, but i recomnends write script in dzVents. It not very hard to learn and in future you will have more posibilities. Is very good documentation on wiki with a lot of egzamples. See https://www.domoticz.com/wiki/DzVents:_ ... _scripting
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents script for heating control

Post by corthebor »

Hello, I am using this script for regulating de heating in our house, but unfortunately the ' Holiday' function does not work.
We are on holiday now and I noticed that de heating was still working.
At for now I lowered the ' Comfort temperature' to holiday-level, so the heating is ok, but I would like to make the script work also when we are on holiday.

Any suggestions to solve this?
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: dzVents script for heating control

Post by Eoreh »

corthebor wrote: Monday 01 April 2019 21:27 Hello, I am using this script for regulating de heating in our house, but unfortunately the ' Holiday' function does not work.
We are on holiday now and I noticed that de heating was still working.
At for now I lowered the ' Comfort temperature' to holiday-level, so the heating is ok, but I would like to make the script work also when we are on holiday.

Any suggestions to solve this?
Does "name" in line nr 25 is the same as SetPoint ?.

Code: Select all

 local devSetpoint_holidays = 'Temperature HOLIDAYS'           -- setpoint: eco temperature for holidays mode
You can debug log from script (of course you have to turn on it in line nr 7)

Code: Select all

 local LOGGING =  true                   -- true or false LOGGING info to domoticz log. 
corthebor
Posts: 13
Joined: Friday 16 October 2015 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents script for heating control

Post by corthebor »

Problem solved: Edited the selector switch ' Working mode' . Changed HOLIDAY into HOLIDAYS. And now it's working.
thanks a lot, Very nice and useful script.
greetings
Cor
elpaul
Posts: 7
Joined: Thursday 11 July 2019 7:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Poland
Contact:

Re: dzVents script for heating control

Post by elpaul »

After updating Domoticz to version 2020.1, errors began to appear in the logs: (Polish version)

Code: Select all

2020-03-31 09:30:34.541 Error: dzVents: Error: (3.0.1) >11. Baxi Włączony bo aktualna temperatura 20.2 niższa niż wymagana 22.0
2020-03-31 09:31:25.949 Error: dzVents: Error: (3.0.1) > 24. Docelowa temperature osiagnieta, Piec-Status => off
2020-03-31 09:31:34.081 Error: dzVents: Error: (3.0.1) > 25. Ogrzewanie jest potrzebne, Piec-Status => on
Can i have some help?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents script for heating control

Post by waaren »

elpaul wrote: Tuesday 31 March 2020 9:32 After updating Domoticz to version 2020.1, errors began to appear in the logs: (Polish version)

Code: Select all

2020-03-31 09:30:34.541 Error: dzVents: Error: (3.0.1) >11. Baxi Włączony bo aktualna temperatura 20.2 niższa niż wymagana 22.0
2020-03-31 09:31:25.949 Error: dzVents: Error: (3.0.1) > 24. Docelowa temperature osiagnieta, Piec-Status => off
2020-03-31 09:31:34.081 Error: dzVents: Error: (3.0.1) > 25. Ogrzewanie jest potrzebne, Piec-Status => on
Can i have some help?
These are just messages from the script but send with a loglevel that is recognized by domoticz as an Error. You can change that by changing the lines which are producing these messages and remove the last ,true.

As example change line:

Code: Select all

log(domoticz,' > 24. Target temperature reached, Status => off',true)
to

Code: Select all

log(domoticz,' > 24. Target temperature reached, Status => off')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
elpaul
Posts: 7
Joined: Thursday 11 July 2019 7:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Poland
Contact:

Re: dzVents script for heating control

Post by elpaul »

waaren wrote: Tuesday 31 March 2020 10:30
elpaul wrote: Tuesday 31 March 2020 9:32 After updating Domoticz to version 2020.1, errors began to appear in the logs: (Polish version)

Code: Select all

2020-03-31 09:30:34.541 Error: dzVents: Error: (3.0.1) >11. Baxi Włączony bo aktualna temperatura 20.2 niższa niż wymagana 22.0
2020-03-31 09:31:25.949 Error: dzVents: Error: (3.0.1) > 24. Docelowa temperature osiagnieta, Piec-Status => off
2020-03-31 09:31:34.081 Error: dzVents: Error: (3.0.1) > 25. Ogrzewanie jest potrzebne, Piec-Status => on
Can i have some help?
These are just messages from the script but send with a loglevel that is recognized by domoticz as an Error. You can change that by changing the lines which are producing these messages and remove the last ,true.

As example change line:

Code: Select all

log(domoticz,' > 24. Target temperature reached, Status => off',true)
to

Code: Select all

log(domoticz,' > 24. Target temperature reached, Status => off')
Thx a lot! it's work fine!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest