Set Temp with LUA for Devolo thermostat

Moderator: leecollings

Post Reply
bullrin
Posts: 38
Joined: Friday 29 January 2016 22:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4403
Location: Germany/BW/Mannheim
Contact:

Set Temp with LUA for Devolo thermostat

Post 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?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post 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.
bullrin
Posts: 38
Joined: Friday 29 January 2016 22:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4403
Location: Germany/BW/Mannheim
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post by bullrin »

Unfortunetaly this did not help :(
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post by jvdz »

Shouldn't that be:

Code: Select all

commandArray['UpdateDevice']='26|0|23'   -- Idx | 0 | temp
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
bullrin
Posts: 38
Joined: Friday 29 January 2016 22:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4403
Location: Germany/BW/Mannheim
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post by bullrin »

Oh dear! I thought there must stand the device name... Great that works!

Now im looking for a good sleep/wait function
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
bullrin
Posts: 38
Joined: Friday 29 January 2016 22:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4403
Location: Germany/BW/Mannheim
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post 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
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post by jvdz »

Code: Select all

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

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
bullrin
Posts: 38
Joined: Friday 29 January 2016 22:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4403
Location: Germany/BW/Mannheim
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post by bullrin »

I really should read the whole page here https://www.domoticz.com/wiki/Events :roll: :roll: :roll: ;)

Thank you very much!
bullrin
Posts: 38
Joined: Friday 29 January 2016 22:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4403
Location: Germany/BW/Mannheim
Contact:

Re: Set Temp with LUA for Devolo thermostat

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest