Page 1 of 1

Script to update temp set points

Posted: Wednesday 16 January 2019 6:51
by svanni
New to this forum, thanks for having me.

Also newly transitioned from Vera to Domoticz / Raspberry Pi, and have some basic knowledge of lua.

I have two thermostats, so there are 4 setpoints (heat & cool) to regularly update via Domoticz.
Currently I update uservariables with the setpoint values at every XX:00:00.
I then use lua timer scripts to load these values into the thermostats at every XX:01:00, XX:02:00, XX:03:00, and XX:04:00.
This is done because my thermostats don't like all 4 setpoint values blasted to them simultaneously.

Can somebody suggest a lua script that can tighten up this process from 4 minutes to...let's say 20 seconds...like this:
XX:00:00 - Update uservariables
XX:00:05 - Update Cool SetPoint (east unit)
XX:00:10 - Update Heat SetPoint (east unit)
XX:00:15 - Update Cool SetPoint (west unit)
XX:00:20 - Update Heat SetPoint (west unit)

(FYI: Vera had a delayed function call which was quite handy in this scenario...luup.call_delay("function",5)...where 5 was a delay in SECONDS)

Thank you in advance for any suggestions/recommendations.

Re: Script to update temp set points

Posted: Wednesday 16 January 2019 11:34
by Egregius
With pass2php you would just need to add a sleep(3) for seconds or a usleep(100000) for microseconds.

Re: Script to update temp set points

Posted: Wednesday 16 January 2019 11:47
by waaren
svanni wrote: Wednesday 16 January 2019 6:51 I have two thermostats, so there are 4 setpoints (heat & cool) to regularly update via Domoticz.
Currently I update uservariables with the setpoint values at every XX:00:00.
I then use lua timer scripts to load these values into the thermostats at every XX:01:00, XX:02:00, XX:03:00, and XX:04:00.
This is done because my thermostats don't like all 4 setpoint values blasted to them simultaneously.
Can somebody suggest a lua script that can tighten up this process from 4 minutes to...let's say 20 seconds.
Can you please share your current Lua script(s) here ? That would help to help you.

Script to update temp set points

Posted: Wednesday 16 January 2019 13:31
by mvzut
I don't fully understand what you're trying to do. Why are you putting setpoints in user variables and updating your Domoticz thermostats with them every hour? Why don't you use timers for instance?

By the way, you can do delayed switching in LUA using the AFTER command. The following turns a switch off after 1 minute:

Code: Select all

commandArray ['Some switch'] = 'Off AFTER 60'
I was expecting something similar to be possible with setpoints, but

Code: Select all

 commandArray['SetSetPoint:'..otherdevices_idx['Your thermostat']] = '19 AFTER 60'
doesn't seem to produce the desired result... Maybe a nice future feature for Domoticz...

Re: Script to update temp set points

Posted: Wednesday 16 January 2019 17:54
by svanni
Thank you for your replies.
Here is the current script:
commandArray = {}
local cool = tostring(math.max(uservariables['HVAC Cool SP'] + uservariables['Temperature Adjustment'],22))
local heat = tostring(math.min(uservariables['HVAC Heat SP'] + uservariables['Temperature Adjustment'],23))

if os.date("%M")%60 == 1 then commandArray['UpdateDevice'] = tostring('41|0|'..cool) -- East Cool
elseif os.date("%M")%60 == 2 then commandArray['UpdateDevice'] = tostring('40|0|'..heat) -- East Heat
elseif os.date("%M")%60 == 3 then commandArray['UpdateDevice'] = tostring('68|0|'..cool) -- West Cool
elseif os.date("%M")%60 == 4 then commandArray['UpdateDevice'] = tostring('67|0|'..heat)
-- West Heat
end
return commandArray
This would be a great solution, if it worked:
commandArray['SetSetPoint:'..otherdevices_idx['Your thermostat']] = '19 AFTER 60'

Re: Script to update temp set points

Posted: Wednesday 16 January 2019 22:34
by waaren
svanni wrote: Wednesday 16 January 2019 17:54 Thank you for your replies.
This would be a great solution, if it worked:

Code: Select all

commandArray['SetSetPoint:'..otherdevices_idx['Your thermostat']] = '19 AFTER 60'
Please have a look at the dzVents script below and make sure you read and understand the comment lines about prerequisites

When not yet familiar with dzVents please start with reading the quick start of the wiki
Before implementing.

Code: Select all

--[[

        -- delayedSetPoints.lua    
        
        !!    Please note that afterSec(), afterMin() and afterHour() is available for the 
        !!    updateSetPoint function for standard Thermostat setpoint devices (not for Evohome or Zwave yet)
        !!    in domoticz version V4.10360 (dzVents 2.4.10) or later.
        
        When not yet familiar with dzVents please start with reading 
        
        https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting#Using_dzVents_with_Domoticz

        Before implementing. Special attention please for 
        "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

]]--

return {
            on = { devices = { "at *:01" }},    
   
   execute = function(dz, item)
        local adjustment  =  dz.variables("Temperature Adjustment").value 
        local cool        =  math.max(dz.variables("HVAC Cool SP").value + adjustment,22)
        local heat        =  math.min(dz.variables("HVAC Heat SP").value + adjustment,23)
  
        dz.devices(41).updateSetPoint(cool)
        dz.devices(40).updateSetPoint(heat).afterMin(1)
        dz.devices(67).updateSetPoint(cool).afterMin(2)
        dz.devices(68).updateSetPoint(heat).afterMin(3)
       
   end
}

Re: Script to update temp set points

Posted: Thursday 17 January 2019 0:09
by svanni
Waaren,
This is great, thank you for the info.
I suspected this might go the route of DZVents.
I'll give this a test tonight.
Thanks again.

Re: Script to update temp set points

Posted: Thursday 17 January 2019 5:47
by Egregius
So you'll gonna change the script to tighten up the time from 4 minutes to... 4 minutes?

Re: Script to update temp set points

Posted: Thursday 17 January 2019 8:53
by waaren
Egregius wrote: Thursday 17 January 2019 5:47 So you'll gonna change the script to tighten up the time from 4 minutes to... 4 minutes?
Possible. But also to 4 hours.. and yes, 4 seconds would be possible as well. As described in the comments of this example; afterSec(), afterMin(), afterHour() options are available with most recent Beta's in combination with dzVents 2.4.10