Page 1 of 1

What is wrong in this script, i think i see over it

Posted: Thursday 20 August 2020 17:18
by hoeby
I made this script for my blinds.
I doesn't give an error, but it doesn't work like i hoped

It has to read the value of a variable, named 'OudersRolluikStore'. This is an integer
The script starts with reading the value of the blind and write this in de variable.
I have done this, because the remote send 5 commands when i push it 1 time. Otherwise the script runs 5 times, because the blind starts to move and the value is already changed. (i hope you understand what i mean)

The UP part works, but that is basci

Code: Select all

  if dz.devices(Afstandsbediening_O).level == 10 then -- UP
	            if debug then
	                print ('Openen van rolluik: '..Rolluik_OL..'.')
	            end
	        dz.devices(Rolluik_OL).dimTo(50)
	        dz.devices(Rolluik_OR).dimTo(50)
	    end
But as soon as i need to read the "VariableOname" then something goes wrong, because nothing happens. But i don't see
When i copy the final command to the top (before "VariableOname" is needed) then control works.
So i know the remote works and part of the script works.

PS, don't ask why i called the blinds as shutter :oops: (typo)

Code: Select all

local Afstandsbediening_O = 'Zigbee_Remote_PapaMama'
local Rolluik_OL          = 'Shutter_Ouders_Links'
local Rolluik_OR          = 'Shutter_Ouders_Rechts'
local VariableOname       = 'OudersRolluikStore'
local SetValueFirstPush_O = 98
local SetCloseValue_O     = 99

local debug = true

