Script editor Topic is solved
Moderators: leecollings, remb0
- Dnpwwo
- Posts: 820
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Script editor
Hi Brutus,
The theme is saved when you 'Save' a script, can you try that?
Also, the standard way to change settings is to use "<ctrl>," which should work in every browser and is built into the editor.
In Firefox its easy to add things to the right click menu (so I did).
The theme is saved when you 'Save' a script, can you try that?
Also, the standard way to change settings is to use "<ctrl>," which should work in every browser and is built into the editor.
In Firefox its easy to add things to the right click menu (so I did).
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
- remb0
- Posts: 499
- Joined: Thursday 11 July 2013 22:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: Script editor
Tested it on edge and chrome but no option. So I used firefox portable to change theme and I see it on my other browsers
a little work around but good for me.
Thanks!

Thanks!
- Brutus
- Posts: 249
- Joined: Friday 26 September 2014 9:33
- Target OS: Windows
- Domoticz version:
- Location: Netherlands
- Contact:
Re: Script editor
I think i didn't saved the script indeed. I have installad the latest Windows Build V2.4707 and now it is working right away.Dnpwwo wrote:Hi Brutus,
The theme is saved when you 'Save' a script, can you try that?
Also, the standard way to change settings is to use "<ctrl>," which should work in every browser and is built into the editor.
In Firefox its easy to add things to the right click menu (so I did).
Changed some LUA scripts and saved them.
Firefox is fine for me

Thnx for your help and making this option available!
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
Re: Script editor
Maybe a silly question
, but where can i find this Script Editor in the latest beta?

- Dnpwwo
- Posts: 820
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Script editor
On the normal 'Events' page.
By default the page shows Blockly but there is a drop down to switch from Blockly to Lua (& Python if Domoticz was built with Python support turned on). If you select Lua then the editor is shown.
By default the page shows Blockly but there is a drop down to switch from Blockly to Lua (& Python if Domoticz was built with Python support turned on). If you select Lua then the editor is shown.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
-
- Posts: 81
- Joined: Tuesday 03 November 2015 5:07
- Target OS: Linux
- Domoticz version: beta
- Contact:
Re: RE: Re: Script editor
Could you please guide me through how to change the theme? I am not seeing any way/option to do this and I don't understand what <ctrl> means in this context... Nothing happens when I hit the control key.Dnpwwo wrote:Hi Brutus,
The theme is saved when you 'Save' a script, can you try that?
Also, the standard way to change settings is to use "<ctrl>," which should work in every browser and is built into the editor.
In Firefox its easy to add things to the right click menu (so I did).
Thanks.
- Dnpwwo
- Posts: 820
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Script editor
There are 2 ways to do it:
- The default built in way: Hold the Control Key and the comma key at the same time. Works on all browsers.
- The custom way (firefox only): Right click the editor and there is a menu item for it
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
-
- Posts: 81
- Joined: Tuesday 03 November 2015 5:07
- Target OS: Linux
- Domoticz version: beta
- Contact:
Re: Script editor
Thank you! I feel a bit silly though because I didn't realise this was just for the script editor. I thought there was some way of changing the blocky theme as well (since I've seen various color schemes and different visual representations of similar blocky systems online).Dnpwwo wrote:There are 2 ways to do it:Note that the theme is saved every time you save an event.
- The default built in way: Hold the Control Key and the comma key at the same time. Works on all browsers.
- The custom way (firefox only): Right click the editor and there is a menu item for it
-
- Posts: 31
- Joined: Monday 27 April 2015 16:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.4547
- Location: The Netherlands
- Contact:
Re: RE: Re: Script editor
How can one add Python afterwards? My domoticz does not show Python so I guess I need to add somethingDnpwwo wrote:On the normal 'Events' page.
By default the page shows Blockly but there is a drop down to switch from Blockly to Lua (& Python if Domoticz was built with Python support turned on). If you select Lua then the editor is shown.

Verstuurd vanaf mijn HTC One_M8 met Tapatalk
- Dnpwwo
- Posts: 820
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Script editor
I believe you need to build from source on Uniz or Mac and enable python support.
See http://www.domoticz.com/forum/viewtopic ... =40#p71795. Also try searching the forum for posts by the same person, I believe he/she added python support to Domoticz.
See http://www.domoticz.com/forum/viewtopic ... =40#p71795. Also try searching the forum for posts by the same person, I believe he/she added python support to Domoticz.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
-
- Posts: 31
- Joined: Monday 27 April 2015 16:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.4547
- Location: The Netherlands
- Contact:
Re: RE: Re: Script editor
ThanksDnpwwo wrote:I believe you need to build from source on Uniz or Mac and enable python support.
See http://www.domoticz.com/forum/viewtopic ... =40#p71795. Also try searching the forum for posts by the same person, I believe he/she added python support to Domoticz.

Verstuurd vanaf mijn HTC One_M8 met Tapatalk
- Brutus
- Posts: 249
- Joined: Friday 26 September 2014 9:33
- Target OS: Windows
- Domoticz version:
- Location: Netherlands
- Contact:
Re: Script editor
Python for Windows can that be supported?Dnpwwo wrote:I believe you need to build from source on Uniz or Mac and enable python support.
See http://www.domoticz.com/forum/viewtopic ... =40#p71795. Also try searching the forum for posts by the same person, I believe he/she added python support to Domoticz.
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
-
- Posts: 81
- Joined: Tuesday 03 November 2015 5:07
- Target OS: Linux
- Domoticz version: beta
- Contact:
Re: Script editor
This is probably a dumb question but related to the theme discussion I guess... Is it actually possible to alter the theme of blocky too, like lua? Im thinking colors primarily. Totally aesthetic I know but just curious.
- Dnpwwo
- Posts: 820
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Script editor
Finally got around to updating the wiki with some details http://www.domoticz.com/wiki/Events please have a look before posting. I tried to answer most of the common questions in the wiki.
Blockly editor can not be themed (according to my Google search), happy to be corrected.
Python support is in another thread on the forum. The database, Events page and editor will handle Python if support was compiled in but that's as far as I went.
Blockly editor can not be themed (according to my Google search), happy to be corrected.
Python support is in another thread on the forum. The database, Events page and editor will handle Python if support was compiled in but that's as far as I went.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
-
- Posts: 81
- Joined: Tuesday 03 November 2015 5:07
- Target OS: Linux
- Domoticz version: beta
- Contact:
Re: Script editor
@dnpwwo, thanks for this. Your efforts on this change are much appreciated.
PS - thanks for investigating if blocky could be themed. I only ask as I've seen various similar looking blocky implementations on the web which suggested to me it might be possible. Here's a recent example being built for Vera but perhaps it's based on something entirely different: http://forum.micasaverde.com/index.php? ... msg#254021
PS - thanks for investigating if blocky could be themed. I only ask as I've seen various similar looking blocky implementations on the web which suggested to me it might be possible. Here's a recent example being built for Vera but perhaps it's based on something entirely different: http://forum.micasaverde.com/index.php? ... msg#254021
- remb0
- Posts: 499
- Joined: Thursday 11 July 2013 22:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: Script editor
Dnpwwo wrote:Finally got around to updating the wiki with some details http://www.domoticz.com/wiki/Events please have a look before posting. I tried to answer most of the common questions in the wiki.
Thanks! Great work!
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: Script editor
Does anyone have the solution for:
Even though it's happening for pretty much all scripts, here is my lua motion script:
Thanks
I'm trying to work out why my scripts sometimes take a long time to execute (up to 5 seconds), my log is just getting filled with these errors non-stop, I've searched the whole forum but can't find what is causing it. I'm using the latest beta 3.6224 and this has been happening for a long time.2016-12-22 22:54:00.431 Error: EventSystem: in Motion: [string "-- General time calc..."]:29: attempt to index global 'devicechanged' (a nil value)

