Logic Machine Forum
Fasades lighting script by time and outside sensor - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Fasades lighting script by time and outside sensor (/showthread.php?tid=4322)



Fasades lighting script by time and outside sensor - AlexLV - 25.10.2022

Hi, I started to create widget for fasades lighting and easy script, but all not so easy for me. Idea - swich On/off by time or/and outside sensor.

At widget I need enter hour/min for On time and hour.min for Off time. Also I added Sensor control - Light level form sensor, Lux when Light will be On, and Delta when Light should be off.

Below my widget (not finished) and script. 

Some moments I need help:

1. How to show zero in front if hours or minutes from 0 to 9 ?
2. For me my idea not forking correctly, fasades light is flashing some times.
3. How check "mistakes" settings better?

Not found example at forum. 
i used resident script 1 minute.

Code:
HStart = grp.getvalue('0/1/100') -- Hours to start Fasades Light On
MinStart = grp.getvalue('0/1/101') -- Minutes to start Fasades Light On
HStop = grp.getvalue('0/1/102') -- Hours to stop Fasades Light On
MinStop = grp.getvalue('0/1/103') -- Minutes to stop Fasades Light On
SensorValue = grp.getvalue('1/0/100') -- Outside Light Sensor Value LUX
SensorLightOn = grp.getvalue('0/1/105') -- LightOn Value LUX
LightOffHysteresis = grp.getvalue('0/1/106') -- LightOff Hysteresis LUX


-------------------------------------------------------------------------
now = os.date('*t')


-- time table
time = {
day = wday,
hour = now.hour,
minute = now.min,
second = now.sec,
}

if (now.hour == HStart) and (now.min == MinStart)then
  FasadesLightTime = 1
  grp.write ('0/2/19', 1) -- Group Fasades Light
  end
if (now.hour == HStop) and (now.min == MinStop) then
  FasadesLightTime = 0
  grp.write ('0/2/19', 0)
  end
if SensorValue <= SensorLightOn then
SensorOn = 1
  grp.write ('0/2/19', 1)
end
if SensorValue > SensorLightOn + LightOffHysteresis then
SensorOn = 0
  grp.write ('0/2/19', 0)
end
   

BR, 

Alex


RE: Fasades lighting script by time and outside sensor - admin - 25.10.2022

You have 4 independent IF statements. This causes the light to flicker if more than one statement is true.
I think it makes more sense to create a scheduler tied to sunrise/sunset instead of manually specifying the time.


RE: Fasades lighting script by time and outside sensor - AlexLV - 25.10.2022

Yes, but customer wants such way. I will try to propose sunset/sunrise variant to him.

Alex


RE: Fasades lighting script by time and outside sensor - admin - 25.10.2022

Then you need to define your logic correctly. Right now time and sensor value are independent. I suppose you want to control the light using sensor value only when the current time is between user-defined on/off time.


RE: Fasades lighting script by time and outside sensor - Gadjoken - 26.10.2022

Hello,

I use several scripts to achieve I think what you want:

Script 1 : Scheduled Minute 1,16,31,46 every Hour every Month every day name COMMANDE ECLAIRAGE EXTERIEUR (The name is used in a script to disable it):

Code:
-- Commande Eclairage exterieur
ConsigneLux = grp.getvalue('35/1/3') -- Consigne Lux spaceLYNK
StationBat = grp.getvalue('3/0/0') -- Valeur station météo

if ConsigneLux > StationBat then
    grp.write('0/0/53', true)
    grp.write('0/0/54', true)
    --grp.write('0/0/63', true)
elseif ConsigneLux < StationBat then
    grp.write('0/0/53', false)
    grp.write('0/0/54', false)
    --grp.write('0/0/63', false)
end

Script 2 : Event-Based sur 35/1/2=Commande calendrier éclairage extérieur :

Code:
ConsigneH = event.getvalue() -- Retour calendrier - Eclairage exterieur
AutoManu = grp.getvalue('35/1/1') -- Auto / Manu Eclairage exterieur (true=Auto false=Manu)

if ConsigneH == true and AutoManu == true then
    script.enable('COMMANDE ECLAIRAGE EXTERIEUR')
elseif ConsigneH == false and AutoManu == true then
    script.disable('COMMANDE ECLAIRAGE EXTERIEUR')
  grp.write('0/0/53', false)
  grp.write('0/0/54', false)
  --grp.write('0/0/63', false)
end

Script 3 : Event-Based sur 35/1/1=Auto/manu eclairage extérieur :

Code:
ConsigneLux = grp.getvalue('35/1/3') -- Consigne Lux spaceLYNK
StationBat = grp.getvalue('3/0/0') -- Valeur station
ConsigneH = grp.getvalue('35/1/2') -- Retour calendrier - Eclairage exterieur
AutoManu = grp.getvalue('35/1/1') -- Auto / Manu Eclairage exterieur (true=Auto false=Manu)

if AutoManu == false then
    script.disable('COMMANDE ECLAIRAGE EXTERIEUR')                        -- Si nous passons en Mode Manu. alors nous désactivons le script de l'auto. nous gardons l'état précédent de l'éclairage
 
elseif ConsigneH == true and AutoManu == true and ConsigneLux > StationBat then
    grp.write('0/0/53', true)
    grp.write('0/0/54', true)
    --grp.write('0/0/63', true)
    script.enable('COMMANDE ECLAIRAGE EXTERIEUR')                         -- Si nous passons en Auto. et qu'il y a besoin de l'éclairage, que nous sommes dans la tranche Horraire alors nous allumons et nous activons le script Auto.
 
elseif ConsigneH == true and AutoManu == true and ConsigneLux < StationBat then
    grp.write('0/0/53', false)
    grp.write('0/0/54', false)
    --grp.write('0/0/63', false)
    script.enable('COMMANDE ECLAIRAGE EXTERIEUR')                         -- Si nous passons en Auto. et qu'il n'y a pas besoin de l'éclairage, que nous sommes dans la tranche Horraire alors nous éteignons et nous activons le script Auto.
 
elseif ConsigneH == false and AutoManu == true then
    grp.write('0/0/53', false)
    grp.write('0/0/54', false)
    --grp.write('0/0/63', false)
    script.enable('COMMANDE ECLAIRAGE EXTERIEUR')                         -- Si nous passons en Auto. et que nous ne sommes pas dans la tranche Horraire alors nous éteignons et nous désactivons le script Auto.
end

Then you create a calendar with 35/1/2 Exterior lighting control and you integrate it in addition to your lux setpoint (35/1/3) in your supervision which will give the attached photo, the customer can modify via the schedule the start/stop times in the morning and evening as well as the lux setpoint.

I also added on another page the auto/manu object so that the customer can turn on or off his lighting as he wishes without this automation.

B.R.