Page 1 of 1
PIR Sensor, Telegram and schedule
Posted: Thursday 30 June 2016 18:14
by Ritmeester
I have a PIR sensor with the following Domoticz options:
It has an On Action with a script to send me a snapshot to my Telegram bot
It has Custom Message to send to my Telegram bot
All is just working fine now
How can I make this PIR sensor to send me the messages only between 23:00 and 07:00?
I look in the Switch options itself but I can’t find a solution. Do I have to make this in Blocky?
Re: PIR Sensor, Telegram and schedule
Posted: Friday 01 July 2016 20:32
by georgesattali
hello,
here's some lua code, that you must test first, I cannot garantee it will work first time :
It is a "Device" script, so go to Setting / More Options / Events / Lua,
remove everything from the example and past the following code,
click "All" and choose "Device" instead of "All",
click "Event active" and save.
Of course, put the exact name of your PIR Device and copy the script call (without the leading "script://").
I recommand you keep an exact copy of the script call because you have to remove it from the PIR "On Action" (or you will receive them twice during the night).
Code: Select all
commandArray = {} -- needed by dz
now = os.date("*t")
if devicechanged["Name of your PIR here"] == "On" then
-- only if after 23 or before 7
if (now.hour >= 23) or (now.hour < 07) then
os.execute("bash " .. "put script and args here without the script://")
end
end
return commandArray -- needed by dz
See you,
GD
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 16:55
by Ritmeester
Hi GD,
Thanks for your input. This lua script is working fine and does the job.
There is only every minut an error in the log file after the script runs one time.
Code: Select all
2016-07-03 14:44:00.428 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
2016-07-03 14:45:00.458 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
2016-07-03 14:46:00.488 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
2016-07-03 14:47:00.018 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
2016-07-03 14:48:00.048 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
2016-07-03 14:49:00.079 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
2016-07-03 14:50:00.110 Error: EventSystem: in PIR Test aanroep Script: [string "commandArray = {} -- needed by dz ..."]:5: attempt to index global 'devicechanged' (a nil value)
Other option
My second question is why this "can’t" be working?

- 2016-07-03_16-54-56.png (16.64 KiB) Viewed 1872 times
Code: Select all
2016-07-03 14:21:52.773 Error: Error opening url: script:///home/pi/domoticz/scripts/camera1.sh
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 17:31
by Derik
I think this a "problem" with Blockley...
Some of my blockleys are switching every minute to...
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 17:37
by jvdz
Ritmeester wrote:Hi GD,
Thanks for your input. This lua script is working fine and does the job.
There is only every minut an error in the log file after the script runs one time.
Change the Box under LUA from All to Devices, this will fix this error!
Jos
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 17:43
by Ritmeester
Hi Jos,
Thanks, this did the trick.
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 17:47
by Derik
jvdz wrote:Ritmeester wrote:Hi GD,
Thanks for your input. This lua script is working fine and does the job.
There is only every minut an error in the log file after the script runs one time.
Change the Box under LUA from All to Devices, this will fix this error!
Jos
I mean...
What is the different thing between this options?
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 18:05
by jvdz
@Derik, Guess the "?" means you don't know what I am trying to say?
In the case you get the nil error for devicechanged[] table every minute on the minute, it simply means the script is ran as a TIME script as well. This happens when using the internal editor and you leave the dropdown selection box under the LUA dropdownbox on ALL as that will run the script for ALL events: Device/Time/Variable/Security events. With a Time event, the devicechanged[] table isn't generate leading to this nil error.
Making sense?
Jos
Re: PIR Sensor, Telegram and schedule
Posted: Sunday 03 July 2016 18:09
by Ritmeester
Thanks for the explanation.
For me this makes sense now. I hope also for @Derik