I don't know why it doesn't work

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

Moderator: leecollings

Post Reply
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

I don't know why it doesn't work

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

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

Post by pascal »

No I don't see anything in logfile. even with yours. Amazing
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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"
?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

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

Post by pascal »

I just did, but nothing happens. Probably something I did not do properly, but I don't know what.
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

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

Post 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 :-)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Last edited by waaren on Thursday 19 July 2018 7:14, edited 2 times in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

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

Post 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)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

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

Post by pascal »

any clue? :-(
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pascal
Posts: 9
Joined: Sunday 28 September 2014 15:31
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Contact:

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

Post 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
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

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

Post 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)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests