Chicken control - Project Overview

Hi there, you might smile about the Topic, i am building a Control for my Chicken Hut with ESPHOME…

There are IOs for Door-Motor,Door-Motor-Direction,Up and Down Switches, LightSwitch, IN/OUT/WATER Temps, LDR Sensor and a WS2812 LED as Status LED.

here my ESPHOME Listing so far:

substitutions:
  plug_name: huehnerstall
  
esphome:
  name: huehnerstall
  platform: ESP8266
  board: esp01_1m

logger:

api:
  password: "xxx"

ota:
  password: "xxx"

wifi:
  networks:
  - ssid: "xxxx"
    password: "xx"
  - ssid: "xxxx2"
    password: "xx"
  - ssid: "xxxx3"
    password: "xx"
  manual_ip:
    static_ip: 192.168.3.19
    gateway: 192.168.2.1
    subnet: 255.255.252.0

web_server:
  port: 80

dallas:
  - pin: GPIO01
    update_interval: 10s
  
sensor:
  - platform: dallas
    address: 0x1c0000031edd2a28
    name: "Stall_Innentemp"      
    id: "DS18B20_Stall_Innentemp"
    filters:
      - filter_out: nan
      - filter_out: -127.0

  - platform: dallas
    address: 0x3401212ed1e6a728
    name: "Stall_Aussentemp"      
    id: "DS18B20_Stall_Aussentemp"
    filters:
      - filter_out: nan
      - filter_out: -127.0

  - platform: dallas
    address: 0x1c0000031edd2a26
    name: "Stall_Wassertemp"      
    id: "DS18B20_Stall_Wassertemp"
    filters:
      - filter_out: nan
      - filter_out: -127.0

  - platform: adc
    pin: A0
    name: "Light Sensor"
    update_interval: 60s
    device_class: illuminance
    unit_of_measurement: lx
    filters:
      - lambda: |-
          return (x * 5 / 10000.0) * 2000000.0;

  - platform: uptime
    name: ${plug_name}_Uptime Sensor

  - platform: wifi_signal
    name: ${plug_name}_WiFi Signal
    update_interval: 60s

light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: 03
    num_leds: 1
    name: "WS2812 LED"
    id: stall_status
    effects:
      - addressable_rainbow:
      - addressable_rainbow:
          name: Rainbow Effect With Custom Values
          speed: 10
          width: 50
          
binary_sensor:
  - platform: gpio
    pin:
      number: 00
      inverted: true
      mode:
        input: true
        pullup: true
    name: "stall_klappe_auf"
    id: "Stall_Klappe_auf"
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms
          
  - platform: gpio
    pin:
      number: 04
      inverted: true
      mode:
        input: true
        pullup: true
    name: "stall_klappe_zu"
    id: "Stall_Klappe_zu"      
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms
  - platform: gpio
    pin:
      number: 05
      inverted: true
      mode:
        input: true
        pullup: true
    name: "stall_tuer_auf"
    id: "Stall_Tuer_auf"      
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms

   
switch:
  - platform: gpio
    id: relays_motor_on
    name: "Relays_Motor_On"
    pin: GPIO16
    inverted: true

  - platform: gpio
    id: relays_motor_dir
    name: "Relays_Motor_Dir"
    pin: GPIO14
    inverted: true

  - platform: gpio
    id: relays_lampen
    name: "Relays_Lampen"
    pin: GPIO12
    inverted: true

  - platform: gpio
    id: relays_aussenlampe
    name: "Relays_Aussenlampe"
    pin: GPIO13
    inverted: true

  - platform: gpio
    id: relays_luefter
    name: "Relays_Luefter"
    pin: GPIO02
    inverted: true

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${plug_name}_WiFi IP
    ssid:
      name: ${plug_name}_WiFi SSID


i want to
turn on the WS2812 LED to green, if stall_klappe_auf is on
turn on the WS2812 LED to red, if stall_klappe_zu is on
turn on the WS2812 LED to yellow, if stall_klappe_auf is off AND stall_klappe_auf is off
flash the LED in blue. if Water-Temp is <=0 degree (keeping the previos state colour)

i am hanging on doing the action, tried something like this but i always get errors, syntax maybe…
(the rainbow-effect is only to test if the led works)

I want to get the esp let take control, not HA, so even WiFi is lost it still runs and open/close the door if getting dark or bright. HA will be used just for monitoring or manual open/close door.

So can someone help me with this?

1 Like

I wish I could help with what you are asking but, in reality, I just want pictures. I am intrigued by the chicken house and what you have going on. :slight_smile:

:grin:

@mega-hz: Because the issue is so cute I immediately remembered that there were a few projects. Type in the search chick in:title

1 Like

Thanks!! There appear to be quite a few people automating their coops!

@mega-hz All the best to you!! May your chickens live in the luxury of a smart-coop!

@pedolski:
in my earlier versions of chicken-control i also used a stepper motor, but because it is outside of the house it might get dusty or wet , so i made it with a geared 12v motor and a chain, this is very strong.
I also use 2 switches inseatd of magnetic switches, those had failure some times!
@atomicpapa:
what pics you would like to see? Motor/door/house or of the chicken? :slight_smile:

i got further today: i can switch on the inside-lights if human-door is opened, stop the motor when up or down position is reached and turn the ws2812 to red when closed, green when opende and yellow when not closed and not opened. also turn on the 230v fan if inside-temp is over 30degree. takes some time to understand esphome…
here my listing from today 18.10.2022:

substitutions:
  plug_name: huehnerstall
  
esphome:
  name: huehnerstall
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: 600
    # ...
    then:
      - light.turn_off: stall_status
      - switch.turn_on: relays_motor_on
      - switch.turn_off: relays_motor_dir
      - switch.turn_off: relays_lampen
      - switch.turn_off: relays_aussenlampe
      - switch.turn_off: relays_luefter

logger:

api:
  password: "xxxxx"

ota:
  password: "xxxxx"

wifi:
  networks:
  - ssid: "xxxxx"
    password: "xxxxx"
  - ssid: "xxxxx2"
    password: "xxxxx"
  - ssid: "xxxxx3"
    password: "xxxxx"
  manual_ip:
    static_ip: 192.168.3.19
    gateway: 192.168.2.1
    subnet: 255.255.252.0

web_server:
  port: 80

dallas:
  - pin: GPIO01
    update_interval: 10s
  
sensor:
  - platform: dallas
    address: 0x1c0000031edd2a28
    name: "Stall_Innentemp"      
    id: "DS18B20_Stall_Innentemp"
    filters:
      - filter_out: nan
      - filter_out: -127.0

  - platform: dallas
    address: 0x3401212ed1e6a728
    name: "Stall_Aussentemp"      
    id: "DS18B20_Stall_Aussentemp"
    filters:
      - filter_out: nan
      - filter_out: -127.0
    on_value:
      then:
        lambda: |-
          if (id(DS18B20_Stall_Aussentemp).state > 30.0) 
          {
            id(relays_luefter).turn_on(); 
          }
          else if (id(DS18B20_Stall_Aussentemp).state < 30.0)
          {
            id(relays_luefter).turn_off(); 
          }

  - platform: dallas
    address: 0x1c0000031edd2a26
    name: "Stall_Wassertemp"      
    id: "DS18B20_Stall_Wassertemp"
    filters:
      - filter_out: nan
      - filter_out: -127.0

  - platform: adc  # GND-1K-2.2K-3.3V Voltage Divider>!>
    pin: A0
    name: "Light Sensor"
    update_interval: 60s
    device_class: illuminance
    unit_of_measurement: lx
    filters:
      - lambda: |-
          return (x * 5 / 10000.0) * 2000000.0;

  - platform: uptime
    name: ${plug_name}_Uptime Sensor

  - platform: wifi_signal
    name: ${plug_name}_WiFi Signal
    update_interval: 60s

light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: 03
    num_leds: 1
    name: "WS2812 LED"
    id: stall_status
    effects:  # just for testing....
      - addressable_rainbow:
      - addressable_rainbow:
          name: Rainbow Effect With Custom Values
          speed: 10
          width: 50
          
binary_sensor:
  - platform: gpio
    pin:
      number: 00
      inverted: true
      mode:
        input: true
        pullup: true
    name: "stall_klappe_auf"
    id: "Stall_Klappe_auf"
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms
    on_press:
      - switch.turn_off: relays_motor_on
      - light.addressable_set:
          id: stall_status
          red: 0%
          green: 50%
          blue: 0%
    on_release:
      - light.addressable_set:
          id: stall_status
          red: 50%
          green: 50%
          blue: 0%
          
  - platform: gpio
    pin:
      number: 04
      inverted: true
      mode:
        input: true
        pullup: true
    name: "stall_klappe_zu"
    id: "Stall_Klappe_zu"      
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms
    on_press:
      - switch.turn_off: relays_motor_on
      - light.addressable_set:
          id: stall_status
          red: 50%
          green: 0%
          blue: 0%
    on_release:
      - light.addressable_set:
          id: stall_status
          red: 50%
          green: 50%
          blue: 0%

  - platform: gpio
    pin:
      number: 05
      inverted: true
      mode:
        input: true
        pullup: true
    name: "stall_tuer_auf"
    id: "Stall_Tuer_auf"      
    filters:
      - delayed_on: 50ms
      - delayed_off: 1000ms
    on_press:
      - switch.turn_on: relays_lampen
    on_release:
      - switch.turn_off: relays_lampen

   
switch:
  - platform: gpio
    id: relays_motor_on
    name: "Relays_Motor_On"
    pin: GPIO16
    inverted: true

  - platform: gpio
    id: relays_motor_dir
    name: "Relays_Motor_Dir"
    pin: GPIO14
    inverted: true

  - platform: gpio
    id: relays_lampen
    name: "Relays_Lampen"
    pin: GPIO12
    inverted: true

  - platform: gpio
    id: relays_aussenlampe
    name: "Relays_Aussenlampe"
    pin: GPIO13
    inverted: true

  - platform: gpio
    id: relays_luefter
    name: "Relays_Luefter"
    pin: GPIO02
    inverted: true

time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${plug_name}_WiFi IP
    ssid:
      name: ${plug_name}_WiFi SSID


We want it all! :smiley:

Eggs-acty!!! Sorry, couldn’t help myself!

I can help here. What part is not working for you now? I see you have relays for up and down. Have you considered cover for that?

Please send us some pictures :slight_smile:

pictures will come!

I didnt know about Cover Component… but i managed it myself.

I think the code and hardware is ready for shifting into the chicken house!
All simulations on my desk are working well!

Here my Listing today:

substitutions:
 plug_name: huehnerstall
 
esphome:
 name: huehnerstall
 platform: ESP8266
 board: esp01_1m
 on_boot:
   priority: 600
   # ...
   then:
     - light.turn_off: stall_status
     - switch.turn_on: relays_motor_on
     - switch.turn_on: relays_motor_dir
     - switch.turn_off: relays_lampen
     - switch.turn_off: relays_aussenlampe
     - switch.turn_off: relays_luefter
     - switch.turn_off: relays_heater

logger:
 baud_rate: 0

api:
 password: "xxxx"

ota:
 password: "xxxx"

wifi:
 networks:
 - ssid: "xxxx"
   password: "xxxx"
 - ssid: "xxxxxxx2"
   password: "xxxxx"
 - ssid: "xxxx3"
   password: "xxxxxxx"
 manual_ip:
   static_ip: 192.168.3.19
   gateway: 192.168.2.1
   subnet: 255.255.252.0

web_server:
 port: 80

dallas:
 - pin: GPIO01
   update_interval: 10s
 
sensor:
 - platform: dallas
   address: 0x1c0000031edd2a28
   name: "Stall_Innentemp"      
   id: "DS18B20_Stall_Innentemp"
   filters:
     - filter_out: nan
     - filter_out: -127.0
   on_value:
     then:
       lambda: |-
         if (id(DS18B20_Stall_Innentemp).state > 30.0) 
         {
           id(relays_luefter).turn_on(); 
         }
         else if (id(DS18B20_Stall_Innentemp).state < 30.0)
         {
           id(relays_luefter).turn_off(); 
         }

 - platform: dallas
   address: 0x3401212ed1e6a728
   name: "Stall_Aussentemp"      
   id: "DS18B20_Stall_Aussentemp"
   filters:
     - filter_out: nan
     - filter_out: -127.0

 - platform: dallas
   address: 0x1c0000031edd2a26
   name: "Stall_Wassertemp"      
   id: "DS18B20_Stall_Wassertemp"
   filters:
     - filter_out: nan
     - filter_out: -127.0
   on_value:
     then:
       lambda: |-
         if (id(DS18B20_Stall_Wassertemp).state < 0.1) 
         {
           id(relays_heater).turn_on(); 
         }
         else if (id(DS18B20_Stall_Wassertemp).state > 0.1)
         {
           id(relays_heater).turn_off(); 
         }

 - platform: adc  # GND-1K-2.2K-3.3V Voltage Divider>!>
   pin: A0
   name: "Stall Light Sensor"
   id: stall_light_sensor
   update_interval: 10s
   device_class: illuminance
   on_value:
     then:
       lambda: |-
         if (id(stall_light_sensor).state < 0.1 && id(Stall_Klappe_zu).state == true) 
         {
           id(relays_motor_on).turn_on(); 
           id(relays_motor_dir).turn_off(); 
         }
         else if (id(stall_light_sensor).state > 0.6 && id(Stall_Klappe_auf).state == true)
         {
           id(relays_motor_on).turn_on(); 
           id(relays_motor_dir).turn_on(); 
         }

 - platform: uptime
   name: ${plug_name}_Uptime Sensor

 - platform: wifi_signal
   name: ${plug_name}_WiFi Signal
   update_interval: 60s

