Delayed switching  [Solved]

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

Moderator: leecollings

Post Reply
wahrens
Posts: 6
Joined: Monday 02 March 2020 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Delayed switching

Post by wahrens »

I'm looking for a solution of the following idea:

Actually i'm using a door switch to shut my heating if the door is open and the outside temperatur is less than 15° C.

Code: Select all

return {
	on = {
		devices = {
			'Tuer Wohnzimmer',
			'Zigbee Terrassentuer'
		}
	},
	execute = function(domoticz, device)
	    local WZHeat = domoticz.devices('WZ Heat')
	    local WZThermostat = domoticz.devices('WZ Thermostat');
	    local OAT = domoticz.devices('THB Darksky'); 
 	    if OAT.temperature < 15 then
    		if device.state == 'Open' then
                domoticz.log(device.name .." is now Open; setting Mode to Off")  
                WZThermostat.updateMode('Off')
                -- WZHeat.updateSetPoint(16)
            elseif device.state == 'Closed' then
                domoticz.log(device.name .." is now Closed; setting Mode to Heat " )
                WZThermostat.updateMode('Heat')
            end
        end
  end
}
This works fine, but i now look for a solution to only shut the heating if the door is not closed within 30 seconds or is open more than 30 seconds which is the same, but i dont know how to fix the timing problem.
Thanks for any idea
Matthiasfr
Posts: 17
Joined: Saturday 10 August 2019 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Delayed switching

Post by Matthiasfr »

In Lua you can request current time. As soon as the door opens you can store this time. Maybe you can use a while loop that constantly checks current time. As soon as 30s are passend, you want to go out of the loop and re evaluate if the door is still open.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Delayed switching

Post by waaren »

wahrens wrote: Monday 09 November 2020 11:49 i now look for a solution to only shut the heating if the door is not closed within 30 seconds or is open more than 30 seconds which is the same, but i dont know how to fix the timing problem.
Can you try with below script?

Code: Select all

local scriptVar = 'delayedMode'

return
{
    on =
    {
        devices =
        {
            'Tuer Wohnzimmer',
            'Zigbee Terrassentuer',
        },
        customEvents =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
        marker = scriptVar,
    },

    execute = function(dz, item)
        local WZHeat = dz.devices('WZ Heat')
        local WZThermostat = dz.devices('WZ Thermostat')
        local OAT = dz.devices('THB Darksky')
        local wohnZimmerTuer = dz.devices('Tuer Wohnzimmer')
        local terrassenTuer = dz.devices('Zigbee Terrassentuer')
        local delay = 30

        local doorOpen = wohnZimmerTuer.state == 'Open' or terrassenTuer.state == 'Open'

        if OAT.temperature < 15 then
            if item.isDevice then
                if not(doorOpen) then
                    dz.log('All doors closed; setting Mode to Heat', dz.LOG_DEBUG )
                    WZThermostat.updateMode('Heat')
                else
                    dz.log('At least one door is open. I will check again in ' .. delay .. ' seconds', dz.LOG_DEBUG)
                    dz.emitEvent(scriptVar).afterSec(delay)
                end
            elseif doorOpen then
                dz.log('At least one door is still open; setting Mode to Off')
                WZThermostat.updateMode('Off')
                -- WZHeat.updateSetPoint(16)
            else
                dz.log('No action needed. (Door closed during delay)', dz.LOG_DEBUG )
            end
        else
            dz.log('No action needed. (temperature > 15)', dz.LOG_DEBUG )
        end
  end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Matthiasfr
Posts: 17
Joined: Saturday 10 August 2019 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Delayed switching

Post by Matthiasfr »

Off course. You can simply use the delay functionality. :|
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Delayed switching

Post by waaren »

Matthiasfr wrote: Monday 09 November 2020 12:05 In Lua you can request current time. As soon as the door opens you can store this time. Maybe you can use a while loop that constantly checks current time. As soon as 30s are passend, you want to go out of the loop and re evaluate if the door is still open.
Please don't do this. It will block the domoticz eventSystem (classic Lua, dzVents and Blockly scripts) for the duration of the loop.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
wahrens
Posts: 6
Joined: Monday 02 March 2020 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Delayed switching  [Solved]

Post by wahrens »

Thanks Waaren and Matthias !

Waarens script ist working fine.

Where can i find any documentation about: dz.emitEvent
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Delayed switching

Post by waaren »

wahrens wrote: Monday 09 November 2020 12:43 Where can i find any documentation about: dz.emitEvent
This wiki page seems to be a good start..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests