Easy text file based temperature and switch scheduler v0.1

Moderator: leecollings

Post Reply
User avatar
blitzkneisser
Posts: 43
Joined: Tuesday 01 December 2015 8:39
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Villach, Austria
Contact:

Easy text file based temperature and switch scheduler v0.1

Post by blitzkneisser »

As I was not totally satisfied how scheduling works in domoticz, I wrote a LUA script to make things easier. Now you only need a text file with a schedule and can assign that to any switch or temperature setpoint device. The advantages:
  • you can use the same schedule for multiple devices
  • you can easily switch between different schedules (summer, winter, vacation, party...)
  • if for some reason your controller is down during a scheduled switching time, it reads the condition it should currently have from the schedule file and sets it. So even after having the device switched off for a while, the setpoints are all restored --> My main motivation to write that.
  • more to come...
A temperature schedule file looks like this. You can have comments after the line or between the lines, just have an @ only in front of a schedule item and keep the spaces/digits the same:

Code: Select all

Zeitplan Badezimmer:

-- Heizen Früh
@111.... 04:30 23.0
@...11.. 05:00 23.0
@.....11 06:00 23.0
@11111.. 06:00 18.0
@.....11 07:30 18.0
@...
Easy readable as you can see, especially the weekdays. The first column sets the weekday (starting with Moday), a '1' for every active day, something else for inactive days. Then comes the time and the desired temperature. For switches it looks the same, instead of the temperature have 'on' or 'off:

Code: Select all

Zeitplan Schalter 1:

@1111111 13:10 on
@1111111 13:12 off
@1111111 13:14 on
@1111111 13:16 off
@1111111 13:18 on
You only need these script files in your LUA directory:
  • func_misc.lua ... misc functions, so far only one to get the device name from the index
  • func_scheduler.lua ... all the scheduler functionality
  • script_time_scheduler.lua ... the only file to edit, here the schedules and switches are assigned
Assigning a schedule is very easy, looks like this... just add some more lines to script_time_scheduler.lua:

Code: Select all

local schedules = {}
schedules [666] = 'temp_debug.txt'
schedules [157] = 'switch_Stecker2.txt'
schedules [145] = 'temp_arbeitszimmer.txt'
schedules [120] = 'temp_badezimmer.txt'
schedules [123] = 'temp_dusche.txt'
schedules [...
In the square brackets put the id of the switch or setpoint device, then the name of the schedule text file. Voila! Everything else is done by the script. It checks the schedules every minute and sets all appropriate switches. If it does not find a valid switching point for the current day, it just takes the last valid one from the previous day. It's still work in progress, but works nice so far. I welcome all inputs and ideas for improvement.
If you don't want all the spam in the protocol, just set debugmode = 0 in the script

Planned upgrades/fixes:
  • Manual overrides are currently overwritten within a minute -> make manual overrides possible (inputs welcome!)
  • Add more comments to the code (also for my own sake in a year or so)
  • Script only checks for last switching point on previous day if none is found on current day, go back further if not every day has a schedule item
  • tie debug outputs to an external switch
  • misc. code improvements, some of that stuff has been written at 3 in the morning - and looks like that
  • you tell me!
The scripts can be found here:

Misc. Function(s)
Scheduler Function
Scheduler Time Script

As I said, it's work in progress, there will be for sure improvements. And please share your ideas and improvements!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest