control heating with doorsensor
Posted: Tuesday 06 October 2020 18:54
Open source Home Automation System
https://forum.domoticz.com/
Something like this?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
![]()
Code: Select all
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
}
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.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
Code: Select all
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
}
Code: Select all
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