Page 1 of 1

[Solved] Script for turning on a charger at specific time

Posted: Saturday 27 January 2018 19:39
by void
Edit: Solved, at the bottom of this post the working version for anyone that's interested.


Hi all,

I've tried to make this script which will turn on a switch (HomeEasy) at weekdays at 23:15 so the attached devices (phones, tablets, etc) can be charged with the cheaper power at night. However I keep getting this error and I must be getting blind but I can't figure out what I'm doing wrong...
Log:
2018-01-27 19:33:00.449 Error: dzVents: Error: error loading module 'ChargerStation' from file '/home/pi/domoticz/scripts/dzVents/scripts/ChargerStation.lua':
...e/pi/domoticz/scripts/dzVents/scripts/ChargerStation.lua:8: '}' expected (to close '{' at line 1) near 'execute'
Here is the script:

Code: Select all

return {
        active = false,
        on = {
                timer = {
                        'at 23:15 on mon,tue,wed,thu,fri',
                        }
                }
        execute = function(domoticz, timer)
                domoticz.log('Daluren stroom, ChargerStation aangezet')
                domoticz.log('The rule that triggered the event was: ' .. timer.trigger')
                domoticz.devices('Lamp_4').switchOn().forMin(240)
                end
        end
}
Can someone please point me in the right direction?

Cheers,
void



Working version:

Code: Select all

return {
        active = true,
        on = {
                timer = {
                        'at 23:15 on mon,tue,wed,thu,fri',
                        }
                },
        execute = function(domoticz, timer)
                domoticz.log('Daluren stroom, ChargerStation aangezet')
                domoticz.devices('Lamp_4').switchOn().forMin(240)
                end
}

Re: Script for turning on a charger at specific time

Posted: Saturday 27 January 2018 19:43
by waaren
You need a comma between } and execute

Re: Script for turning on a charger at specific time

Posted: Saturday 27 January 2018 19:53
by void
... <voeg hier een aantal scheldwoorden in>
Ik wist wel dat het niet iets groots kon zijn, man man man... en maar haakjes tellen :D

Thanks!

Re: [Solved] Script for turning on a charger at specific time

Posted: Saturday 27 January 2018 20:11
by waaren
To make it work (dzVents 2.4.1)

Code: Select all

return {       
        on = { timer = {'at 23:15 on mon,tue,wed,thu,fri' }},
        -- on = { timer = {'every minute' }},

       execute = function(domoticz, device, triggerInfo)
      
                print ('Daluren stroom, ChargerStation aangezet')
                print ('The rule that triggered the event was: ' .. triggerInfo.trigger)
                domoticz.devices('Bedlampjes').switchOn().forMin(240)
	end
}