YAR (yet another rules) question - calling an action from an action, not working?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

YAR (yet another rules) question - calling an action from an action, not working?

#1 Post by JR01 » 25 Mar 2017, 16:05

In the wiki it shows an example, lets call them rules actions:

Code: Select all

on givemesomewater do
  gpio,2,1  // open valve
  timerSet 1,600 // 10 minute timer
endon
I have a same ''action", as follows:

Code: Select all

on SetPoolVarPump do
    TaskValueSet 4,2,%eventvalue%
    gpio,16,%eventvalue%
    Publish sensors/espeasy/%sysname%/Var/PoolPump,%eventvalue%
endon
But now I want to call the above action from another action, as follows:

Code: Select all

on Clock#Time=All,17:00 do
    if [Var#Auto] = 1
          gpio,16,0
          SetPoolVarPump,0
          Publish sensors/espeasy/%sysname%/Switch/R1,0
    endif
endon
So, can I call SetPoolVarPump action, from the 2nd action? This does not work. Did I do it correctly, or is this not possible?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: YAR (yet another rules) question - calling an action from an action, not working?

#2 Post by paxi » 26 Mar 2017, 01:04

Code: Select all

On whatever#event do
    Event SetPoolVarPump=1
Endon
Not sure if a fixed eventvalue suits your need, you can make the line conditional or use [another#value].
You get the idea. ;)

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: YAR (yet another rules) question - calling an action from an action, not working?

#3 Post by JR01 » 26 Mar 2017, 08:47

This works, thanks, did not know about using, tis is also not on wiki ?

Code: Select all

Event DoSomeAction = 1
To call another action.

Thanks !
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

AndrewJ
Normal user
Posts: 229
Joined: 14 Feb 2017, 12:38

Re: YAR (yet another rules) question - calling an action from an action, not working?

#4 Post by AndrewJ » 26 Mar 2017, 09:54

This will be **really** useful - thanks for sharing! :D
AndrewJ

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: YAR (yet another rules) question - calling an action from an action, not working?

#5 Post by JR01 » 26 Mar 2017, 14:36

Another 'YARQ', seams like we have people in the community that have sussed Rules out...

I want to use clock time as follows, but this does not seam to work, calling the same function...

Code: Select all

On Rules#Time=2 do
   if Clock#Time > All,10:00 do
       if Clock#Time < All,15:30 do
           Event SetPoolVarPump = 1
       endif
   endif
endon
Any ideas if this is possible?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: YAR (yet another rules) question - calling an action from an action, not working?

#6 Post by paxi » 26 Mar 2017, 22:33

There is a syntax error in line 1: rules#timer not time. ;)
Sadly you can't use clock#time with <> operators, only =.

Here is a working example of "time framed" switching including boot handling:

Code: Select all

//ceiling lamp with sonoff

on switchon do 
    TaskValueSet 2,1,1 //State#Relay=1
    gpio 12,1 //Relay on
    pwm 13,1024 //LED off
endon

on switchoff do
    TaskValueSet 2,1,0 //State#Relay=0
    gpio 12,0 //Relay off
    pwm 13,[State#Bright] //LED on
endon

on Button#switch do
    if [State#Relay]=0
        event,switchon
    else
        event,switchoff
    endif
endon

on System#Boot do
    timerSet,1,5
    event switchon
endon

on Rules#Timer=1 do
    if %systime% > 7:59 
        TaskValueSet 2,2,500 //LED medium brightness
    endif
    if %systime% > 19:59
        TaskValueSet 2,2,990 //LED dim
    endif
endon

on Clock#Time=All,20:00 do //dim LED at night
    TaskValueSet 2,2,990
endon

on Clock#Time=All,8:00 do //medium LED at day
    TaskValueSet 2,2,500
endon

on State#Bright do
    If [State#Relay]=0
        PWM 13,[State#Bright],5000
    Endif
endon

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: YAR (yet another rules) question - calling an action from an action, not working?

#7 Post by JR01 » 27 Mar 2017, 21:43

Thank you! I did not know about %systime%, and thanks for my syntax correction !
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 95 guests