Page 1 of 1

Variables for use in rules??

Posted: 09 Jan 2019, 21:19
by bastibasti
Hi,

I'm trying to do something like this
(its a simple dimmer, a push button increases a variable, and the pwm output is set according to one of the 5 available dimmer levels)

Code: Select all

on button#switch do
 
  if [button#switch]=0
   $a=$a+1
  endif

  if $a=5
   $a=0
  endif

 if $a=0
  pwm,2,1024,750
 endif

 if $a=1
  pwm,2,1000,750
 endif

 if $a=2
  pwm,2,800,750
 endif

 if $a=3
  pwm,2,500,750
 endif

 if $a=4
  pwm,2,0,750
 endif

endon 
any idea how to achieve this??

Re: Variables for use in rules??

Posted: 09 Jan 2019, 21:25
by Domosapiens
In rules you can use the command let
let,1,10 this will assign the value 10 to %v1%.

To get the value of %v1%, you can use %v1% or [VAR#1] depending on the rule syntax:
if %v1%=10
or
taskvalueset,1,1,%v1%
or
taskvalueset,1,1,[VAR#1]

Re: Variables for use in rules??

Posted: 11 Jan 2019, 01:28
by Jackill
Domosapiens wrote:
09 Jan 2019, 21:25
In rules you can use the command let
let,1,10 this will assign the value 10 to %v1%.
WOW!
Great info! Searched for it resultless..

Where did you find the list of commands to use in rules?

Re: Variables for use in rules??

Posted: 11 Jan 2019, 05:35
by grovkillen
I'm doing my best but need to work on my daytime job too. But the commands are found here: https://espeasy.readthedocs.io/en/lates ... mmand.html

Not all are listed, I will do my best adding them but I don't have the the time just now.

Re: Variables for use in rules??

Posted: 11 Jan 2019, 10:06
by Domosapiens
Where did you find the list of commands to use in rules?
While reading the forum, I collect snippets of Rules as examples in a document.

The (new) "Let" statement one was found here:
viewtopic.php?f=4&t=5961&p=32580&hilit= ... ill#p32580

Re: Variables for use in rules??

Posted: 11 Jan 2019, 14:44
by Jackill
grovkillen wrote:
11 Jan 2019, 05:35
I'm doing my best but need to work on my daytime job too.
Shure. This is not even discussed, daytime job on first place.
Nevertheless, system variables can save much.
Face this when I had to do calculations for my solar heating system.
Code like this: "if [Boiler#Temp]<[Solar#Temp]+5 <do smthng> endif" not worked, it need to be passed thru dummy (taskValueSet).
Now I'll save 1 of 12 tasks.
Domosapiens wrote:
11 Jan 2019, 10:06
While reading the forum, I collect snippets of Rules as examples in a document.
Good practice! I will put into service.

Re: Variables for use in rules??

Posted: 14 Jan 2019, 12:11
by bastibasti
any idea how to increment a value?

let 1,%v1%+1??

Re: Variables for use in rules??

Posted: 14 Jan 2019, 13:45
by grovkillen

Code: Select all

Let,1,[VAR#1]+1