Page 1 of 1

State don't change after switchOff

Posted: Tuesday 13 March 2018 23:24
by hestia
Hi
I wrote this script
--------------------------------

Code: Select all

local DOMAIN = ':TEST'
local LIGHT = {112,  142, 173, 178} 
local TIME_INTERVAL = 'every 30 minutes'

return {
    active = true,
    logging = {
	level = domoticz.LOG_INFO, 
	marker = DOMAIN
	},
    on = {
        devices = LIGHT,
        timer = { TIME_INTERVAL },
    },
    data = {
		deviceOn = {initial={}},
		},
        
    execute = function(dz, the_device, triggerInfo)
        
        local LOG_LEVEL = dz.LOG_INFO -- LOG_INFO (LOG_DEBUG, LOG_ERROR, LOG_FORCE)
        
       dz.log(the_device.id .. '  ' .. the_device.name .. ' ' .. the_device.state, LOG_LEVEL)
  
	    if the_device.active then
	        the_device.switchOff().silent()
	        dz.log(the_device.id .. '  ' .. the_device.name .. ' switchOff ' , LOG_LEVEL)
        end
  
        dz.log(the_device.id .. '  ' .. the_device.name .. ' ' .. the_device.state, LOG_LEVEL)
      
end} 
---------------

the log is
2018-03-13 23:09:22.592 User: Admin initiated a switch command (178/Allée/On)
2018-03-13 23:09:22.721 dzVents: Info: :TEST: ------ Start internal script: test_state: Device: "Allée (Z-Wave Plus Z-Stick Gen5)", Index: 178
2018-03-13 23:09:22.722 dzVents: Info: :TEST: 178 Allée On
2018-03-13 23:09:22.723 dzVents: Info: :TEST: 178 Allée switchOff
2018-03-13 23:09:22.723 dzVents: Info: :TEST: 178 Allée On
2018-03-13 23:09:22.723 dzVents: Info: :TEST: ------ Finished test_state
2018-03-13 23:10:03.261 EventSystem: reset all events...


=> after 178 was switched Off, the state in the log remains On

Did I missed something?!

Version: 3.9034
Build Hash: 7f6249c9
Compile Date: 2018-03-12 18:52:16
dzVents Version: 2.4.1

Re: State don't change after switchOff

Posted: Wednesday 14 March 2018 0:19
by waaren
My 2 cents..

the execute = function statement passes the complete domoticz and triggering device objects to the rest of your script.
Within the rest of the script any call to retrieve information from these objects are not accessing the database but -the objects.

I am sure Danny can explain it much better and can also comment if this is accurate and as designed.

PS please put your code between "[ code] [ /code]" tags to improve readability.

Re: State don't change after switchOff

Posted: Wednesday 14 March 2018 8:58
by dannybloe
The state change is handled by Domoticz after the script has finished. So the device state inside your script doesn't change.
Also, as you have two kinds of triggers (timer and device) you have to check for it in your code. As the second argument of your execute function in case of a timer trigger is NOT a device object but a timer object. Check the documentation about the execute function and how you check for this. Coz if it is a timer object you cannot treat it as a device.

Re: State don't change after switchOff

Posted: Wednesday 14 March 2018 22:25
by hestia
Thank you waaren and dannybloe for your quick answers

I wasn't aware that "The state change is handled by Domoticz after the script has finished."
A note in the DzVents documentation could be useful?. Perhaps it's the same with LUA, but I don't do LUA ;-)

So it is not possible to have in a log the result of a script if it is about device state.

For the timer trigger, it is ok. That was just a part of the script to show the issue.

Re: State don't change after switchOff

Posted: Wednesday 14 March 2018 22:47
by dannybloe
That is how al event scripting systems work. If you put dzvents into debug logging mode you will see the commands being sent back to domoticz. See the dzvents docs about logging.

Re: State don't change after switchOff

Posted: Wednesday 14 March 2018 22:53
by hestia
Ok dannybloe
Thanks again