/scoop

Smart chicken coop 🐔🏠 with webcam 🎥, door automation 🚪, light 💡 and heating 🌞, sensors 📟.

Primary LanguageJavaScriptMIT LicenseMIT

scoop 🐔

This is our smart chicken coop server. It is providing a web-based backend and (somewhat limited and hacky) frontend to control the coop's hatch and view its webcam and sensor data.

Screenshot

Screenshot of Frontend

Hardware

The control unit consists of:

  • Raspberry Pi as control unit
  • 12V DC power supply
  • 12V motor (an old Ford window lifter) to wind the nylon thread that is lifting the hatch
  • Relay to control motor and LED
  • Webcam (Wide-Angle Raspberry Pi webcam)
  • Infrared LED lamp for night vision (powered separately via 12V DC)
  • BME280 Sensor (Temperature, Humidity, Pressure)
  • Tactile Sensors to determine the hatch's final positions
  • Shelly v1 230V relay for a light bulb.
  • Light bulb. I use a 60W traditional bulb, it does a good job heating the coop up in the winter and keeping temperatures above 0°C.

Configuration File

Parameters are configured in config.json.

Hatch Automation

You can maintain fixed times and times relative to sunset, sunrise, or any other suncalc object like dusk or dawn. For relative times to work, location needs to be maintained in config.json. You always have to specify an offset.

"location": {
    "lat": 52.00, 
    "lon": 8.00
},
"hatchAutomation": {
    "openTimes": ["06:30", "08:00", "sunrise+30","sunrise+60","sunrise+120","sunrise+180","sunrise+240","sunrise+300","sunrise+360","sunrise+420"],
    "closeTimes": ["22:00","sunset-30"]
}

Heating via light bulb (via shelly)

The heating module lights up the (preferrably non-LED) light bulb to warm up the coop if the temperatures are low. The light bulb is operated by a Shelly relay, see below.

The coop will only be heated if the current temperature falls below the treshold temperature set in heatBelowC. To prevent disco feeling, the light stays on for a minimum duration of minimumHeatingMins minutes (if it does not run out of time frame within this time).

To prevent that the light turns on in the middle of a cold night, the time frame in which the bulb should be used for heating is to be specified in the same notation as the hatch automation times.

The config parameters for the heating are:

"heating": {
    "enabled": true,
    "heatBelowC": 5,
    "minimumHeatingMins": 30,
    "timeFrame": {
      "from": "sunrise+0",
      "to": "dusk-60"
    }
  }

Requirements

  • Node v14+
  • fswebcam installed to use USB Webcam (Installation)

Install & Run

Install with npm install.

Run with node stall.js. I host the service with pm2.

Web Endpoints

General

  • /frontend A hacky frontend (AngularJS)
  • /status Status as JSON-Object
  • /log Latest log messages

Door

Moves the door up or down.

  • /up open the door entirely
  • /down close the door entirely

Calibration

To initialize your door state, on if the door is not entirely open/closed, small correction movements can be fired

  • /calibrate/up Move up the door for config.door.correctionSecs (default is 0.5s) and consider the door entirely open
  • /calibrate/down Move down the door for config.door.correctionSecs (default is 0.5s) and consider the door entirely close

Webcam

  • /cam/new Take a new picture
  • /cam/:timestamp? Retrieve the webcam picture. Can optionally provide a timestamp (which isn't even used in backend) if the url needs to change to load the new picture
  • /camsvg/:timestamp? Provides an svg version, with timestamp/current temps rendered into the picture
  • /nightvision/new Take a new night vision (IR) picture
  • /nightvision/:timestamp? Same as /cam/:timestamp?
  • /nightvisionsvg/:timestamp?

Administrative

  • /heapdump will send a heapdump
  • /reset will restart the application if it's run via nodemon (will modify a test.js file). Don't judge, please!

Coop Event Stream

  • /events A server-sent events (SSE) stream informing about things happening in the coop:
    • newWebcamPic
    • newWebcamPicIR
    • doornStatus
    • doornPosition
    • shellyRelayIsOn
    • heating

Shelly Integration

A Shelly v1 230V relay is used to control the light bulb inside the coop. It can be controlled from the coop:

  • /shelly/turn/on turns the relay/bulb on.
  • /shelly/turn/off turns it off.
  • /shelly/update can be used to poll the current Shelly state from its web endpoint.

In case the Shelly app/web interface is used, shelly also informs the coop if it was triggered by using I/O URL actions:

  • OUTPUT SWITCHED ON URL: http://<coop>/shelly/inform/on
  • OUTPUT SWITCHED OFF URL: http://<coop>/shelly/inform/off

Heating

  • /heating/enable turns the heating logic on. beware, light goes on only if all preconditions (time-frame, cold temps) are met!
  • /heating/disable turns it off.