Window Switch + Temperatur + Timer

Moderator: leecollings

Post Reply
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Window Switch + Temperatur + Timer

Post by Schorschi »

Hello,

It is my First home automation with domoticz.
My hardware configuration:
- raspberry Pi 1 with domoticz
- xiaomi gatewy
- window Switch
- temperature Sensor

I habe Running this Setup. I Cam Read sensors, control gateway light etc.

My usw case:
It Switch Open then Start Timer
Else Reset Timer

It Switch Open AND timer bigger 3 minutes AND temperatur smaller 10 Athen
Toggle gateway light
Play continuous an mp3 File
Else
Switch Off light
Stop Play mp3 File

My Problem is that i don't know how to configure this sequence?

I Need some First steps Tutorials or something similar.

Thx
Schorsci
mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Window Switch + Temperatur + Timer

Post by mayyam »

I have something like this for my cat flap:

Code: Select all

-- print('cat')

-- script_time_cat_flap.lua
t1 = os.time()
s = otherdevices_lastupdate['KON_aqara_salon_koty']
-- returns a date time like 2013-07-11 17:23:12

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['KON_aqara_salon_koty'] == 'On' and difference > 15 and difference < 700) then
    		commandArray['SendNotification']='Warning! Cat flap opened to long.#Cat flap opened to long!'
    		print('cats')
    		commandArray['Xiaomi_Gateway_Volume']='Set Level: 70'
    		commandArray['Mid Value']='Set Level: 4'
    		commandArray['Xiaomi_Gateway_MP3']='On'
    		commandArray['Xiaomi_Gateway_Volume']='Set Level: 40'
	end

return commandArray
I have Aqara door sensors too but i switched them in Domoticz to regular switches, because i can change the icon then.
Thats why i have "if (otherdevices['KON_aqara_salon_koty'] == 'On" "On" here instead of "Open". You should use "Open"
You can add another "and" for temperature and another "commandArrays" for things You want to do.
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Window Switch + Temperatur + Timer

Post by Schorschi »

Hello,

thank you for this helpfull script.
But i don't get any script running.

I wrote one easy script:

Code: Select all

#!/usr/bin/lua


--print('this will end up in the domoticz log')

commandArray = {}
if (devicechanged['SW_1OG_BAD'] == 'On') then
      commandArray['Xiaomi RGB Gateway']='On'
--    print('this will end up in the domoticz log')
end
return commandArray
But i get:

2017-12-03 16:57:29.888 (Xiaomi Gateway 1) Light/Switch (SW_1OG_BAD)
2017-12-03 16:57:30.071 Executing script: /home/pi/domoticz/scripts/lua//script_device_switch.lua
2017-12-03 16:57:30.101 Error: Error executing script command (/home/pi/domoticz/scripts/lua//script_device_switch.lua). returned: 256

If i try to start this script directly from linux i get:

pi@raspberrypi:~/domoticz/scripts/lua $ ./script_device_switch.lua
/usr/bin/lua: ./script_device_switch.lua:7: attempt to index global 'devicechanged' (a nil value)
stack traceback:
./script_device_switch.lua:7: in main chunk
[C]: ?

Someone any idea?
I readed some threads but nothing helps me.

thx.
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Window Switch + Temperatur + Timer

Post by Schorschi »

Hi,

additional i tried also lua and this cyclic started script "script_device_switch.lua".

Code: Select all


#!/usr/bin/lua
--print('this will end up in the domoticz log')

commandArray = {}
if (devicechanged['SW_1OG_BAD'] == 'On') then
      commandArray['Xiaomi RGB Gateway']='Off'
end
if (devicechanged['SW_1OG_BAD'] == 'Off') then
      commandArray['Xiaomi RGB Gateway']='On'
end
return commandArray

But if i wait of devicechanged event nothing happens.
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Window Switch + Temperatur + Timer

Post by Schorschi »

Hello,

now i get some scripts running.

But i have some basic questions:

1. script_device_*.lua
When is this script called?
In my configuration it is not called on every change event of my door switch.
I see that the state is changed (switch is on dashboard) but the script is not called.

2. script_time_*.lua
This script is called every 60 seconds. Correct?

3. custom_script.lua
I tried to start an script from an event of my switch.
Directly configured in the switch config. Start script on event...
There i get no access to domotics arrays. Is there any was to implement them?

thx
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Window Switch + Temperatur + Timer

Post by Schorschi »

HI,

now i read some documentation and understand how the scripts working.

I have one problem:

My use case is still the same as i wrote in first entry.

Sometimes i see on the dashboard and also in the log of the window switch that the window switch is "closed".
BUT my time script don't get this information. The state is always old and stay on "open"
It looks like the time script don't get the last update.

Some ideas?
Is it possible to force an update?

Here my code:

Code: Select all

commandArray = {}
	-- *** Switch ON!!!
	if (otherdevices['SW_1OG_BAD'] == 'Open' and (timedifference(s) > waitTime or uservariables["FlagsSwitchBad"] == 1 )) then
	    commandArray['Xiaomi RGB Gateway']='Set Level:'..tostring(GatewayBrightness) -- set brightness LED light from Gateway
	    commandArray['Xiaomi Gateway Volume']='Set Level:'..tostring(volume)
		commandArray['Xiaomi Gateway Doorbell']='Set Level:'..tostring(sound)
		commandArray['Variable:FlagsSwitchBad'] = tostring(1)
	end
	
	-- *** Switch OFF!!!
	if (otherdevices['SW_1OG_BAD'] == 'Closed' and uservariables["FlagsSwitchBad"] == 1) then
		print('Switch Closed..')
		commandArray['Xiaomi RGB Gateway']='Off'
		commandArray['Xiaomi Gateway Doorbell']='Off'
		commandArray['Variable:FlagsSwitchBad'] = tostring(0)
	end 

return commandArray
thx
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Window Switch + Temperatur + Timer

Post by Schorschi »

Hi,


i solved my problem.
The door switch don't send any closed event any more.
I removed them from the config and added it new.

Now it works again.
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Window Switch + Temperatur + Timer

Post by Schorschi »

Hi,

is not solved :cry:

I see that my window switch is closed in the switch overview but the log of the switch show no off event.
Also the time script reads open from the array and device script detect no event on this switch.

Any Ideas??? :cry:

thx
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest