Page 1 of 1

Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 15:00
by bullrin
Hi,

starting with my first LUA script, but it is not working as it should.
For taking a shower I want to create a script which will set the temperature of the thermostat in the bathroom on 23°C for 30minutes.
I'm using Devolo thermostats which are equal to danfoss thermostats.
The name of the thermostat is 'Heizung Bad' and the idx is 26.

Here is my script:

Code: Select all

commandArray = {}

local clock = os.clock
function sleep(n)  -- seconds
   local t0 = clock()
   while clock() - t0 <= n do
   end
end

print ("All based event fired");
-- loop through all the devices
for deviceName,deviceValue in pairs(otherdevices) do
    
    
    if (deviceName == 'Jetzt Duschen') then
        if deviceValue == "On" then
            print("Bad heizen auf 23 Grad")
            commandArray['Heizung Bad']='26|0|23' -- Idx | 0 | temp
            sleep(1800) -- 30min warm
            commandArray['Heizung Bad']='17'
            commandArray['Jetzt Duschen']='Off'
            print("Duschen fertig! Heizung aus!")
        end
end

return commandArray
First problem is, the sleep method is not working, because I'm getting errors in the log
"Lua script execution exceeds maximum number of lines"

ok turning it off for testing...
But setting the tempeature to 23degree is also not working. Nothing changes on the thermostat.
idx is 26 on the devicelist and the name is "Heizung Bad"

Could you please help me?

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 15:04
by Egregius
Not sure, but try it with 23.0 instead of 23
I think that's the case when you use JSON, could be the same for lua.

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 18:17
by bullrin
Unfortunetaly this did not help :(

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 18:24
by jvdz
Shouldn't that be:

Code: Select all

commandArray['UpdateDevice']='26|0|23'   -- Idx | 0 | temp
Jos

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 19:31
by bullrin
Oh dear! I thought there must stand the device name... Great that works!

Now im looking for a good sleep/wait function

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 19:36
by jvdz
You don't want to use a sleep function in the event scripts as the event system would become unresponsive during that period.
You could set up a dummy switch and switch that on for 30 minutes and set the temp to the correct level when the dummy switch is switched On or Off.

Jos

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 19:41
by bullrin
In blockly that was easy to do. But how to set the dummy switch to on for a specific time? I have already created a dummy switch

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 20:01
by jvdz

Code: Select all

commandArray['Jetzt Duschen']='On FOR 30'
Should do it. :)

Jos

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 20:04
by bullrin
I really should read the whole page here https://www.domoticz.com/wiki/Events :roll: :roll: :roll: ;)

Thank you very much!

Re: Set Temp with LUA for Devolo thermostat

Posted: Sunday 07 February 2016 21:15
by bullrin
Finally got it!

If someone is interested in it:

Code: Select all

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

-- Duschen
idxBad = 26
duschTemp = 23.0
afterDuschTemp = 17.0
duschZeit = 30 * 60 -- 30min
puffer = 120 -- sekunden
if (otherdevices['Jetzt Duschen'] == "On" and tonumber(otherdevices_svalues['Heizung Bad']) < duschTemp) then
    
    commandArray['UpdateDevice']= string.format("%.1f|0|%.1f", idxBad, duschTemp)  -- Idx | 0 | temp
    commandArray['Jetzt Duschen']= string.format("Off AFTER %d", duschZeit) -- nach 30 min schalter aus
    
-- Duschen vorbei
else if (otherdevices['Jetzt Duschen'] == "Off" and 
            tonumber(otherdevices_svalues['Heizung Bad']) == duschTemp and 
            timedifference(otherdevices_lastupdate['Jetzt Duschen']) < puffer ) then 
            -- damit bei manueller eingabe von 23 grad nicht automatisch runtergeregelt wird,
            -- wird geprüft ob der schalter gerade erst ausgeschalten wurde ( 2min puffer)
    
    commandArray['UpdateDevice']= string.format("%.1f|0|%.1f", idxBad, afterDuschTemp)
    
end