Page 1 of 1
several rules
Posted: 05 Jun 2018, 18:20
by TungstenE2
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
Re: several rules
Posted: 06 Jun 2018, 16:18
by grovkillen
I need you to explain more what you're trying to do, like in, show some screenshot of all the devices.
Re: several rules
Posted: 06 Jun 2018, 20:32
by TungstenE2
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?
Re: several rules
Posted: 06 Jun 2018, 21:50
by grovkillen
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
Re: several rules
Posted: 07 Jun 2018, 08:44
by TungstenE2
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?
Re: several rules
Posted: 07 Jun 2018, 10:54
by grovkillen
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.
Re: several rules
Posted: 08 Jun 2018, 08:51
by TungstenE2
any ideas yet?
Re: several rules
Posted: 08 Jun 2018, 10:14
by grovkillen
Have you tried my approach with concat:ing multiple values into one value?
Re: several rules
Posted: 08 Jun 2018, 11:27
by TungstenE2
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?
Re: several rules
Posted: 08 Jun 2018, 13:12
by grovkillen
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
Re: several rules
Posted: 08 Jun 2018, 15:39
by TungstenE2
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
Re: several rules
Posted: 08 Jun 2018, 15:48
by grovkillen
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.
Re: several rules
Posted: 08 Jun 2018, 17:16
by TungstenE2
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
Re: several rules
Posted: 08 Jun 2018, 17:31
by grovkillen
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
Re: several rules
Posted: 08 Jun 2018, 17:52
by TungstenE2
edited that, but no change. motor is not triggered if conditions are met.
Re: several rules
Posted: 08 Jun 2018, 17:53
by grovkillen
What does the log look like?
Re: several rules
Posted: 08 Jun 2018, 18:17
by grovkillen
I will think some more about this.
Re: several rules
Posted: 08 Jun 2018, 18:21
by TungstenE2
log is empty
Re: several rules
Posted: 09 Jun 2018, 13:58
by TungstenE2
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
Re: several rules
Posted: 09 Jun 2018, 18:32
by danmero
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
Re: several rules
Posted: 09 Jun 2018, 21:34
by TungstenE2
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.
Re: several rules
Posted: 10 Jun 2018, 01:49
by danmero
Post your code and add comments (//) where is not working.
Regards,
Re: several rules
Posted: 10 Jun 2018, 09:48
by TungstenE2
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.
Re: several rules
Posted: 10 Jun 2018, 12:39
by TungstenE2
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
Re: several rules
Posted: 10 Jun 2018, 14:00
by danmero
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
Re: several rules
Posted: 11 Jun 2018, 21:02
by TungstenE2
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
Re: several rules
Posted: 12 Jun 2018, 00:16
by danmero
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.
Re: several rules
Posted: 14 Jun 2018, 22:07
by TungstenE2
thx danmero, changed it.