Variables for use in rules??

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
bastibasti
Normal user
Posts: 25
Joined: 31 Jul 2018, 11:41

Variables for use in rules??

#1 Post by bastibasti » 09 Jan 2019, 21:19

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??

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Variables for use in rules??

#2 Post by Domosapiens » 09 Jan 2019, 21:25

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]
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

Jackill
Normal user
Posts: 5
Joined: 10 Jan 2019, 08:38

Re: Variables for use in rules??

#3 Post by Jackill » 11 Jan 2019, 01:28

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?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Variables for use in rules??

#4 Post by grovkillen » 11 Jan 2019, 05:35

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Variables for use in rules??

#5 Post by Domosapiens » 11 Jan 2019, 10:06

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
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

Jackill
Normal user
Posts: 5
Joined: 10 Jan 2019, 08:38

Re: Variables for use in rules??

#6 Post by Jackill » 11 Jan 2019, 14:44

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.

bastibasti
Normal user
Posts: 25
Joined: 31 Jul 2018, 11:41

Re: Variables for use in rules??

#7 Post by bastibasti » 14 Jan 2019, 12:11

any idea how to increment a value?

let 1,%v1%+1??

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Variables for use in rules??

#8 Post by grovkillen » 14 Jan 2019, 13:45

Code: Select all

Let,1,[VAR#1]+1
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
EDsteve
Normal user
Posts: 56
Joined: 11 May 2018, 21:13

Re: Variables for use in rules??

#9 Post by EDsteve » 08 Feb 2020, 07:40

Somehow i can't get it working 100% with the Let command.

When soil humidity is higher than 900 it should set varia#2 to 2. And if this var#2 is 2 it should trigger a relay and increment a second variable (The incrementation of the second variable works). But somehow it doesn't enter the "if [var#2]=2 do".

Code: Select all

on Soil#Analog do
 SendToHTTP,192.168.8.115,8080,/json.htm?param=udevice&type=command&idx=25&nvalue=[Soil#Analog]
 if [soil#Analog]>900 do
   timerSet,1,2
   Let,2,[var#2]=2
 endif
endon

On Rules#Timer=1 do
 if [var#2]=2 do
  GPIO,12,1
  Let,1,[var#1]+1
  timerSet,2,2
 endif
endon

On Rules#Timer=2 do
  if [var#1]=3 do
   GPIO,12,0
   Let,1,[var#1]=0
   Let,2,[var#2]=0
  else
   GPIO,12,0
   timerSet,1,6
  endif
endon
I am also not really sure how it all works with the Let command.

What exactly does the number 1 stand for: Let,1,[VAR#1]+1
And my Dummy devices don't change it's value. So with the Let command i can have a variable without connected to a Dummy device?
So the Let command has nothing to do with TaskValueSet ?

Sorry for my maybe stupid questions.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Variables for use in rules??

#10 Post by grovkillen » 08 Feb 2020, 09:42

Your syntax is wrong, see here:

Code: Select all

on Soil#Analog do
 SendToHTTP,192.168.8.115,8080,/json.htm?param=udevice&type=command&idx=25&nvalue=[Soil#Analog]
 if [soil#Analog]>900 do
   timerSet,1,2
   Let,2,2  //<---- no equal sign.
 endif
endon

On Rules#Timer=1 do
 if [var#2]=2 do
  GPIO,12,1
  Let,1,[var#1]+1  //THIS WILL ADD 1 to the variable one i.e. "Let,1,1" would make the var one = 1 and "Let,15,33" would make var fifteen = 33
  timerSet,2,2
 endif
endon

On Rules#Timer=2 do
  if [var#1]=3 do
   GPIO,12,0
   Let,1,0  //<---- no equal sign.
   Let,2,0  //<---- no equal sign.
  else
   GPIO,12,0
   timerSet,1,6
  endif
endon
I guess the most user friendly way would be the syntax "Let,v1=..." but that would make the syntax for Let be completely different from the other commands. So we will keep it using the comma instead of the equal sign for consistency.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Variables for use in rules??

#11 Post by grovkillen » 08 Feb 2020, 09:45

Let are internal variables, the task values are just that, task values. So they have nothing to do with each other, BUT one can be used to influence the other using formulas and task value set. So if you want to use an internal value for a task value you would need to use a dummy variable and set it by using the TaskValueSet (or TaskValueSetAndRun) to populate it with the number from the internal variable.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
EDsteve
Normal user
Posts: 56
Joined: 11 May 2018, 21:13

Re: Variables for use in rules??

#12 Post by EDsteve » 08 Feb 2020, 10:47

Ohh. Thanks so much. Now i understand. I should have thought about that :D
I know... script kiddies like me are annoying.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Variables for use in rules??

#13 Post by grovkillen » 08 Feb 2020, 11:54

EDsteve wrote: 08 Feb 2020, 10:47 Ohh. Thanks so much. Now i understand. I should have thought about that :D
I know... script kiddies like me are annoying.
Don't say that, I'm a script kid myself. :D
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests