dzVent script device trigger * bug?

Easy to use, 100% Lua-based event scripting framework.
Post Reply
snuiter
Posts: 47
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

dzVent script device trigger * bug?

Post by snuiter » Sunday 25 February 2018 13:49

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
}

User avatar
emme
Posts: 798
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: dzVent script device trigger * bug?

Post by emme » Sunday 25 February 2018 14:07

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
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

snuiter
Posts: 47
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: dzVent script device trigger * bug?

Post by snuiter » Sunday 25 February 2018 21: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
Schermafdruk 2018-02-25 20.55.46.png (53.15 KiB) Viewed 444 times

User avatar
emme
Posts: 798
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: dzVent script device trigger * bug?

Post by emme » Sunday 25 February 2018 22:02

oh, then it would be
devices = {
'deur1','deur2','*deur*' to trigger also for Voltage - Deur ;)
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
waaren
Posts: 490
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVent script device trigger * bug?

Post by waaren » Sunday 25 February 2018 22:51

snuiter wrote:
Sunday 25 February 2018 21: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) 
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

snuiter
Posts: 47
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: dzVent script device trigger * bug?

Post by snuiter » Sunday 25 February 2018 23:54

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 430 times

User avatar
waaren
Posts: 490
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVent script device trigger * bug?

Post by waaren » Monday 26 February 2018 0:30

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

dannybloe
Posts: 1407
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: dzVent script device trigger * bug?

Post by dannybloe » Monday 26 February 2018 9: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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

User avatar
waaren
Posts: 490
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVent script device trigger * bug?

Post by waaren » Monday 26 February 2018 9:45

dannybloe wrote:
Monday 26 February 2018 9: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 "*"
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

dannybloe
Posts: 1407
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: dzVent script device trigger * bug?

Post by dannybloe » Monday 26 February 2018 10:00

Which matching goes wrong then?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

User avatar
waaren
Posts: 490
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVent script device trigger * bug?

Post by waaren » Tuesday 27 February 2018 1:27

dannybloe wrote:
Monday 26 February 2018 10: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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests