do I need to define a variable state?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

do I need to define a variable state?

#1 Post by opentoideas » 21 Sep 2018, 16:32

hi,

I have created a dummy device called "Dimmer" and given it values names "1" and "2"

creating the following rule and without the IF I can switch on and off at the given times but I want the PWM to increment by 1 every second and as it stands nothing happens.

what am I doing wrong?

something daft I am sure but a pointer would be a huge help :oops:


on Clock#Time=All,15:22 do //will run once a day at ?am
if [Dimmer#1]<4095
Delay 1000
[Dimmer#1]=[Dimmer#1]+1
PCAPWM,0,[Dimmer#1]
PCAPWM,1,[Dimmer#1]
endif
endon

on Clock#Time=All,15:30 do //will run once a day at ?am
if [Dimmer#1]>0
Delay 1000
[Dimmer#1]=[Dimmer#1]-1
PCAPWM,0,[Dimmer#1]
PCAPWM,1,[Dimmer#1]
endif
endon

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#2 Post by opentoideas » 21 Sep 2018, 17:16

ok made a few changes and slowly getting there.....

I have changed the dummy device to "light" and variables to "dim1" and "dim2"

on Clock#Time=All,16:15 do //will run once a day at ?am
if [light#dim1]<4095
Delay 100
TaskValueSet 2,1,[light#dim1]+1
PCAPWM,0,[light#dim1]
PCAPWM,1,[light#dim1]
else TaskValueSet 2,1,4321
endif
endon

I now have "dim1" increasing with each run through the if and the PWM is set to one less than dim1 but the if only runs once.

how can I get it to loop until "dim1" =4095? this is how I would expect an if to work being captured until the condition is met to move on but this does not seem to be how its working here.

changed to :

on Clock#Time=All,16:24 do //will run once a day at ?am
if [light#dim1] and [light#dim1]<4095
Delay 100
TaskValueSet 2,1,[light#dim1]+1
PCAPWM,0,[light#dim1]
PCAPWM,1,[light#dim1]
else TaskValueSet 2,1,4321
endif
endon

thinking this should trigger on value change but nope - might be as its in the on command - will take it out see if that works

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#3 Post by opentoideas » 21 Sep 2018, 21:24

well 4 hours later and I am getting fed up of something that should be simple giving garbage outputs and nonsensical logs.

is this just a case of not being something that can be done with rules?

I have tried multiple ways of getting a trigger and simple increments to variables which according to the wiki should work but that's not what I am finding.

current code that's getting close to doing something is :

Code: Select all

on Clock#Time=All,19:49 do //will run once a day at ?am
  if [light#dim1] < 4095
    TaskValueSet 2,3,[light#dim1]+1
    TaskValueSet 2,1,[light#dim3]
    Delay 100
    PCAPWM,0,[light#dim1]
    PCAPWM,1,[light#dim1]
        else 
         TaskValueSet 2,2,1
  endif



  if [light#dim1] < 4095
    TaskValueSet 2,3,[light#dim1]+5
    TaskValueSet 2,1,[light#dim3]
    Delay 100
    PCAPWM,0,[light#dim1]
    PCAPWM,1,[light#dim1]
        else 
         TaskValueSet 2,4,1
  endif


TaskValueSet 2,3,[light#dim1]+2
TaskValueSet 2,1,[light#dim3]
endon
problem is the log which shows :

Code: Select all

32719: EVENT: light#dim1=0.00
32733: EVENT: light#dim2=0.00
32745: EVENT: light#dim3=0.00
32758: EVENT: light#dim4=0.00
34516: ACT  : Delay 100
34533: ACT  : PCAPWM,0,0
34539: PCA 0x40: GPIO 0
34548: ACT  : PCAPWM,1,0
34553: PCA 0x40: GPIO 1
34577: ACT  : TaskValueSet 2,3,0+5
34596: ACT  : TaskValueSet 2,1,0
34609: ACT  : Delay 100
34627: ACT  : PCAPWM,0,0
34630: PCA 0x40: GPIO 0
34639: ACT  : PCAPWM,1,0
34644: PCA 0x40: GPIO 1
34659: ACT  : TaskValueSet 2,3,0+2
34678: ACT  : TaskValueSet 2,1,0
34740: Dummy: value 1: 0.00
34740: Dummy: value 2: 0.00
34740: Dummy: value 3: 0.00
34741: Dummy: value 4: 0.00
34744: EVENT: light#dim1=0.00
34764: EVENT: light#dim2=0.00
34784: EVENT: light#dim3=0.00
34800: EVENT: light#dim4=0.00
34818: Command: taskvalueset
34820: Command: taskvalueset
34821: Command: delay
34928: Command: taskvalueset
34935: Command: taskvalueset
34937: Command: delay
35045: Command: taskvalueset
35046: Command: taskvalueset
35716: Dummy: value 1: 0.00
35716: Dummy: value 2: 0.00
35716: Dummy: value 3: 2.00
35716: Dummy: value 4: 0.00
35719: EVENT: light#dim1=0.00
35732: EVENT: light#dim2=0.00
35745: EVENT: light#dim3=2.00
35757: EVENT: light#dim4=0.00
grasping at straws I split out incrementing light#dim1 so that it is light#dim3 that becomes light#dim1+1. this is then copied back to light#dim1.

this should be unnecessary but it was done to help debug where its going wrong as are the varying number increases used.

whats got me confused is the log shows taskvalueset commands that have numerical detail but the numbers are not changed and other taskvalueset commands with no detail. it looks like its gone through the loop a couple of times but none of the dummy variables have updated as expected.

hopefully someone can help point me in the right direction but I have had it for today. need to come back to this with a clear head and a nights sleep :lol:

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

Re: do I need to define a variable state?

#4 Post by grovkillen » 21 Sep 2018, 21:29

Multiple ifs are not yet supported.
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: do I need to define a variable state?

#5 Post by grovkillen » 21 Sep 2018, 21:31

And you should really start small and add stuff as you go.
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: do I need to define a variable state?

#6 Post by grovkillen » 21 Sep 2018, 21:34

Try this

Code: Select all

on Clock#Time=All,19:49 do //will run once a day at ?am
  if [light#dim1] < 4095
    TaskValueSet,2,3,[light#dim1]+1
   else 
     TaskValueSet,2,2,1
  endif
endon
And go from there
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#7 Post by opentoideas » 21 Sep 2018, 21:58

grovkillen wrote: 21 Sep 2018, 21:29 Multiple ifs are not yet supported.
ok.....

but each if on its own only runs once. I would have expected a if to loop until the condition was satisfied but this does not work either.

what I am trying to achieve shouldn't be too tricky but if the rules don't let me then will I need to do this in the firmware and re upload?

how else can this result be achieved?

was hoping to avoid having to recompile and upload for any small changes but if that's the only way then thats how its done :|

I have started as described with just switching which worked then adding the dummy var and so on but as responses were unusual I added more complexity to see where it was breaking down.

will start again in the morning but its to inconsistent for me at the moment and wont loop cleanly. possibly use the timer commands to control the loop :?:
Last edited by opentoideas on 21 Sep 2018, 22:24, edited 1 time in total.

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

Re: do I need to define a variable state?

#8 Post by grovkillen » 21 Sep 2018, 22:12

Yes you can use events to do multiple ifs but you cannot do multiple ifs in the same "on".

But remember to do the event command last in the if/else to be sure any other commands are being processed before the event.
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: do I need to define a variable state?

#9 Post by grovkillen » 21 Sep 2018, 22:13

If you upload all your settings (screenshots) I'd be able to assist you better.
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: do I need to define a variable state?

#10 Post by grovkillen » 21 Sep 2018, 22:15

And to make it clear, the rules are parsed in the core loop. It's not a actual running code inside the ESP. So it's pseudo coding.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#11 Post by opentoideas » 21 Sep 2018, 22:36

grovkillen wrote: 21 Sep 2018, 22:13 If you upload all your settings (screenshots) I'd be able to assist you better.
not sure there are any settings. vanilla upload and added the PCA9685 as 2w on D3 and D4

added rules from the advanced tools and NTP server

doesn't look like I can upload a pic to this site and don't have any image hosting so hope that's enough. not even thought about adding MQTT and Domoticz control yet as I was hoping this should be able to be stand alone

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

Re: do I need to define a variable state?

#12 Post by grovkillen » 21 Sep 2018, 22:45

You can upload using the attachment tab found below the response text editor.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#13 Post by opentoideas » 21 Sep 2018, 22:55

grovkillen wrote: 21 Sep 2018, 22:15 And to make it clear, the rules are parsed in the core loop. It's not a actual running code inside the ESP. So it's pseudo coding.
sounds similar to Domoticz "blocky" great for really simple things but falls over if you want to do anything less simple.

hoping I can work with or around any limitations.

all I am trying to do is bring 2 channels on the PCA9685 up gently over time so a simplification of one channel might look like :

Code: Select all

10 at 09:00 start
20 set dim1 =0
30 if dim1 < 4095 (channel 1 PWM value = dim1 ) and (dim1 = dim1 + 1)
40 delay 1000
50 goto 30
off code would be the same but counting down

both channels can be the same but would be nice to have them different.

if I can get one working ramp then I could go from there.

I know there is a PWM fade parameter but as this would be fading over hours not minutes or seconds its no good as it locks into the single thread.

I suspect this may be problematic with what I am seeing of rules and I may have to write it into the sketch and compile a new version but hopefully I am wrong.

:idea: thanks for that - missed the attachments below - was looking at the top with the other buttons - if only all forum were the same :lol:

any settings you need? like I said I have changed almost nothing from the default.
esp devices.PNG
esp devices.PNG (56.18 KiB) Viewed 15875 times
thank you for the help
P.S. sorry for the bast back to BASIC mixed in - showing my age! cut my teeth on BASIC, COBAL and COMAL - I really dont miss those days! but a LOT has changed - mainly for the better!

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

Re: do I need to define a variable state?

#14 Post by grovkillen » 21 Sep 2018, 23:06

Instead of delay you can use timer. That way you can build a "loop". Tomorrow I hope to have some time to help you out with that.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#15 Post by opentoideas » 21 Sep 2018, 23:15

grovkillen wrote: 21 Sep 2018, 23:06 Instead of delay you can use timer. That way you can build a "loop". Tomorrow I hope to have some time to help you out with that.
thanks,

I may be getting there :D

Code: Select all

on Clock#Time=All,22:12 do //will run once a day at ?am
   timerSet,1,1     //Set Timer 1 for the next event in 1 seconds
    TaskValueSet,2,1,0
endon

On Rules#Timer=1 do  //When Timer1 expires, do
     if [light#dim1] < 4095
      TaskValueSet,2,1,[light#dim1]+1
      timerSet,1,1     //Set Timer 1 for the next event in 1 seconds
     else 0.5
     TaskValueSet,2,2,1
    endif
endon
seems to be giving me a loop counting up and setting the PWM is an easy addin. when you get a chance can I set timer for less than 1 second? not an issue if not and I think this may get me where I need

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

Re: do I need to define a variable state?

#16 Post by grovkillen » 21 Sep 2018, 23:17

We are going to add sub second timers but we are not there just yet. But it's on the horizon.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#17 Post by opentoideas » 22 Sep 2018, 00:47

amazing what a large G&T some food and great advice can do.

I think I got there....

Code: Select all

on Clock#Time=All,09:00 do //will run once a day at 9am
   timerSet,1,10     //Set Timer 1 for the next event in 10 seconds
   timerSet,2,10     //Set Timer 2 for the next event in 10 seconds
    TaskValueSet,2,1,4095
    TaskValueSet,2,2,4095
    TaskValueSet,2,3,0
    TaskValueSet,2,4,0
endon

on Clock#Time=All,15:00 do //will run once a day at 3pm
   timerSet,3,10     //Set Timer 3 for the next event in 10 seconds
   timerSet,4,10     //Set Timer 4 for the next event in 10 seconds
endon

On Rules#Timer=1 do  //When Timer1 expires, do
     if [light#dim1] > 2000
      PCAPWM,0,[light#dim1]
      TaskValueSet,2,1,[light#dim1]-1
      timerSet,1,10     //Set Timer 1 for the next event in 10 seconds
     else 
     TaskValueSet,2,3,1
    endif
endon

On Rules#Timer=2 do  //When Timer2 expires, do
     if [light#dim2] > 2000
      PCAPWM,1,[light#dim2]
      TaskValueSet,2,2,[light#dim2]-1
      timerSet,2,10     //Set Timer 2 for the next event in 10 seconds
     else 
     TaskValueSet,2,4,1
    endif
endon

On Rules#Timer=3 do  //When Timer3 expires, do
     if [light#dim1] < 4095
      PCAPWM,0,[light#dim1]
      TaskValueSet,2,1,[light#dim1]+1
      timerSet,3,10     //Set Timer 3 for the next event in 10 seconds
     else 
     TaskValueSet,2,1,4095
     PCAPWM,0,[light#dim1]
    endif
endon

On Rules#Timer=4 do  //When Timer4 expires, do
     if [light#dim2] < 4095
      PCAPWM,1,[light#dim2]
      TaskValueSet,2,2,[light#dim2]+1
      timerSet,4,10     //Set Timer 4 for the next event in 10 seconds
     else 
     TaskValueSet,2,2,4095
      PCAPWM,1,[light#dim2]
    endif
endon
I think it works, will find out if it turns on in the morning :lol:

need to tidy up so if the unit reboots the lights are either on or off but will do for now.

thanks again for the help

P.S. possible change would be if you go over the 2048 character limit then not deleting all changes and carefully commented lines back to the last version saved and just warn that you went over! (guess how I know it does this :roll: :lol: )

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

Re: do I need to define a variable state?

#18 Post by grovkillen » 22 Sep 2018, 07:18

Yes the rules editor need some love, I will give it some in a couple of weeks.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#19 Post by opentoideas » 22 Sep 2018, 10:04

grovkillen wrote: 22 Sep 2018, 07:18 Yes the rules editor need some love, I will give it some in a couple of weeks.
just thinking about ways to make this one more usable for me and thinking that I can split the ON routine from the OFF routine and the Reset routine when I write it and make them separate rules so that I can comment more thoroughly. also any reason that I cant use a dummy variable in the timer command so that the timer duration could be controlled without a rule change? also same with clock#time command.(see a problem as this is formatted differently :? )

going forward I will want to control 5 PWM channels so will need more space so splitting across several rules would be needed.

thinking rule 1 to set all the variables and reset timer

rule 2 with ON routine
rule 3 with OFF routine
rule 4 with RESET routine

good news is the lighting just came on :geek:

this is an aquarium LED lighting system but with 700W of lighting a soft start is nice :lol:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#20 Post by opentoideas » 22 Sep 2018, 10:45

with the clock#time command would this work?

on Clock#Time=All,[clock#onh]:[clock#onm] do

esp devices clock.PNG
esp devices clock.PNG (51.04 KiB) Viewed 15794 times

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

Re: do I need to define a variable state?

#21 Post by grovkillen » 22 Sep 2018, 10:51

It should work but you should change the dummy type to quad.

And you can use up to 4 "pages" of rules (2048 bits each).
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#22 Post by opentoideas » 22 Sep 2018, 10:55

what difference does the dummy type make?

just curious as I set that the first time but the 4 variables show no matter the type set

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#23 Post by opentoideas » 22 Sep 2018, 10:57

my poor fish will be getting a disco today as I start testing this :lol:

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

Re: do I need to define a variable state?

#24 Post by grovkillen » 22 Sep 2018, 11:02

You used to have it set to quad for the core loop to take notice of all four values.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#25 Post by opentoideas » 22 Sep 2018, 11:14

just thinking about - on Clock#Time=All,[clock#onh]:[clock#onm] do

if [clock#onm] is less than 10 will missing the leading 0 cause an issue?

so with :

[clock#onh] = 9
[clock#onm] = 0

[clock#onh]:[clock#onm] = 9:0 which I could see being a problem as the format isn't what is expected.

do you know what the result of this would be or will I need to test?

I think i will give my poor fish a break and set up another unit to test this on :lol:

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

Re: do I need to define a variable state?

#26 Post by grovkillen » 22 Sep 2018, 12:06

Yes that would not render in a match. Time stamps need that leading zero.

You could use system variables maybe? And do tests on a bead board? 8-)
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#27 Post by opentoideas » 22 Sep 2018, 12:51

grovkillen wrote: 22 Sep 2018, 12:06 Yes that would not render in a match. Time stamps need that leading zero.

You could use system variables maybe? And do tests on a bead board? 8-)
I keep forgetting I have breadboard! :oops:

never have the correct dupont cables when I need them! need M-M so of course today can only find M-F or F-F but a breadboard will solve that too.

not ideal but for the moment just have to make sure I use minutes at 15, 30,45 not 00

I will have a look at system variables once I get it all working. if it goes according to plan then changes should be easy enough

thanks again ;)

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

Re: do I need to define a variable state?

#28 Post by grovkillen » 22 Sep 2018, 13:26

Instead of 00 you can use 59
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#29 Post by opentoideas » 22 Sep 2018, 13:52

grovkillen wrote: 22 Sep 2018, 13:26 Instead of 00 you can use 59
:lol: exactly what I am doing. it works but its messy

trying to decide how far I want to go at the moment as I can add loads of variables so could setup everything in one rule and make any editing easy but not sure if I want to go that far.

its tempting as this is stand alone I don't need to add anything else

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#30 Post by opentoideas » 22 Sep 2018, 15:37

well I almost have it. the on and off routines work fine but the reset on boot is causing a problem.

I think I need to reference %systime% rather than clock#time but its not playing nice.

I started with :

If %systime% > [clock#onh]:[clock#onm]:00 and %systime% < [clock#offh]:[clock#offm]:00

but simplified to :

If %systime% > [clock#onh]:[clock#onm]:00

wont work either way though

I added the delays to make sure the clock updated and I can see from the log that the clock is running before the last delay

would you mind having a quick look at the following and if there is a better way let me know?

Code: Select all

// Rule 1 set up
 On System#Boot do    //When the ESP boots, do

delay 1000

TaskValueSet,2,1,4095  // [light#dim1]
TaskValueSet,2,2,4095  // [light#dim2]
TaskValueSet,2,3,2000  // [light#dim3]
TaskValueSet,2,4,2000  // [light#dim4]
TaskValueSet,3,1,10    // [timer#on]
TaskValueSet,3,2,10    // [timer#off]
TaskValueSet,3,3,1     // [timer#reset]
TaskValueSet,3,4,0     //
TaskValueSet,4,1,14     // [clock#onh]
TaskValueSet,4,2,20    // [clock#onm]
TaskValueSet,4,3,14    // [clock#offh]
TaskValueSet,4,4,59    // [clock#offm]
TaskValueSet,5,1,1     // [step#on]
TaskValueSet,5,2,1     // [step#off]
TaskValueSet,5,3,100   // [step#reset]
TaskValueSet,5,4,0     //

PCAPWM,0,[light#dim1]
PCAPWM,1,[light#dim2]
delay 1000
delay 1000

If %systime% > [clock#onh]:[clock#onm]:00 
timerSet,5,[timer#reset]     //Set Timer 5 
timerSet,6,[timer#reset]     //Set Timer 6
endif

endon

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#31 Post by opentoideas » 22 Sep 2018, 17:13

also tried :

If %syshour% > 13

cant get this to trip the timers.

having got everything else to work I must have missed something daft but stuck again :lol:

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

Re: do I need to define a variable state?

#32 Post by grovkillen » 22 Sep 2018, 17:22

You can always first try to add it to a dummy. I'm not sure system variables are up to speed for it to be used inline.
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#33 Post by opentoideas » 22 Sep 2018, 17:48

grovkillen wrote: 22 Sep 2018, 17:22 You can always first try to add it to a dummy. I'm not sure system variables are up to speed for it to be used inline.
do you mean like :

TaskValueSet,3,4,%syshour%

tried this and the dummy is not set even though the clock is up and running :?

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

Re: do I need to define a variable state?

#34 Post by grovkillen » 22 Sep 2018, 17:59

Okay I need to try it myself. I'm currently in the move with getting this ship floating 😋
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:

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#35 Post by opentoideas » 22 Sep 2018, 18:07

grovkillen wrote: 22 Sep 2018, 17:59 Okay I need to try it myself. I'm currently in the move with getting this ship floating 😋
:lol: no worries, it's working just need to prepare for resets and power outs so not critical :D

TD-er
Core team member
Posts: 8751
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: do I need to define a variable state?

#36 Post by TD-er » 23 Sep 2018, 12:35

Just a pointer to help you write rules.
In the latest firmware builds (last 2 weeks I guess) I added a page on Tools => System Variables.
These show all system variables and their current output.
That may be useful for debugging.

opentoideas
Normal user
Posts: 23
Joined: 15 Mar 2018, 19:32

Re: do I need to define a variable state?

#37 Post by opentoideas » 23 Sep 2018, 15:35

TD-er wrote: 23 Sep 2018, 12:35 Just a pointer to help you write rules.
In the latest firmware builds (last 2 weeks I guess) I added a page on Tools => System Variables.
These show all system variables and their current output.
That may be useful for debugging.
Hi,

thank you. I was using that but while I have managed to solve this eventually I don't understand why but I do know how :lol:

what I have found is that for some reason the %syshour% result is always "0" when this is used within On System#Boot do :?:

even though the clock is up and running as confirmed by the logs and use of delays ....

to work around I just set a timer in the System#Boot then add the call for the %syshour% from outside the System#Boot command.

I don't think this is a bug as such just an unexpected way of using the commands.

I now have this up and running so I may post a copy into the applications in case someone else wants to have aquarium lighting but I need to add all the other channels as I only have the 2 white channels (cold and warm white) and need to add in the RGB control as well.

for debugging rules the logs could be better. I tried several options but in the end found throwing variable changes into places in each rule and watching the device tab the only way to see what was going on but it was hard work. the logs only told me a taskvalueset had happened but not what or which value was changed likewise no real timer info.

while the rules are a powerful tool they do not always perform as expected and when they don't debugging can be extremely difficult when there is no information to work with. in this case without putting variable changes into each command I had no way of knowing if the trigger or if statement or the actual command was the problem. and the comand giving an unexpected result only when used in a certain place was not the first thing you would expect when debugging

unfortunately I suspect that adding in this kind of debugging information for the rules would not be a simple task so while its frustrating at times I do understand that there are limitations.

TD-er
Core team member
Posts: 8751
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: do I need to define a variable state?

#38 Post by TD-er » 29 Sep 2018, 19:53

We have several events you can use in rules.
The system#boot is just that, the boot.
There are also events when the time is set, so if you depend on the system time, I suggest to trigger a rule on that event and consider that one as a boot like event.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 128 guests