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

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

Moderator: leecollings

Post Reply
void
Posts: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
}
Last edited by void on Saturday 27 January 2018 19:56, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script for turning on a charger at specific time

Post by waaren »

You need a comma between } and execute
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
void
Posts: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script for turning on a charger at specific time

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

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest