Page 1 of 1

Need help in diagnosing a script

Posted: Wednesday 26 February 2020 9:18
by darkdude
Hello,

I need some help in diagnosing a script.

In my setup when a pump is turned on, waterflow readings are being sent to Domoticz every second. They are fed to a waterflow sensor and a variable (as I could not get dzVents or Blockly to work with the sensor). I need a script to check the waterflow around 20 seconds after the pump was started. If it's too low, a safety switch should be triggered. My script looks like this:

Code: Select all

return {

	on = {	variables = {"pompa_zbiornika_przeplyw"},
	   
	data = { count = { initial = 0 }
	   
	    },
 
 
   execute = function(domoticz, _)
	    
       local przeplyw = domoticz.variables("pompa_zbiornika_przeplyw").value
       local pompa = domoticz.devices("POMPA ZBIORNIKA").state

       if (pompa == "On")  then
       
           domoticz.data.count = domoticz.data.count + 1
        
       
       elseif (pompa ~= "On") then
       
           domoticz.data.count = 0 
         
       end     
        
       if  (domoticz.data.count >= 20 ) then 
        
           if (przeplyw >= 0 and przeplyw <= 5 and pompa == 'On' ) then 
	
	      domoticz.devices("BLOKADA POMPY ZBIORNIKA").switchOn().checkFirst()
              domoticz.data.count = 0 
              
           elseif (przeplyw > 5 and przeplyw < 22 and  pompa == 'On' ) then 
		 
	      domoticz.devices("BRUDNY FILTR ZBIORNIKA").switchOn().checkFirst()
	      domoticz.data.count = 0 
	      
          end
        end
     end  
}
}
It doesn't report any errors, however it's never triggered. I get constant info on the log that the variable was updated, however the script does not run. Updating the waterflow variable manually also does not trigger the script.

Regards, darkdude

Re: Need help in diagnosing a script

Posted: Wednesday 26 February 2020 10:01
by waaren
darkdude wrote: Wednesday 26 February 2020 9:18 I need some help in diagnosing a script.
It doesn't report any errors, however it's never triggered. I get constant info on the log that the variable was updated, however the script does not run. Updating the waterflow variable manually also does not trigger the script.
You made a small mistake misplacing one of the }

To prevent such easy made mistakes you could use an approach where you align all opening and closing ones at the same column.

Code: Select all

return 
{
    on = 
    {    
        variables = 
        {
            "pompa_zbiornika_przeplyw",
        },
    },
    
    data = 
    { 
        count = 
        { 
            initial = 0, 
        },
    },
     
     logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'waterflow',
    },
 
   execute = function(domoticz)
        
       local przeplyw = domoticz.variables("pompa_zbiornika_przeplyw").value
       local pompa = domoticz.devices("POMPA ZBIORNIKA").state

       if pompa == "On"  then
           domoticz.data.count = domoticz.data.count + 1
       else
           domoticz.data.count = 0 
       end     
        
        if  (domoticz.data.count >= 20 ) then 
            if (przeplyw >= 0 and przeplyw <= 5 and pompa == 'On' ) then 
                domoticz.devices("BLOKADA POMPY ZBIORNIKA").switchOn().checkFirst()
                domoticz.data.count = 0 
            elseif (przeplyw > 5 and przeplyw < 22 and  pompa == 'On' ) then 
                domoticz.devices("BRUDNY FILTR ZBIORNIKA").switchOn().checkFirst()
                domoticz.data.count = 0 
            end
        end
     end  
}

Re: Need help in diagnosing a script  [Solved]

Posted: Wednesday 26 February 2020 11:40
by darkdude
Thanks!