Wildcards * in dzvents 2.0

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

Moderator: leecollings

Post Reply
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Wildcards * in dzvents 2.0

Post by TheCondor »

Hello, i'm trying to convert all my script to dzvents and optimize that. Currently probably i don't understood how wildcards character works. Thanks in advance for the help!

Code: Select all

2017-07-04 22:15:00.664 dzVents: Info: ------ Start internal script: Tapparelle:, trigger: at 22:15
2017-07-04 22:15:00.664 Error: dzVents: Error: There is no device with that name or id: *_Tapparella
2017-07-04 22:15:00.664 Error: dzVents: Error: An error occured when calling event handler Tapparelle
2017-07-04 22:15:00.664 Error: dzVents: Error: ...omoticz/scripts/dzVents/generated_scripts/Tapparelle.lua:12: attempt to index a nil value
And this is my script that should close all the blinds at 22:15 in one is open:

Code: Select all

return {
        active = true,

        on = {
                timer = {
                        'at 22:15'
                }
        },

        execute = function(domoticz, dummy)

                if domoticz.devices('*_Tapparella').state ~= 'Closed' then
                        if domoticz.devices('Sala_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Sala_Tapparella').close()
                        end
                        if domoticz.devices('Camera_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Camera_Tapparella').close()
                        end
                        if domoticz.devices('Bagno_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Bagno_Tapparella').close()
                        end
                        if domoticz.devices('Stanzina_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Stanzina_Tapparella').close()
                        end
                                                if domoticz.devices('Cucina_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Cucina_Tapparella').close()
                        end
                end
        end
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Wildcards * in dzvents 2.0

Post by dannybloe »

Ah, you can only use wildcards in the 'on' section to specify a group of devices you wish to trigger.
In your case I would do it differently by first filtering out all devices with 'Taparella' in their name and then looping through those filtered devices to close them when necessary:

Code: Select all

return {
	active = true,
	on = {
		timer = {
			'at 22:15'
		}
	},
	execute = function(domoticz, dummy)
		-- close all Tarapellas 
		domoticz.devices().filter(function(device)
			return (string.match(device.name, '_Tapparella')~=nil)
		end).forEach(function(taparella)
			if (taparella.state ~= 'Closed') then
				taparella.close()
			end
		end)
		
	end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Wildcards * in dzvents 2.0

Post by TheCondor »

Awesome! Really thanks for your incredible job danny and your kind support here!!!
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Wildcards * in dzvents 2.0

Post by EdwinK »

So, to run this, I need to change the names _Tapparella to what I use (zonwering)? Or what else do I need? First time trying this dzevents thing.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Wildcards * in dzvents 2.0

Post by TheCondor »

Exactly, _Tapparella is A part of the nane of the devices i want to recoursive "Scan"
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Wildcards * in dzvents 2.0

Post by EdwinK »

Thanks. Will see if I can adapt it to my needs
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest