dzvents Silent() seems not to be working

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

Moderator: leecollings

broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

dzvents Silent() seems not to be working

Post by broker »

Hello,

I have a script to automatically turn on my waterpump at the moment a watergroup "asks" water, for instance druppelslang.
then the pump and the druppelslang will run for a set amount of time, and it will stop, or it has to be manually disabled.

I use silent() to overcome the script rerunning if it has been manually disabled within the time of the timer. however I see that the pump will be switched on, and I am unsure what could be causing that it is still triggered when the timer is finished?
here is my code:

Code: Select all

return {
	on = {
		devices = {
			'Waterpomp',
			'Sproeier Voor',
			'Sproeier Achter',
			'Druppelslang'
		},
	},
	data = {
	    voor_aan    = {initial='false'},
	    achter_aan  = {initial='false'},
	    druppel_aan = {initial='false'}
	},
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Waterpomp',
    },
	
	execute = function(domoticz, device)
	    --declaratie van devices
	    local pomp          = domoticz.devices('Waterpomp')
	    local sachter       = domoticz.devices('Sproeier Achter')
	    local svoor         = domoticz.devices('Sproeier Voor')
	    local druppel       = domoticz.devices('Druppelslang')

	    --Hoelang moet er gesproeid worden (in minuten)
	    local sproeitijd    = 1
	    print("stap 1: ".. device.name)
 -- silent functie gebruiken, anders gaat de pomp meteen weer uit aangezien er dan weer een state change is.
	    --help functie
	    local function schakelPomp(pomp,sproeitijd)
	        print("stap functie: ".. device.name.. " en ".. domoticz.data.druppel_aan)
	        if pomp.active == false
	           then 
	               stroeitimer = sproeitijd * 60
	               pomp.switchOn().silent()
	               pomp.switchOff().silent().afterSec(stroeitimer - 5)
	               print ("Pomp gaat aan via functie")
	       elseif pomp.active == true and (domoticz.data.voor_aan == 'false' or domoticz.data.voor_aan == nill) and (domoticz.data.achter_aan == 'false' or domoticz.data.achter_aan == nill) and (domoticz.data.druppel_aan == 'false' or domoticz.data.druppel_aan == nill) 
	           then 
	               print("stap stop functie: ".. device.name.." en ".. domoticz.data.druppel_aan)
	               pomp.switchOff().silent()
	               print("pomp gaat uit via functie")
	            end
            return self --om te testen dat het is gelukt
        end
        
	    --pomp alleen aan, let op de druk van de pomp!
	    if 
	        device.name == 'Waterpomp' and (domoticz.data.voor_aan == 'false' or domoticz.data.voor_aan == nill) and (domoticz.data.achter_aan == 'false' or domoticz.data.achter_aan == nill) and (domoticz.data.druppel_aan == 'false' or domoticz.data.druppel_aan == nill)
    	    then  
    	        device.switchOff().silent().afterMin(sproeitijd)
    	       print("pomp aan via schakelaar")
        --Sproeier in voortuin aan
        elseif 
            device.name == 'Sproeier Voor'
            then
                if device.active
                    then
                        svoor.switchOff().silent().afterMin(sproeitijd)
                        domoticz.data.voor_aan = 'true'
                        print('Voor aan')
                        schakelPomp(pomp,sproeitijd)
                        
                    else
                        domoticz.data.voor_aan = 'false'
                        schakelPomp(pomp,sproeitijd)
                        print("Voor uit")
                end
        --Sproeier in achtertuin aan        
        elseif 
            device.name == 'Sproeier Achter'
	        then 
	            if device.active
	                then
                        sachter.switchOff().silent().afterMin(sproeitijd)
                        domoticz.data.achter_aan = 'true'
                        schakelPomp(pomp,sproeitijd)
                        print("Achter aan")
                    else
                        domoticz.data.achter_aan = 'false'
                        schakelPomp(pomp,sproeitijd)
                        print("achter uit")
                end
        --Druppelslang voor en achter
        elseif 
            device.name == 'Druppelslang'
            then 
                if device.active
                    then
                        print("stap 2: ".. device.name)
                        druppel.switchOff().silent().afterMin(sproeitijd)
                        domoticz.data.druppel_aan = 'true'
                        schakelPomp(pomp,sproeitijd,domoticz.data.druppel_aan)
                        print("Druppel aan "..domoticz.data.druppel_aan)
                    else
                        print("stap 3: ".. device.name)
                        domoticz.data.druppel_aan = 'false'
                        schakelPomp(pomp,sproeitijd)
                        print("Druppel uit ".. domoticz.data.druppel_aan)
                    end
                end
	    print("*********Echo van de trigger**********")
        print(device.name)
        print("*********einde van de trigger*********")
	end
}
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

