Thermostat Control

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Thermostat Control

Post by emme »

Hi,

I had a look to the Thermostat_Control wiki and because it was intend to be use to maintain a certain temperature, while my need is to handle 2 different temps at different times

I'm not a professional programmer, so maybe I've used a dirty way to reach the same result... please feel free to clean the code :P :P

THE PURPUSE:
- Have my COLD bathroom maintain a minimun temperature
- Have my COLD bathroom warm on working days (Mon->Fri) in the morning

THE REQUIREMENTS:
Because I do not have a thermostat, I've used some variables for setting up temps and tollerance, while the local temperature is gathered via an Oregon Scientific probe
of course, you need also something to power on to heat the room :P

the variables used are:
Bagnetto_Debug int 0
used for debugging in the code

Bagnetto_tDelta float 0.3
temperature tollerance

Bagnetto_tMin float 18.5
Min temperature to maintain

Bagnetto_tSet float 21.7
temperature in the morning :P

THE SCRIPT (type: DEVICE)

Code: Select all

debugger = tonumber(uservariables['Bagnetto_Debug'])

tSet      = tonumber(uservariables['Bagnetto_tSet'])
tMin      = tonumber(uservariables['Bagnetto_tMin'])
tDelta    = tonumber(uservariables['Bagnetto_tDelta'])
tAct      = tonumber(devicechanged['T. Bagnetto_Temperature'])
startTime = {"6","40"}  -- Inizio T1 6:40
stopTime  = {"7","00"}  -- Fine T1 7:00

-- Acquisizione dell'orario
cTime = os.date("*t")
gTime = tonumber(os.date("%w")) -- Giorno della settimana 0-6 Domenica - Sabato

-- Conversione in decimale degli orari per la comparazione successiva
cTimeDec = (tonumber(cTime.hour) * 60) + tonumber(cTime.min)
startDec  = (tonumber(startTime[1]) * 60) + tonumber(startTime[2])
stopDec  = (tonumber(stopTime[1]) * 60) + tonumber(stopTime[2])

if debugger == 1 then
   print ('>>> [TB] DEBUG >> start/stop:'..tostring(startTime[1])..':'..tostring(startTime[2])..'/'..tostring(stopTime[1])..':'..tostring(stopTime[2])..' vs real: '..tostring(cTime.hour)..':'..tostring(cTime.min))
   print ('>>> [TB] DEBUG >> '..startDec..':'..stopDec..':'..cTimeDec)
end

commandArray = {}
    if devicechanged['T. Bagnetto'] then
        if ((gTime ~= 0) and (gTime ~= 6)) and (cTimeDec >= startDec and cTimeDec <= stopDec) then
            tUse = tSet
            pPfx = ">>> [TB] SVEGLIA >>> "
        else
            tUse = tMin
            pPfx = ">>> [TB] MINIMO >>> "
        end
        
        if (tAct < (tUse - tDelta)) and (otherdevices['Presa Bagnetto'] == 'Off') then
            commandArray['Presa Bagnetto'] = 'On'
            print (pPfx..'Temperatura Attuale/Impostata: '..tAct..'/'..tUse..' (±'..tDelta..') Accensione Caldobagno')
        elseif (tAct > (tUse + tDelta)) and (otherdevices['Presa Bagnetto'] == 'On') then
            commandArray['Presa Bagnetto'] = 'Off'
            print (pPfx..'Temperatura Attuale/Impostata: '..tAct..'/'..tUse..' (±'..tDelta..') Spegnimento Caldobagno')
        else
            if debugger == 1 then
                print ('>>> [TB] NTD >>> Temperatura Attuale/Impostata: '..tAct..'/'..tUse..' (±'..tDelta..') Nessuna Azione da intraprendere ['..otherdevices["T. Bagnetto"]..']')
            end
        end
    end
return commandArray
THE SOLUTION
I use to convert time minutes and then compare them (i found this way the easier one... having a variable set as time does not allow me to compare with present time...)

Code: Select all

startTime = {"6","40"}  -- Inizio T1 6:40
stopTime  = {"7","00"}  -- Fine T1 7:00
setting up the time frame this way allows me to better handle them in the code

this way I have the bathroom at 22° when it's time to use it and at 18 during the rest of the day
It works fine to me...

I would like to implement a physical thermostat for the min temp in the room (rfxcom433 or ZWave)... any ideas about what to use? :P :P
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Thermostat Control

Post by Egregius »

This is my solution for the bathroom:

Code: Select all

