several rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#11 Post by TungstenE2 » 08 Jun 2018, 15:39

thanks, looked at it and tried to understand your rules provided.

what I do not unterstand:
- default value for Dummy#Concat is set to '999' on boot, but after couple of seconds value is set to '1100'.
but why? in the rule the '1100' is in checked in if-statement, not set.

- what exactly is this rule doing?

Code: Select all

On Rules#Timer=1 do
	TaskValueSet 8,1,1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
	timerSet,1,10
endon

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

Re: several rules

#12 Post by grovkillen » 08 Jun 2018, 15:48

999 to just to make sure that it's not triggering anything right at start.

The part that you are asking about is actually where it all happens. Each time the timer expire the Concat is updated with latest info about the reeds and the light. That makes the Dummy#Concat event trigger and the check(s) are done.

Watch the log and you'll see.
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:

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#13 Post by TungstenE2 » 08 Jun 2018, 17:16

ah, got it!

changed the rule a bit, but motor is not triggered even '[Dummy#Concat]=1101'
also 'TaskValueSet 7,3,1' is not set.
Seems like the 'if' is to working, but dont know why.

[Dummy#Concat] is updated as expected.


Code: Select all

//999 default
//1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
//1110 day door open
//1101 day door down
//1010 night door open
//1001 night door down


On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,100 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
  TaskValueSet 7,4,0 // Timer off
  TaskValueSet 8,1,999 // To concat of some dummys (named Dummy#Concat) '999' just as a default ref
  timerSet,2,10
endon


// day or night
On Lichtsensor#Analog do
	if [Lichtsensor#Analog] > [Dummies#HelligkeitTriggerTag]
		TaskValueSet 7,1,1
	else
		TaskValueSet 7,1,0
	endif
endon


On Dummy#Concat do
// if day and door not open than motor backwards
	if [Dummy#Concat]=1101
		WemosMotorShieldCMD 0 Backward 50
		TaskValueSet 7,3,1
		timerSet,1,60
		timerSet,2,0
	endif
// if night and door not closed than motor backwards
	if [Dummy#Concat]=1010
		WemosMotorShieldCMD 0 Forward 50
		TaskValueSet 7,3,1
		timerSet,1,60
		timerSet,2,0
	endif
	// you can add multiple [Dummy#Concat]= statements here... 
endon


//every 10 sek Timer1 is adding values from the devices to the concat dummy
On Rules#Timer=1 do
	TaskValueSet 8,1,1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
	timerSet,1,10
endon


// if motor run for more than 60 seconds and no reed is read, stop
On Rules#Timer=2 do
	if [Dummies#DCmotor]=1
		WemosMotorShieldCMD 0 Stop
		TaskValueSet 7,3,0
	endif
	timerSet,1,10
endon

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

Re: several rules

#14 Post by grovkillen » 08 Jun 2018, 17:31

Sorry, you might need to add TaskRun to this part:

Code: Select all

On Rules#Timer=1 do
	TaskValueSet 8,1,1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
	timerSet,1,10
endon
I.e

Code: Select all

On Rules#Timer=1 do
	TaskValueSet 8,1,1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
	timerSet,1,10
	taskRun,8
endon
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:

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#15 Post by TungstenE2 » 08 Jun 2018, 17:52

edited that, but no change. motor is not triggered if conditions are met.

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

Re: several rules

#16 Post by grovkillen » 08 Jun 2018, 17:53

What does the log look like?
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: several rules

#17 Post by grovkillen » 08 Jun 2018, 18:17

I will think some more about this.
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:

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#18 Post by TungstenE2 » 08 Jun 2018, 18:21

log is empty

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#19 Post by TungstenE2 » 09 Jun 2018, 13:58

I have tested now with the rules and concatination. I have the feeling this is not working stable.

I got working rules were the concat value was updated as expected. When I changed the rule a bit the value was no longer updated.
Rolling back to the previous rule code the value was still not updated.

I exirienced reboot of the divce twice after rule was updated, but it was minor change in rule.

So currently I am still struggeling with the rules.

Do rules need to follow a certain order of rule elements?

Just some testing:

Code: Select all

//Dummy1
//999 default
//1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
//1110 day door open
//1101 day door down
//1010 night door open
//1001 night door down


On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,200 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
  TaskValueSet 7,4,0 // Timer off
  TaskValueSet 8,1,999 // To concat of some dummys (named Dummy1#Concat) '999' just as a default ref
  timerSet,2,10
endon




// day or night
On Lichtsensor#Analog do
	if [Lichtsensor#Analog] > [Dummies#HelligkeitTriggerTag]
		TaskValueSet 7,1,1
	else
		TaskValueSet 7,1,0
	endif
endon

//every 1 sek Timer1 is adding values from the devices to the concat dummy
On Rules#Timer=1 do
	TaskValueSet 8,1,1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
 	timerSet,1,1
endon



// Taster1 pressed and door not open motor backwards
On Taster1#Switch do
if [Taster1#Switch]=1 and [Reed1-oben#Switch]=0
WemosMotorShieldCMD 0 Backward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon

danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: several rules

#20 Post by danmero » 09 Jun 2018, 18:32

Code: Select all

// Taster1 pressed and door not open motor backwards
On Taster1#Switch do
if [Taster1#Switch]=1 and [Reed1-oben#Switch]=0
WemosMotorShieldCMD 0 Backward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon
Hmm, the motor will run until you keep the switch on, once you release the switch(event) Taster1#Switch the value will be 0 and else will be executed.

Try to use events , maybe like that you can simplify the logic

Code: Select all

On Taster1#Switch do
	If [Taster1#Switch]=1 and [Reed1-oben#Switch]=0
		Event,DoorClose
	Else
		Event,DoorStop
endif
endon

On DoorStop Do
	WemosMotorShieldCMD 0 Stop
	TaskValueSet 7,3,0
EndOn

On DoorOpen Do
	WemosMotorShieldCMD 0 Backward 50
	TaskValueSet 7,3,1
EndOn

On DoorClose Do
	WemosMotorShieldCMD 0 Forward 50
	TaskValueSet 7,3,1
EndOn

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#21 Post by TungstenE2 » 09 Jun 2018, 21:34

thx, the event works in general, but the motor does not stop if [Reed1-oben#Switch] changes from 0 to 1.
But this should be the case, right?

If I release the [Taster1#Switch] and press it again, while [Reed1-oben#Switch] is still 1 motor does not start again. This is correct.

Also if [Reed1-oben#Switch] is 1 when [Taster1#Switch] is pressed the motor does not start. Keeping the [Taster1#Switch] pressed and [Reed1-oben#Switch] changes from 1 to 0 the motor starts. This is alos correct.

danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: several rules

#22 Post by danmero » 10 Jun 2018, 01:49

Post your code and add comments (//) where is not working.

Regards,

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#23 Post by TungstenE2 » 10 Jun 2018, 09:48

I was refering to this:

Code: Select all

//Dummy1
//999 default
//1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
//1110 day door open
//1101 day door down
//1010 night door open
//1001 night door down


On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,200 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
  TaskValueSet 7,4,0 // Timer off
  TaskValueSet 8,1,999 // To concat of some dummys (named Dummy1#Concat) '999' just as a default ref
  timerSet,2,10
endon




// day or night
On Lichtsensor#Analog do
	if [Lichtsensor#Analog] > [Dummies#HelligkeitTriggerTag]
		TaskValueSet 7,1,1
	else
		TaskValueSet 7,1,0
	endif
endon

//every 1 sek Timer1 is adding values from the devices to the concat dummy
On Rules#Timer=1 do
	TaskValueSet 8,1,1[Dummies#Tag][Reed1-oben#Switch][Reed2-unten#Switch]
 	timerSet,1,1
endon




On Taster1#Switch do
	If [Taster1#Switch]=1 and [Reed1-oben#Switch]=0
		Event,DoorClose
	Else
		Event,DoorStop
endif
endon

On DoorStop Do
	WemosMotorShieldCMD 0 Stop
	TaskValueSet 7,3,0
EndOn

On DoorOpen Do
	WemosMotorShieldCMD 0 Backward 50
	TaskValueSet 7,3,1
EndOn

On DoorClose Do
	WemosMotorShieldCMD 0 Forward 50
	TaskValueSet 7,3,1
EndOn

And I would have expected the motor to stop, when [Reed1-oben#Switch] changes from 0 to 1.

Code: Select all

Else
		Event,DoorStop

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#24 Post by TungstenE2 » 10 Jun 2018, 12:39

ok, got this now working with events. door motor is triggered by push button or cmd.

so basic version is working, as wife is asking for POC...

but this is manual interaction. next step is automation. either based on light sensor or weekday and time.

Code: Select all

On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,200 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
  TaskValueSet 7,4,0 // Timer off
  TaskValueSet 8,1,999 // To concat of some dummys (named Dummy1#Concat) '999' just as a default ref
  timerSet,2,10
endon


//close door if Taster1 is pressed and door is not closed
On Taster1-close#Switch do
	If [Taster1-close#Switch]=1 and [Reed2-close#Switch]!=1
		Event,DoorClose
	Else
		Event,DoorStop
endif
endon

//stop door close if reed2 changes from 0 to 1
On Reed2-close#Switch do
	If [Dummies#DCMotorOn]=1 and [Reed2-close#Switch]=1
		Event,DoorStop
	endif
endon

//stop door open if reed1 changes from 0 to 1
On Reed1-open#Switch do
	If [Dummies#DCMotorOn]=1 and [Reed1-open#Switch]=1
		Event,DoorStop
	endif
endon


//Events
On DoorStop Do
	WemosMotorShieldCMD 0 Stop
	TaskValueSet 7,3,0
EndOn

On DoorOpen Do
If [Reed1-open#Switch]!=1
	WemosMotorShieldCMD 0 Backward 50
	TaskValueSet 7,3,1
EndOn

On DoorClose Do
    If [Reed2-close#Switch]!=1
  	WemosMotorShieldCMD 0 Forward 50
	TaskValueSet 7,3,1
EndOn




danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: several rules

#25 Post by danmero » 10 Jun 2018, 14:00

Just to simplify, both reed should stop the motor regardless the state of the motor.

Code: Select all

  TaskValueSet 7,3,0 // Door state

On Reed2-close#Switch do
	If [Reed2-close#Switch]=1
		TaskSet,7,1// here you can set the state of the door for later use
		Event,DoorStop
	endif
endon

On Reed1-open#Switch do
	If [Reed1-open#Switch]=1
		TaskSet,7,0// here you can set the state of the door for later use
		Event,DoorStop
	endif
endon

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#26 Post by TungstenE2 » 11 Jun 2018, 21:02

thx, added your rules partly.
state of door is already known by state of reed1 and reed2.

Code: Select all

On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,200 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
  TaskValueSet 7,4,0 // Timer off
  TaskValueSet 8,1,999 // To concat of some dummys (named Dummy1#Concat) '999' just as a default ref
  timerSet,2,10
endon


// day or night
On Lichtsensor#Analog do
	if [Lichtsensor#Analog] > [Dummies#HelligkeitTriggerTag]
		TaskValueSet 7,1,1
	else
		TaskValueSet 7,1,0
	endif
endon

//close door if Taster1 is pressed and door is not closed
On Taster1-close#Switch do
	If [Taster1-close#Switch]=1 and [Reed2-close#Switch]!=1
		Event,DoorClose
	Else
		Event,DoorStop
endif
endon

//close door if Taster2 is pressed and door is not open
On Taster2-open#Switch do
	If [Taster2-open#Switch]=1 and [Reed1-open#Switch]!=1
		Event,DoorOpen
	Else
		Event,DoorStop
endif
endon

//stop door close if reed2 changes from 0 to 1
On Reed2-close#Switch do
	If [Dummies#DCMotorOn]=1 and [Reed2-close#Switch]=1
		Event,DoorStop
endif
endon

//stop door open if reed1 changes from 0 to 1
On Reed1-open#Switch do
	If [Dummies#DCMotorOn]=1 and [Reed1-open#Switch]=1
		Event,DoorStop
endif
endon

//stop motor if Reed1 or Reed2 triggered
On Reed1-open#Switch do
	If [Reed1-open#Switch]=1
		Event,DoorStop
	endif
endon

On Reed2-close#Switch do
	If [Reed2-close#Switch]=1
		Event,DoorStop
	endif
endon


// for all day close door at time if not closed
On Clock#Time=All,22:30 do 
	If [Reed2-close#Switch]!=1
		Event,DoorClose
	Else
		Event,DoorStop
endif
endon


//Events

On DoorOpen Do
If [Reed1-open#Switch]!=1
	WemosMotorShieldCMD 0 Backward 50
	TaskValueSet 7,3,1
endif
EndOn

On DoorClose Do
    If [Reed2-close#Switch]!=1
  	WemosMotorShieldCMD 0 Forward 50
	TaskValueSet 7,3,1
endif
EndOn

On DoorStop Do
	WemosMotorShieldCMD 0 Stop
	TaskValueSet 7,3,0
EndOn

danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: several rules

#27 Post by danmero » 12 Jun 2018, 00:16

You complicate yourself
This:

Code: Select all

On Reed1-open#Switch do
	If [Dummies#DCMotorOn]=1 and [Reed1-open#Switch]=1
		Event,DoorStop
endif
endon

//stop motor if Reed1 or Reed2 triggered
On Reed1-open#Switch do
	If [Reed1-open#Switch]=1
		Event,DoorStop
	endif
endon
Should be only

Code: Select all

On Reed1-open#Switch do
	If [Reed1-open#Switch]=1
		TaskSet,7,0// here you can set the state of the door for later use
		Event,DoorStop
	endif
endon
You don't need to check the state of the motor if you want to stop it.

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: several rules

#28 Post by TungstenE2 » 14 Jun 2018, 22:07

thx danmero, changed it.

Post Reply

Who is online

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