Even though it's happening for pretty much all scripts, here is my lua motion script:
Code: Select all
-- General time calc
t1 = os.time()
-- Time between Main Bathroom Motion
s1 = otherdevices_lastupdate['Main Bathroom Motion']
year = string.sub(s1, 1, 4)
month = string.sub(s1, 6, 7)
day = string.sub(s1, 9, 10)
hour = string.sub(s1, 12, 13)
minutes = string.sub(s1, 15, 16)
seconds = string.sub(s1, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference1 = (os.difftime (t1, t2))
-- Time between Main Bathroom Hallway Motion
s2 = otherdevices_lastupdate['Main Bedroom Hallway Motion']
year = string.sub(s2, 1, 4)
month = string.sub(s2, 6, 7)
day = string.sub(s2, 9, 10)
hour = string.sub(s2, 12, 13)
minutes = string.sub(s2, 15, 16)
seconds = string.sub(s2, 18, 19)
t3 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference2 = (os.difftime (t1, t3))
commandArray = {}
--- Main Bathroom
if (devicechanged["Main Bathroom Motion"] == 'On' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bathroom'] = 'On'
end
--- Main Bedroom Hallway
if (devicechanged["Main Bedroom Hallway Motion"] == 'On' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bedroom Hallway'] = 'On'
end
--- Second Bathroom
if (devicechanged["Second Bathroom Motion"] == 'On' and otherdevices["Motion Detection"] == 'On') then
commandArray['Second Bathroom'] = 'On'
end
--- Living Room and Kitchen
if (devicechanged["Living Room Entrance Motion"] == 'On' and otherdevices["Motion Detection"] == 'On') then
commandArray['Kitchen'] = 'On'
commandArray['Living Room Middle'] = 'On'
end
--- Main Entrance Hallway
if (devicechanged["Main Entrance Motion Sensor"] == 'On' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Entrance Hallway'] = 'On'
end
--- Main Bedroom Entrance
if (devicechanged["Main Bedroom Entrance Motion"] == 'On' and otherdevices["Main Bedroom Door Sensor"] == 'Open' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bedroom'] = 'On'
end
if (devicechanged["Main Bedroom Door Sensor"] == 'Open' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bedroom'] = 'On'
commandArray['Main Entrance Hallway'] = 'On'
end
if (devicechanged["Main Bedroom Door Sensor"] == 'Closed' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Entrance Hallway'] = 'Off'
commandArray['Second Bathroom'] = 'Off'
commandArray['Kitchen'] = 'Off'
commandArray['Living Room Middle'] = 'Off'
commandArray['Living Room Window'] = 'Off'
end
--- Second Bedroom Entrance
if (devicechanged["Second Bedroom Entrance Motion"] == 'On' and otherdevices["Second Bedroom Door Sensor"] == 'Open' and otherdevices["Motion Detection"] == 'On') then
commandArray['Second Bedroom'] = 'On'
end
if (devicechanged["Second Bedroom Door Sensor"] == 'Open' and otherdevices["Motion Detection"] == 'On') then
commandArray['Second Bedroom'] = 'On'
commandArray['Main Entrance Hallway'] = 'On'
end
if (devicechanged["Second Bedroom Door Sensor"] == 'Closed' and otherdevices["Main Bedroom Door Sensor"] == 'Closed' and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Entrance Hallway'] = 'Off'
commandArray['Second Bathroom'] = 'Off'
commandArray['Kitchen'] = 'Off'
commandArray['Living Room Middle'] = 'Off'
commandArray['Living Room Window'] = 'Off'
end
-- Automatic light turn off power control
if (devicechanged["Main Entrance Motion Sensor"] == 'On' and difference1 > 900 and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bathroom'] = 'Off'
end
if (devicechanged["Living Room Entrance Motion"] == 'On' and difference1 > 900 and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bathroom'] = 'Off'
end
if (devicechanged["Main Entrance Motion Sensor"] == 'On' and difference2 > 900 and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bedroom Hallway'] = 'Off'
end
if (devicechanged["Living Room Entrance Motion"] == 'On' and difference2 > 900 and otherdevices["Motion Detection"] == 'On') then
commandArray['Main Bedroom Hallway'] = 'Off'
end
return commandArray
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
- Westcott
- Posts: 423
- Joined: Tuesday 09 December 2014 17:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: UK - Glos
- Contact:
Re: Script editor
Hi Ben53252642,
Is it a 'Time' script, rather than a 'Device' script?
That's invariably what "attempt to index global 'devicechanged' " means!
Is it a 'Time' script, rather than a 'Device' script?
That's invariably what "attempt to index global 'devicechanged' " means!
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: Script editor
It should be a device change script (that's the trigger) and then it references last changed times during the execution, but how to differentiate when script is stored in the database?
If it we're a file I would just call it "script_device_motion.lua", what is the equivalent for the database script manager?
I'm hoping getting rid of these errors might speed up the script execution times.
If it we're a file I would just call it "script_device_motion.lua", what is the equivalent for the database script manager?
I'm hoping getting rid of these errors might speed up the script execution times.

Last edited by ben53252642 on Thursday 22 December 2016 14:40, edited 1 time in total.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
- Egregius
- Posts: 2589
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Script editor
You're script is faulty.
If motion is on = light on
If motion is on and timediff > 900 = light on?
You can't combine a device and time script in one. In a time script the devicechanged table isn't available.
Edit for your last respone: in the dropdown list at the right: All/device/timee
If motion is on = light on
If motion is on and timediff > 900 = light on?
You can't combine a device and time script in one. In a time script the devicechanged table isn't available.
Edit for your last respone: in the dropdown list at the right: All/device/timee
Who is online
Users browsing this forum: No registered users and 1 guest