function badkamervuurb(){global $a,$s,$i,$t;
    if($s['deurbadkamer']=="Open"){
        if($s['badkamer_set']!=10&&(strtotime($t['deurbadkamer'])<eenmin||$s['lichtbadkamer']=='Off')){
            ud($i['badkamer_set'],0,10,'badkamer_set 10 deur open');
            $s['badkamer_set']=10.0;
        }
    }elseif($s['deurbadkamer']=="Closed"&&$s['heating']=='On'){
        if($s['lichtbadkamer']=='On'&&$s['badkamer_set']!=22.5){
            ud($i['badkamer_set'],0,22.5,'badkamer_set 22.5 deur dicht en licht aan');
            $s['badkamer_set']=22.5;
        }elseif($s['lichtbadkamer']=='Off'&&$s['badkamer_set']!=15){
            ud($i['badkamer_set'],0,15,'badkamer_set 15 deur dicht en licht uit');
            $s['badkamer_set']=15.0;
        }
    }
    $difbadkamer=number_format($s['badkamer_temp']-$s['badkamer_set'],1);$timebadkvuur=time-strtotime($t['badkamervuur']);
    if         ($difbadkamer<=-0.2&&$s['badkamervuur']=="Off"&&$timebadkvuur>180)sw($i['badkamervuur'],'On','badkamervuur dif = '.$difbadkamer.' was off for '.$timebadkvuur.' seconds');
    elseif($difbadkamer<=-0.1&&$s['badkamervuur']=="Off"&&$timebadkvuur>240)sw($i['badkamervuur'],'On','badkamervuur dif = '.$difbadkamer.' was off for '.$timebadkvuur.' seconds');
    elseif($difbadkamer<=    0    &&$s['badkamervuur']=="Off"&&$timebadkvuur>360)    sw($i['badkamervuur'],'On','badkamervuur dif = '.$difbadkamer.' was off for '.$timebadkvuur.' seconds');
    elseif($difbadkamer>=0&&$s['badkamervuur']=="On"&&$timebadkvuur>30)            sw($i['badkamervuur'],'Off','badkamervuur dif = '.$difbadkamer.' was on for '.$timebadkvuur.' seconds');
    elseif($difbadkamer>=-0.2&&$s['badkamervuur']=="On"&&$timebadkvuur>120)    sw($i['badkamervuur'],'Off','badkamervuur dif = '.$difbadkamer.' was on for '.$timebadkvuur.' seconds');
    elseif($difbadkamer>=-0.4&&$s['badkamervuur']=="On"&&$timebadkvuur>180)    sw($i['badkamervuur'],'Off','badkamervuur dif = '.$difbadkamer.' was on for '.$timebadkvuur.' seconds');
}
 
The dummy setpoint for the bathroom is set depending if the light is on and the door is closed.
If the setpoint is higher than the actual temperature the heater 'badkamervuur' is switched on.
If the setpopint is nearly reached some switching is done to prevent overheating.
The minimum temperature is given by a classic radiator with normal thermostatic valve set at 17°.

I don't like to schedule the heating of my bathroom. How long do you need to heat it? I take a shower in the morning somewhere between 4 and 9 am. The heater I use manages to raise the temperature 5° in 10 minutes, so by the time I get out of the shower I have a nice 22°.

What do you mean by 'physical thermostat'? How do you switch now?
If you mean a thermometer I can surely recommend the Fibaro smoke sensor for that. They are extremely fast and accurate.
Maybe a coincidence but I just took a shower and looked at my floorplan and the old 433 thermometer. The Fibaro already knew it was 22° while the old thermometer still indicated 19°.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Thermostat Control

Post by emme »

the physical thermostat is supposed to do exactely what you said: I specify that time and temp because I know I will use it...
but if I want to take a shower out of that frame I have to rise manually the temp by changing the value on the user variable for tMin.

A physical thermostat should do the same but in a much easier way... I set the new tMin... do what I need to do, move it back and exit

let's say.... my wife will not accept to change a user variable under domoticz and move it back each time she wants to have a shower :D :D :P
The most dangerous phrase in any language is:
"We always done this way"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Thermostat Control

Post by Egregius »

Can't you use a dummy setpoint for that?
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Thermostat Control

Post by emme »

It was... I moved to variables for a testing purpuse, but soon I'll move back to dummy setpoints
but this will not fix... I wish to have a physical device in place :P
The most dangerous phrase in any language is:
"We always done this way"
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Re: Thermostat Control

Post by jkimmel »

Rfxcom
Raspi 4
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Thermostat Control

Post by emme »

uuuuuuh.... you make my day!!!!!
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest