In my home, I have three Fibaro roller shutters to control the shutters in front of my windows. However, if the window is open, the shutter (or the window) can get damaged if the shutter closes. Since I don't want to put a lot of 'window checks' in all scripts/scenes where I want to a automatically close the shutters, I needed a general script that checks if the window is open when someone (or somewhat ) tries to close the shutter.
When analyzing the log of the shutter, I found out that domoticz uses two ways to issue a close command: it can either say that it needs to switch to 'Closed' or it can set the level of the shutter to the closed level (100 for a regular shutter, 0 for an inverted shutter). So the script needs to deal with both situations.
Also, domoticz does not show if the shutter is moving, it just shows two events: when a motion is started and when the motion has ended. So in order to check if a motion is started (e.g. closing the shutter), I use a user variable. If the current position of the shutter is the same as the old position (saved in the variable), this implies that a motion is starting. If they differ, the motion has ended.
Unfortunately, it turns out that activating the shutter through the hardware button connected to the Fibaro control, does not generate an event. So any user using that button, should pay attention. Fortunately, he or she is next to the window so it is quite easy to see if anything is going wrong...
Since I have three shutters, two with one window and one with two windows, I created a script that can deal with all of these shutters at once. It also takes into account the fact that two of the shutters have inverted wiring (need to change that sometime) so the values of the shut position differ from the regular wired shutter.
Feel free to adjust the code at your will or let me know how to improve it further.
Code: Select all
-- script to ensure that the shutter cannot be closed while there is a window open (blocking the shutter)
-- script only works on closing events initiated from domoticz
-- unfortunately, if the button next to the window is used, it only generates an event when
-- the shutter has stopped moving
--
-- it turns out that closing the shutter can be done in two ways:
-- 1. the svalue is set to 99
-- 2. the device is set to 'closed'
-- In both cases, the device first changes one of these attributes but after that
-- tells domoticz again the current starting position for the movement
-- therefore line ... checks if the two attributes are 'in sync'
-- If they are not in sync, the situation is ignored
--
-- The device normally sends two situations to Domoticz: when the movement
-- starts and when the movement has ended.
-- The script requires a separate variable to check the inital position
-- If the current position and the initial position (variable) are the same,
-- this implies that a movement has started.
-- If the current position and the initial position (variable) are not the same,
-- this implies that the movement has ended.
-- local shutter_device = 'Rolluik rechts'
-- local shutter_open_value = '0' -- Could differ per device if you use an inverted shutter switch
-- local window_device = 'Slaapkamerraam rechts'
-- local luik_positie_variable = 'RolluikRechtsPositie'
commandArray = {}
-- Array of shutters to be checked
shutters = {
Masterrechts = {shutter_device = 'Rolluik rechts' ; shutter_open_value = '0'; window_device_1 = 'Slaapkamerraam rechts'; window_device_2 = 'Slaapkamerraam rechts'; luik_positie_variable = 'RolluikRechtsPositie'};
Masterlinks = {shutter_device = 'Rolluik Links' ; shutter_open_value = '100'; window_device_1 = 'Slaapkamerraam links';window_device_2 = 'Slaapkamerraam links'; luik_positie_variable = 'RolluikLinksPositie'};
Kamerdaniel = {shutter_device = 'Rolluik Daniël' ; shutter_open_value = '0'; window_device_1 = 'Raam Daniël rechts';window_device_2 = 'Raam Daniël links'; luik_positie_variable = 'RolluikDanielPositie'};
}
for shutter ,credentials in pairs(shutters) do
if (devicechanged[credentials.shutter_device]) then
print('<font color="blue"> Stand rolluik ' ..shutter ..': ' ..otherdevices[credentials.shutter_device])
print('<font color="blue"> Positie rolluik ' ..shutter ..': ' ..otherdevices_svalues[credentials.shutter_device])
print('<font color="blue"> Rolluik positie variabele: ' ..uservariables[credentials.luik_positie_variable])
if ((otherdevices_svalues[credentials.shutter_device] == credentials.shutter_open_value) and (otherdevices[credentials.shutter_device] == 'Open')) then -- ignore if two attributes are not in sync
if (otherdevices_svalues[credentials.shutter_device] == tostring(uservariables[credentials.luik_positie_variable])) then --als gelijk dan wordt beweging ingezet
print('<font color="blue"> rolluik ' ..shutter ..' beweging naar beneden ingezet')
if ((otherdevices[credentials.window_device_1]== 'Open') or (otherdevices[credentials.window_device_2]== 'Open')) then
print('<font color="red">Rolluik ' ..shutter ..' wordt gesloten terwijl raam nog open staat')
commandArray[1] = {[credentials.shutter_device]='Set Level ' ..credentials.shutter_open_value}
commandArray[2]={['SendNotification']='Rolluik ' ..shutter ..' wordt gesloten terwijl raam nog open staat'}
commandArray[3] = {['Variable:' ..credentials.luik_positie_variable] = tostring('50')}
end
else
print('<font color="blue"> variabele en positie rolluik waren niet gelijk dus dat wordt gecorrigeerd')
commandArray[1] = {['Variable:' ..credentials.luik_positie_variable] = tostring(otherdevices_svalues[credentials.shutter_device])}
end
end
end
end
return commandArray