I'm trying to write a simple scripy with Blocky to switch of the heating when the door is open.
Unfortunately Blocky doesn't the functionality to set the heatingpoint with a UserVariable.
Can somebody help me with this or help with some programming in LUA or Dzvent
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
madpatrick wrote: ↑Tuesday 06 October 2020 18:54
Hi,
I'm trying to write a simple scripy with Blocky to switch of the heating when the door is open.
Unfortunately Blocky doesn't the functionality to set the heatingpoint with a UserVariable.
Can somebody help me with this or help with some programming in LUA or Dzvent
Something like this?
btw. I used dzVents persistent data to save the setPoint. Let me know if you really need in a domoticz uservariable.
return
{
on =
{
devices =
{
'Sensor - Achterdeur', -- Did I set the spaces in the name OK?
},
},
data =
{
lastSetpoint =
{
initial = -99,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all OK
marker = 'Heating control',
},
execute = function(dz, item)
local toon = dz.devices('Toon Thermostaat')
dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
if item.state == 'Open' and dz.data.lastSetpoint == -99 then
dz.data.lastSetpoint = toon.setPoint
toon.updateSetPoint(15)
elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
toon.updateSetPoint(dz.data.lastSetpoint)
dz.data.lastSetpoint = -99
end
end
}
madpatrick wrote: ↑Wednesday 07 October 2020 9:31
The script works great !!
I also like to have timer of 10 seconds before the heating is set off when the door is open
That complicates it a bit because the last time I checked afterSec() did not work for setting a thermostat. To work around that I added a customEvents trigger.
local scriptVar = 'heatingControl'
local doorContact = 'Sensor - Achterdeur' -- Did I set the spaces in the name OK?
return
{
on =
{
devices =
{
doorContact,
},
customEvents =
{
scriptVar,
},
},
data =
{
lastSetpoint =
{
initial = -99,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all OK
marker = scriptVar,
},
execute = function(dz, item)
local delay = 10
local toon = dz.devices('Toon Thermostaat')
local door = dz.devices(doorContact)
if item.isDevice then
dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
if item.state == 'Open' and dz.data.lastSetpoint == -99 then
dz.emitEvent(scriptVar).afterSec(delay)
elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
toon.updateSetPoint(dz.data.lastSetpoint)
dz.data.lastSetpoint = -99
end
else
if door.state == 'Open' and dz.data.lastSetpoint == -99 then
dz.data.lastSetpoint = toon.setPoint
toon.updateSetPoint(15)
end
end
end
}
Small question: If the door/window is still open and "somebody or a scheduled task" will change set point on thermostat, what could be done to reinforce the value again to 15°C?
I tryed like that but without success with another elseif:
execute = function(dz, item)
local delay = 10
local toon = dz.devices('Toon Thermostaat')
local door = dz.devices(doorContact)
if item.isDevice then
dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
if item.state == 'Open' and dz.data.lastSetpoint == -99 then
dz.emitEvent(scriptVar).afterSec(delay)
elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
toon.updateSetPoint(dz.data.lastSetpoint)
dz.data.lastSetpoint = -99
end
else
if door.state == 'Open' and dz.data.lastSetpoint == -99 then
dz.data.lastSetpoint = toon.setPoint
toon.updateSetPoint(15)
elseif door.state == 'Open' and toon.setPoint ~= 16 then
dz.log('!!!DEBUG only, when last elseif was called' , dz.LOG_DEBUG)
toon.updateSetPoint(15)
end
end