The script works, but it shouldn't. Why?  [Solved]

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

Moderator: leecollings

Post Reply
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

The script works, but it shouldn't. Why?

Post by besix »

Hello, I have a script that should execute in time.
Domoticz last beta.
Why is it working now?
It's October
The date and time in domoticz is up to date

Code: Select all

return {
	on = {
	    timer = {'at 21:17 on mon,wed,fri,sun on 20/04-28/09'},
	    devices = {'Przekaźnik 1'}  
      },

	   logging =	{   
					--	level   =   domoticz.LOG_ERROR,
						level   =   domoticz.LOG_DEBUG,
						marker  =   "Time and relay" 
					},	
					
	execute = function(dz, item)
        
       	local relay = dz.devices("Przekaźnik 1")
		local relay2 = dz.devices("Przekaźnik 2")
		
		
		if (item.isTimer) then 
		   relay.switchOn()
		elseif relay.state == "On" then   
			relay2.switchOn().afterSec(4)
	end
end
}

The full script is here

Code: Select all

return {
	on = {
	    timer = {'at 3:00 on mon,wed,fri,sun on 20/04-28/09'},
	     devices = {'Nawadnianie'} 
      },

	   logging =	{   
						level   =   domoticz.LOG_ERROR,
						-- level   =   domoticz.LOG_DEBUG,
						marker  =   "Nawadnianie ogrodu" 
					},	
					
	execute = function(dz, item)
        
       	local selector = dz.devices("Nawadnianie")
        local zone1 = dz.devices("Podlew Róże")
		local zone2 = dz.devices("Podlew Front")
		local zone3 = dz.devices("Podlew Trawnik1")
		local zone4 = dz.devices("Podlew Trawnik2")
		local zone5 = dz.devices("Podlew Trawnik3")
		local zone6 = dz.devices("Podlew Trawnik4")
		local zones = { zone1, zone2, zone3, zone4,zone5, zone6 }
         
		dz.log(selector.name .. ' Jest w trybie ' .. selector.state, dz.LOG_DEBUG)

		for _, zone in ipairs(zones) do
			zone.cancelQueuedCommands() -- usuwa stare zaplanowane  start / stop
			zone.switchOff().checkFirst()
		
		if (item.isTimer) then 
		   selector.switchSelector(10)
		elseif selector.state == "Auto" then   
			zone1.switchOn().forMin(40)
			zone2.switchOn().afterMin(10).forMin(30)
			zone3.switchOn().afterMin(40).forMin(30)
			zone4.switchOn().afterMin(70).forMin(30)
			zone5.switchOn().afterMin(100).forMin(30)
			zone6.switchOn().afterMin(130).forMin(30)
			selector.switchSelector(0).afterMin(161)
		elseif selector.state == "Stop" then
			zone1.switchOff()
		    zone2.switchOff()
		    zone3.switchOff()
		    zone4.switchOff()
		    zone5.switchOff()
		    zone6.switchOff()
		end
	end
end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The script works, but it shouldn't. Why?

Post by waaren »

besix wrote: Wednesday 14 October 2020 21:18 Hello, I have a script that should execute in time.
Why is it working now? It's October
This script can be triggered by either the timer trigger or the devices trigger.
Given it is October it will now only execute when triggered by the device.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The script works, but it shouldn't. Why?

Post by besix »

Thank you for your response.
Yes I know the trigger is time or relay, but two relays are OFF and at 21:17 the script is doing relay1 On. Then, of course, relay 2 On after 4sec

log

Code: Select all

2020-10-14 21:02:00.379 Status: dzVents: Info: Nawadnianie ogrodu: ------ Start internal script: Script #1:, trigger: "at 21:02 on mon,wed,fri,sun on 20/04-28/09"
2020-10-14 21:02:00.398 Status: dzVents: Debug: Nawadnianie ogrodu: Processing device-adapter for Przekaźnik 1: Switch device adapter
2020-10-14 21:02:00.399 Status: dzVents: Debug: Nawadnianie ogrodu: Processing device-adapter for Przekaźnik 2: Switch device adapter
2020-10-14 21:02:00.399 Status: dzVents: Debug: Nawadnianie ogrodu: Constructed timed-command: On
2020-10-14 21:02:00.399 Status: dzVents: Info: Nawadnianie ogrodu: ------ Finished Script #1
2020-10-14 21:02:00.400 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-14 21:02:00.521 Status: dzVents: Info: Handling events for: "Przekaźnik 1", value: "On"
2020-10-14 21:02:00.521 Status: dzVents: Info: Nawadnianie ogrodu: ------ Start internal script: Script #1: Device: "Przekaźnik 1 (AFE)", Index: 18
2020-10-14 21:02:00.522 Status: dzVents: Debug: Nawadnianie ogrodu: Processing device-adapter for Przekaźnik 2: Switch device adapter
2020-10-14 21:02:00.522 Status: dzVents: Debug: Nawadnianie ogrodu: Constructed timed-command: On
2020-10-14 21:02:00.522 Status: dzVents: Debug: Nawadnianie ogrodu: Constructed timed-command: On AFTER 4 SECONDS
2020-10-14 21:02:00.522 Status: dzVents: Info: Nawadnianie ogrodu: ------ Finished Script #1
2020-10-14 21:02:00.523 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The script works, but it shouldn't. Why?

Post by waaren »

besix wrote: Wednesday 14 October 2020 22:55 Yes I know the trigger is time or relay, but two relays are OFF and at 21:17 the script is doing relay1 On. Then, of course, relay 2 On after 4sec
Thx for reporting!
Seems indeed not working as expected. Have to check the code in Time.lua and the wiki to see what is wrong

[EDIT] the code in Time.lua does not handle timeRules with multiple on correct.

Can you please check after replacing line 527 of <domoticz dir>/dzVents/runtime/Time.lua from

Code: Select all

		local dates = string.match(rule, 'on% ([0-9%*%/%,% %-]*)') 
to

Code: Select all

		local dates = rule:gsub('(on%s+[%a+])',''):match('on%s+([0-9%*%/%,% %-]*)') -- strip on ddd before matching rule
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The script works, but it shouldn't. Why?  [Solved]

Post by besix »

Hello
After changing the line 527 the script works fine.
When I set September, it does not start. And it only works when relay is trigger
When there is a date October follows the date
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The script works, but it shouldn't. Why?

Post by waaren »

besix wrote: Thursday 15 October 2020 8:56 Hello
After changing the line 527 the script works fine.
When I set September, it does not start. And it only works when relay is trigger
When there is a date October follows the date
Thx for testing ! See my previous post (I shortened the test to one line again)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The script works, but it shouldn't. Why?

Post by besix »

When I change it, will it be valid in the new beta domoticz?

EDIT

I did the 527 line change again and it works wrong again

log

Code: Select all

2020-10-15 09:29:00.608 Status: dzVents: Info: Time and relay: ------ Start internal script: time + relay:, trigger: "at 09:29 on mon,wed, thu, fri,sun on 20/04-28/09"
2020-10-15 09:29:00.626 Status: dzVents: Debug: Time and relay: Processing device-adapter for Przekaźnik 1: Switch device adapter
2020-10-15 09:29:00.627 Status: dzVents: Debug: Time and relay: Processing device-adapter for Przekaźnik 2: Switch device adapter
2020-10-15 09:29:00.627 Status: dzVents: Info: Time and relay: Time = true
2020-10-15 09:29:00.628 Status: dzVents: Debug: Time and relay: Constructed timed-command: On
2020-10-15 09:29:00.628 Status: dzVents: Info: Time and relay: ------ Finished time + relay
2020-10-15 09:29:00.628 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-15 09:29:00.726 Status: dzVents: Info: Handling events for: "Przekaźnik 1", value: "On"
2020-10-15 09:29:00.727 Status: dzVents: Info: Time and relay: ------ Start internal script: time + relay: Device: "Przekaźnik 1 (AFE)", Index: 18
2020-10-15 09:29:00.728 Status: dzVents: Debug: Time and relay: Processing device-adapter for Przekaźnik 2: Switch device adapter
2020-10-15 09:29:00.728 Status: dzVents: Debug: Time and relay: Constructed timed-command: On
2020-10-15 09:29:00.728 Status: dzVents: Info: Time and relay: ------ Finished time + relay
2020-10-15 09:29:00.729 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
line 527

Code: Select all

   function self.ruleIsOnDate(rule)
                local dates = rule:match('on%s+([0-9%*%/%,% %-]*)')
                if (isEmpty(dates)) then
                        return nil
                end
Last edited by besix on Thursday 15 October 2020 9:36, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The script works, but it shouldn't. Why?

Post by waaren »

besix wrote: Thursday 15 October 2020 9:20 When I change it, will it be valid in the new beta domoticz?
Yes. I will merge this in a next beta but until then you can change the line yourself.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The script works, but it shouldn't. Why?

Post by besix »

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

Re: The script works, but it shouldn't. Why?

Post by waaren »

besix wrote: Thursday 15 October 2020 9:37 See the post above
Reverted my earlier simplification in the post so back to the previous 4 lines ... :(
Need to study these patterns a bit more..

[EDIT] found a one solution.

Code: Select all

		local dates = rule:gsub('(on%s+[%a+])',''):match('on%s+([0-9%*%/%,% %-]*)') -- strip on ddd before matching rule
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The script works, but it shouldn't. Why?

Post by besix »

Your last solution works. Thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest