Page 4 of 5

Re: Script editor

Posted: Sunday 21 February 2016 21:55
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).

Re: Script editor

Posted: Monday 22 February 2016 9:59
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!

Re: Script editor

Posted: Monday 22 February 2016 19:09
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!

Re: Script editor

Posted: Tuesday 23 February 2016 20:53
by Eduard
Maybe a silly question :oops:, but where can i find this Script Editor in the latest beta?

Re: Script editor

Posted: Wednesday 24 February 2016 3:36
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.

Re: RE: Re: Script editor

Posted: Saturday 05 March 2016 22:36
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.

Re: Script editor

Posted: Saturday 05 March 2016 23:24
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.

Re: Script editor

Posted: Sunday 06 March 2016 3:17
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).

Re: RE: Re: Script editor

Posted: Sunday 06 March 2016 20:27
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

Re: Script editor

Posted: Sunday 06 March 2016 21:12
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.

Re: RE: Re: Script editor

Posted: Sunday 06 March 2016 21:29
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

Re: Script editor

Posted: Monday 07 March 2016 0:35
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?

Re: Script editor

Posted: Thursday 10 March 2016 22:03
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.

Re: Script editor

Posted: Friday 11 March 2016 5:37
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.

Re: Script editor

Posted: Friday 11 March 2016 22:21
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 3268 times

Re: Script editor

Posted: Saturday 12 March 2016 8:03
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!

Re: Script editor

Posted: Thursday 22 December 2016 13:03
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 2820 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

Re: Script editor

Posted: Thursday 22 December 2016 14:33
by Westcott
Hi Ben53252642,
Is it a 'Time' script, rather than a 'Device' script?
That's invariably what "attempt to index global 'devicechanged' " means!

Re: Script editor

Posted: Thursday 22 December 2016 14:38
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 2804 times
I'm hoping getting rid of these errors might speed up the script execution times. :D

Re: Script editor

Posted: Thursday 22 December 2016 14:39
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