Thanks!
After a bit of playing I think I got it the way I wanted. I do not want the event to trigger every minute or so, only when something changes.
I have created a user variable "recordTemp" to keep track of the last temperature change done. The challenge is that I have two interfaces to change the temperature of the zone: via the TRV on a wall tablet and via the Evohome display console. What I wanted to for them to keep in sync and display the same information. This is what I have done (in case someone finds it useful):
1.- Create a user variable "recordTemp" float number as we will need decimal points.
2.- Create two dzVents scripts, one to handle the changes via the TRV interface and one to handle the changes via the Evohome display.
Code for the TRV handler:
Code: Select all
--[[
TRV handler
]]--
return {
on = { devices = { 'Downstairs Thermostat'} }, -- EvoHome trigger
execute = function(domoticz, Thermostat)
local DownTRV = Thermostat.setPoint
local oldTemp = domoticz.variables('recordTempDown').value
if DownTRV ~= oldTemp and domoticz.variables('updateBusy').value == 0 then
domoticz.variables('updateBusy').set(1) -- I'm busy
local myZone = domoticz.devices('Downstairs') -- EvoHome Slave
local untilDateTime = os.date("!%Y-%m-%dT%TZ",os.time()+7200) -- current time + 2 hours
myZone.updateSetPoint(DownTRV,"TemporaryOverride",untilDateTime)
domoticz.variables('recordTempDown').set(DownTRV)
print ("************ SETPOINT Evohome zone " .. myZone.name .. " to: " .. DownTRV .. " , until: " .. untilDateTime .. " *******")
domoticz.variables('updateBusy').set(0) -- Not busy anymore
end
end
}
and code for the Evohome display hadler:
Code: Select all
--[[
Evohome handler
]]--
return {
on = { devices = { 'Downstairs'} }, -- EvoHome trigger
execute = function(domoticz, Thermostat)
local DownEV = Thermostat.setPoint
local oldTemp1 = domoticz.variables('recordTempDown').value
if DownEV ~= oldTemp1 and domoticz.variables('updateBusy').value == 0 then
domoticz.variables('updateBusy').set(1) -- I'm busy
domoticz.devices('Downstairs Thermostat').updateSetPoint(DownEV)
domoticz.variables('recordTempDown').set(DownEV)
print ("***************** TRV Down UPDATED!! to: " ..DownEV.." ********************")
domoticz.variables('updateBusy').set(0) -- Not busy anymmore
end
end
}
This way, it stops the scripts chasing each other. I also had to create a integer variable "updateBusy" as I noticed that both scripts were launched almost at the same time; and it created some conflicts while one was working on it by having the other doing changes at the same time.
So far so good!
The only thing I notice is that from time to time without any kind of action I get this (maybe once, twice or even three times in a row):
2018-04-01 18:00:57.983 dzVents: Info: Handling events for: "Downstairs", value: "15.50;16.50;TemporaryOverride;2018-04-01T18:56:00"
2018-04-01 18:00:57.983 dzVents: Info: ------ Start internal script: DownstairsThermoUpdate: Device: "Downstairs (Evohome)", Index: 630
2018-04-01 18:00:57.984 dzVents: Info: ------ Finished DownstairsThermoUpdate
2018-04-01 18:00:57.984 dzVents: Info: ------ Start internal script: VirtulaHallTemp: Device: "Downstairs (Evohome)", Index: 630
2018-04-01 18:00:57.986 dzVents: Info: ------ Finished VirtulaHallTemp
2018-04-01 18:00:57.994 EventSystem: Script event triggered: /home/pi/domosense/scripts/dzVents/runtime/dzVents.lua
I think it probably has to do with messages arriving from the Evohome as I have it connected via USB which trigger the check. I need to check the wiki if there's a way to run the script only on changes rather than anything happening. -- Pretty powerful dzVents!