JuanUil wrote:Hi there,
I have made a script to controll my Essent Thermostat.
It controlls the temperature on time for weekdays and weekends.
But it also switches to nighttemperature after 1.5 hour as we are away.
and back to daytemperature when we come home between certain hours
The dummyswitch Thuis is controlled by pinging both mine and my wifes telephone.
You have to set your thermostat to vaste temperatuur, it then overrides the program of the thermostat itself.
Any comment is welcome!
Enjoy...
Code: Select all
-- ~/domoticz/scripts/lua/script_device_Thermostaat.lua
-- deze functie berekend de verstreken tijd
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
-- bepalen dag, tijd, setpoint en kamertemperatuur
dag = tostring(os.date("%a"));
uur = tonumber(os.date("%H"));
min = tonumber(os.date("%M"));
setpoint = tonumber(otherdevices_svalues['Room Setpoint'])
werkelijk= tonumber(otherdevices_svalues['Room Temperature'])
-- Temperatuur instellingen
dagtemperatuur = uservariables["dagtemperatuur"]
nachttemperatuur = uservariables["nachttemperatuur"]
vorstbeveiliging = uservariables["vorstbeveiliging"]
commandArray = {}
-- Bepaling werkweek of weekend
if (dag=='Sun' or dag=='Mon' or dag=='Tue' or dag=='Wed' or dag=='Thu') then
werkweek = true; weekend = false
elseif (dag=='Fri' or dag=='Sat') then
werkweek = false ; weekend = true
end
-- Als we thuis zijn temperatuur instellen volgens een schema
if (otherdevices['Thuis']=='On') then
-- Dagtemperatuur instellen voor werkdagen en weekend
if (werkweek and dag ~= 'Sun'and uur==7 and min>=0 and min<2 and setpoint<dagtemperatuur) then
setpoint=dagtemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
elseif ((weekend or dag=='Sun')and uur==8 and min>=0 and min<2 and setpoint<dagtemperatuur) then
setpoint=dagtemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
end
-- Nachttemperatuur instellen voor werkdagen en weekend
if (werkweek and uur==22 and min>=30 and min<32 and setpoint>nachttemperatuur) then
setpoint=nachttemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
elseif (weekend and uur==23 and min>=30 and min<32 and setpoint>nachttemperatuur) then
setpoint=nachttemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
end
end
-- Als we thuiskomen temp aanpassen
-- Thuis = dagtemperatuur
if (devicechanged['Thuis']=='On' and uur >8 and uur<24 and setpoint<dagtemperatuur) then
setpoint=dagtemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
commandArray ['Vaste temperatuur']= 'Off'
end
-- om 1 uur 's-nachts controleren of nachttempteratuur daadwerkelijk is ingeschakeld
if (uur==1 and setpoint~=nachttemperatuur) then
setpoint=nachttemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
end
-- Thermostaat naar nachttemperatuur als 1,5 uur niemand thuis is
-- tijdsduur voor schakelen van de thermostaat (tijd in seconden)
timeon2 = 5400
if (otherdevices['Thuis']=='Off') then
difference = timedifference(otherdevices_lastupdate['Thuis'])
if (difference > timeon2 and difference < (timeon2 + 60) and setpoint~=nachttemperatuur) then
setpoint=nachttemperatuur
set = "6|0|" .. setpoint
commandArray ['UpdateDevice']= '6|0|' .. setpoint
commandArray ['Vaste temperatuur']= 'On'
end
end
return commandArray
Grtz Jan
Script look great but are you sure it works?
I mean, the script when i use it isn't setting the new setpoint if needed.
Amended a little bit and now it does set a new setpoint when needed.
Just a little tip, some more information/details on what to change or create for users who don't have the knowledge would be handy.
Had to look how you wrote it and what i needed to create.
Compare my amended script to yours...
Code: Select all
-- ~/domoticz/scripts/lua/script_device_Thermostaat.lua
-- deze functie berekend de verstreken tijd
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
-- bepalen dag, tijd, setpoint en kamertemperatuur
dag = tostring(os.date("%a"));
uur = tonumber(os.date("%H"));
min = tonumber(os.date("%M"));
setpoint = tonumber(otherdevices_svalues['Thermostaat Setpoint'])
werkelijk = tonumber(otherdevices_svalues['Kamer Temperatuur'])
-- Temperatuur instellingen
dagtemperatuur = uservariables["dagtemperatuur"]
nachttemperatuur = uservariables["nachttemperatuur"]
vorstbeveiliging = uservariables["vorstbeveiliging"]
local idx = 95 --IDX is de idx van je E-Thermostaat device
commandArray = {}
-- Bepaling werkweek of weekend
if (dag=='Sun' or dag=='Mon' or dag=='Tue' or dag=='Wed' or dag=='Thu') then
werkweek = true; weekend = false
elseif (dag=='Fri' or dag=='Sat') then
werkweek = false ; weekend = true
end
-- Als we thuis zijn temperatuur instellen volgens een schema
if (otherdevices['Iemand Thuis']=='On') then
-- Dagtemperatuur instellen voor werkdagen en weekend
if (werkweek and dag ~= 'Sun'and uur==7 and min>=0 and min<2 and setpoint<dagtemperatuur) then
setpoint=dagtemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
elseif ((weekend or dag=='Sun')and uur==8 and min>=0 and min<2 and setpoint<dagtemperatuur) then
setpoint=dagtemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
end
-- Nachttemperatuur instellen voor werkdagen en weekend
if (werkweek and uur==22 and min>=30 and min<32 and setpoint>nachttemperatuur) then
setpoint=nachttemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
elseif (weekend and uur==23 and min>=30 and min<32 and setpoint>nachttemperatuur) then
setpoint=nachttemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
end
end
-- Als we thuiskomen temp aanpassen
-- Thuis = dagtemperatuur
if (devicechanged['Iemand Thuis']=='On' and uur >8 and uur<24 and setpoint<dagtemperatuur) then
setpoint=dagtemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
commandArray ['Thermostaat Dummy Switch']= 'Off'
end
-- om 1 uur 's-nachts controleren of nachttempteratuur daadwerkelijk is ingeschakeld
if (uur==1 and setpoint~=nachttemperatuur) then
setpoint=nachttemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
end
-- Thermostaat naar nachttemperatuur als 1,5 uur niemand thuis is
-- tijdsduur voor schakelen van de thermostaat (tijd in seconden)
timeon2 = 5400
if (otherdevices['Iemand Thuis']=='Off') then
difference = timedifference(otherdevices_lastupdate['Iemand Thuis'])
if (difference > timeon2 and difference < (timeon2 + 60) and setpoint~=nachttemperatuur) then
setpoint=nachttemperatuur
commandArray['UpdateDevice'] = idx .. '|0|' .. tostring(setpoint)
commandArray ['Thermostaat Dummy Switch']= 'On'
end
end
return commandArray
Setup:
- DS923+ Docker
Domoticz Latest Stable
Mosquitto / ZwaveJSUI @ Aeotec Z-Stick Gen5+ / PiHole Unbound
P1 USB Gas/Power, HW watermeter
- A lot of Zwave switches, contacts, plugs, smoke/Co2 ect
- DiY 7.5kWh Solar Storage @
GitHuB