several rules

Moderators: grovkillen, Stuntteam, TD-er

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

several rules

#1 Post by TungstenE2 » 05 Jun 2018, 18:20

Hi all,

I am trying to build a door automatic on wemos D1 mini with mega 24052018.
Created a plugin to control wemos motorshield.

I am trying to build rules bases on light sensor and reed switches.

The rules below do work, but not together. Together the motor stops and starts every second.

Can somebody guide me to the correct rule settings?

https://drive.google.com/open?id=1vbuuN ... ZweMvd6Kkh

Code: Select all

On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,100.00 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
TaskValueSet 7,4,0 // Timer off
endon

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

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

// if night and door not closed than motor forward 
On Dummies#Tag do
if [Dummies#Tag]=0 and [Reed2-unten#Switch]=0
WemosMotorShieldCMD 0 Forward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon

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

Re: several rules

#2 Post by grovkillen » 06 Jun 2018, 16:18

I need you to explain more what you're trying to do, like in, show some screenshot of all the devices.
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

#3 Post by TungstenE2 » 06 Jun 2018, 20:32

Okay, will try to explain.

I am build automation for a chicken house with Wemos D1 mini and Wemos motorshield.
Plan is to open and close a slide door when certain conditions are met.

I have following devices:
- light sensor with analog signal
- 2 reed switch
- 2 buttons (1 still needs to be bought and installed)
- motor
- 4 dummy devices (Tag, HelligkeitTriggerTag, DCMotorOn, TimerActive)

dummy devices:
Tag: 0=night, 1=day
HelligkeitTriggerTag: threshold light sensor value to switch dummy 'Tag' from night(0) to day(1)
DCMotorOn: 0=motor off, 1=motor on
TimerActive: not used for the moment

What I want rules to do:

- if day and door not open than motor backwards

Code: Select all

On Dummies#Tag do
if [Dummies#Tag]=1 and [Reed1-oben#Switch]=0
WemosMotorShieldCMD 0 Backward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon
- if night and door not closed than motor forward

Code: Select all

On Dummies#Tag do
if [Dummies#Tag]=0 and [Reed2-unten#Switch]=0
WemosMotorShieldCMD 0 Forward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon
if button 1 is pressed and door not than motor backwards

Code: Select all

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
if button 2 is pressed and door not closed than motor forward

Code: Select all

On Taster2#Switch do
if [Taster2#Switch]=1 and [Reed2-unten#Switch]=0
WemosMotorShieldCMD 0 Forward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon
All those rules do already work in single rule, but in combination the motor is triggered and stopped every second.
So I am searching for optimization of this.

Later on I also want to control status from mobile and open and close door from mobile.

Does this better explain what I am trying?

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

Re: several rules

#4 Post by grovkillen » 06 Jun 2018, 21:50

Yeah, I think I got it now. I will need to think more about it but I tend to try to combine multiple dummy values into one value. See this (very extreme) example I made for finding color from RGB:

viewtopic.php?f=2&t=3021&p=17923#p17512
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

#5 Post by TungstenE2 » 07 Jun 2018, 08:44

Thnx for looking into this.

One question: seems like only Rules Page 1 is working in my testing build from 24.05.
Are the diferent rules pages only for better overview or is there a logical sequence?

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

Re: several rules

#6 Post by grovkillen » 07 Jun 2018, 10:54

The first approach with more that one rule page was just to add more rule pages.

Later on we got the idea of being able to enable/disable different pages using rules but this is not implemented.
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

#7 Post by TungstenE2 » 08 Jun 2018, 08:51

any ideas yet?

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

Re: several rules

#8 Post by grovkillen » 08 Jun 2018, 10:14

Have you tried my approach with concat:ing multiple values into one value?
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

#9 Post by TungstenE2 » 08 Jun 2018, 11:27

Thats what I am already doing with the dummy device.

But I did not get your idea on how to further get multiple values into one value and how this should be controlled by the rules.

Can you explain?

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

Re: several rules

#10 Post by grovkillen » 08 Jun 2018, 13:12

Instead of your rules:

Code: Select all

On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,100.00 // Helligkeit on dummy sensor
  TaskValueSet 7,3,0 // DC Motor off
  TaskValueSet 7,4,0 // Timer off
endon

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

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

// if night and door not closed than motor forward 
On Dummies#Tag do
if [Dummies#Tag]=0 and [Reed2-unten#Switch]=0
WemosMotorShieldCMD 0 Forward 50
TaskValueSet 7,3,1
else
WemosMotorShieldCMD 0 Stop
TaskValueSet 7,3,0
endif
endon
Do something like this:

Code: Select all

On System#Boot do
  TaskValueSet 7,1,0 // no day = 0
  TaskValueSet 7,2,100.00 // 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

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

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

#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: No registered users and 23 guests