Page 1 of 1

script for controlling Essent (ICY) Thermostat

Posted: Sunday 08 November 2015 12:36
by JuanUil
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

Re: script for controlling Essent (ICY) Thermostat

Posted: Thursday 12 November 2015 19:45
by Siewert308SW
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




Re: script for controlling Essent (ICY) Thermostat

Posted: Friday 13 November 2015 8:51
by JuanUil
Yes script is working fine with me at home.
But I admid I could have and should have pointed out where users have to put their own data in.
Thnx for adjusting the script.

Jan

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 09 March 2016 0:31
by djgodlike
Sorry for my ignorance but i made a dummy 'Vaste Temperatuur' and have a correct working dummy 'IemandThuis'.
Is the dummy 'Vaste Temperatuur' or 'Thermostaat Dummy Switch' needed for the script to work? I dont see an IDX of this dummy in the script.. ?

Can someone explain the exact dummy's connected to this script, and how they are called?

Ive marked my uncertainties.. Sorry i'm new to lua..

Code: Select all

   
       setpoint = tonumber(otherdevices_svalues['E-thermostaat'])
    werkelijk = tonumber(otherdevices_svalues['Kamer Temperatuur'])
   
       commandArray ['Vaste Temperatuur']= 'Off'                                   No IDX?
 
       commandArray ['Vaste Temperatuur']= 'On'
 
Update: The script seems to work fine to 20C and when away to 15C! What does the dummy 'Vaste Temperatuur' or 'Thermostaat Dummy Switch' do?

An error occurs: 2016-03-09 11:02:00.453 Error: EventSystem: in script_device_Thermostaat.lua: [string " -- ~/domoticz/scripts/lua/script_device_Ther..."]:62: attempt to index global 'devicechanged' (a nil value)

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 06 April 2016 11:19
by JuanUil
Hi There,

the dummy switch vaste temp is ment to prevent the thermostat to go to nighttemp when he sees no movement for 2 hours

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 27 December 2017 3:17
by sander
Hello, anyone, is there a Json command to set ''vaste temperatuur'' on a icy thermostat? I am not handy with Lua yet and would just like to enforce this setting in some cases.
Thanks in advance.

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 03 January 2018 10:32
by g00fy
I think everything you need is in here: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s.

Something like json.htm?type=command&param=udevice&idx=<idx>&nvalue=0&svalue=<temperatuur>?

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 19 December 2018 20:37
by eevolute
Hello,

I have implemented this script and it seems to work, however i'm wondering something: The value 'setpoint' that is read from and written to the thermostat idx. This idx in my case is the hardware device type 'icy thermostat' i created in hardware setiings and this polls from the icy-e online server using login/password. However, ICY has announced that this service will stop (or continue as a paid service) on 1-2-2019. Am I missing something here or will this mean the script will stop functioning then as the value cannot be polled anymore?

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 19 December 2018 20:39
by eevolute
Hello,

I have implemented this script with some schedule changes, and it seems to work, but i'm wondering something: the value 'setpoint' that is read from and written to the thermostat idx. This idx in my case is the hardware device of type 'icy thermostat' i created in hardware setiings, and this polls from the icy-e online server using login/password. However, ICY has announced that this service will stop (or continue as a paid service) on 1-2-2019. Am I missing something here or will this mean the script will stop functioning then as the value cannot be polled anymore?

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 19 December 2018 20:39
by jvdz

Re: script for controlling Essent (ICY) Thermostat

Posted: Wednesday 19 December 2018 20:46
by eevolute
Ah, thank you Jos. That is unfortunate, as you pointed out there is no known way of connecting to the thermostat locally at this point. Maybe we should ask ICY..