State don't change after switchOff

Easy to use, 100% Lua-based event scripting framework.
Post Reply
hestia
Posts: 7
Joined: Tuesday 26 December 2017 0:06
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Paris
Contact:

State don't change after switchOff

Post by hestia » Wednesday 14 March 2018 0:24

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
Last edited by dannybloe on Wednesday 14 March 2018 9:55, edited 1 time in total.
Reason: Please use code blocks when posting code

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

Re: State don't change after switchOff

Post by waaren » Wednesday 14 March 2018 1:19

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

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

Re: State don't change after switchOff

Post by dannybloe » Wednesday 14 March 2018 9:58

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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

hestia
Posts: 7
Joined: Tuesday 26 December 2017 0:06
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Paris
Contact:

Re: State don't change after switchOff

Post by hestia » Wednesday 14 March 2018 23:25

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.

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

Re: State don't change after switchOff

Post by dannybloe » Wednesday 14 March 2018 23:47

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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

hestia
Posts: 7
Joined: Tuesday 26 December 2017 0:06
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Paris
Contact:

Re: State don't change after switchOff

Post by hestia » Wednesday 14 March 2018 23:53

Ok dannybloe
Thanks again

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests