Check doors and send command

Moderator: leecollings

Post Reply
Martijn85
Posts: 53
Joined: Wednesday 20 January 2016 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Check doors and send command

Post by Martijn85 »

I use this script to check if my backdoor is open, if so then it wil send a message and set the setpoint to 12°C.
This works good, but i also have front door. If i use the same script for the front door (in total 2 different scripts) only the backdoor working.

When i rename the frontdoor scripts name so the front door is above the backdoor script, only the frontdoor is working.

Can you only run one "time difference" script?

How can i merge this scripts so it checks the back and front door?

Code: Select all

-- Automatically adjust heating setpoint to 12 when back door is left open.

t1 = os.time()
s = otherdevices_lastupdate['Achterdeur']
heater = otherdevices_svalues['Toon Thermostaat']

year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)

commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))

if (otherdevices['Achterdeur'] == 'Open' and difference > 59 and difference < 65) then
        commandArray['SendNotification']='Achterdeur waarschuwing#De Achterdeur staat al meer dan 5 minuten open'
        commandArray['UpdateDevice']='335|0|12.00'
        print("De Achterdeur staat open, zet de thermostraat op 12 graden celsius")
end

return commandArray
tontze
Posts: 317
Joined: Thursday 12 January 2017 15:30
Target OS: Linux
Domoticz version: Beta Ch
Location: Finland
Contact:

Re: Check doors and send command

Post by tontze »

I think other script says door is closed, dont do anything, and other says door open, do something --> conflict ?

Im not guru on these things, so i might be wrong :D
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
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: Check doors and send command

Post by emme »

is the front door a door contact or a simple switch?

the value could change from Open/Closed to On/Off
The most dangerous phrase in any language is:
"We always done this way"
Martijn85
Posts: 53
Joined: Wednesday 20 January 2016 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Check doors and send command

Post by Martijn85 »

emme wrote:is the front door a door contact or a simple switch?
It's a door contact, so it will be open or closed.

Maybe someone can tell me how to putt a second device in the script and check the times for both devices and then send a command for one or both devices if there are longer than 5 minutes open?
User avatar
Siewert308SW
Posts: 288
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Check doors and send command

Post by Siewert308SW »

Maybe something like this

Code: Select all


--[[
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

	@ script_time_doors.lua
	@ Check doors
	
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
--]]

--
-- **********************************************************
-- Time Difference
-- **********************************************************
--

function timedifference(s)
	year = string.sub(s, 1, 4)
	month = string.sub(s, 6, 7)
	day = string.sub(s, 9, 10)
	hour = string.sub(s, 12, 13)
	minutes = string.sub(s, 15, 16)
	seconds = string.sub(s, 18, 19)
	t1 = os.time()
	t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
	difference = os.difftime (t1, t2)
	return difference
end

time_open_max = 300 --300 seconds is 5min
	  
commandArray = {}
-- Frontdoor		
if otherdevices['Voordeur'] == 'Open' 
and timedifference(otherdevices_lastupdate['Voordeur']) > time_open_max 
then	
commandArray['SendNotification']='Voordeur waarschuwing#De voordeur staat al meer dan 5 minuten open'
commandArray['UpdateDevice']='335|0|12.00'
print("De voordeur staat open, zet de thermostraat op 12 graden celsius")
end
		
-- BackDoor		
if otherdevices['Achterdeur'] == 'Open' 
and timedifference(otherdevices_lastupdate['Achterdeur']) > time_open_max 
then	
commandArray['SendNotification']='Achterdeur waarschuwing#De Achterdeur staat al meer dan 5 minuten open'
commandArray['UpdateDevice']='335|0|12.00'
print("De Achterdeur staat open, zet de thermostraat op 12 graden celsius")
end
		
return commandArray
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
gerard76
Posts: 53
Joined: Wednesday 22 March 2017 9:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Check doors and send command

Post by gerard76 »

Code: Select all

commandArray = {}
doors               = {'Voordeur','Achterdeur'}
max_open        = 300 -- in seconds

function timedifference(timestamp)
  y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
  return os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
end

for i, door in pairs(doors) do
  if otherdevices[door] == 'Open' and timedifference(otherdevices_lastupdate[door]) > max_open then
    commandArray['SendNotification'] = 'Waarschuwing#De '..door..' staat al meer dan 5 minuten open'
    commandArray['UpdateDevice']='335|0|12.00'
    print("De "..door.." staat open, zet de thermostraat op 12 graden celsius")
  end
end

return commandArray
Martijn85
Posts: 53
Joined: Wednesday 20 January 2016 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Check doors and send command

Post by Martijn85 »

Wow! Thanks for sharing, works great guys :D
User avatar
mvveelen
Posts: 678
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Check doors and send command

Post by mvveelen »

Nice, and may come in handy But, what if you receive the message, close the door.....it should return to the old (temp) setting, shouldn't it? So the script might be incomplete to accomplish a full automated system in this case.
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest