The configuration of SmartHome.py is split up in four areas:
Following attributes are supported in smarthome.conf:
# /usr/local/smarthome/etc/smarthome.conf lat = 51.1633 lon = 10.4476 elev = 500 tz = 'Europe/Berlin'
It is possible to use a blank file (touch logic.conf) for the first steps.
Logic items within SmartHome.py are simple python scripts, which are placed in /usr/local/smarthome/logics/. See the logic introduction for howto write logics.
An example of a very simple logic.conf:
# /usr/local/smarthome/etc/logic.conf [MyLogic] filename = logic.py crontab = init
SmartHome.py would look in /usr/local/smarthome/logics/ for the file logic.py. The logic would be started - once - when the system starts.
Following attributes are supported control the behavior of the logics:
The list of items will be monitored for changes.
watch_item = house.door | terrace.door
Every change of these two items triggers (run) the logic. Or you could use a regular expression:
watch_item = *.door
Defines the time interval for repeating the logic (in seconds).
cycle = 60
Special use:
cycle = 15 = 42
Calls the logic with trigger[‘value’] # == ‘42’
Like Unix crontab with the following options:
crontab = init Run the logic during the start of SmartHome.py.
crontab = minute hour day wday
crontab = sunrise Runs the logic at every sunrise. Use sunset to run at sunset. For sunset / sunrise you could provide:
an horizon offset in degrees e.g. crontab = sunset-6 You have to specify your latitude/longitude in smarthome.conf.
an offset in minutes specified by a ‘m’ e.g. crontab = sunset-10m
a boundary for the execution
crontab = 17:00<sunset # sunset, but not bevor 17:00 (locale time) crontab = sunset<20:00 # sunset, but not after 20:00 (locale time) crontab = 17:00<sunset<20:00 # sunset, beetween 17:00 and 20:00
crontab = 15 * * * = 50 Calls the logic with trigger[‘value’] # == 50
Combine several options with ‘|’:
crontab = init = 'start' | sunrise-2 | 0 5 * *
Priority of the logic used by the internal scheduling table. By default every logic has the the priority of ‘3’. You could assign [0-10] as a value. You could change it to ‘1’ to prefer or to ‘4’ to penalise the logic in comparison to other logics.
Other attributes could be accessed from the the logic with self.attribute_name.
# /usr/local/smarthome/etc/logic.conf [Time] filename = time.py cyle = 60 [DoorBell] filename = bell.py watch_item = dorr.bell # monitor for changes [Blind Living] filename = blind.py crontab = 10,25,40,55 * * * # run every 15 minutes # cycle = 900 # could be used instead sunshine = no # accessed by self.sunshine [BlindKitchen] filename = blind.py # you could run the same logic file several times crontab = 10,25,40,55 * * * # run every 15 minutes sunshine = yes
It is possible to use a blank file (touch plugin.conf) for the first steps.
Plugins extend the core functionality of SmartHome.py. You could access these plugins from every logic script. For example there is a plugin for the prowl notification service to send small push messages to your iPhone/iPad. Plugins are placed in /usr/local/smarthome/plugins/.
Plugins are configured in the plugin.conf file. A simple plugin.conf:
# /usr/local/smarthome/etc/plugin.conf [notify] # object instance name e.g. sh.notify class_name = Prowl # class name of the python class class_path = plugins.prowl # path to the plugin apikey = abc123abc123 # attribute for the plugin e.g. secret key for prowl
The object name, class name and class path must be provided. The other attributes depend on the individual plugin. See the corresponding plugin page for more information.
The example above would generate the following statement sh.notify = plugins.prowl.Prowl(apikey='abc123abc123'). From now on there is the object sh.notify and you could access the function of this object with sh.notify.function().
Items could be specified in one or several conf files placed in the items directory of SmartHome.py Valid characters for the item name are: a-z, A-Z and ‘_’!
A simple item configuration:
# /usr/local/smarthome/items/living.conf [living_room_temp] type = num
Use nested items to build a tree representing your environment.
# /usr/local/smarthome/items/living.conf [living_room] [[temperature]] type = num [[tv]] type = bool [[[channel]]] type = num
For using scenes a config file into the scenes directory for every ‘scene item’ is necessary. The scene config file consists of lines with 3 space separated values in the format ItemValue ItemPath|LogicName Value:
# items/example.conf [example] type = scene [otheritem] type = num
# scenes/example.conf 0 otheritem 2 1 otheritem 20 1 LogicName run 2 otheritem 55 3 LogicName stop
This attribute is useful for small evaluations and corrections. The input value is accesible with value.
# items/level.conf [level] type = num eval = value * 2 - 1 # if you call sh.level(3) sh.level will be evaluated and set to 5
Trigger the evaluation of an item with eval_trigger:
# items/room.conf [room] [[temp]] type = num [[hum]] type = num [[dew]] type = num eval = sh.tools.dewpoint(sh.room.temp(), sh.room.hum()) eval_trigger = room.temp | room.hum # every change of temp or hum would trigger the evaluation of dew.
Eval keywords to use with the eval_trigger:
# items/rooms.conf [room_a] [[temp]] type = num [[presence]] type = bool [room_b] [[temp]] type = num [[presence]] type = bool [rooms] [[temp]] type = num name = average temperature eval = avg eval_trigger = room_a.temp | room_b.temp [[presence]] type = bool name = movement in on the rooms eval = or eval_trigger = room_a.presence | room_b.presence
Every item provides the following methods:
Returns the item id (path).
Returns the parent item. sh.item.return_parent()
Returns the children of an item. for child in sh.item.return_children(): ...
Set a timer to run at every item change. Specify the time (in seconds), or use m to specify minutes. e.g. autotimer(‘10m’, 42) to set the item after 10 minutes to 42. If you call autotimer() without a timer or value, the functionality will be disabled.
Same as autotimer, excepts it runs only once.
Returns the age of the current item value as seconds.
Returns the previous age of the item value as seconds.
Returns a datetime object with the time of the last change.
Returns a datetime object with the time of the next to last change.
Returns the value of the next to last change.
Returns a datetime object with the time of the last update.
Returns the caller of the latest update.
Fades the item to a specified value with the defined stepping (int or float) and timedelta (int or float in seconds). E.g. sh.living.light.fade(100, 1, 2.5) will in- or decrement the living room light to 100 by a stepping of ‘1’ and a timedelta of ‘2.5’ seconds.