Need help with script

Begonnen von VVlasy, 05 April 2015, 14:51:32

Vorheriges Thema - Nächstes Thema

VVlasy

I have problem writng a script in perl... More precisely, I have no idea what I am doing...

I need to wait 15 minutes and if state is still open, set device on

define close_gate notify gate:open {"sleep 900", "if ([gate] eq "open") (set gate close)"}

Icinger

There's no need for writing a script for that usecase.

Just use a watchdog:

define wd_closeGate watchdog gate:open 00:15:00 SAME set gate close;;trigger wd_closeGate .

That should do the job.

Happy Easter,

Ici
Verwende deine Zeit nicht mit Erklärungen. Die Menschen hören (lesen) nur, was sie hören (lesen) wollen. (c) Paulo Coelho

VVlasy

At first, I thought it was working perfect, but now, it seems,  ihave found a flaw... When the gate is opned and is closed before the timeout period, it still triggers, so it opens, but then it closes... So if I would let it be, after closing manually, it would open and close again, any thoughts?

Zrrronggg!

I have done this in 2 steps along the line:


define gate_check dummy
define check_gate notify gate:open delete reset_gate ;; define reset_gate at +00:15:00 set gate_check on
define close_gate notify gate_check:on { if (Value("gate") eq "open") { fhem("set gate close")}}


Some remarks:
- delete reset_gate  prolongs the 15 Minutes every time an gate:open event occures.
- every first time check_gate is triggered an error will be occur: "please define reset_gate first" as delete reset_gate will find nothing to delete. This is a cosmetic problem.
- a much easier solution could be:

define check_gate notify gate:open delete reset_gate ;; define reset_gate at +00:15:00 set gate close
This just omits the check if the gate is still open. I mean why do you want to check that?
It the gate is open it will be closed. If it IS allready closed... it will be closed again (which will do just nothing in most environments)

Last hint: There might be an easier way to do this by using the DOIF command.
As I "grew up" with perl {if...}, I don't use DOIF , so I don't know.
FHEM auf Linkstation Mini, CUL 868 SlowRF, 2xCUL 868 RFR, CUL 433 für IT, 2xHMLAN-Configurator mit VCCU, ITV-100 Repeater, Sender und Aktoren von FHT, FS20, S300, HM, IT, RSL

VVlasy

#4
The problem I have is my gate only has 1 button to control it, if it is closed it opens, if it is open it closes, I cannot specifically tell it to close or open... It would have been easy if I could tell it to close or open...

Thanks for sharing your solution, worked for me perfectly, really appreciate it :)

Zrrronggg!

#5
Yep, my gate has the same problem.

I did that a bit different along the line of this wiki article:
http://www.fhemwiki.de/wiki/Garagentorsteuerung
its in german, but maybe it helps.

The "trick" is to put an abstraction-layer to the gate.

I guess that you have some sort of sensor to figure if the gate is open or closed, a FHTTK or HM Shutter Controll such as HM-SEC-SC.

Then you build a dummy and a define like:

define act_on_gate_close notify Gate_close { if (Value("gate") eq "Open" && "%" ne "off") { fhem("set gate_sw on-for-timer 1") } }

where "gate" is your sensor and "gate_sw" is the actual gate actor.

Then in subsequent calls you only use Gate_close to close the gate. In this scenario, everytime an ON from "Gate_close" closes the gate if its open and does nothing if its closed.

This allows you to have something (Button on GUI, Remote, Script) to use as a "closer" " which always leaves you with a closed gate upon activation, no matter what the state of the gate was before.

You additional build something similar to open the gate.

I use two dummys: one to open the gate and one to close it. Its also no problem to use the same dummy to open and close the gate:

define act_on_gate_close notify Gate_open_close { if (Value("gate") eq "Open" && "%" eq "off") { fhem("set gate_sw on-for-timer 1") } }
define act_on_gate_close notify Gate_open_close { if (Value("gate") eq "Closed" && "%" eq "on") { fhem("set gate_sw on-for-timer 1") } }


A "set Gate_open_close off" leaves you with a closed gate no matter if it was open or not, and "set Gate_open_close on" always leads to an open gate, no matter if it was closed or already open.



The advantage of this solution is, that you need to take care of the logic only once and alle the rest can be done as if you had a gate with a separate absolute open and close command.

(I frankly  don't know if this does make any sense to you, ask me if not)

Anyhow, If you are satisfied with the current solution I have one other comment. Just after I wrote down my last post I learned that there is a slightly easier way. This line:

define check_gate notify gate:open delete reset_gate ;; define reset_gate at +00:15:00 set gate_check on

can be done better. I learned that FHEM has a new command since about a week or so. Its called defmod and makes this line a bit shorter:

define check_gate notify gate:open defmod reset_gate at +00:15:00 set gate_check on

This should also avoid the error messages you get. So if your FEHM installation is up to date you may want to try this.

I have however not tried that myself so far.
FHEM auf Linkstation Mini, CUL 868 SlowRF, 2xCUL 868 RFR, CUL 433 für IT, 2xHMLAN-Configurator mit VCCU, ITV-100 Repeater, Sender und Aktoren von FHT, FS20, S300, HM, IT, RSL