Page 1 of 1

Insert delay option in script?

Posted: Thursday 23 December 2021 10:51
by njlammerts
I have a bathroom with a door and a window. Both have a open/close detection switch.
I made a Blockly script with a dummy switch to heat (CV5=Zigbee Radiator Valve) the bathroom when door and window are closed. When one of them is open, the "Badkamer" button switches of after 0.5 sec. After enabling, the dummy switch lights up and goes off again if the closed door/room condition is not closed.

Schermafbeelding 2021-12-23 om 10.37.17.png
Schermafbeelding 2021-12-23 om 10.37.17.png (100.62 KiB) Viewed 2715 times

If I walk in/out the bathroom the heating is switched off, because of the switch rule.

Is there a way to build in a kind of delay that keeps this scene enabled if the open/close door is < 10sec, so I can walk in and out again to fetch something without the script to stop. If the door is left open for >10sec it means it is open permanently and script should turn off

Re: Insert delay option in script?

Posted: Thursday 23 December 2021 15:41
by madpatrick
You can check this dzventz script. viewtopic.php?p=257729#p257729
I think this answers your question

For me it is working perfectly and you can customize it easily.

Re: Insert delay option in script?

Posted: Thursday 23 December 2021 16:28
by njlammerts
Thanks for the reply, but I I would like it implemented in Blockly
My Programm skills are not great and Blockly is for me an easy way to get things working

Re: Insert delay option in script?

Posted: Thursday 23 December 2021 17:15
by madpatrick
Blocky is user friendly, but limited in functionality

Dzvents is very powerful and once you tried it will get understandable.
Also there is some support on the forum to help

Post your complete Blocky and i’ll check if i can help

Re: Insert delay option in script?

Posted: Saturday 25 December 2021 21:36
by BennY
With Blockly you have everything you need for most House Automation, except calculation...

I think you are looking for this?

Re: Insert delay option in script?

Posted: Sunday 26 December 2021 11:52
by madpatrick
You could try this as an example

Check the variable (local) names if this matches your setting

Code: Select all

local scriptVersion = 'Versie 1.00'
local scriptVar     = '-=# Badkamer #=-'
local ContactDoor   = 'Badkamer Door'  
local ContactWindow = 'Badkamer Windows'  
local Thermostat    = 'Badkamer'

return
{
    active   = true,
    on       = {
                devices         = {ContactDoor,ContactWindow},

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

    execute = function(dz, item)

        local delay = 10
        local temp = dz.devices(Thermostat)
        local door = dz.devices(ContactDoor)
        local windows = dz.devices(ContactWindow)

        if temp.state == "On" and (door.state =="On" or window.state =="On") then
            if window.lastUpdate.secondsAgo or door.lastUpdate.secondsAgo >= delay then
                dz.log('Last update Sensors : ' .. door.lastUpdate.secondsAgo .. ' and ' .. window.lastUpdate.secondsAgo, dz.LOG_FORCE)
                dz.log('Badkamer temperaure set to 5°C ', dz.LOG_FORCE)
                temp.setpoint(5)
            else
                dz.log('Nothing to do' , dz.LOG_FORCE)
            end
    end
end
}

Re: Insert delay option in script?

Posted: Monday 27 December 2021 15:21
by kuifje
njlammerts,

You can also use an user variable.
When the door and the window are closed then set the user variable to 1.
When one of them is open set user variable to 0.
When zero then badkamer is off.

Kuifje
Badkamer.JPG
Badkamer.JPG (56.69 KiB) Viewed 2589 times

Re: Insert delay option in script?

Posted: Friday 28 January 2022 17:05
by njlammerts
BennY wrote: Saturday 25 December 2021 21:36 With Blockly you have everything you need for most House Automation, except calculation...

I think you are looking for this?
Im am told that "Nested Commands". can not be used?
Schermafbeelding 2022-01-28 om 17.04.11.png
Schermafbeelding 2022-01-28 om 17.04.11.png (257.3 KiB) Viewed 2418 times

Re: Insert delay option in script?

Posted: Friday 28 January 2022 17:11
by jvdz
njlammerts wrote: Friday 28 January 2022 17:05 Im am told that "Nested Commands". can not be used?
Guess you mean Nested IF commands as the shown blockly doesn't have any nested commands and only a one level If- ELSEIF. ;)
The AND OR logic could be a little bit tricky though.

Re: Insert delay option in script?

Posted: Friday 28 January 2022 17:16
by njlammerts
I mean

....................AF-badkamer
........and
...............or. AF badkamer door
....................AF Badkamer window

I am repeating the command for AF badkamer door and AF badkamer windows

Re: Insert delay option in script?

Posted: Saturday 05 February 2022 11:47
by njlammerts
Sorry for the late reply, but the suggestions displayed above is not what I mean/want.

I have a window and door switch in the bathroom. When they both are open, I want the radiator valve in the bathroom to be closed, even if the temperature sensor "says" heat the bathroom. Only when window and door are closed and temperature sensor is below the set value, I want the radiator valve to open, so the bathroom can be heated with a script.

In my script the bathroom is heated when both window and door are closed. But when the bathroom door is opened, the script is set to "close valve" , even when you only walk in and out within 10-20 sec. I would like a delay in the door sensor, that leaves the script "running" when the door is opened for less the 10-20 sec (so the valve/script won't close). When the door is opened longer then I assume the door is "normal" open and should the valve close/script end

Re: Insert delay option in script?

Posted: Friday 11 February 2022 9:11
by BennY
njlammerts wrote: Saturday 05 February 2022 11:47 In my script the bathroom is heated when both window and door are closed. But when the bathroom door is opened, the script is set to "close valve" , even when you only walk in and out within 10-20 sec. I would like a delay in the door sensor, that leaves the script "running" when the door is opened for less the 10-20 sec (so the valve/script won't close). When the door is opened longer then I assume the door is "normal" open and should the valve close/script end
That is what the blockly do, i Made for you on 25.12. You need a Dummy Switch for your delayed door. Then you use the Dummy instead your door Switch.

Benny