return {
	on = {
		devices = {
		    Afstandsbediening_O,
			
		}
	},
	execute = function(dz, device)

--[[  OSRAM Smart+ Switch selector values

      0  = Off
      10 = Up
      20 = Up: Hold
      30 = Up: Release
      40 = Circle: Click
      50 = Circle: Hold
      60 = Circle: Release
      70 = Down
      80 = Down: Hold
      90 = Down: Release
      
]]--


-- Instellingen voor Ouders remote rolluik control	    
	    
	    if dz.variables(VariableOname).value == 1000 then
	        local valueO = dz.devices(Rolluik_OL).level
	        if debug then
	            print (valueO)
	        end
	            dz.variables(VariableOname).set(valueO)
	            if debug then
	                dz.variables(VariableOname).set(1000).afterSec(30)
	            else
	                dz.variables(VariableOname).set(1000).afterSec(5)
	            end
        end
        
        local SetValueFirstPush_Omin1 = SetValueFirstPush_O - 1
	    
	    if dz.devices(Afstandsbediening_O).level == 70 then -- Down
	        if debug then
	            print ('Sluiten van rolluik: '..Rolluik_OL..'.')
	        end
	            if dz.variables(VariableOname).value <= 100 and dz.variables(VariableOname).value >= SetValueFirstPush_O then
	            if debug then
                        print ('Waarde ligt tussen de '..SetValueFirstPush_O..' en 100.')
                    end
	                dz.devices(Rolluik_OL).dimTo(SetCloseValue_O)
	                dz.devices(Rolluik_OR).dimTo(100)
	         
	            elseif dz.variables(VariableOname).value <= SetValueFirstPush_Omin1 and dz.variables(VariableOname).value >= 80 then
                    if debug then
                        print ('Waarde ligt tussen de 80 en '..SetValueFirstPush_Omin1..'.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetCloseValue_O).afterSec(15)
	         
	            elseif dz.variables(VariableOname).value <= 79 and dz.variables(VariableOname).value >= 60 then
                    if debug then
                        print ('Waarde ligt tussen de 60 en 79.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetCloseValue_O).afterSec(20)
	         
	            elseif dz.variables(VariableOname).value <= 59 and dz.variables(VariableOname).value >= 40 then
                    if debug then
                        print ('Waarde ligt tussen de 40 en 59.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetCloseValue_O).afterSec(25)
                
                elseif dz.variables(VariableOname).value <= 39 and dz.variables(VariableOname).value >= 1 then
	                if debug then
                        print ('Waarde ligt tussen de 1 en 39.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetCloseValue_O).afterSec(30)
	                
	            elseif dz.variables(VariableOname).value == 0 then
	                if debug then
                        print ('Waarde is 0.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetCloseValue_O).afterSec(30)
	                 
	            end
	    end
	    
	    if dz.devices(Afstandsbediening_O).level == 10 then -- UP
	            if debug then
	                print ('Openen van rolluik: '..Rolluik_OL..'.')
	            end
	        dz.devices(Rolluik_OL).dimTo(50)
	        dz.devices(Rolluik_OR).dimTo(50)
	    end
	    
        if  dz.devices(Afstandsbediening_O).level == 0 then -- CIRCLE
	            if debug then
	                print ('Selector 0, Met 1 klik volledig openen van rolluik: '..Rolluik_OL..', geen ventilatie stand.')
	            end
	            if dz.variables(VariableOname).value <= 101 and dz.variables(VariableOname).value >= SetValueFirstPush_O then 
	                if debug then
                        print ('Waarde ligt tussen de '..SetValueFirstPush_O..' en 100.')
                    end
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O)
	         
	            elseif dz.variables(VariableOname).value <= SetValueFirstPush_Omin1 and dz.variables(VariableOname).value >= 80 then
                    if debug then
                        print ('Waarde ligt tussen de 80 en '..SetValueFirstPush_Omin1..'.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(15)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(15)
	         
	            elseif dz.variables(VariableOname).value <= 79 and dz.variables(VariableOname).value >= 60 then
                    if debug then
                        print ('Waarde ligt tussen de 60 en 79.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(20)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(20)
	         
	            elseif dz.variables(VariableOname).value <= 59 and dz.variables(VariableOname).value >= 40 then
                    if debug then
                        print ('Waarde ligt tussen de 40 en 59.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(25)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(25)
             
                elseif dz.variables(VariableOname).value <= 39 and dz.variables(VariableOname).value >= 1 then
                    if debug then
                        print ('Waarde ligt tussen de 1 en 39.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(30)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(30)
	                
	            elseif dz.variables(VariableOname).value == 0 then
                    if debug then
                        print ('Waarde is 0.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(30)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(30)
	                
	            end
	    end
	    
	    if  dz.devices(Afstandsbediening_O).level == 40 then -- CIRCLE
	            if debug then
	                print ('Selector 40, Met 1 klik volledig openen van rolluik: '..Rolluik_OL..', geen ventilatie stand.')
	            end
	            if dz.variables(VariableOname).value <= 101 and dz.variables(VariableOname).value >= SetValueFirstPush_O then
	                if debug then
                        print ('Waarde ligt tussen de '..SetValueFirstPush_O..' en 100.')
                    end
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O)
	         
	            elseif dz.variables(VariableOname).value <= SetValueFirstPush_Omin1 and dz.variables(VariableOname).value >= 80 then
                    if debug then
                        print ('Waarde ligt tussen de 80 en '..SetValueFirstPush_Omin1..'.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(15)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(15)
	         
	            elseif dz.variables(VariableOname).value <= 79 and dz.variables(VariableOname).value >= 60 then
                    if debug then
                        print ('Waarde ligt tussen de 60 en 79.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(20)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(20)
	         
	            elseif dz.variables(VariableOname).value <= 59 and dz.variables(VariableOname).value >= 40 then
                    if debug then
                        print ('Waarde ligt tussen de 40 en 59.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(25)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(25)
             
                elseif dz.variables(VariableOname).value <= 39 and dz.variables(VariableOname).value >= 1 then
                    if debug then
                        print ('Waarde ligt tussen de 1 en 39.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(30)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(30)
	               
	            elseif dz.variables(VariableOname).value == 0 then
                    if debug then
                        print ('Waarde is 0.')
                    end
                    dz.devices(Rolluik_OL).dimTo(100)
                    dz.devices(Rolluik_OR).dimTo(100)
	                dz.devices(Rolluik_OL).dimTo(SetValueFirstPush_O).afterSec(30)
	                dz.devices(Rolluik_OR).dimTo(SetValueFirstPush_O).afterSec(30)     
	            end
	    end
   end
}

Re: What is wrong in this script, i think i see over it

Posted: Thursday 20 August 2020 20:50
by waaren
hoeby wrote: Thursday 20 August 2020 17:18 I made this script for my blinds.
I doesn't give an error, but it doesn't work like i hoped
What do you see in the log and what do you expect to see in the log?

Re: What is wrong in this script, i think i see over it

Posted: Thursday 20 August 2020 20:53
by hoeby
In the log it just executes, no error.
But the blinds are not moving.

It looks like it can't read the variable.
When i remove the variable read function and fill in fixed numbers, then it works

Re: What is wrong in this script, i think i see over it

Posted: Thursday 20 August 2020 21:24
by waaren
hoeby wrote: Thursday 20 August 2020 20:53 In the log it just executes, no error.
But the blinds are not moving.

It looks like it can't read the variable.
When i remove the variable read function and fill in fixed numbers, then it works
I understand you don't get errors but you have a whole bunch of debug statements. Without sharing what they write in the log it will be too difficult for others to help you.
Also add some debug lines to show the content of the variable , immediate after reading the variable.

Re: What is wrong in this script, i think i see over it

Posted: Thursday 20 August 2020 22:15
by hoeby
I added the debug rows in the script.
The row to set the variable is in the top of the script, but it updates the variable when the script is finished

Could this be a difference in hardware, that could caused this?
I was first running this script on a Pi3B+, and from what i can remember, it worked without issues there.
Now it runs on a Pi4 (8gb) and i noticed this behavior.
Both where running the last buster (27-5-2020) and the last stable (2022.2)

Must i make 2 scripts?
One which sets the variable and start the other script which reads the value and does something with it.

Code: Select all

2020-08-20 22:02:25.197 Status: User: Admin initiated a switch command (131/Zigbee_Remote_M/Set Level)
2020-08-20 22:02:25.373 Status: dzVents: Info: Handling events for: "Zigbee_Remote_M", value: "Down"
2020-08-20 22:02:25.373 Status: dzVents: Info: ------ Start internal script: Rolluik-M-test: Device: "Zigbee_Remote_M (Zigbee2MQTT)", Index: 131
2020-08-20 22:02:25.374 Status: dzVents: Dit is de huidige stand van rolluik met naam Shutter_M: 73
2020-08-20 22:02:25.374 Status: dzVents: Wat is value van VariableMname met naam MRolluikStore alvorens updaten: 1000.
2020-08-20 22:02:25.374 Status: dzVents: Wat is value van VariableMname met naam MRolluikStore na updaten: 1000.
2020-08-20 22:02:25.374 Status: dzVents: Selector 70, Sluiten van rolluik: Shutter_M.
2020-08-20 22:02:25.374 Status: dzVents: Selector 70, VariableMname met naam MRolluikStore is 1000.
2020-08-20 22:02:25.374 Status: dzVents: Info: ------ Finished Rolluik-M-test
2020-08-20 22:02:25.375 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-08-20 22:02:25.398 Status: Set UserVariable MRolluikStore = 73
2020-08-20 22:02:55.386 Status: Set UserVariable MRolluikStore = 1000
2020-08-20 22:03:00.258 Status: dzVents: Info: ------ Start internal script: 
The code with the added debug rows

Code: Select all

local Afstandsbediening_M = 'Zigbee_Remote_M'
local Rolluik_M           = 'Shutter_M'
local VariableMname       = 'MRolluikStore'
local SetValueFirstPush_M = 98
local SetCloseValue_M     = 99

local debug = true

return {
	on = {
		devices = {
		    Afstandsbediening_M,
			
		}
	},
	execute = function(dz, device)

--[[  OSRAM Smart+ Switch selector values

      0  = Off
      10 = Up
      20 = Up: Hold
      30 = Up: Release
      40 = Circle: Click
      50 = Circle: Hold
      60 = Circle: Release
      70 = Down
      80 = Down: Hold
      90 = Down: Release
      
]]--


-- Instellingen voor M remote rolluik control	    
	    local VarValue = dz.variables(VariableMname).value
	    
	    if dz.variables(VariableMname).value == 1000 then
	        local valueM = dz.devices(Rolluik_M).level
	        if debug then
	            print ('Dit is de huidige stand van rolluik met naam '..Rolluik_M..': '..valueM..'.')
	            print ('Wat is value van VariableMname met naam '..VariableMname..' alvorens updaten: '..VarValue..'.')
	        end
	            dz.variables(VariableMname).set(valueM)
	            if debug then
                    dz.variables(VariableMname).set(1000).afterSec(30)
                    print ('Wat is value van VariableMname met naam '..VariableMname..' na updaten: '..VarValue..'.')
                else    
                    dz.variables(VariableMname).set(1000).afterSec(5)
                    print ('Wat is value van VariableMname met naam '..VariableMname..' na updaten: '..VarValue..'.')
                end
        end

        local SetValueFirstPush_Mmin1 = SetValueFirstPush_M - 1
        
	    if dz.devices(Afstandsbediening_M).level == 70 then -- Down
	        if debug then
	            print ('Selector 70, Sluiten van rolluik: '..Rolluik_M..'.')
	            print ('Selector 70, VariableMname met naam '..VariableMname..' is '..VarValue..'.')
	        end
	            if dz.variables(VariableMname).value <= 100 and dz.variables(VariableMname).value >= SetValueFirstPush_M then
	                if debug then
                        print ('Waarde ligt tussen de '..SetValueFirstPush_M..' en 100.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
	                dz.devices(Rolluik_M).dimTo(SetCloseValue_M)
	         
	            elseif dz.variables(VariableMname).value <= SetValueFirstPush_Mmin1 and dz.variables(VariableMname).value >= 80 then
                    if debug then
                        print ('Waarde ligt tussen de 80 en '..SetValueFirstPush_Mmin1..'.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetCloseValue_M).afterSec(15)
	         
	            elseif dz.variables(VariableMname).value <= 79 and dz.variables(VariableMname).value >= 60 then
                    if debug then
                        print ('Waarde ligt tussen de 60 en 79.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetCloseValue_M).afterSec(20)
	         
	            elseif dz.variables(VariableMname).value <= 59 and dz.variables(VariableMname).value >= 40 then
                    if debug then
                        print ('Waarde ligt tussen de 40 en 59.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetCloseValue_M).afterSec(25)
                
                elseif dz.variables(VariableMname).value <= 39 and dz.variables(VariableMname).value >= 1 then
                    if debug then
                        print ('Waarde ligt tussen de 1 en 39.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetCloseValue_M).afterSec(30)
	            
	            elseif dz.variables(VariableMname).value == 0 then
                    if debug then
                        print ('Waarde ligt is 0.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetCloseValue_M).afterSec(30)    
	                 
	            end
	    end
	    
	    if dz.devices(Afstandsbediening_M).level == 10 then -- UP
	            if debug then
	                print ('Openen van rolluik: '..Rolluik_M..'.')
	                print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
	            end
	        dz.devices(Rolluik_M).dimTo(0)
	    end
	    
        if  dz.devices(Afstandsbediening_M).level == 0 then -- CIRCLE
	            if debug then
	                print ('Selector 0, Met 1 klik volledig openen van rolluik: '..Rolluik_M..', geen ventilatie stand.')
	                print ('Selector 0, VariableMname met naam '..VariableMname..' is '..VarValue..'.')
	            end
	            if dz.variables(VariableMname).value <= 101 and dz.variables(VariableMname).value >= SetValueFirstPush_M then 
	                if debug then
                        print ('Waarde ligt tussen de '..SetValueFirstPush_M..' en 100.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M)
	         
	            elseif dz.variables(VariableMname).value <= SetValueFirstPush_Mmin1 and dz.variables(VariableMname).value >= 80 then
                    if debug then
                        print ('Waarde ligt tussen de 80 en '..SetValueFirstPush_Mmin1..'.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(15)
	         
	            elseif dz.variables(VariableMname).value <= 79 and dz.variables(VariableMname).value >= 60 then
                    if debug then
                        print ('Waarde ligt tussen de 60 en 79.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(20)
	         
	            elseif dz.variables(VariableMname).value <= 59 and dz.variables(VariableMname).value >= 40 then
                    if debug then
                        print ('Waarde ligt tussen de 40 en 59.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(25)
             
                elseif dz.variables(VariableMname).value <= 39 and dz.variables(VariableMname).value >= 1 then
                    if debug then
                        print ('Waarde ligt tussen de 1 en 39.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(30)
	            
	            elseif dz.variables(VariableMname).value == 0 then
                    if debug then
                        print ('Waarde ligt is 0.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(30)    
	                 
	            end
	    end
	    
	    if  dz.devices(Afstandsbediening_M).level == 40 then -- CIRCLE
	            if debug then
	                print ('Selector 40, Met 1 klik volledig openen van rolluik: '..Rolluik_M..', geen ventilatie stand.')
	                print ('Selector 40, VariableMname met naam '..VariableMname..' is '..VarValue..'.')
	            end
	            if dz.variables(VariableMname).value <= 101 and dz.variables(VariableMname).value >= SetValueFirstPush_M then
	                if debug then
                        print ('Waarde ligt tussen de '..SetValueFirstPush_M..' en 100.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M)
	         
	            elseif dz.variables(VariableMname).value <= SetValueFirstPush_Mmin1 and dz.variables(VariableMname).value >= 80 then
                    if debug then
                        print ('Waarde ligt tussen de 80 en '..SetValueFirstPush_Mmin1..'.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(15)
	         
	            elseif dz.variables(VariableMname).value <= 79 and dz.variables(VariableMname).value >= 60 then
                    if debug then
                        print ('Waarde ligt tussen de 60 en 79.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(20)
	         
	            elseif dz.variables(VariableMname).value <= 59 and dz.variables(VariableMname).value >= 40 then
                    if debug then
                        print ('Waarde ligt tussen de 40 en 59.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(25)
             
                elseif dz.variables(VariableMname).value <= 39 and dz.variables(VariableMname).value >= 1 then
                    if debug then
                        print ('Waarde ligt tussen de 1 en 39.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(30)
	            
	            elseif dz.variables(VariableMname).value == 0 then
                    if debug then
                        print ('Waarde ligt is 0.')
                        print ('VariableMname met naam '..VariableMname..' is '..VarValue..'.')
                    end
                    dz.devices(Rolluik_M).dimTo(100)
	                dz.devices(Rolluik_M).dimTo(SetValueFirstPush_M).afterSec(30)    
	                 
	            end
	    end


	end
}

Re: What is wrong in this script, i think i see over it

Posted: Friday 21 August 2020 2:00
by waaren
hoeby wrote: Thursday 20 August 2020 22:15 Must i make 2 scripts?
One which sets the variable and start the other script which reads the value and does something with it.
You cannot set a domoticz uservariable in a Lua or dzVents script and read it during the same execution. The set is only performed by domoticz after the script finished.
If you need something like that you might want to look at dzVents persistent (global) variables.

Re: What is wrong in this script, i think i see over it

Posted: Friday 21 August 2020 9:12
by hoeby
I changed the script to persistent variables.
Now it almost works like i would like it to work.

The value is stored, that is not the problem.
But i don't know if afterSec is possible with setting the value in the persistent variable.
This was a kind of build in, that when pushing up/down/up/down on the remote. That only the first command was executed.
Now the persistent data is set back to waiting value in 0.001 second

Re: What is wrong in this script, i think i see over it

Posted: Friday 21 August 2020 10:25
by waaren
hoeby wrote: Friday 21 August 2020 9:12 But i don't know if afterSec is possible with setting the value in the persistent variable.
It is not possible to use afterSec in combination with setting the value of a persistent variable. They are updated immediate and therefore the new value is directly available in the script. Contrair to the way setting a domoticz uservariable works (effective after the script finished).

Re: What is wrong in this script, i think i see over it

Posted: Friday 21 August 2020 10:38
by hoeby
So i have to add a variable to the script which is set afterSec(x).

Add the variable to the "ON { }" at the top of the script.
And then add a part that if variable triggers the script, that the persitent data is set to waiting value.

Maybe not a nice way to do, but could work (i think)
Only have to figger out, how not to make a loop