thermostat for cooling and heating

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: thermostat for cooling and heating

Post by Maxx »

Hello

I solved it with a file on the SD card:

Code: Select all

    local myFile        = "www/LightSettings.json"
    local f = assert(io.open(myFile, "r"))
    local t = f:read("*all")
    f:close()
Put the LightSettings.json with a string, as long as you like, on your sd card

Then you can read the json from t
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: thermostat for cooling and heating

Post by waaren »

Skippiemanz wrote: Friday 30 November 2018 17:31 Maybe anyone has a idea for the user variables limitation
Can you try this one ? (moved from JSON formatted var to internal / persistent data)

Code: Select all

--[[ 
    version: 20181130-02
    
    This script manage the different heating zones 
    
    Before making this script active you should first enter your rooms , sensors and valves indexes below in function initPersistent
    define a switch for chiller if there is a main switch
    define a switch for heater if there is a main switch
   
    the value heater is the idx or name of the main heater switch. If your system does not have this, leave it out completely
    the value cooler is the idx or name of the main cooler switch. If your system does not have this, leave it out completely. 
    the value selector is the idx or name of the selector switch that control if the heating or cooling system is active or stopped both.
    the values room1, room2 etc, are the zonenames or roomnames and can be changed
    the value after "s" is the id of the setpoint device in that room
    the value after "t" is the id of the temperature sensor in that room
    the value after "v" is the id of the radiator valve in that room (can be valvetype switch or valvetype setPoint  )
    idx are without "" and names are with ""

    Change history:
    20181012-01 Initial setup
    20181012-02 Add Season selector
    20181012-03 Add optional control for main heater / cooler device. Moved some code to functions
    20181012-04 Add optional control for main heater / cooler device
    20181013-01 Moved heater, cooler and selector idx to (JSON) uservariable
    20181014-01 Bugfixes:   defined local heating inside if block causing it to be nil. 
                            return false from open and shut function could overwrite previous true state
    20181114-01 Open and Shut also for setPoint TRV's
    20181130-01 Add On and Off Hysterisis
    20181130-02 Use internal / persistent table for systems with more than 3 rooms

]]--
return {
   	         on     = {  timer       = { "every minute" },    -- adjust to your needs
            },
             
    logging =   {   level   =   domoticz.LOG_DEBUG,        -- Comment this and the next line if script execute as expected  
                    marker  =   "zoneTemperatures" },

    data    =   {  heating  =   { initial = {}        },
                },
                
    execute = function(dz)
        -- initialize table
        t = {}
        
        openTemperature    = 28 
        closeTemperature   = 16.5
        
        local function initPersistent()
            t.heater      = 1095
            t.cooler      = 1096
            t.selector    = "Season"
            t.rooms       = {}
            t.rooms       =  {  -- Fill table below with roomNames, setPoint IDX, temp sensors IDX,and valve IDX 
                                {room="room1",s=1088,t=144,v=1093},
                                {room="room2",s=1089,t=145,v=1094},
                                {room="room3",s=1090,t=146,v=1095},
                                {room="room4",s=1091,t=147,v=1096},
                                {room="room5",s=1092,t=148,v=1097},
                             }
                             
            dz.data.heating = t
        end
        
        -- do everything :-)
        local function processRooms(t)
            local heating if t.heater ~= nil then heating = dz.devices(t.heater) end
            local cooling if t.cooler ~= nil then cooling = dz.devices(t.cooler) end
            local action if t.selector ~= nil then action  = dz.devices(t.selector).levelName else action = "Heating" end  -- defaults to "Heating"
            
            local hysteresisOn      = 0.5
            local hysteresisOff     = 0.2
            local openHeatingValves 
            local openCoolingValves 

            local function open(device) 
                if device == nil then return openHeatingValves end
                if device.deviceSubType == "SetPoint" then
                    device.updateSetPoint(openTemperature)
                else
                    device.switchOn().checkFirst()
                end
                return true
            end

            local function shut(device)
                if device == nil then return openCoolingValves end
                if device.deviceSubType == "SetPoint" then
                    device.updateSetPoint(closeTemperature)
                else
                    device.switchOff().checkFirst()
                end
            end
            
            for i=1,#t.rooms do                            -- loop trough the rooms
                local roomName      = t.rooms[i].room
                local setPoint      = dz.devices(t.rooms[i].s).setPoint
                local temperature   = dz.devices(t.rooms[i].t).temperature
                local radiatorValve = dz.devices(t.rooms[i].v)

                if  action == "Cooling" then
                    if      temperature <  setPoint                 then shut(radiatorValve)  -- stop cooling
                    elseif  temperature > ( setPoint + hysteresis ) then openCoolingValves = open(radiatorValve) end --start cooling
                elseif action == "Heating" then
                    if      temperature > ( setPoint - hysteresisOff ) then shut(radiatorValve)  -- stop heating
                    elseif  temperature < ( setPoint - hysteresisOn ) then openHeatingValves = open(radiatorValve) end --start heating
                elseif action == "Stop" then 
                    shut(cooling) shut(heating) shut(radiatorValve)
                end 
            end
            if openCoolingValves then open(cooling) else shut(cooling) end
            if openHeatingValves then open(heating) else shut(heating) end
           
        end
        
        -- Get table from init function or persistent data
        if not next(dz.data.heating) then
            initPersistent()
        else
            t = dz.data.heating
        end
        
        processRooms(t)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JvDorst
Posts: 3
Joined: Sunday 07 June 2015 16:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10363
Location: The Netherlands
Contact:

Re: thermostat for cooling and heating

Post by JvDorst »

Hi,

The developed scripts look usefull for my situation. More specific, I use the following devices 4 Popp radiator valves, 2 Honeywell radiator valves (controlled by Fibaro switches) and a thermostat (Essent e-thermostat). Next to implementing this script I want to add day/night scheme, triggering by presence switch and 24/7 temperature control of my daughter's (2 weeks old) bedroom. At this moment I just want to implement the script as added below by Waaren.

The above added plans for further developing this script are on my wish list (of course I will give an update when this is completed!). For now I created some dummy switches (temp, setpoint, etc.) to see if it works. Cooling is not relevant for me, but before removing the lines I want the script to work with dummy devices. Unfortunately I'm not managing to get it working.

Perhaps I missed something... Since this is my first step in programming/dzVents: can someone please indicate if the scipt works and which steps I have to follow?

Thanks!

waaren wrote: Friday 30 November 2018 20:13
Skippiemanz wrote: Friday 30 November 2018 17:31 Maybe anyone has a idea for the user variables limitation
Can you try this one ? (moved from JSON formatted var to internal / persistent data)

Code: Select all

--[[ 
    version: 20181130-02
    
    This script manage the different heating zones 
    
    Before making this script active you should first enter your rooms , sensors and valves indexes below in function initPersistent
    define a switch for chiller if there is a main switch
    define a switch for heater if there is a main switch
   
    the value heater is the idx or name of the main heater switch. If your system does not have this, leave it out completely
    the value cooler is the idx or name of the main cooler switch. If your system does not have this, leave it out completely. 
    the value selector is the idx or name of the selector switch that control if the heating or cooling system is active or stopped both.
    the values room1, room2 etc, are the zonenames or roomnames and can be changed
    the value after "s" is the id of the setpoint device in that room
    the value after "t" is the id of the temperature sensor in that room
    the value after "v" is the id of the radiator valve in that room (can be valvetype switch or valvetype setPoint  )
    idx are without "" and names are with ""

    Change history:
    20181012-01 Initial setup
    20181012-02 Add Season selector
    20181012-03 Add optional control for main heater / cooler device. Moved some code to functions
    20181012-04 Add optional control for main heater / cooler device
    20181013-01 Moved heater, cooler and selector idx to (JSON) uservariable
    20181014-01 Bugfixes:   defined local heating inside if block causing it to be nil. 
                            return false from open and shut function could overwrite previous true state
    20181114-01 Open and Shut also for setPoint TRV's
    20181130-01 Add On and Off Hysterisis
    20181130-02 Use internal / persistent table for systems with more than 3 rooms

]]--
return {
   	         on     = {  timer       = { "every minute" },    -- adjust to your needs
            },
             
    logging =   {   level   =   domoticz.LOG_DEBUG,        -- Comment this and the next line if script execute as expected  
                    marker  =   "zoneTemperatures" },

    data    =   {  heating  =   { initial = {}        },
                },
                
    execute = function(dz)
        -- initialize table
        t = {}
        
        openTemperature    = 28 
        closeTemperature   = 16.5
        
        local function initPersistent()
            t.heater      = 1095
            t.cooler      = 1096
            t.selector    = "Season"
            t.rooms       = {}
            t.rooms       =  {  -- Fill table below with roomNames, setPoint IDX, temp sensors IDX,and valve IDX 
                                {room="room1",s=1088,t=144,v=1093},
                                {room="room2",s=1089,t=145,v=1094},
                                {room="room3",s=1090,t=146,v=1095},
                                {room="room4",s=1091,t=147,v=1096},
                                {room="room5",s=1092,t=148,v=1097},
                             }
                             
            dz.data.heating = t
        end
        
        -- do everything :-)
        local function processRooms(t)
            local heating if t.heater ~= nil then heating = dz.devices(t.heater) end
            local cooling if t.cooler ~= nil then cooling = dz.devices(t.cooler) end
            local action if t.selector ~= nil then action  = dz.devices(t.selector).levelName else action = "Heating" end  -- defaults to "Heating"
            
            local hysteresisOn      = 0.5
            local hysteresisOff     = 0.2
            local openHeatingValves 
            local openCoolingValves 

            local function open(device) 
                if device == nil then return openHeatingValves end
                if device.deviceSubType == "SetPoint" then
                    device.updateSetPoint(openTemperature)
                else
                    device.switchOn().checkFirst()
                end
                return true
            end

            local function shut(device)
                if device == nil then return openCoolingValves end
                if device.deviceSubType == "SetPoint" then
                    device.updateSetPoint(closeTemperature)
                else
                    device.switchOff().checkFirst()
                end
            end
            
            for i=1,#t.rooms do                            -- loop trough the rooms
                local roomName      = t.rooms[i].room
                local setPoint      = dz.devices(t.rooms[i].s).setPoint
                local temperature   = dz.devices(t.rooms[i].t).temperature
                local radiatorValve = dz.devices(t.rooms[i].v)

                if  action == "Cooling" then
                    if      temperature <  setPoint                 then shut(radiatorValve)  -- stop cooling
                    elseif  temperature > ( setPoint + hysteresis ) then openCoolingValves = open(radiatorValve) end --start cooling
                elseif action == "Heating" then
                    if      temperature > ( setPoint - hysteresisOff ) then shut(radiatorValve)  -- stop heating
                    elseif  temperature < ( setPoint - hysteresisOn ) then openHeatingValves = open(radiatorValve) end --start heating
                elseif action == "Stop" then 
                    shut(cooling) shut(heating) shut(radiatorValve)
                end 
            end
            if openCoolingValves then open(cooling) else shut(cooling) end
            if openHeatingValves then open(heating) else shut(heating) end
           
        end
        
        -- Get table from init function or persistent data
        if not next(dz.data.heating) then
            initPersistent()
        else
            t = dz.data.heating
        end
        
        processRooms(t)
    end
}
Raspberry Pi 2B, AEON labs Z-wave USB, Fibaro devices (dimmers, switches, universal sensor, motion, smoke, CO), Popp thermostat valves, Honeywell radiator valves NC.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: thermostat for cooling and heating

Post by waaren »

JvDorst wrote: Sunday 27 January 2019 21:30 The developed scripts look usefull for my situation. More specific, I use the following devices 4 Popp radiator valves, 2 Honeywell radiator valves (controlled by Fibaro switches) and a thermostat (Essent e-thermostat). Unfortunately I'm not managing to get it working.
Can you please elaborate on the "not managing to get it working bit" ?

If you are not yet familiar with dzvents then please look at the 10 lines using dzVents with Domoticz for an intro to dzVents and howto get this script active in domoticz.

When you activate the script what do you see in the log ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JvDorst
Posts: 3
Joined: Sunday 07 June 2015 16:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10363
Location: The Netherlands
Contact:

Re: thermostat for cooling and heating

Post by JvDorst »

Thanks for your reply. I missed that section of the manual. At this moment I have no errors in the log and I will monitor the script for the coming days.

Still planning to further develop the script for my own purposes and in case of progress I will give an update. Now time to start learning dzVents will become my issue ;)
Raspberry Pi 2B, AEON labs Z-wave USB, Fibaro devices (dimmers, switches, universal sensor, motion, smoke, CO), Popp thermostat valves, Honeywell radiator valves NC.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest