Page 1 of 1

I don't know why it doesn't work

Posted: Tuesday 17 July 2018 21:31
by pascal
Who could explain to me why it does not seem to work. Here is my script:
return {
on = {
timer = { 'every minute' }
},
execute = function(domoticz, timer)
if (device'Fin_chauffage'.state == 'On')
then
device'prise ordi'.switchOff()
device'prise TV Chambre'.switchOff()
domoticz.notify('Hey pas mal')
else
device'prise TV Chambre'.switchOn()
device'prise ordi'.switchOn()
end
end
}
Thanks for your help
Pascal

Re: I don't know why it doesn't work

Posted: Tuesday 17 July 2018 22:14
by waaren
You missed a couple of () in your code. Do you see anything in the domoticz logfile ?
Please use code tags around your code to improve readability on the forum.

Code: Select all

return {
    on = { timer = { 'every minute'} },
    
    logging = {     level = domoticz.LOG_ERROR, 
                    marker = "chauffage actions" },

    execute = function(domoticz, timer)
        if (device('Fin_chauffage').state == 'On') then
            device('prise ordi').switchOff()
            device('prise TV Chambre').switchOff()
            domoticz.notify('Hey pas mal')
        else
            device('prise TV Chambre').switchOn()
            device('prise ordi').switchOn()
        end
    end
}

Re: I don't know why it doesn't work

Posted: Tuesday 17 July 2018 22:56
by pascal
No I don't see anything in logfile. even with yours. Amazing

Re: I don't know why it doesn't work

Posted: Tuesday 17 July 2018 23:27
by waaren
pascal wrote: Tuesday 17 July 2018 22:56 No I don't see anything in logfile. even with yours. Amazing
Did you enable logging in your /etc/init.d/domoticz.sh ?

by removing the # on the line

Code: Select all

#DAEMON_ARGS="$DAEMON_ARGS -log /tmp/domoticz.txt" 
so that it reads

Code: Select all

DAEMON_ARGS="$DAEMON_ARGS -log /tmp/domoticz.txt"
?

Re: I don't know why it doesn't work

Posted: Wednesday 18 July 2018 21:05
by pascal
I just did, but nothing happens. Probably something I did not do properly, but I don't know what.

Re: I don't know why it doesn't work

Posted: Wednesday 18 July 2018 21:15
by pascal
Here is the error I have:
2018-07-18 21:10:56.190 Status: dzVents: Error (2.4.6): chauffage actions: ...e/pi/domoticz/scripts/dzVents/generated_scripts/kiki.lua:8: attempt to call global 'device' (a nil value)

Thanks for your help :-)

Re: I don't know why it doesn't work

Posted: Wednesday 18 July 2018 21:25
by waaren
pascal wrote: Wednesday 18 July 2018 21:15 Here is the error I have:
2018-07-18 21:10:56.190 Status: dzVents: Error (2.4.6): chauffage actions: ...e/pi/domoticz/scripts/dzVents/generated_scripts/kiki.lua:8: attempt to call global 'device' (a nil value)
We are getting somewhere now. Please try this modified script.

Code: Select all

return {
    on = { timer = { 'every minute'} },
    
    logging = {     level = domoticz.LOG_ERROR, 
                    marker = "chauffage actions" },

    execute = function(domoticz, trigger)
        if (domoticz.devices('Fin_chauffage').state == 'On') then
            domoticz.devices('prise ordi').switchOff()
            domoticz.devices('prise TV Chambre').switchOff()
            domoticz.notify('Hey pas mal')
        else
            domoticz.devices('prise TV Chambre').switchOn()
            domoticz.devices('prise ordi').switchOn()
        end
    end
}

Re: I don't know why it doesn't work

Posted: Wednesday 18 July 2018 21:40
by pascal
here it is:
2018-07-18 21:39:00.664 Status: dzVents: Error (2.4.6): chauffage actions: ...e/pi/domoticz/scripts/dzVents/generated_scripts/kiki.lua:8: attempt to call local 'device' (a table value)

Re: I don't know why it doesn't work

Posted: Wednesday 18 July 2018 22:00
by waaren
pascal wrote: Wednesday 18 July 2018 21:40 here it is:
2018-07-18 21:39:00.664 Status: dzVents: Error (2.4.6): chauffage actions: ...e/pi/domoticz/scripts/dzVents/generated_scripts/kiki.lua:8: attempt to call local 'device' (a table value)
My mistake. I edited the previous post

Re: I don't know why it doesn't work

Posted: Wednesday 18 July 2018 23:17
by pascal
any clue? :-(

Re: I don't know why it doesn't work

Posted: Thursday 19 July 2018 0:18
by waaren
pascal wrote: Wednesday 18 July 2018 23:17any clue? :-(
Did you try the edited version ?

the logic in your script causes dzVents to send you a notifications every minute for as long as "Fin_chauffage" state is On. It will also switch the other devices with a delay varying from 1 - 60 seconds. If you want to change the script in such a way that it triggers direct and only when the state of "Fin_chauffage" changes; modify it to:

Code: Select all

return {
    on = { devices = { 'Fin_chauffage'} },
    
    logging = {     level = domoticz.LOG_ERROR, 
                    marker = 'chauffage actions' },

    execute = function(domoticz, trigger)
       if trigger.state == 'On' then
            domoticz.devices('prise ordi').switchOff()
            domoticz.devices('prise TV Chambre').switchOff()
            domoticz.notify('Hey pas mal')
        else
            domoticz.devices('prise TV Chambre').switchOn()
            domoticz.devices('prise ordi').switchOn()
        end
    end
}

Re: I don't know why it doesn't work

Posted: Thursday 19 July 2018 13:59
by pascal
:roll: Thanks a lot Waaren. It is working exactly how I wanted. What is the difference between:
execute = function(domoticz, trigger) and execute = function(domoticz, Device)?

Thanks again.
Pascal :P :P

Re: I don't know why it doesn't work

Posted: Thursday 19 July 2018 14:18
by jake

pascal wrote::roll: Thanks a lot Waaren. It is working exactly how I wanted. What is the difference between:
execute = function(domoticz, trigger) and execute = function(domoticz, Device)?

Thanks again.
Pascal Image :P
Please check the wiki:
https://www.domoticz.com/wiki/DzVents:_ ... gerInfo.29

There they use the word 'item'. It is your choice what word to use. In your script you didn't make use of the'trigger word', so you can skip it as well:
execute = function(domoticz)

Re: I don't know why it doesn't work

Posted: Thursday 19 July 2018 15:35
by waaren
jake wrote: Thursday 19 July 2018 14:18
pascal wrote:What is the difference between:
execute = function(domoticz, trigger) and execute = function(domoticz, Device)?
Please check the wiki:
https://www.domoticz.com/wiki/DzVents:_ ... gerInfo.29

There they use the word 'item'. It is your choice what word to use. In your script you didn't make use of the'trigger word', so you can skip it as well:
execute = function(domoticz)
@Jake, in the example based on the device state change trigger is used so better to leave it like it is.

@pascal, the the second parm in the function(domoticz,Device) (or function(domoticz,trigger) ) is the object that is triggering the script.
It can be a device, variable, scene, group, timer, security or httpResponse depending on what you defined in the on = (....) section.

Re: I don't know why it doesn't work

Posted: Thursday 19 July 2018 19:02
by jake
@waaren, I based my comment on the initial scripts. Now I see in your suggested improved script (which I think is much better in this situation) that you used the 'trigger' in your script as intended.