LUA optimize scripts
Posted: Friday 20 November 2015 9:39
Hi, I have 12 Lua scripts on my system that is used to do different tasks throughout the day.
I have a feeling that this can be done in a cleaner way, maybe not relying on that many scripts? Also I am certain that these scripts can be greatly improved.
- script_device_movement.lua - detects movement and turns on a dummy-switch called Movement Livingroom.
- script_device_homeon.lua - detects if Movement Livingroom and/or dummy-switches for me and my wife's cellphones ar switched on, then turns on a dummy-switch called Home.
- script_time_homeoff.lua - switches off the dummy-switch Home if Movement Livingroom and cellphones are off.
- script_device_noonehome.lua - executes a scene that turns off lights if Home and a dummy-switch for my Chromecast is off.
- script_device_lux_lvingroomoff.lua turns off all lights if lux is below a given value.
- script_device_override.lua turns on all lights if a dummy-switch called Override is turned on. (I have also added a condition in all scripts that commands for turning off lights only runs if the Override-switch is off.
- script_device_watchestv.lua checks the time and switches scene when watching TV if the time is between 8am and 8pm, or otherwise. It also checks lux values to keep lights off if its not necessary to turn them on.
- script_device_livingroomon.lua turns on day/evening scenes depending on the time of day when motion is triggered and lux is below a given value. Also if media device like Chromecast is switched off.
- script_device_livingroomon2.lua same as above, the only difference is that it is not checking if motion is detected, only of the motion-switch is in an 'On' state.
- script_time_bevegelseoff.lua turns off Movement Livingroom if no motion is detected the last 30 minutes.
- script_time_lightdaynight.lua switches scenes depending on the time of day and if the TV is on or not.
- script_time_nightmode.lua turns off all lights if no movement and TV/Chromecast is off between 11PM and 6 AM.
I have attached the scrips as a zip if anyone want to take a look and maybe come with improvements.
Also this post may help others get a better grip of all the possibilities with lua in Domoticz.
Thanks!
I have a feeling that this can be done in a cleaner way, maybe not relying on that many scripts? Also I am certain that these scripts can be greatly improved.
- script_device_movement.lua - detects movement and turns on a dummy-switch called Movement Livingroom.
- script_device_homeon.lua - detects if Movement Livingroom and/or dummy-switches for me and my wife's cellphones ar switched on, then turns on a dummy-switch called Home.
- script_time_homeoff.lua - switches off the dummy-switch Home if Movement Livingroom and cellphones are off.
- script_device_noonehome.lua - executes a scene that turns off lights if Home and a dummy-switch for my Chromecast is off.
- script_device_lux_lvingroomoff.lua turns off all lights if lux is below a given value.
- script_device_override.lua turns on all lights if a dummy-switch called Override is turned on. (I have also added a condition in all scripts that commands for turning off lights only runs if the Override-switch is off.
- script_device_watchestv.lua checks the time and switches scene when watching TV if the time is between 8am and 8pm, or otherwise. It also checks lux values to keep lights off if its not necessary to turn them on.
- script_device_livingroomon.lua turns on day/evening scenes depending on the time of day when motion is triggered and lux is below a given value. Also if media device like Chromecast is switched off.
- script_device_livingroomon2.lua same as above, the only difference is that it is not checking if motion is detected, only of the motion-switch is in an 'On' state.
- script_time_bevegelseoff.lua turns off Movement Livingroom if no motion is detected the last 30 minutes.
- script_time_lightdaynight.lua switches scenes depending on the time of day and if the TV is on or not.
- script_time_nightmode.lua turns off all lights if no movement and TV/Chromecast is off between 11PM and 6 AM.
I have attached the scrips as a zip if anyone want to take a look and maybe come with improvements.
Also this post may help others get a better grip of all the possibilities with lua in Domoticz.
Thanks!