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

Moderator: leecollings

Post Reply
buchu
Posts: 3
Joined: Thursday 19 May 2016 10:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5817
Location: Rome
Contact:

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

Post 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
Giulio - Rome (IT)
Raspberry Pi 3 Jessie OS - Domoticz 3.5834 with USB Aeotec DSA02203 Z-Stick S2
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

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

Post 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.
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
buchu
Posts: 3
Joined: Thursday 19 May 2016 10:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5817
Location: Rome
Contact:

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

Post by buchu »

I'll try... today if we stop dancing! :-(

Inviato dal mio SM-G935F utilizzando Tapatalk
Giulio - Rome (IT)
Raspberry Pi 3 Jessie OS - Domoticz 3.5834 with USB Aeotec DSA02203 Z-Stick S2
buchu
Posts: 3
Joined: Thursday 19 May 2016 10:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5817
Location: Rome
Contact:

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

Post 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
Giulio - Rome (IT)
Raspberry Pi 3 Jessie OS - Domoticz 3.5834 with USB Aeotec DSA02203 Z-Stick S2
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post 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!
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest