Help with Eval on incoming signal

http://automagucally.weebly.com

Moderators: davka003, Telldus

Post Reply
MHM
Posts: 4
Joined: Thu Jan 18, 2018 11:08 am
Location: Sweden

Help with Eval on incoming signal

Post by MHM » Thu Jan 18, 2018 11:08 am

Hello everyone!

Need some help on how to make "if-else" eval of incoming signal, or if anyone have any better ideas they are of course welcome as well :)

Background:
Idea is to use a 1-wire RFID-reader and RFID keyfobs to keep track of family members coming home and leaving and use Automagically to enable "away" or "home" mode which includes power on/off for IP-cameras and recording, whether lightningschedules should be active or not. This works as of today with my setup but i have to use mobile phone to turn on/off and can not track who turned it on/off.

I have set up an 1-wire RFID-reader which emulates Dallas ibutton to a small openwrt-router in client-mode which works as owserver. For simplicity I used owfs to mount 1-wire units on my raspberry from remote owserver. When I hold keyfob in front of RFID-reader a folder with id-file is mounted on raspberry, when I remove it folder dissapears within 2 min. I then use datafetcher to read id from id-file and this shows in Automagically signal feed.

Since same RFID is supposed to both turn ON and OFF group devices and change variables my approach is to use Treshold function, below 5 and above 5 for instance so that if "away"-variable is set to 0 someone is home and if set at 10 everyone is away, this makes it possible for the same RFID to trigger ON/OFF when passing "5". This also works when i manually set signal parse-result to 0 or 10 !

So far so good! But now I need som help since I am not familiar with Python and not particularily skilled in coding in general: When parsing signal i simply go

Code: Select all

parse_away:1
or

Code: Select all

parse_away:10
which works fine and triggers above mentioned manually.
However I would like to do

Code: Select all

parse_away: if GVaway>5 then 0 else 10
or something similar, how do I do this in Python? An $EVAL: function is mentioned but I simply don't get how to do it, is my global variable called GV"whatever number", or $Away$ ? How do I type above in Python-code? Is this possible to do when parsing signal? Certainly hope so, otherwise adding the possibility would increase use of Automagically substantially.

Help and comments are very much appreciated!

KHolm
Posts: 163
Joined: Thu Jan 18, 2018 11:08 am

Re: Help with Eval on incoming signal

Post by KHolm » Thu Jan 18, 2018 11:08 am

Hi,
I think your Signal to send should be:

Code: Select all

$EVAL:"parse_away:" + ("0","10")[$away$>5]
Have not tested it though. When reading I became uncertain if $EVAL works on the incoming signal or the signal to send...

/Marcus

MHM
Posts: 4
Joined: Thu Jan 18, 2018 11:08 am
Location: Sweden

Re: Help with Eval on incoming signal

Post by MHM » Thu Jan 18, 2018 11:08 am

Hello, thank you for your reply!

Tried your suggestion and it works as expected, just had to change ">" to an "<" :D

Code: Select all

$EVAL:"parse_away:" + ("0","10")[$Away$<5]
which results in (starting with Away=0):
2014-02-27 20:05:48.905504 datafetcher parse_away:10
2014-02-27 20:05:49.636015 system currentvalue_changed,GV10:10
2014-02-27 20:05:49.643082 system variable_changed,Away:10
2014-02-27 20:05:49.657611 system threshold_triggerd,2:10,0
2014-02-27 20:05:50.507384 tellstick tellstick,device:camera_hallway,id:55,method:ON,data:0
2014-02-27 20:05:50.641758 system currentvalue_changed,DV115:ON:0
And the other way around if Away=10 of course :)

Another problem appeared however.. When datafetcher repeats its fetch one minute later it still manages to fetch the now absent id-file (directory is missing at the time if I check in command prompt)... Seems like it somehow stores the successful fetch?

Know that I wrote that directory with id-file is mounted for 2 minutes above but when I test more thoroughly with a stopwatch it seems to be around 1 min.

Maybe I should delete all fetchers and variables and start over now that I know how to eval the above signals... Something weird in the database maybe? Even if i change datafetcher interval to 2 mins and save, it will still fetch every 1 min according to signal log...

And finally, even if i delete a datafetcher it still fetches according to signal log... This seems strange, maybe this is the explanation, some of my test-fetchers are still active even though I deleted them? Does Automagically need a reboot or possibly a clean install to wipe database?

KHolm
Posts: 163
Joined: Thu Jan 18, 2018 11:08 am

Re: Help with Eval on incoming signal

Post by KHolm » Thu Jan 18, 2018 11:08 am

Test to wrap the action desired in a script (sh, etc.) where you can control the output, then use that file with Automagically. Worth a try.
/Marcus

MHM
Posts: 4
Joined: Thu Jan 18, 2018 11:08 am
Location: Sweden

Re: Help with Eval on incoming signal

Post by MHM » Thu Jan 18, 2018 11:08 am

Actually managed to make a workaround without much trouble, used "Find repeats" to listen for signal for 120 seconds and then output ONE new signal which i just named "trigger,fetched:NNNNNNNNN" and then used this signal as input to the above mentioned signal handler.

This works, delay is however about 2 mins but not a problem for my intended use :)

Another problem though is that it seems like owserver only mounts the device directory needed to read id-number if i do a read operation when keyfob is in front of the reader. A simple "ls" in the mount directory is enough to make directory visible and live for 1 min. However, if i just place the keyfob in front of reader for a few seconds and then remove it, no directory is mounted unless I type "ls" in mountdirectory or make owdir / owread when keyfob is within reading range of reader.

I am looking through http://owfs.org/index.php?page=owserver to see if there is a solution here, seems like there are different timing settings for 1-wire bus masters which also might solve the above problem as timeout_directory and timeout_presence of a device seems to be separate and might explain how Automagically somehow is able to fetch even though file is not visible in command prompt?? If anyone have any experience with this I would appreciate comments.

MHM
Posts: 4
Joined: Thu Jan 18, 2018 11:08 am
Location: Sweden

Re: Help with Eval on incoming signal

Post by MHM » Thu Jan 18, 2018 11:08 am

Got some time to do further testing last night...

Changed timing presets from default on owserver, added --timeout_presence=60 and --timeout_directory=60 to make sure both timeout after 1 min, this also made it possible to remove my "Find repeats"-workaround mentioned in previous post.. :)

Investigating problem with reading a bit more it seemed like the RFID-reader (or probably the owserver) was checking for RFID-tag to read in some interval (~30 sec), OR when adressing with owread (controlled by presence above) or simple "ls" in filestructure (controlled by directory above). A simple workaround was to run a script in the background, initially my idea was to use owread since this would make it unnecessary to mount owfs only reading straight from owserver. Did however not get owread to work trough datafetcher, however a "ls" shell script listing mounted 1wire directory every second in the background worked just fine and everything is now working as it should, I flash RFID-keyfob to reader and within 1 min home/away global variable changes status :D

If possible I would like to use owread through datafetcher instead to skip mounting 1-wire-filesystem. Owread works as owread -s 192.x.x.x /01.XXXXXXXXXXXX/id and returns id from file (12 digits).

I just used fetchtype "execute" in datafetcher and wrote as above in executable, then let "line,character position,length" remain and line,char,size: 0,0,0 to fetch entire line (also tried with size=12). This however did not work, where do I go wrong, should scanf or regexp be used in some way?

Post Reply