The whole point of having a tellstick connected to a raspberry pie is to let the raspberry control the switches in the house in a defined way. A telldus duo is also able do more like monitoring temperature and humidity sensors as well as PIR/magnetic sensors.
Ok, let’s stick to controlling the switches. One way is to build a program that falls asleep and then wakes up at certain times. In Linux however this functionality is built into the system process crontab. It is possible to configure crontab to run any command at a certain time each day for example. Crontab is very flexible and it is possible to have other configuration but the example covers what is most useful for lamp switches. How do you configure crontab? As always there is a easy to use library called ‘python-crontab’ where it is possible to configure crontab in an intuitive way.
Most often a lamp switch shall be turned on when dusk appears. However sunset is at different hours depending on the date and where you live geographically since the earth is moving around it’s axle. Luckily it is possible to calculate the dusk if the date and the geographically position is given. Another python library called ‘astral’ has everything needed since it possible to give it a location (through google map service) as well as the actual date, receiving the time of sun dawn/sun dusk/sun set.
Installing the mentioned libraries and their dependencies:
> pip install python-crontab > pip install astral > pip install pytz > pip install nptime
Next post is how to write the setup program configuring the crontab using the libraries mentioned in this post!