Skip to content

Control a greenhouse by using Telegram app (Bot API) and a RaspberryPi.

License

Unlicense, Unlicense licenses found

Licenses found

Unlicense
LICENSE
Unlicense
UNLICENSE
Notifications You must be signed in to change notification settings

kaulketh/greenhouse

My Greenhouse

Control a greenhouse by using Telegram app and a Raspberry Pi. I did not reinvent the wheel.

Thank you for inspiring me, Stefan Weigert and Felix Stern


release size commit platform languages coverage license

This repository is used to gather and show information and experiences during the building of a smart control possibility. All code is written or adapted by myself and w/o any copyrights. I have tried to use no copyright protected stuff. Almost everything published already exists, to be found on the net, and was adapted and used only by me accordingly.

And please excuse the mistakes made and violations of any conventions, I am new to this matter. Do not be afraid to correct or improve me and inform me accordingly. Consider and refer Contributor Covenant Code of Conduct!

Table of Contents


Installation and usage

Currently no installation routine is planned. Feel free to use, adapt, download or copy all the published stuff. Main programming language is Python and shell scripting is used also.

Telegram app

Install the app and create bot
Name: 	ThK1220RealGreenhouse
TOKEN: 	<api_token>
ChatID:	<chat_id>

Raspberry Pi OS image

  • download latest stretch lite w/o desktop
  • prepare sd card / flash image, e.g. use Etcher
  • enable SSH access
    • As of the November 2016 release, Raspbian has the SSH server disabled by default. You will have to enable it manually.
    • For headless setup, SSH can be enabled by placing a file named "ssh", without any extension, onto the boot partition of the SD card.

Boot raspi and connect via ssh


Configure (static) IP

adapt /etc/dhcpcd.conf
sudo service dhcpcd status 
sudo service dhcpcd start // if not yet started 
sudo systemctl enable dhcpcd 
sudo nano /etc/dhcpcd.conf
sudo reboot

Retest and doublecheck network conection and settings before executing next steps!!!!!


Make updates and adapt main config

sudo apt-get update --yes && sudo apt-get upgrade --yes
sudo raspi-config
    Hostname:	greenhouse
    User:		pi
    Password:	******************
sudo rpi-update //update firmware
sudo reboot

Install and configure dyn dns client (ddclient)

ignore config let it empty e.g can be configured due next steps

sudo apt-get update
sudo apt-get install libio-socket-ssl-perl
sudo apt-get install ddclient

use e.g. FreeDNS and update ddclient.conf accordingly the dns provider


sudo nano /etc/ddclient.conf

other possible method could be e.g insert crontabs
0,5,10,15,20,25,30,35,40,45,50,55 * * * * sleep 31 ; wget -O - http://freedns.afraid.org/dynamic/update.php?******************************************** >> /tmp/freedns_greenhouse_my_to.log 2>&1 &
3,8,13,18,23,28,33,38,43,48,53,58 * * * * sleep 44 ; wget -O - http://freedns.afraid.org/dynamic/update.php?******************************************** >> /tmp/freedns_greenhouse_chickenkiller_com.log 2>&1 &

Install and configure remote ftp if required

sudo apt-get install pure-ftpd
sudo groupadd ftpgroup
sudo useradd ftpuser -g ftpgroup -s /sbin/nologin -d /dev/null
sudo mkdir /home/pi/FTP
sudo chown -R ftpuser:ftpgroup /home/pi/FTP
sudo pure-pw useradd upload -u ftpuser -g ftpgroup -d /home/pi/FTP -m
sudo pure-pw mkdb
sudo ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb 
sudo service pure-ftpd restart

Configure the live stream

install motion and update /etc/motion/motion.conf
sudo apt-get install motion -y
sudo nano /etc/motion/motion.conf   //additional: output_pictures off
sudo nano /etc/default/motion
mkdir /home/pi/Monitor
sudo chgrp motion /home/pi/Monitor
chmod g+rwx /home/pi/Monitor
sudo service motion start

Configure port forwarding in router accordingly the dns and port settings


Install required packages (python, python-telegram-bot, python-pip, telepot and wiringpi)

sudo apt-get install build-essential python-dev python-pip python-smbus python-openssl git --yes //python
sudo pip install python-telegram-bot
sudo pip install telepot
First check that wiringPi is not already installed.
gpio -v
If you get something, then you have it already installed. The next step is to work out if it’s installed via a standard package or from source. If you installed it from source, then you know what you’re doing – carry on – but if it’s installed as a package, you will need to remove the package first. To do this:
sudo apt-get purge wiringpi
hash -r
WiringPi is maintained under GIT for ease of change tracking. If required to install do it like described as followed.
sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
cd git
git clone git://git.drogon.net/wiringPi
cd ~/wiringPi
git pull origin
cd ~/wiringPi
./build

Add scripts in pi user directory

e.g in this case in scripts/TelegramBot

Make them executable and chown root:root!


Enable autostart of the bot application

Add the program as service. To enable autostart add it to the init.d directory, insert telegrambot.sh in /etc/init.d as root and execute commands as followed.
sudo chmod +x telegrambot.sh
sudo update-rc.d telegrambot.sh defaults
sudo reboot

Additional functionality

Add as required or wished
Crontabs examples
# update check every 10 minutes
0,10,20,30,40,50 * * * * bash /home/pi/scripts/TelegramBot/update_bot.sh <access token repository> <chat id> <api token>
	
# update check every hour
0 * * * * bash /home/pi/scripts/TelegramBot/update_bot.sh <access token repository> <chat id> <api token>

# backup bot every day at 1:30AM
30 1 * * * tar -zcf /home/pi/backups/greenhouse.tgz --exclude='*.pyc' /home/pi/scripts/TelegramBot/

# also move log backups to backup folder
31 1 * * * mv -v /*.gz /home/pi/backups/
Logrotate to compress and clear log files
sudo nano /etc/logrotate.conf
/update_bot.log {
	missingok
	daily
	rotate 1
	compress
	dateext
	create 644 root root
}

/greenhouse.log {
	missingok
	daily
	rotate 1
	compress
	dateext
	create 644 root root
}

License

license