I am unsure what could be causing that it is still triggered when the timer is finished?
I have not analyzed you program logic, but "nill" should be "nil".
Maybe you can tell us what type and subtype your devices are, what values do they carry?
Edit: to clarify, if the devices are switches, then they probably have the state "On" or"Off".
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

should that not be sproeitimer?
It is a consistent typo, so no problem.
Before that: stroeitimer = sproeitijd * 60, so 60 - 5
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

the devices are z-wave sockets that are controlling a waterpump, and 3 watervalves that are powered by 24v transformers, and again to z-wave sockets.
the idea of the program is that if one area is enabled, the pump should get pumping, and if another are is added the pump should continue for the remaining time, or until the last zone has been disabled (druppelslang, sproeier_voor and sproeier_achter). after that the pump needs to shut down.

so what now happens is that the last zone is shut, the pump disables, and after the timer has ended it seems that another trigger is given, although .slient() has been used... and that does toggle the pump (to on :-() and causing to pump to run causing to to running dry.
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

What I meant is what kind of domoticz devices are they, f.e. General, Custom Sensor, or Light/Switch, Switch?
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

ah, yes, light switches (on/off)
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

Ok. Could you first change all the 'nill' in 'nil' and see what happens?
(I am trying to understand your program, but I find it hard to read other people's code. @waaren is the true master in that)
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

I did, that breaks the script... and yes I totally understand, its an art itself :)
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

that breaks the script...
Strange. What error message did you get?

What if you change the initial data? No quotes, but use really true and false?

Code: Select all

data = {
	    voor_aan    = {initial = false },
Edit: sorry, have to sign off for other urgent matters.
Last edited by plugge on Sunday 25 April 2021 16:55, edited 1 time in total.
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

there is no error, but the toggle seems to break, when it is in place as is, it seems to be working.
I will try with the real booleans, but I thought that is was not supported in dzvents...?
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

broker wrote: Sunday 25 April 2021 16:53 I thought that is was not supported in dzvents...?
It is. It is pure lua.
The reason why it works in your script, is because it is probably irrelevant.
That part of the or-statement (domoticz.data.achter_aan == nill) evaluates to 'false' except when domoticz.data.achter_aan is also 'nil').
Your 'nill' is treated as a variable that evaluates to nil since it never got a value assigned.
(really signing off now)
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

I have made some changes to the code:

Code: Select all

return {
	on = {
		devices = {
			'Waterpomp',
			'Sproeier Voor',
			'Sproeier Achter',
			'Druppelslang'
		},
	},
	data = {
	    voor_aan    = {initial= false},
	    achter_aan  = {initial= false},
	    druppel_aan = {initial= false}
	},
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Waterpomp',
    },
	
	execute = function(domoticz, device)
	    --declaratie van devices
	    local pomp          = domoticz.devices('Waterpomp')
	    local sachter       = domoticz.devices('Sproeier Achter')
	    local svoor         = domoticz.devices('Sproeier Voor')
	    local druppel       = domoticz.devices('Druppelslang')

	    --Hoelang moet er gesproeid worden (in minuten)
	    local sproeitijd    = 1
	    print("stap 1: ".. device.name)
 -- silent functie gebruiken, anders gaat de pomp meteen weer uit aangezien er dan weer een state change is.
	    --help functie
	    local function schakelPomp(pomp,tijd)
	        print("stap functie: ".. device.name.. " en ".. domoticz.data.druppel_aan)
	        if pomp.active == false
	           then 
	               stroeitimer = tijd * 60
	               pomp.switchOn().silent()
	               pomp.switchOff().silent().afterSec(stroeitimer - 5)
	               print ("Pomp gaat aan via functie")
	       elseif pomp.active == true and not domoticz.data.voor_aan and not domoticz.data.achter_aan and not domoticz.data.druppel_aan 
	           then 
	               print("stap stop functie: ".. device.name.." en ".. domoticz.data.druppel_aan)
	               pomp.switchOff().silent()
	               print("pomp gaat uit via functie")
	            end
            return self --om te testen dat het is gelukt
        end
        
	    --pomp alleen aan, let op de druk van de pomp!
	    if 
	        device.name == 'Waterpomp' and not domoticz.data.voor_aan and not domoticz.data.achter_aan and not domoticz.data.druppel_aan
    	    then  
    	        device.switchOff().silent().afterMin(sproeitijd)
    	       print("pomp aan via schakelaar")
        --Sproeier in voortuin aan
        elseif 
            device.name == 'Sproeier Voor'
            then
                if device.active
                    then
                        svoor.switchOff().silent().afterMin(sproeitijd)
                        domoticz.data.voor_aan = true
                        print('Voor aan')
                        schakelPomp(pomp,sproeitijd)
                        
                    else
                        domoticz.data.voor_aan = false
                        schakelPomp(pomp,sproeitijd)
                        print("Voor uit")
                end
        --Sproeier in achtertuin aan        
        elseif 
            device.name == 'Sproeier Achter'
	        then 
	            if device.active
	                then
                        sachter.switchOff().silent().afterMin(sproeitijd)
                        domoticz.data.achter_aan = true
                        schakelPomp(pomp,sproeitijd)
                        print("Achter aan")
                    else
                        domoticz.data.achter_aan = false
                        schakelPomp(pomp,sproeitijd)
                        print("achter uit")
                end
        --Druppelslang voor en achter
        elseif 
            device.name == 'Druppelslang'
            then 
                if device.active
                    then
                        print("stap 2a: ".. device.name)
                        druppel.switchOff().silent().afterMin(sproeitijd)
                        print("stap 2b: ".. device.name)
                        domoticz.data.druppel_aan = true
                        print("stap 2c: ".. device.name)
                        schakelPomp(pomp,sproeitijd)
                        print("Druppel aan "..domoticz.data.druppel_aan)
                    else
                        print("stap 3: ".. device.name)
                        domoticz.data.druppel_aan = false
                        schakelPomp(pomp,sproeitijd)
                        print("Druppel uit ".. domoticz.data.druppel_aan)
                    end
                end
	    print("*********Echo van de trigger**********")
        print(device.name)
        print("*********einde van de trigger*********")
	end
}
what I notice when I start debugging, is that I see that the function is not entered and that the script does not continue after that step, when I start druppelslang, I see the comments of stap 2a,2b and 2c, but not further

Code: Select all

2021-04-25 17:20:26.467 Status: User: Admin (IP: 192.168.1.21) initiated a switch command (16/Druppelslang/On)
2021-04-25 17:20:26.724 Status: dzVents: Info: Handling events for: "Druppelslang", value: "On"
2021-04-25 17:20:26.724 Status: dzVents: Info: Waterpomp: ------ Start internal script: pomp_lua_test: Device: "Druppelslang (Z-wave stick)", Index: 16
2021-04-25 17:20:26.726 Status: dzVents: Debug: Waterpomp: Processing device-adapter for Waterpomp: Switch device adapter
2021-04-25 17:20:26.726 Status: dzVents: Debug: Waterpomp: Processing device-adapter for Sproeier Achter: Switch device adapter
2021-04-25 17:20:26.727 Status: dzVents: Debug: Waterpomp: Processing device-adapter for Sproeier Voor: Switch device adapter
2021-04-25 17:20:26.727 Status: dzVents: stap 1: Druppelslang
2021-04-25 17:20:26.727 Status: dzVents: stap 2a: Druppelslang
2021-04-25 17:20:26.727 Status: dzVents: Debug: Waterpomp: Constructed timed-command: Off
2021-04-25 17:20:26.727 Status: dzVents: Debug: Waterpomp: Constructed timed-command: Off NOTRIGGER
2021-04-25 17:20:26.727 Status: dzVents: Debug: Waterpomp: Constructed timed-command: Off AFTER 60 SECONDS NOTRIGGER
2021-04-25 17:20:26.728 Status: dzVents: stap 2b: Druppelslang
2021-04-25 17:20:26.728 Status: dzVents: stap 2c: Druppelslang
2021-04-25 17:20:26.728 Status: dzVents: Info: Waterpomp: ------ Finished pomp_lua_test
2021-04-25 17:20:26.729 Status: EventSystem: Script event triggered: /home/nl18663/domoticz/dzVents/runtime/dzVents.lua
plugge

