Script editor Topic is solved

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

User avatar
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

Post by Dnpwwo »

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 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
User avatar
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

Post by remb0 »

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!
User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Script editor

Post by Brutus »

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).
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.
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
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Script editor

Post by Eduard »

Maybe a silly question :oops:, but where can i find this Script Editor in the latest beta?
User avatar
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

Post by Dnpwwo »

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.
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
raym
Posts: 81
Joined: Tuesday 03 November 2015 5:07
Target OS: Linux
Domoticz version: beta
Contact:

Re: RE: Re: Script editor

Post by raym »

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).
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.

Thanks.
User avatar
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

Post by Dnpwwo »

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
Note that the theme is saved every time you save an event.
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
raym
Posts: 81
Joined: Tuesday 03 November 2015 5:07
Target OS: Linux
Domoticz version: beta
Contact:

Re: Script editor

Post by raym »

Dnpwwo wrote: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
Note that the theme is saved every time you save an event.
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).
JustME125
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

Post by JustME125 »

Dnpwwo 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.
How can one add Python afterwards? My domoticz does not show Python so I guess I need to add something Image ?

Verstuurd vanaf mijn HTC One_M8 met Tapatalk
User avatar
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

Post by Dnpwwo »

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.
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
JustME125
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

Post by JustME125 »

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.
Thanks :)

Verstuurd vanaf mijn HTC One_M8 met Tapatalk
User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Script editor

Post by Brutus »

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.
Python for Windows can that be supported?
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
raym
Posts: 81
Joined: Tuesday 03 November 2015 5:07
Target OS: Linux
Domoticz version: beta
Contact:

Re: Script editor

Post by raym »

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.
User avatar
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

Post by Dnpwwo »

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.
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
raym
Posts: 81
Joined: Tuesday 03 November 2015 5:07
Target OS: Linux
Domoticz version: beta
Contact:

Re: Script editor

Post by raym »

@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
Rules_Engine_0.01_example.png
Rules_Engine_0.01_example.png (34.84 KiB) Viewed 3167 times
User avatar
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

Post by remb0 »

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!
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Script editor

Post by ben53252642 »

Does anyone have the solution for:
2016-12-22 22:54:00.431 Error: EventSystem: in Motion: [string "-- General time calc..."]:29: attempt to index global 'devicechanged' (a nil value)
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. :(
Screen Shot 2016-12-22 at 10.58.08 pm.jpg
Screen Shot 2016-12-22 at 10.58.08 pm.jpg (392.52 KiB) Viewed 2719 times
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
Thanks
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
User avatar
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

Post by Westcott »

Hi Ben53252642,
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
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Script editor

Post by ben53252642 »

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?
Screen Shot 2016-12-23 at 12.35.18 am.png
Screen Shot 2016-12-23 at 12.35.18 am.png (111.93 KiB) Viewed 2703 times
I'm hoping getting rid of these errors might speed up the script execution times. :D
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
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Script editor

Post by Egregius »

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

Who is online

Users browsing this forum: No registered users and 1 guest