light:
 - platform: neopixelbus
   type: GRB
   variant: WS2812
   pin: 03
   num_leds: 1
   name: "WS2812 LED"
   id: stall_status
   effects:
     - addressable_rainbow:
     - addressable_twinkle:
         
binary_sensor:
 - platform: gpio
   pin:
     number: 00
     inverted: true
     mode:
       input: true
       pullup: true
   name: "stall_klappe_auf"
   id: "Stall_Klappe_auf"
   filters:
     - delayed_on: 10ms
     - delayed_off: 10ms
   on_press:
     - switch.turn_off: relays_motor_on
     - switch.turn_off: relays_motor_dir
     - light.addressable_set:
         id: stall_status
         red: 0%
         green: 50%
         blue: 0%
   on_release:
     - light.addressable_set:
         id: stall_status
         red: 50%
         green: 50%
         blue: 0%
         
 - platform: gpio
   pin:
     number: 04
     inverted: true
     mode:
       input: true
       pullup: true
   name: "stall_klappe_zu"
   id: "Stall_Klappe_zu"      
   filters:
     - delayed_on: 10ms
     - delayed_off: 10ms
   on_press:
     - switch.turn_off: relays_motor_on
     - switch.turn_off: relays_motor_dir
     - light.addressable_set:
         id: stall_status
         red: 50%
         green: 0%
         blue: 0%
   on_release:
     - light.addressable_set:
         id: stall_status
         red: 50%
         green: 50%
         blue: 0%

 - platform: gpio
   pin:
     number: 05
     inverted: true
     mode:
       input: true
       pullup: true
   name: "stall_tuer_auf"
   id: "Stall_Tuer_auf"      
   filters:
     - delayed_on: 50ms
     - delayed_off: 1000ms
   on_press:
     - switch.turn_on: relays_lampen
   on_release:
     - switch.turn_off: relays_lampen

  
switch:
 - platform: gpio
   id: relays_motor_on
   name: "Relays_Motor_On"
   pin: GPIO16
   inverted: true

 - platform: gpio
   id: relays_motor_dir
   name: "Relays_Motor_Dir"
   pin: GPIO14
   inverted: true

 - platform: gpio
   id: relays_lampen
   name: "Relays_Lampen"
   pin: GPIO12
   inverted: true

 - platform: gpio
   id: relays_aussenlampe
   name: "Relays_Aussenlampe"
   pin: GPIO13
   inverted: true

 - platform: gpio
   id: relays_luefter
   name: "Relays_Luefter"
   pin: GPIO02
   inverted: true

 - platform: gpio
   id: relays_heater
   name: "Relays_Heater"
   pin: GPIO15
   inverted: true

time:
 - platform: homeassistant
   id: homeassistant_time

text_sensor:
 - platform: wifi_info
   ip_address:
     name: ${plug_name}_WiFi IP
   ssid:
     name: ${plug_name}_WiFi SSID


Waiting for a 12V SMPS, new LDR and new DS18B20 waterproof.
Additional there also comes a little heater, so the water for chickens doesnt freeze.
If everthing is working well, i will make a pcb layout, so everyone can use this.
It is not only for chicken houses, there could be many uses .

If someone finds some errors, bad coding oder has hints for make it better i am thankful for suggestions!

EDIT: how can i turn on ws2812 Rainbow-Effect on boot? (Syntax?)

I was thinking, everyone is laughing about your robot chicken, but no one has answered the poor guy’s question! Glad you sorted it.

I think something like

light.turn_on:
  id: stall_status
  effect:
    addressable_rainbow

However Light Component — ESPHome suggests it may be

light.turn_on:
  id: stall_status
  effects:
    addressable_rainbow:
    addressable_rainbow:
      speed: (etc)

i have tried this but i get errors:

C:\Users\mega->esphome run D:\Home-Assistant\Huehnerstall2.yaml
←[32mINFO Reading configuration D:\Home-Assistant\Huehnerstall2.yaml...←[0m
←[31mERROR Error while reading config: Invalid YAML syntax:

mapping values are not allowed here
  in "D:\Home-Assistant\Huehnerstall2.yaml", line 20, column 18:
              effects:
                     ^←[0m
esphome:
  name: huehnerstall
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: 600
    # ...
    then:
      - light.turn_off: stall_status
      - switch.turn_on: relays_motor_on
      - switch.turn_on: relays_motor_dir
      - switch.turn_off: relays_lampen
      - switch.turn_off: relays_aussenlampe
      - switch.turn_off: relays_luefter
      - switch.turn_off: relays_heater
      - light.turn_on: stall_status
          effects:
            addressable_rainbow          

or like this, same error:

esphome:
  name: huehnerstall
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: 600
    # ...
    then:
      - light.turn_off: stall_status
      - switch.turn_on: relays_motor_on
      - switch.turn_on: relays_motor_dir
      - switch.turn_off: relays_lampen
      - switch.turn_off: relays_aussenlampe
      - switch.turn_off: relays_luefter
      - switch.turn_off: relays_heater
      - light.turn_on:
          id: stall_status
            effects:
              addressable_rainbow          

doesnt matter if there is effect: or effects:

Your code is indented wrong.

where please?

EDIT:
Ah, ok! found it!
but it does not work as aspected: The WS2812 turns on but only bright white, no effect!
on the esphome website i can select the effekt and turn it on by hand, so the effect itself works…

EDIT2:
i found out that the effects even won’t work on other part of code, i’ve tried it at the binary sensor on_release call. it still only turns on full white.
Well, it is not a real must-have feature i need, so i can control it later in HA if i want to.
only thing i assume is: light.turn_on overrides the following effect…

My new LDRs and DS18B20 and the PSU has arrived, i think i find the time on weekend to assmble it into the chicken-house (and make pictures :wink: )

To be honest, I just took the click bait and came here to :rooster:

Hope your project works well for you:)

First assembly was nearly finished, but i made an mistake and killed my esp…
Now with the new esp it runs as it should!
Some little things i have to do like connecting the inside-light to the relays, assemble 2 power-outlets for Outside Lights and water-heater, but main function works, the little door opens when it gets brighter and closes if it gets dark outside, fan starts if inside-temp is greater than 30 degree (to prevent cooking of the eggs :wink: ), turn on little heater if drinking-water gets below 0.1 degree (chicks dont eat ice).

Here 2 Pictures of the chicken and the hoese: (not all chicken visible, 4 of 8 Chickens)


Picture of the door-mechanic and the esp with electronics coming!
BTW: the whole thing runs without mainpower! i’ve got a little MPPT Charger connected to 4 small PV (80W) and a 12V/7Ah SLA Battery with a 5V StepDown Converter. Ther is a 12V PSU coming though just for backup.
The Fan and the heater are running on 230VAC…
One importend thing is to mention: I have the door-up-contact connected to GPIO 0, that switches the esp into flash-mode, when a powerup or reset accours with door open!
At the moment i put a little switch into that line, but i am thinking of a additionel small relays.
Took me some time to find out why the esp didnt started :slight_smile: For the future: a firmware update only at night when door is closed :wink:

4 Likes

Awww! Thank you for the pictures and congrats that finally everything went well.

Looks really good, and a very luxurious chicken coop.

So what happens if a chicken is stuck on the wrong side when the door closes?

one thing i need help with is there yet:

I need to have start a timer wich counts down if light detection has reached a certain level!
I found out if there is a car with high-beam passing by the LDR gets high values, even if it is a short time it reacts and opens the door!
I was looking for a timer in esphome but couldnt find one.
Can someone help?
Something in the lambda maybe?

  - platform: adc  # GND-1K-2.2K-3.3V Voltage Divider>!>
    pin: A0
    name: "Stall Light Sensor"
    id: stall_light_sensor
    update_interval: 10s
    device_class: illuminance
    on_value:
      then:
        lambda: |-
          if (id(stall_light_sensor).state > 0.3 && id(Stall_Klappe_zu).state == true) 
          {
            id(relays_motor_on).turn_on(); 
            id(relays_motor_dir).turn_on(); 
          }
          else if (id(stall_light_sensor).state < 0.02 && id(Stall_Klappe_auf).state == true)
          {
            id(relays_motor_on).turn_on(); 
            id(relays_motor_dir).turn_off(); 
          }

if have watched the behaivior of the chickens, at a certain level of darkness they all get together, have a small-talk and go all into the house. The Switch-Down level of brighness is about 60min after they went into the house, so there is enough time-out for them.
in over ten years i only had it one time and the chicken was sitting under a rain-cover outside, when its getting dark they cant see anything so it stayed there.
First i thought about RFID-Rings on each chicken on the right leg, so i could count them and could see if they are going in or out, but i cant get a rfid distance of about 20cm, so that idea was for the trash…
But i have a look every evening to say good night :slight_smile:

1 Like

Thanks for the pics. Mighty fine chicken coop you have there! Lucky lil cluckers.