Re: dzvents Silent() seems not to be working

Post by plugge »

Hi @broker,

I got your script running in the setup that you chose.
NB: The sequence of afterMin and silent etc. is important, you can't put them just anywhere.
I changed the print statements into logWrite with a LOG_FORCE and turned off debugging, so that I have more control of what is appearing on screen (less lines). If you want you can turn on debugging level info, ofcourse
Could you try this on your system: (maybe give it adifferent name to save your script, but make your script inactive.)

Code: Select all

return {
    active = { true,
        },
	on = {
		devices = {
			'Waterpomp',
			'Sproeier Voor',
			'Sproeier Achter',
			'Druppelslang'
		},
	},
	data = {
	    voor_aan    = {initial= false},
	    achter_aan  = {initial= false},
	    druppel_aan = {initial= false}
	},
    
    logging =
    {
        level = domoticz.LOG_INFO,
        marker = 'Bewatering',
    },
	
	execute = function(domoticz, device)
	    
        local function logWrite(str,level)
            domoticz.log(str,level or domoticz.LOG_FORCE)
        end

	    
	    --declaratie van devices
	    local pomp          = domoticz.devices('Waterpomp')
	    local sachter       = domoticz.devices('Sproeier Achter')
	    local svoor         = domoticz.devices('Sproeier Voor')
	    local druppel       = domoticz.devices('Druppelslang')

	    --Hoelang moet er gesproeid worden (in minuten)
	    local sproeitijd    = 1
	    logWrite("stap 1: ".. device.name)
        
        -- silent functie gebruiken, anders gaat de pomp meteen weer uit aangezien er dan weer een state change is.
	    
	    --help functie
	    local function schakelPomp(pomp,tijd)
	        logWrite("stap functie: ".. device.name)
	        if pomp.active == false
	           then 
	               sproeitimer = sproeitijd * 60
	               pomp.switchOn().forSec(sproeitimer - 5).silent()
	               -- pomp.switchOff().silent().afterSec(sproeitimer - 5)
	               logWrite("Pomp gaat aan via functie")
	       elseif pomp.active == true and not domoticz.data.voor_aan and not domoticz.data.achter_aan and not domoticz.data.druppel_aan 
	           then 
	               logWrite("stap stop functie: ".. device.name)
	               pomp.switchOff().silent()
	               logWrite("pomp gaat uit via functie")
	            end
            return self --om te testen dat het is gelukt
        end
        
	    --pomp alleen aan, let op de druk van de pomp!
	    if device.name == 'Waterpomp' and 
	       (not domoticz.data.voor_aan) and 
	       (not domoticz.data.achter_aan) and 
	       (not domoticz.data.druppel_aan)
    	then  
    	   device.switchOff().afterMin(sproeitijd).silent()
    	   logWrite("pomp aan via schakelaar")

        --Sproeier in voortuin aan
        elseif device.name == 'Sproeier Voor'
        then
            if device.state == 'On'
            then
                svoor.switchOff().afterMin(sproeitijd).silent()
                domoticz.data.voor_aan = true
                logWrite('Sproeier Voor aan')
                schakelPomp(pomp,sproeitijd)
            else
                domoticz.data.voor_aan = false
                schakelPomp(pomp,sproeitijd)
                print("Sproeier Voor uit")
            end
        --Sproeier in achtertuin aan        
        elseif device.name == 'Sproeier Achter'
	        then 
	            if device.active
	            then
                    sachter.switchOff().afterMin(sproeitijd).silent()
                    domoticz.data.achter_aan = true
                    schakelPomp(pomp,sproeitijd)
                    logWrite("Sproeier Achter aan")
                else
                    domoticz.data.achter_aan = false
                    schakelPomp(pomp,sproeitijd)
                    logWrite("Sproeier Achter uit")
                end
        --Druppelslang voor en achter
        elseif device.name == 'Druppelslang'
            then 
                if device.active
                then
                    logWrite("stap 2a: ".. device.name)
                    druppel.switchOff().afterMin(sproeitijd).silent()
                    logWrite("stap 2b: ".. device.name)
                    domoticz.data.druppel_aan = true
                    logWrite("stap 2c: ".. device.name)
                    schakelPomp(pomp,sproeitijd)
                    if domoticz.data.druppel_aan
                    then
                        logWrite('Druppel aan Sproeitijd='..sproeitijd)
                    else
                        logWrite('Druppel uit Sproeitijd ='..sproeitijd)
                    end
                else
                    logWrite("stap 3: ".. device.name)
                    domoticz.data.druppel_aan = false
                    schakelPomp(pomp,sproeitijd)
                    logWrite("Druppel uit ")
                end
            end
	    logWrite('Last device triggering = '..device.name)
	end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Silent() seems not to be working

Post by waaren »

plugge wrote: Sunday 25 April 2021 23:29 NB: The sequence of afterMin and silent etc. is important, you can't put them just anywhere.
'
as long as the action ( switchOff(), switchOn(), dimTo() etc.. ) is first, the order of the options does not matter.

Code: Select all

dz.devices('bla').switchOn().silent().checkFirst().afterSec(23) 
is equivalent to

Code: Select all

dz.devices('bla').switchOn().checkFirst().afterSec(23).silent()


@broker. looking at your script it is not clear to me why you need to keep the state of your hose switches in persistent data. You can determine the current state without that. Is this for a future requirement?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

plugge wrote: Sunday 25 April 2021 23:29 Hi @broker,

I got your script running in the setup that you chose.
NB: The sequence of afterMin and silent etc. is important, you can't put them just anywhere.
I changed the print statements into logWrite with a LOG_FORCE and turned off debugging, so that I have more control of what is appearing on screen (less lines). If you want you can turn on debugging level info, ofcourse
Could you try this on your system: (maybe give it adifferent name to save your script, but make your script inactive.)

Code: Select all

return {
    active = { true,
        },
	on = {
		devices = {
			'Waterpomp',
			'Sproeier Voor',
			'Sproeier Achter',
			'Druppelslang'
		},
	},
	data = {
	    voor_aan    = {initial= false},
	    achter_aan  = {initial= false},
	    druppel_aan = {initial= false}
	},
    
    logging =
    {
        level = domoticz.LOG_INFO,
        marker = 'Bewatering',
    },
	
	execute = function(domoticz, device)
	    
        local function logWrite(str,level)
            domoticz.log(str,level or domoticz.LOG_FORCE)
        end

	    
	    --declaratie van devices
	    local pomp          = domoticz.devices('Waterpomp')
	    local sachter       = domoticz.devices('Sproeier Achter')
	    local svoor         = domoticz.devices('Sproeier Voor')
	    local druppel       = domoticz.devices('Druppelslang')

	    --Hoelang moet er gesproeid worden (in minuten)
	    local sproeitijd    = 1
	    logWrite("stap 1: ".. device.name)
        
        -- silent functie gebruiken, anders gaat de pomp meteen weer uit aangezien er dan weer een state change is.
	    
	    --help functie
	    local function schakelPomp(pomp,tijd)
	        logWrite("stap functie: ".. device.name)
	        if pomp.active == false
	           then 
	               sproeitimer = sproeitijd * 60
	               pomp.switchOn().forSec(sproeitimer - 5).silent()
	               -- pomp.switchOff().silent().afterSec(sproeitimer - 5)
	               logWrite("Pomp gaat aan via functie")
	       elseif pomp.active == true and not domoticz.data.voor_aan and not domoticz.data.achter_aan and not domoticz.data.druppel_aan 
	           then 
	               logWrite("stap stop functie: ".. device.name)
	               pomp.switchOff().silent()
	               logWrite("pomp gaat uit via functie")
	            end
            return self --om te testen dat het is gelukt
        end
        
	    --pomp alleen aan, let op de druk van de pomp!
	    if device.name == 'Waterpomp' and 
	       (not domoticz.data.voor_aan) and 
	       (not domoticz.data.achter_aan) and 
	       (not domoticz.data.druppel_aan)
    	then  
    	   device.switchOff().afterMin(sproeitijd).silent()
    	   logWrite("pomp aan via schakelaar")

        --Sproeier in voortuin aan
        elseif device.name == 'Sproeier Voor'
        then
            if device.state == 'On'
            then
                svoor.switchOff().afterMin(sproeitijd).silent()
                domoticz.data.voor_aan = true
                logWrite('Sproeier Voor aan')
                schakelPomp(pomp,sproeitijd)
            else
                domoticz.data.voor_aan = false
                schakelPomp(pomp,sproeitijd)
                print("Sproeier Voor uit")
            end
        --Sproeier in achtertuin aan        
        elseif device.name == 'Sproeier Achter'
	        then 
	            if device.active
	            then
                    sachter.switchOff().afterMin(sproeitijd).silent()
                    domoticz.data.achter_aan = true
                    schakelPomp(pomp,sproeitijd)
                    logWrite("Sproeier Achter aan")
                else
                    domoticz.data.achter_aan = false
                    schakelPomp(pomp,sproeitijd)
                    logWrite("Sproeier Achter uit")
                end
        --Druppelslang voor en achter
        elseif device.name == 'Druppelslang'
            then 
                if device.active
                then
                    logWrite("stap 2a: ".. device.name)
                    druppel.switchOff().afterMin(sproeitijd).silent()
                    logWrite("stap 2b: ".. device.name)
                    domoticz.data.druppel_aan = true
                    logWrite("stap 2c: ".. device.name)
                    schakelPomp(pomp,sproeitijd)
                    if domoticz.data.druppel_aan
                    then
                        logWrite('Druppel aan Sproeitijd='..sproeitijd)
                    else
                        logWrite('Druppel uit Sproeitijd ='..sproeitijd)
                    end
                else
                    logWrite("stap 3: ".. device.name)
                    domoticz.data.druppel_aan = false
                    schakelPomp(pomp,sproeitijd)
                    logWrite("Druppel uit ")
                end
            end
	    logWrite('Last device triggering = '..device.name)
	end
}
thanks! I loaded the script in, and it works again, however if I disable before the end of the timer, the pump switches on again. what did you change that the function is correctly called again?
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

waaren wrote: Monday 26 April 2021 0:52
plugge wrote: Sunday 25 April 2021 23:29 NB: The sequence of afterMin and silent etc. is important, you can't put them just anywhere.
'
as long as the action ( switchOff(), switchOn(), dimTo() etc.. ) is first, the order of the options does not matter.

Code: Select all

dz.devices('bla').switchOn().silent().checkFirst().afterSec(23) 
is equivalent to

Code: Select all

dz.devices('bla').switchOn().checkFirst().afterSec(23).silent()


@broker. looking at your script it is not clear to me why you need to keep the state of your hose switches in persistent data. You can determine the current state without that. Is this for a future requirement?
Hello Waaren,

the idea is that if one or more valves are enabled, this wil start the pump and will disable the valves and pump (minus 5 sec), meaning that if the last valve has been disabled, it needs to shut down the pump. the pump needs to continue when at least one valve is on, even if the other valves are turned on or of. hence that I read that they all need to be disabled before shutting down the pump.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Silent() seems not to be working

Post by waaren »

broker wrote: Monday 26 April 2021 8:54 the idea is that if one or more valves are enabled, this wil start the pump and will disable the valves and pump (minus 5 sec), meaning that if the last valve has been disabled, it needs to shut down the pump. the pump needs to continue when at least one valve is on, even if the other valves are turned on or of. hence that I read that they all need to be disabled before shutting down the pump.
OK.

Can you have a look at this one (without the need for persistent data)

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Waterpomp',
            'Sproeier Voor',
            'Sproeier Achter',
            'Druppelslang',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Waterpump',
    },
    
    execute = function(dz, device) 
        local waterpump = dz.devices('Waterpomp')
        local backGardenSprinkler = dz.devices('Sproeier Achter')
        local frontGardenSprinkler = dz.devices('Sproeier Voor')
        local dripperHose = dz.devices('Druppelslang')

        local spraytime = 1 
        
        local function hosesActive()
            local activeHoses = backGardenSprinkler.active and 1 or 0 
            activeHoses = activeHoses + ( frontGardenSprinkler.active and 1  or 0 ) 
            activeHoses = activeHoses + ( dripperHose.active and 1  or 0 )
            return activeHoses
        end
 
        local function switchWaterpump( sprayMinutes )
            if not(sprayMinutes) then 
                dz.log('All hoses closed. Stop waterpump now', dz.LOG_DEBUG)
                waterpump.switchOff().checkFirst().silent()
                
            else
                local delay = sprayMinutes * 60 - 5
                waterpump.cancelQueuedCommands()
                waterpump.switchOn().checkFirst().silent()
                waterpump.switchOff().silent().afterSec(delay)
                dz.log('Switching waterpump On for ' .. delay .. ' seconds ', dz.LOG_DEBUG)
            end
        end

        if device == waterpump and device.active then 
            if hosesActive() > 0 then  
                device.switchOff().silent().afterMin(spraytime)
                dz.log('One or more hoses active. Stop waterpump after ' .. spraytime .. ' minutes', dz.LOG_DEBUG )
            else
                switchWaterpump()
            end
            return
        end

        if device.active then
            device.switchOff().silent().afterSec(spraytime * 60)
            dz.log('Switching ' .. device.name .. ' Off after ' .. spraytime .. ' minutes', dz.LOG_DEBUG )
            switchWaterpump( spraytime )
        elseif hosesActive() == 0 then 
            switchWaterpump()
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

waaren wrote: Monday 26 April 2021 9:36
broker wrote: Monday 26 April 2021 8:54 the idea is that if one or more valves are enabled, this wil start the pump and will disable the valves and pump (minus 5 sec), meaning that if the last valve has been disabled, it needs to shut down the pump. the pump needs to continue when at least one valve is on, even if the other valves are turned on or of. hence that I read that they all need to be disabled before shutting down the pump.
OK.

Can you have a look at this one (without the need for persistent data)

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Waterpomp',
            'Sproeier Voor',
            'Sproeier Achter',
            'Druppelslang',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Waterpump',
    },
    
    execute = function(dz, device) 
        local waterpump = dz.devices('Waterpomp')
        local backGardenSprinkler = dz.devices('Sproeier Achter')
        local frontGardenSprinkler = dz.devices('Sproeier Voor')
        local dripperHose = dz.devices('Druppelslang')

        local spraytime = 1 
        
        local function hosesActive()
            local activeHoses = backGardenSprinkler.active and 1 or 0 
            activeHoses = activeHoses + ( frontGardenSprinkler.active and 1  or 0 ) 
            activeHoses = activeHoses + ( dripperHose.active and 1  or 0 )
            return activeHoses
        end
 
        local function switchWaterpump( sprayMinutes )
            if not(sprayMinutes) then 
                dz.log('All hoses closed. Stop waterpump now', dz.LOG_DEBUG)
                waterpump.switchOff().checkFirst().silent()
                
            else
                local delay = sprayMinutes * 60 - 5
                waterpump.cancelQueuedCommands()
                waterpump.switchOn().checkFirst().silent()
                waterpump.switchOff().silent().afterSec(delay)
                dz.log('Switching waterpump On for ' .. delay .. ' seconds ', dz.LOG_DEBUG)
            end
        end

        if device == waterpump and device.active then 
            if hosesActive() > 0 then  
                device.switchOff().silent().afterMin(spraytime)
                dz.log('One or more hoses active. Stop waterpump after ' .. spraytime .. ' minutes', dz.LOG_DEBUG )
            else
                switchWaterpump()
            end
            return
        end

        if device.active then
            device.switchOff().silent().afterSec(spraytime * 60)
            dz.log('Switching ' .. device.name .. ' Off after ' .. spraytime .. ' minutes', dz.LOG_DEBUG )
            switchWaterpump( spraytime )
        elseif hosesActive() == 0 then 
            switchWaterpump()
        end

    end
}
Hello Waaren, yes that solved that the pump will not enable if the valves are shut within the time frame. now I am not able to let the pump run on itself if it needs to be primed, what needs to happen every now and then... ooow it feels that we are soow close :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents Silent() seems not to be working

Post by waaren »

broker wrote: Monday 26 April 2021 10:18 Now I am not able to let the pump run on itself if it needs to be primed, what needs to happen every now and then.
How often does this happen and for how long does the pump need to run in that situation?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
broker
Posts: 19
Joined: Friday 08 January 2016 14:57
Target OS: Linux
Domoticz version: 2020.2
Contact:

Re: dzvents Silent() seems not to be working

Post by broker »

waaren wrote: Monday 26 April 2021 10:35
broker wrote: Monday 26 April 2021 10:18 Now I am not able to let the pump run on itself if it needs to be primed, what needs to happen every now and then.
How often does this happen and for how long does the pump need to run in that situation?
It depends on how much air there is in the suction pipe.
at least twice, three time a year.

otherwise I could also disable the script for that moment.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest