Page 1 of 1

[LUA - PIR and DIMMER] How to override the "SET... FOR... " command

Posted: Sunday 30 October 2016 0:53
by buchu
Hi all and thank you all for all your ideas around this forum!
In my system (DOMOTICZ on RASPBERRY) I have a PIR sensor in a hallway.
During the night, from bedroom you must to pass in this hallway (where I have a Fibaro Motion Sensor) to go to the bathroom (where there is a FIBARO DIMMER) .
In LUA I write a simple script that SET LEVEL 20% to batroom FOR 2 MINUTES during nighttime (so your eyes are safe!) :-D.
All is ok, but only when we are sleeping!
Because, if someone go to bathroom for a shower in the evening, in example, the light turn off after 2 minutes (it must to pass through the hallway).

I would like to understand if there is the possibility to "cancel" the LUA command ("set 20 for 2") if I press the BATHROOM SWITCH (linked to S1 of the DIMMER).
I read all the SMART LUA and SMART PIR sections, but no idea there to cancel (or what else!) the first command set from the LUA SCRIPT.

Code: Select all

-- NightLightBathroom.lua
-- Bathroom Dimmer name: Level Luce Bagno
-- Hallway PIR SENSOR: Sensore Disimpegno

local DeviceDimmer = 'Level Luce Bagno'
local DeviceSensore = 'Sensore Disimpegno'
local SetLevel = 'Off'

commandArray = {}

if (devicechanged[DeviceSensore]) then
    		if (timeofday['Nighttime']) and (otherdevices[DeviceDimmer]=="Off") then
        		SetLevel = 'Set Level 20 FOR 2';
        commandArray[DeviceDimmer] = SetLevel
    end
end
So... anyone can explain me how to make a shower with light on after dinner? :-)

Thank you a lot in advance!
If you need some other informations to help me, please ask me.

Giulio

Re: [LUA - PIR and DIMMER] How to override the "SET... FOR... " command

Posted: Sunday 30 October 2016 7:43
by bobkersten
Could you try sending an On command from Lua (so in addition to the manual press)? It should cancel all future events for the same device.

Re: [LUA - PIR and DIMMER] How to override the "SET... FOR... " command

Posted: Sunday 30 October 2016 12:08
by buchu
I'll try... today if we stop dancing! :-(

Inviato dal mio SM-G935F utilizzando Tapatalk

Re: [LUA - PIR and DIMMER] How to override the "SET... FOR... " command

Posted: Tuesday 01 November 2016 23:27
by buchu
OK, after earthquake I tried and let me say that I'm losing for now!
I tried to add a lua script to run when I switch on the dimmer manually, but after 2 minutes light goes already off... :-(
The problem is that the first script sets "... FOR 2" and then the script is not running when I execute the "Switch on" LUA as you suggested.

I'm trying... and trying... LOL

Thank you a lot.
Giulio

Re: [LUA - PIR and DIMMER] How to override the "SET... FOR... " command

Posted: Wednesday 02 November 2016 17:36
by emme
Ciao Giulio

let's assume that you are having a shower... so you switch on the S1 on the dimmer to switch the bathroom

We also assume that once you finish your shower you are suppose to exit the bathroom and switch off the light...
that would be the momento that will trigger the hallway light without caring the PIR :P

Code: Select all

-- NightLightBathroom.lua
-- Bathroom Dimmer name: Level Luce Bagno
-- Hallway PIR SENSOR: Sensore Disimpegno

local DeviceBagno = 'Interruttore Bagno (S1)'
local DeviceDimmer = 'Level Luce Bagno'
local DeviceSensore = 'Sensore Disimpegno'
local SetLevel = 'Off'

commandArray = {}

if (devicechanged[DeviceSensore]) then
        if (timeofday['Nighttime']) and (otherdevices[DeviceDimmer]=="Off") then
              SetLevel = 'Set Level 20 FOR 2'
              commandArray[DeviceDimmer] = SetLevel
        else  -- OPTIONAL... se accendi la luce spegni il corridoio
        	commandArray[DeviceDimmer] = 'Off'
	end
end

-- Valutazione della luce del Bagno
-- Se cambia stato e va in OFF ed รจ notte, il Dimmer viene impostato acceso
if (devicechanged[DeviceBagno]) and (timeofday['Nighttime']) then
	if otherdevice[DeviceBagno] == 'Off' then
		SetLevel = 'Set Level 20 FOR 2'
		commandArray[DeviceDimmer] = SetLevel
	else      -- OPTIONAL - se accedi la luce, si spegne il corridoio
		commandArray[DeviceDimmer] = 'Off'
		
	end
end

return commandArray
got to try it :P :P
ciao
M

P.S.
spero che il terremoto non vi abbia procurato nient'altro che paura!