control heating with doorsensor  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

control heating with doorsensor

Post by madpatrick »

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

Image
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: control heating with doorsensor

Post by waaren »

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

Image
Something like this?
btw. I used dzVents persistent data to save the setPoint. Let me know if you really need in a domoticz uservariable.

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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: control heating with doorsensor

Post by madpatrick »

Hi Waanen,

Thank you very much for your swift reply and support

I don't need a uservariable, but i thought this is the way to store the setpoint.
The script works great !!


I also like to have timer of 10 seconds before the heating is set off when the door is open
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: control heating with doorsensor

Post by waaren »

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.

Can you try this?

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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: control heating with doorsensor  [Solved]

Post by madpatrick »

Hi Waaren,

This is also working !
I'll tested it the next days more in detail

Thanks very much for your effort !
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
MJAvH
Posts: 2
Joined: Saturday 25 April 2020 1:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: control heating with doorsensor

Post by MJAvH »

Hi Waaren,

Thank you for your script, also works for me! :)

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:

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
Thx for your advice
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest