Device script always loop!  [Solved]

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

Moderator: leecollings

Post Reply
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Device script always loop!

Post by Nefsolive »

Hello,

I am trying to develop a script in which when the switchSelector ('On') is "Campainha", then the alarm sounds in the melody, etc! But the problem is that the Script does not put the switchSelector ('Off') and stop the alarm! The script is always looped!

There is some other simpler method to do, I've tried it in many ways, but I'm not able to stop the script loop! In the log does not give errors.

Code: Select all

return {
	on = {
		devices = {'Campainha', 'Alarme',}
	},
	
		logging = {
        	level = domoticz.LOG_DEBUG, 
        	marker = 'Toca Campainha',
   	},
	
	execute = function(dz)
	 
	 if dz.devices('Campainha').switchSelector('On') then 
	        dz.devices('Alarme Volume').dimTo(0)
                dz.devices('Alarme Melodia').dimTo(20)
                dz.devices('Alarme').switchOn()
		dz.devices('Alarme').switchOff().aftersec(5)
			
	 elseif dz.devices('Alarme').state == 'Off' then
                dz.devices('Campainha').dimTo(0)
	        
	 end
  end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Device script always loop!

Post by waaren »

Nefsolive wrote: Thursday 18 February 2021 17:08 I am trying to develop a script in which when the switchSelector ('On') is "Campainha", then the alarm sounds in the melody, etc! But the problem is that the Script does not put the switchSelector ('Off') and stop the alarm! The script is always looped!
There is some other simpler method to do, I've tried it in many ways, but I'm not able to stop the script loop! In the log does not give errors.
Did you try with the option silent()?

Code: Select all

return {
    on = {
        devices = {'Campainha', 'Alarme',}
    },

        logging = {
            level = domoticz.LOG_DEBUG,
            marker = 'Toca Campainha',
       },

    execute = function(dz)

         if dz.devices('Campainha').switchSelector('On') then
            dz.devices('Alarme Volume').dimTo(0)
            dz.devices('Alarme Melodia').dimTo(20)
            dz.devices('Alarme').switchOn().silent()
            dz.devices('Alarme').switchOff().aftersec(5).silent()
        elseif dz.devices('Alarme').state == 'Off' then
            dz.devices('Campainha').dimTo(0).silent()
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Device script always loop!

Post by Nefsolive »

waaren wrote: Thursday 18 February 2021 17:14
Nefsolive wrote: Thursday 18 February 2021 17:08 I am trying to develop a script in which when the switchSelector ('On') is "Campainha", then the alarm sounds in the melody, etc! But the problem is that the Script does not put the switchSelector ('Off') and stop the alarm! The script is always looped!
There is some other simpler method to do, I've tried it in many ways, but I'm not able to stop the script loop! In the log does not give errors.
Did you try with the option silent()?

Code: Select all

return {
    on = {
        devices = {'Campainha', 'Alarme',}
    },

        logging = {
            level = domoticz.LOG_DEBUG,
            marker = 'Toca Campainha',
       },

    execute = function(dz)

         if dz.devices('Campainha').switchSelector('On') then
            dz.devices('Alarme Volume').dimTo(0)
            dz.devices('Alarme Melodia').dimTo(20)
            dz.devices('Alarme').switchOn().silent()
            dz.devices('Alarme').switchOff().aftersec(5).silent()
        elseif dz.devices('Alarme').state == 'Off' then
            dz.devices('Campainha').dimTo(0).silent()
        end

    end
}
Hello waaren,
Thanks for reply.
I try with .silent(), and still looping, "dz.devices('Campainha').switchSelector('On')", and just take me off the selector on switches page, wen i put Off the script!
Iff i dont take Off the script, is always loop On!
Strange!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Device script always loop!

Post by waaren »

Nefsolive wrote: Thursday 18 February 2021 17:42 I try with .silent(), and still looping, "dz.devices('Campainha').switchSelector('On')", and just take me off the selector on switches page, wen i put Off the script!
You are using switchSelector in an if statement but switchSelector is an action and not a state.

Please try again with below version and include the log if it does not work as expected.

Code: Select all

return {
    on = {
        devices = {'Campainha', 'Alarme',}
    },

        logging = {
            level = domoticz.LOG_DEBUG,
            marker = 'Toca Campainha',
       },

    execute = function(dz)

         if dz.devices('Campainha').level ~= 0 then
            dz.devices('Alarme Volume').dimTo(0)
            dz.devices('Alarme Melodia').dimTo(20)
            dz.devices('Alarme').switchOn().silent()
            dz.devices('Alarme').switchOff().aftersec(5).silent()
        elseif dz.devices('Alarme').state == 'Off' then
            dz.devices('Campainha').dimTo(0).silent()
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Device script always loop!

Post by Nefsolive »

waaren wrote: Thursday 18 February 2021 18:20
Nefsolive wrote: Thursday 18 February 2021 17:42 I try with .silent(), and still looping, "dz.devices('Campainha').switchSelector('On')", and just take me off the selector on switches page, wen i put Off the script!
You are using switchSelector in an if statement but switchSelector is an action and not a state.

Please try again with below version and include the log if it does not work as expected.

Code: Select all

return {
    on = {
        devices = {'Campainha', 'Alarme',}
    },

        logging = {
            level = domoticz.LOG_DEBUG,
            marker = 'Toca Campainha',
       },

    execute = function(dz)

         if dz.devices('Campainha').level ~= 0 then
            dz.devices('Alarme Volume').dimTo(0)
            dz.devices('Alarme Melodia').dimTo(20)
            dz.devices('Alarme').switchOn().silent()
            dz.devices('Alarme').switchOff().aftersec(5).silent()
        elseif dz.devices('Alarme').state == 'Off' then
            dz.devices('Campainha').dimTo(0).silent()
        end

    end
}
Waaren,
Doesn´t work! They give me this on log;

Code: Select all

2021-02-18 18:03:31.415 Status: dzVents: Info: Handling events for: "Campainha", value: "on"
2021-02-18 18:03:31.415 Status: dzVents: Info: Toca Campainha: ------ Start internal script: Script #1: Device: "Campainha (Zigbee2MQTT)", Index: 1556
2021-02-18 18:03:31.417 Status: dzVents: Debug: Toca Campainha: Processing device-adapter for Alarme Volume: Switch device adapter
2021-02-18 18:03:31.418 Status: dzVents: Debug: Toca Campainha: Constructed timed-command: Set Level 0
2021-02-18 18:03:31.421 Status: dzVents: Debug: Toca Campainha: Processing device-adapter for Alarme Melodia: Switch device adapter
2021-02-18 18:03:31.421 Status: dzVents: Debug: Toca Campainha: Constructed timed-command: Set Level 20
2021-02-18 18:03:31.423 Status: dzVents: Debug: Toca Campainha: Processing device-adapter for Alarme: Switch device adapter
2021-02-18 18:03:31.424 Status: dzVents: Debug: Toca Campainha: Constructed timed-command: On
2021-02-18 18:03:31.425 Status: dzVents: Debug: Toca Campainha: Constructed timed-command: On NOTRIGGER
2021-02-18 18:03:31.425 Status: dzVents: Debug: Toca Campainha: Constructed timed-command: Off
2021-02-18 18:03:31.425 Status: dzVents: Info: Toca Campainha: ------ Finished Script #1
2021-02-18 18:03:31.430 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-02-18 18:03:31.425 Error: dzVents: Error: (3.0.2) Toca Campainha: An error occurred when calling event handler Script #1
2021-02-18 18:03:31.425 Error: dzVents: Error: (3.0.2) Toca Campainha: ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:17: attempt to call a nil value (field 'aftersec')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Device script always loop!

Post by waaren »

Nefsolive wrote: Thursday 18 February 2021 19:07 2021-02-18 18:03:31.425 Error: dzVents: Error: (3.0.2) Toca Campainha: ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:17: attempt to call a nil value (field 'aftersec')[/code]
aftersec does not exist.

the method is afterSec
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Device script always loop!  [Solved]

Post by Nefsolive »

waaren wrote: Thursday 18 February 2021 19:18
Nefsolive wrote: Thursday 18 February 2021 19:07 2021-02-18 18:03:31.425 Error: dzVents: Error: (3.0.2) Toca Campainha: ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:17: attempt to call a nil value (field 'aftersec')[/code]
aftersec does not exist.

the method is afterSec
Yes! You right :) my mistake! passed me.
Now no error on log!
i Take out the lines "elseif dz.devices('Alarme').state == 'Off'" and "dz.devices('Alarme').switchOff().afterSec(5).silent()", and now works great!

You always helping! Thank u. Cheers
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest