invalid device active state after switchOn or switchOff

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

Moderator: leecollings

Post Reply
Sjoko
Posts: 15
Joined: Sunday 11 April 2021 16:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

invalid device active state after switchOn or switchOff

Post by Sjoko »

In DzVents time triggered script,
immediately after switchOn a device, the active status is still false.
switchEventTestSwich.switchOn()
if switchEventTestSwich.active then
... never getting here
else
...
end
On next run of the script, the active status is correct.
Am I missing something ?

I have isolated this problem in the following script;

Code: Select all

return {
	on = {
		timer = {
			'every minute',				-- causes the script to be called every minute
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'switchOnAndActive',
	},
	execute = function(domoticz, timer)
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
		
		local switchEventTestSwich = domoticz.devices(113);
		        
		if switchEventTestSwich.active then
		    switchEventTestSwich.switchOff()
		    if switchEventTestSwich.active then
		        domoticz.log('switchEventTestSwich: active but switchOff', domoticz.LOG_ERROR)
		    else
		        domoticz.log('switchEventTestSwich: not active and switchOff', domoticz.LOG_INFO)
		    end
	    else
		    switchEventTestSwich.switchOn()
		    if switchEventTestSwich.active then
		        domoticz.log('switchEventTestSwich: active and switchOn', domoticz.LOG_INFO)
		    else
		        domoticz.log('switchEventTestSwich: not active but switchOn', domoticz.LOG_ERROR)
		    end
	    end

	end
}
Logging output;

Code: Select all

2024-04-25 10:36:00.384 Status: dzVents: Info: switchOnAndActive: ------ Start internal script: Script #test switchOnAndActive:, trigger: "every minute"
2024-04-25 10:36:00.385 Status: dzVents: Info: switchOnAndActive: Timer event was triggered by every minute
2024-04-25 10:36:00.388 Status: dzVents: Info: switchOnAndActive: ------ Finished Script #test switchOnAndActive
2024-04-25 10:36:00.387 Error: dzVents: Error: (3.1.8) switchOnAndActive: switchEventTestSwich: active but switchOff
2024-04-25 10:37:00.393 Status: dzVents: Info: switchOnAndActive: ------ Start internal script: Script #test switchOnAndActive:, trigger: "every minute"
2024-04-25 10:37:00.394 Status: dzVents: Info: switchOnAndActive: Timer event was triggered by every minute
2024-04-25 10:37:00.396 Status: dzVents: Info: switchOnAndActive: ------ Finished Script #test switchOnAndActive
2024-04-25 10:37:00.395 Error: dzVents: Error: (3.1.8) switchOnAndActive: switchEventTestSwich: not active but switchOn 
my system:
Linux pi 5.15.84-v7+ #1613 SMP Thu Jan 5 11:59:48 GMT 2023 armv7l GNU/Linux
Version: 2023.2
Build Hash: 19efd039c
Compile Date: 2023-07-21 17:23:44
dzVents Version: 3.1.8
Python Version: 3.9.2 (default, Mar 12 2021, 04:06:34) [GCC 10.2.1 20210110]
User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: invalid device active state after switchOn or switchOff

Post by boum »

this have been told several time. changes to device states (and probably user variables) are done after the script execution. (that's a good way to avoid infinite loops by the way)
during the execution of the script the states are fixed. if you want to track your changes for later use in the same script, use a local variable
Sjoko
Posts: 15
Joined: Sunday 11 April 2021 16:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Netherlands
Contact:

Re: invalid device active state after switchOn or switchOff

Post by Sjoko »

thanks for the quick reply and the clear explanation.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest