Page 1 of 1

dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 12:49
by snuiter
So I am having two door sensors deur1 and deur2, when I create a script to notify on door open it works fine when triggered by a device. Now I changed script to be triggered by deur* and it is now sending out notifications now and then even when there was no trigger of any of the devices. This is awkward as both deur1 and deur2 have not been triggered since yesterday

Anyone an suggestion what this could be
2018-02-25 12:32:02.905 dzVents: deur script
2018-02-25 12:32:02.906 dzVents: deur open-3
2018-02-25 12:32:02.910 dzVents: deur script
2018-02-25 12:32:02.910 dzVents: deur open-3

It works fine when only using deur1 and deur2 as device triggers but not when I use deur* in the script.

I thought I check my device listings on "deur" and noticed there is also "Voltage - deur1" and "Voltage - deur2" and when there is an update on the voltage the script is triggered. To me this seems to be in error as the trigger is deur* and not *deur*.

Should this be reported as a bug?

This is the script:
Spoiler: show
return {
on = {
devices = {
'deur1','deur2','deur*'
}
},
execute = function(domoticz, device)
local now = domoticz.time -- current time
print("deur script")

if now.hour <= 7 and now.wday ~= 1 then
print("deur open-1")
end

if now.hour >= 22 and now.wday ~= 1 then
print("deur open-2")
end
if now.wday == 1 then
print("deur open-3")
end
end
}

Re: dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 13:07
by emme
well.. deur* already include deur1 and deur2... so you might want to simply specify deur* as on device condition.

then in your script, if you need (but you actually do not in you script) you can use
if device.name == 'deur1' then
...
elseif device.name == 'deur2' then
...
end

to make different action based on the device triggered.

ciao
M

Re: dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 20:59
by snuiter
Thx M for your response.
But the strange behavior is that if the script only has deur* as device listed it also gets triggered by the two devices that only monitor the voltage of the two door switches e.g.
- Voltage - deur1
- Voltage - deur2

So the script is not only triggered by the two "deur" switches but also through an update of the voltage device.

So these four devices trigger the script due to "deur*" So no door is opened but the script gets triggered by an voltage update from battery of the door switch. For now I will use "deur1" and "deur2" as my triggers and not the simple "deur*"
Schermafdruk 2018-02-25 20.55.46.png
Schermafdruk 2018-02-25 20.55.46.png (53.15 KiB) Viewed 1159 times

Re: dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 21:02
by emme
oh, then it would be
devices = {
'deur1','deur2','*deur*' to trigger also for Voltage - Deur ;)

Re: dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 21:51
by waaren
snuiter wrote: Sunday 25 February 2018 20:59 Thx M for your response.
But the strange behavior is that if the script only has deur* as device listed it also gets triggered by the two devices that only monitor the voltage of the two door switches e.g.
- Voltage - deur1
- Voltage - deur2

So the script is not only triggered by the two "deur" switches but also through an update of the voltage device.

So these four devices trigger the script due to "deur*" So no door is opened but the script gets triggered by an voltage update from battery of the door switch. For now I will use "deur1" and "deur2" as my triggers and not the simple "deur*"
Schermafdruk 2018-02-25 20.55.46.png
Kind of interested what the output is of

Code: Select all

print("Script triggered by: " .. device.name) 

Re: dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 22:54
by snuiter
The script got triggered by the batteries and that is the problem I don't want that. To me a bit awkward as this is not matching with "deur*"

Script:
Spoiler: show
return {
on = {
devices = {
'deur*'
}
},

2018-02-25 22:48:41.898 dzVents: Script triggered by: Voltage - deur1
2018-02-25 22:48:41.898 dzVents: deur open-3
2018-02-25 22:48:41.902 dzVents: Script triggered by: Voltage - deur2
2018-02-25 22:48:41.902 dzVents: deur open-3
Schermafdruk 2018-02-25 22.50.25.png
Schermafdruk 2018-02-25 22.50.25.png (115.48 KiB) Viewed 1145 times

Re: dzVent script device trigger * bug?

Posted: Sunday 25 February 2018 23:30
by waaren
Looks indeed to be a bug; but best to ask Danny if it is not working as designed.

Logic in domoticz/dzVents/runtime/Eeventhelpers.lua only checks if an "*" is in the scriptTrigger and if so, if the rest of the scriptTrigger string is found in the target device name, without considering if its at the beginning or at the end.
Although fixable it is not as easy as it looks at first sight.

Until it is fixed I propose a rename of your voltage or door contacts.

Re: dzVent script device trigger * bug?

Posted: Monday 26 February 2018 8:20
by dannybloe
Indeed.. what you can try is in Eventhelpers.lua, function self.findScriptForTarget, replace this line:

Code: Select all

scriptTrigger = string.gsub(scriptTrigger, "*", ".*")
with

Code: Select all

scriptTrigger = '^' .. string.gsub(scriptTrigger, "*", ".*")
I think that should do the trick.

Re: dzVent script device trigger * bug?

Posted: Monday 26 February 2018 8:45
by waaren
dannybloe wrote: Monday 26 February 2018 8:20 Indeed.. what you can try is in Eventhelpers.lua, function self.findScriptForTarget, replace this line:

Code: Select all

scriptTrigger = string.gsub(scriptTrigger, "*", ".*")
with

Code: Select all

scriptTrigger = '^' .. string.gsub(scriptTrigger, "*", ".*")
I think that should do the trick.
Thanks Danny, this indeed does the trick for a trailing "*" but does not change the behaviour for a leading "*"

Re: dzVent script device trigger * bug?

Posted: Monday 26 February 2018 9:00
by dannybloe
Which matching goes wrong then?

Re: dzVent script device trigger * bug?

Posted: Tuesday 27 February 2018 0:27
by waaren
dannybloe wrote: Monday 26 February 2018 9:00 Which matching goes wrong then?
please see my testcode. I also sent you a PM about this.

Code: Select all

--[[ 
Wildcard test

defined three devices

triggertest_wildcard
wildcard_triggertest
triggertest_wildcard_triggertest

 on = { devices = { "wild*"  } },
 This reacts as expected	(triggers on wildcard_triggertest )

 on = { devices = { "*wildcard*"  } },
 This reacts as expected	(triggers on all three devices )
 
  on = { devices = { "*card"  } },
 This reacts not as expected (triggers on all three devices and I expected to only trigger on ttriggertest_wildcard) 
 
 
 ]]--
 
return {
   on = { devices = { "*card"  } },
   		
    execute = function(domoticz, device)
      print("RvW Script triggered by: " .. device.name) 
    end
}