Chicken door and light

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Chicken door and light

#1 Post by SqUaT » 12 Dec 2018, 21:49

Hello,

I was trying to create some rules for my chicken.
Switch light on at 6:00 and switch off at sunrise + light on at sunrise and light off at 20:00
Later I would like to implement the door to open and close them automatically.
Additional I would like to toggle the light by pressing a button (key). Each parts of the code work alone.

My idea was to generate dummy variable to hold the state (light on morning, light on evening) and also use always the same code for switch the light, but it dosn't work propperly.

Could somebody tell me, what I'm doing wrong?

Code: Select all

on System#Boot do
    timerSet,1,20
endon

on Rules#Timer=1 do
    if %systm_hm% > 6:00 and %systm_hm% < %sunrise% or  %systm_hm%  > %sunset% and %systime% < 20:00
         GPIO,12,0//Relais
         GPIO,13,0//LED 
    else
		GPIO,12,1//Relais
         GPIO,13,1//LED 
    endif
endon


On Clock#Time=All,6:00 do // every day at 6:00 hours switch on relay on gpio 12
 gpio,12,0
 GPIO,13,0//LED
 endon

//at sunrise time switch light off//set timer1 for 1 hour
On Clock#Time=All,%sunrise% do
//timerSet,2,3600
 GPIO,12,1//Relais/light off
 GPIO,13,1//LED off
 //GPIO,1,0//door up
 endon

//at sunset time switch light on
On Clock#Time=All,%sunset% do
 timerSet,1,3600
 GPIO,12,0//Relais
 GPIO,13,0//LED
 endon

//When Timer1 expires, <action>
On Rules#Timer=1 do
 GPIO,1,0 // close door
 endon

On Clock#Time=All,20:00 do // every day at 20:00 hours switch off relay on gpio 12
 GPIO,12,1//Relais
 GPIO,13,1//LED
 endon
 

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

Re: Chicken door and light

#2 Post by grovkillen » 12 Dec 2018, 23:01

You have two Rules#Timer=1 which will not work. Only one is allowed.
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:

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#3 Post by SqUaT » 19 Dec 2018, 10:46

OK, one step before.
Switching light on and of via dummy
EASYESP.GIF
EASYESP.GIF (53.56 KiB) Viewed 7008 times

Code: Select all

on System#Boot do
    timerSet,1,10
endon

on Rules#Timer=1 do

if Dummy#Moring=1
 GPIO,13,0
else
//On Dummy#Moring=0 do
 GPIO,13,1
 //TaskValueSet 3, 1, 1
endif
endon
Another test was:

Code: Select all

On Dummy#Moring=1 do
 GPIO,13,0
else
//On Dummy#Moring=0 do
 GPIO,13,1
endon
Or:

Code: Select all

On Dummy#Moring=1 do
 GPIO,13,0
 endon
On Dummy#Moring=0 do
 GPIO,13,1
endon

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

Re: Chicken door and light

#4 Post by Domosapiens » 19 Dec 2018, 14:04

I see
Moring
instead of
Morning
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.

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#5 Post by SqUaT » 19 Dec 2018, 19:50

Thanks, but the error exist. The Led is still off.
If I send the Gpio command via http, I get the following error.

Code: Select all

http://IP/control?cmd=GPIO,13,1
Unknown or restricted command!

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

Re: Chicken door and light

#6 Post by grovkillen » 19 Dec 2018, 19:51

What version?
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:

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#7 Post by SqUaT » 19 Dec 2018, 21:52

GIT version: mega-20181208

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

Re: Chicken door and light

#8 Post by grovkillen » 19 Dec 2018, 23:45

Please update to latest, there might be a bug...
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:

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#9 Post by SqUaT » 20 Dec 2018, 14:28

That helps a bit. The error doesn't appears.

One thing I found was the missing "[]"

Code: Select all

on System#Boot do
 timerSet,1,2
endon

On Rules#Timer=1 do
 if [Dummy#Morning]=1
  //GPIO,13,0
  TaskValueSet,3,1,0
 else
  //GPIO,13,1
  TaskValueSet,3,1,1
 endif
timerSet,1,2
endon
Now the LED will go on an off, but (only by using gpio function), not with the following code.

Code: Select all

On LED#LED=1 do
 if [LED#LED]=1
  GPIO,13,0
 else
  GPIO,13,1
 endif
endon
LED is Task 3 (TaskValueSet,3,...)

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

Re: Chicken door and light

#10 Post by grovkillen » 20 Dec 2018, 17:30

SqUaT wrote: 20 Dec 2018, 14:28 That helps a bit. The error doesn't appears.

One thing I found was the missing "[]"

Code: Select all

on System#Boot do
 timerSet,1,2
endon

On Rules#Timer=1 do
 if [Dummy#Morning]=1
  //GPIO,13,0
  TaskValueSet,3,1,0
 else
  //GPIO,13,1
  TaskValueSet,3,1,1
 endif
timerSet,1,2
endon
Now the LED will go on an off, but (only by using gpio function), not with the following code.

Code: Select all

On LED#LED=1 do
 if [LED#LED]=1
  GPIO,13,0
 else
  GPIO,13,1
 endif
endon
LED is Task 3 (TaskValueSet,3,...)

Code: Select all

On LED#LED do
 if [LED#LED]=1
  GPIO,13,0
 else
  GPIO,13,1
 endif
endon
I would rename the value to state.

Code: Select all

LED#state
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:

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#11 Post by SqUaT » 22 Dec 2018, 00:24

Good. Renaming helps.

Now I create the following Code. On manually changes of state "morning" and "evening", the relay and the Led toggle, also on using the button. But the state will not change on time.

I activate ntp and set the location Settings. Additional I set DSP on.
esp_chicken_door_DSP.PNG
esp_chicken_door_DSP.PNG (16.03 KiB) Viewed 6894 times
Does somebody know, why the time and sunset/sunrise did not set the State properly?

Code: Select all

on System#Boot do
    timerSet,1,20
endon

on Rules#Timer=1 do
 if %systm_hm% > 6:00 and %systm_hm% < %sunrise% //morning - set state to indicate light on
  TaskValueSet 5,1,1
  taskRun,5
 endif
 if %systm_hm%  > %sunset% and %systime% < 20:00 //evening - set state to indicate light on
  TaskValueSet 5,2,1
  taskRun,5
 endif
endon

On Clock#Time=All,6:00 do // every day at 6:00 hours switch on relay on
 TaskValueSet 5,1,1
 taskRun,5
endon


//at sunrise time switch light off//set timer1 for 1 hour
On Clock#Time=All,%sunrise% do
//timerSet,2,3600
 TaskValueSet 5,1,0
 taskRun,5
 endon

//at sunset time switch light on
On Clock#Time=All,%sunset% do
 TaskValueSet 5,2,1
 taskRun,5
 endon


On Clock#Time=All,20:00 do // every day at 20:00 hours switch off relay on gpio 12
 TaskValueSet 5,2,0
 taskRun,5
endon


// morning - relay
on LightState#morning do
  if [LightState#morning]=1
   gpio,12,1
   TaskValueSet 5,2,1
  else
   gpio,12,0
   TaskValueSet 5,2,0
  endif
endon 

// evening - relay
on LightState#evening do
  if [LightState#evening]=1
   gpio,12,1
   TaskValueSet 5,3,1
  else
   gpio,12,0
   TaskValueSet 5,3,0
  endif
endon 

// Button - relay
on button#switch do
  if [button#switch]=1
   gpio,12,1
   TaskValueSet 5,3,1
  else
   gpio,12,0
   TaskValueSet 5,3,0
  endif
 endon 

// LED
on relay#switch do
  if [relay#switch]=1 //change this [relay#switch]=0 for LED off when relay is closed
   gpio,13,0 //or pwm,13,700
  else
   gpio,13,1 //or pwm,13,10
  endif
 endon 

Attachments
esp_chicken_door.PNG
esp_chicken_door.PNG (25.52 KiB) Viewed 6894 times

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

Re: Chicken door and light

#12 Post by Domosapiens » 22 Dec 2018, 00:45

I'm not sure what you are doing but:
- Task LED on GPIO 13 is defined as Task 3 as input
- In the Rule you control GPIO 13 as output

- GPIO-0 is a special one! Has a Pull-up on most boards.
- That means your switch must be active Low (at least ... high at boot!)
- Use GPIO-14 instead, just to make sure
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.

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#13 Post by SqUaT » 26 Dec 2018, 21:31

I update to Version mega-20181220 and delete all devices which aren't in use.
But today at the evening, the LightState does not go to 1. after seting it manually, one Minute later it was switching back to 0 and the light go off.

How can I see the variable %systm_hm% to verify the correct time?

I have also test to delete the %sunrise% and %sunset% to fix times (8:30 and 16:00, but it didn't work.

The switch (button), the led and the relay works now correct.

Code: Select all

on System#Boot do
    timerSet,1,20
endon

on Rules#Timer=1 do
 if %systm_hm% > 6:00 and %systm_hm% < %sunrise% //morning - set state to indicate light on
  TaskValueSet 3,1,1
  taskRun,3
 endif
 if %systm_hm% > %sunset% and %systime% < 20:00 //evening - set state to indicate light on
  TaskValueSet 3,2,1
  taskRun,3
 endif
endon

On Clock#Time=All,6:00 do // every day at 6:00 hours switch on relay on
 TaskValueSet 3,1,1
 taskRun,3
endon


//at sunrise time switch light off//set timer1 for 1 hour
On Clock#Time=All,%sunrise% do
 TaskValueSet 3,1,0
 taskRun,3
 endon

//at sunset time switch light on
On Clock#Time=All,%sunset% do
 TaskValueSet 3,2,1
 taskRun,3
 endon


On Clock#Time=All,20:00 do // every day at 20:00 hours switch off relay on gpio 12
 TaskValueSet 3,2,0
 taskRun,3
 endon

// morning - relay
on LightState#morning do
  if [LightState#morning]=1
   gpio,12,1
  else
   gpio,12,0
  endif
endon

// evening - relay
on LightState#evening do
  if [LightState#evening]=1
   gpio,12,1
  else
   gpio,12,0
  endif
endon

// Button - relay
on button#switch do
  if [button#switch]=1
   gpio,12,1
  else
   gpio,12,0
  endif
 endon

// LED
on relay#switch do
  if [relay#switch]=1 //change this [relay#switch]=0 for LED off when relay is closed
   gpio,13,0 //or pwm,13,700
  else
   gpio,13,1 //or pwm,13,10
  endif
 endon 
Attachments
esp_chicken_door.PNG
esp_chicken_door.PNG (31.18 KiB) Viewed 6828 times
Last edited by SqUaT on 27 Dec 2018, 09:20, edited 1 time in total.

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

Re: Chicken door and light

#14 Post by grovkillen » 26 Dec 2018, 22:59

In tools you have the system variables page.
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:

SqUaT
New user
Posts: 8
Joined: 11 Dec 2018, 22:01

Re: Chicken door and light

#15 Post by SqUaT » 26 Dec 2018, 23:32

OK, the system variable are in the same format and nearly the same time as written before (8:31 an 15:50).

Could somebody find an error in the code, why the LightState was set to 0 today at 17:30?

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests