repeatAfterSec strange behaviour  [Solved]

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

Moderator: leecollings

Post Reply
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

repeatAfterSec strange behaviour

Post by acaonweb »

HI,
I'm trying to create a script for flashing a bulb 3 times from white to red, when a vibration is triggered

My script is like this

Code: Select all

return {
	on = {
		devices = {
			'Vibrazione1'
		}
	},
	execute = function(dz, device)
	        -- send notification
		dz.notify('Camera',"Cassetto in movimento",dz.PRIORITY_NORMAL,0,'iPhone6S',dz.NSS_PUSHOVER)
                -- 
		dz.devices("Luce Sottotetto Cassettiera").setColor(255,0,0).repeatAfterSec(2,3)
		dz.devices("Luce Sottotetto Cassettiera").setColor(255,255,255).afterSec(1).repeatAfterSec(2,3)
			
	end
}

The bulb turns to red,

But i get this error (don't refer to row number, i've deleted some parts :) )

Code: Select all

2020-04-08 08:15:34.678 Error: dzVents: Error: (3.0.1) An error occurred when calling event handler dz_cassetto
2020-04-08 08:15:34.678 Error: dzVents: Error: (3.0.1) ...moticz/scripts/dzVents/generated_scripts/dz_cassetto.lua:12: attempt to call a nil value (field 'repeatAfterSec')
and the bulb never come back to white

It's a bug or i'm doing wrong?

Thanx in advance.

Fabrizio
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: repeatAfterSec strange behaviour

Post by waaren »

acaonweb wrote: Wednesday 08 April 2020 8:26 I'm trying to create a script for flashing a bulb 3 times from white to red, when a vibration is triggered
the repeatAfterSec() is not available for setColor (see this table in the wiki )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: repeatAfterSec strange behaviour

Post by acaonweb »

waaren wrote: Wednesday 08 April 2020 9:27
acaonweb wrote: Wednesday 08 April 2020 8:26 I'm trying to create a script for flashing a bulb 3 times from white to red, when a vibration is triggered
the repeatAfterSec() is not available for setColor (see this table in the wiki )
ok, so how can achive my goal?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: repeatAfterSec strange behaviour

Post by waaren »

acaonweb wrote: Wednesday 08 April 2020 15:23 ok, so how can achive my goal?
You could try with something like

Code: Select all

return 
{
	on = 
	{
		devices = 
		{
			'Vibrazione1'
		}
	},
	
	logging = 
	{
		level = domoticz.LOG_DEBUG,
		marker = 'flashing',
	},
	
	execute = function(dz, item)
		dz.log(item.name .. ', state = ' .. item.state, dz.LOG_DEBUG)
	  
		if item.state == 'On' then
			luce = dz.devices("Luce Sottotetto Cassettiera")
			-- send notification
			dz.notify('Camera',"Cassetto in movimento",dz.PRIORITY_NORMAL,0,'iPhone6S',dz.NSS_PUSHOVER)
			
			for flash = 0, 4, 2 do
				luce.setColor(255,0,0).afterSec(flash)
				luce.setColor(255,255,255).afterSec(flash + 1)
			end
		end
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: repeatAfterSec strange behaviour  [Solved]

Post by acaonweb »

Fast and simple. Thanks to everyone
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

Re: repeatAfterSec strange behaviour

Post by AllesVanZelf »

Hi Waaren,
I'm trying to figure out what happens in this script.

Code: Select all

for flash = 0, 4, 2 do
	luce.setColor(255,0,0).afterSec(flash)
	luce.setColor(255,255,255).afterSec(flash + 1)
end
It look like this will result in a afterSec(0, 4, 2) and for the second line in afterSec(1, 4, 3). But I do not know how this is working then. Could you or someone explain this to me?
I'd like to use this part to make a light flash red/blue. :)
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: repeatAfterSec strange behaviour

Post by waaren »

AllesVanZelf wrote: Thursday 09 July 2020 14:57 I'm trying to figure out what happens in this script.

Code: Select all

for flash = 0, 4, 2 do
	luce.setColor(255,0,0).afterSec(flash)
	luce.setColor(255,255,255).afterSec(flash + 1)
end
Could you or someone explain this to me?

Code: Select all

for flash = 0, 4, 2 do 
       print (flash) 
end
means a start value of 0, an end value of 4 with a step size of 2

this code will print
0
2
4
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

Re: repeatAfterSec strange behaviour

Post by AllesVanZelf »

Yes, very good. I can use that! Thanks Waaren.
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest