Page 1 of 1
Intelligent Multi-Zone Heating Script
Posted: Monday 11 January 2016 22:18
by bobkersten
Hi,
I'd like to share my intelligent multi-zone heating script which I use to control my on/off central heating system. It attempts to predict the time needed to pre-heat a zone so it reaches the desired temperature when a thermostat timer is triggered. It uses an outside temperature sensor to make this prediction even more accurate. It can open/close valves in zones that do not need any heating, although there's still some work to be done there (see todos at the top of the script).
The script uses a separate sqlite database to store temperature deltas used to predict the pre-heat duration. Unfortunately it's currently not possible to load dynamic lua support for sqlite, so access to this database is done through system calls, which get the job done but isn't as robust as I'd like it to be.
Tell me what you think. Any hints, tips or other useful contributions are most welcome
https://github.com/bobkersten/domoticz-lua.git
Cheers,
Bob.
Re: Intelligent Multi-Zone Heating Script
Posted: Friday 15 January 2016 0:32
by PatrickEekhout
Hi Bob,
Your project looks promising. I tried to get it working, but have not yet succeeded. I get this error in the Domoticz-log.
2016-01-15 00:47:00.272 LUA: (Heating) ----- HEATING LOGIC START
2016-01-15 00:47:00.272 Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_heating.lua:130: bad argument #1 to 'sub' (string expected, got nil)
Maybe you can provide an empty domoticz.custom.db
Greetings,
Patrick
Re: Intelligent Multi-Zone Heating Script
Posted: Friday 15 January 2016 8:44
by bobkersten
PatrickEekhout wrote:
2016-01-15 00:47:00.272 Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_heating.lua:130: bad argument #1 to 'sub' (string expected, got nil)
That error comes from within the parseDate method. It seems there isn't a known lastupdate date present (yet), for which I've added checks. It could also mean that you've spelled your heating devicename incorrectly.
PatrickEekhout wrote:
Maybe you can provide an empty domoticz.custom.db
You'll find an empty database in the github project.
Hopefully you'll get it running with these adjustments, please let me know.
Re: Intelligent Multi-Zone Heating Script
Posted: Friday 15 January 2016 10:35
by PatrickEekhout
I checked the logs this morning. The error is gone. It indeed looks like the issue was the lack of a known lastupdate date.
Thnx for the empty database in github. Looks like I won't be needing it. But very useful for new users.
I will continue to put all this into practice. I now use virtual switches for the ValvesDevice and HeatingDevice. Am going to replace those with a ZWave Qubino Flush 2 Relays-module.
Re: Intelligent Multi-Zone Heating Script
Posted: Saturday 16 January 2016 10:49
by PatrickEekhout
New situation, since today is part of Weekends:
I created this entries in the Timer of the ThermostatDevice:
Yes On Time 07:30 20 Weekdays
Yes On Time 23:00 18 Weekdays
Assumed that, since last timer event is 23:00 weekday, tempsetting 18 would continue during the weekend until next weekday (monday). According to the log it works different?
2016-01-16 10:39:00.128 LUA: (THERM Office) The current timer started at 00:00 with temperature 20.4°.
2016-01-16 10:39:00.128 LUA: (THERM Office) The next timer will start at 23:59 with temperature 20.4°.
The ThermostatDevice device still says 18°. I guess the 20.4 value is the value from the TemperatureDevice.
What timers do I have to set / did you set, so that there are no gaps?
Re: Intelligent Multi-Zone Heating Script
Posted: Monday 18 January 2016 21:29
by bobkersten
I've decided not to look past the current day for additional timers because that would complicate the script a lot. I know that's shortsighted, but for my situation it worked. I've set a low temperature timer late at night and a high temperature timer in the morning. I'll take a look if I can easily extend the script to look for timers the following days.
Re: Intelligent Multi-Zone Heating Script
Posted: Tuesday 19 April 2016 11:09
by JvdBosch
I too am interested in creating/assisting in such a script. The repository is offline, can you share it again Bob? I'm happy to add to it where I can. I'm new to Domoticz, but not to programming.
Re: Intelligent Multi-Zone Heating Script
Posted: Tuesday 19 April 2016 11:32
by bobkersten
The script is back on github, but it is currently tweaked to suit my own needs. You should however be able to customize it for your own personal needs, but maybe we can make it as general as possible so other people with the same need can benefit from it aswell. I'd like to hear what you think of it
Re: Intelligent Multi-Zone Heating Script
Posted: Thursday 06 October 2016 12:41
by erikjanverweij
Hi Bob,
The script is no longer available on github. Could you please put it back online? I want to use it for my home heating.
Greetz,
Erik-Jan
Re: Intelligent Multi-Zone Heating Script
Posted: Sunday 06 November 2016 15:05
by erikjanverweij
Hi Bob,
Thanx for putting the files back on github.
I've tried to get it working, but have not yet succeeded. I get this error in the Domoticz-log.
2016-11-06 14:59:40.464 Error: EventSystem: in Verwarming: [string "--[[..."]:64: attempt to index global 'oDatetime' (a nil value)
Could you provide an empty domoticz.custom.db? Maby that solves the problem?
Greetings,
Erik-Jan Verweij
Re: Intelligent Multi-Zone Heating Script
Posted: Sunday 06 November 2016 15:21
by bobkersten
The oDatetime object is created and populated in the variables-script in the inc folder. It has nothing to do with the missing database file. You can create an empty database file using the structures from the script, that should work. You will also need to have sqlite3 installed for the script to work. Also keep in mind that the script is heavily tailored for my personal needs, so a little tinkering might be necessary in your situation.
Re: Intelligent Multi-Zone Heating Script
Posted: Sunday 06 November 2016 16:47
by erikjanverweij
Hi Bob,
I did install sqlite3 and created an empty database file with the structure from the script. But stil get the oDatetime error.
Where do i have to put the inc folder with the variables-script? Can i put the inc folder directly in the domoticz/scripts/lua folder?
Re: Intelligent Multi-Zone Heating Script
Posted: Sunday 06 November 2016 17:27
by bobkersten
Place it anywhere you can include it, or copy and paste it's content into the time_verwarming script.
Re: Intelligent Multi-Zone Heating Script
Posted: Tuesday 07 February 2017 23:20
by Skippiemanz
Bob,
First off al thanks for the work done so far!
Im trying to get your script solution going.
I've made the database and made the lua. The script runs but i have one error. Here is the log:
When heating is desired:
Code: Select all
2017-02-08 01:19:00.512 Error: EventSystem: in Heating: [string "--[[ ..."]:268: attempt to get length of global 'commandArray' (a nil value)
When no heat is desired:
Code: Select all
2017-02-08 01:15:00.881 Error: EventSystem: Lua script Heating did not return a commandArray
The code on line 268 is(from functions.lua):
Code: Select all
function addCommand( sDevice_, sCommand_ )
commandArray[#commandArray + 1] = { [ sDevice_ ] = sCommand_ }
I think it has something to do with the part below:
Code: Select all
-- ___ ___ __ .__
-- / | \ ____ _____ _/ |_|__| ____ ____
-- / ~ \_/ __ \\__ \\ __\ |/ \ / ___\
-- \ Y /\ ___/ / __ \| | | | | \/ /_/ >
-- \___|_ / \___ >____ /__| |__|___| /\___ /
-- \/ \/ \/ \//_____/
if (
oHeating.diff > 0
and otherdevices[sHeatingDeviceName] == 'Off'
) then
addCommand( sHeatingDeviceName, 'On' )
--log( 'Sending ON command to heating device.', sHeatingDeviceName, true )
end
if (
oHeating.diff <= 0
and otherdevices[sHeatingDeviceName] == 'On'
) then
addCommand( sHeatingDeviceName, 'Off' )
--log( 'Sending OFF command to heating device.', sHeatingDeviceName, true )
end
Could you help me out here?
And can you tell me what the valve does in your setup?
Thanks in advance!
Re: Intelligent Multi-Zone Heating Script
Posted: Thursday 09 February 2017 9:02
by bobkersten
My first guess is that you didn't create a commandArray in your script. You can see this being done in the script_device_shared.lua script in my github repository, at the first line. This is necessary for the addCommand function to work properly. Can you verify that adding this line somewhere to the top of your script or include chain solves your problem?
As for the valves part, they are used to open or close valves (or in my case, the underfloor heating pump') depending on the request for heat by their corresponding thermostats. Please note that this script is heavily taylored to my personal needs, with a relatively simple on/off central heating system in mind. The idea was to add z-wave radiator valves to this setup, but the weighted temperature error already provided for enough comfort as it is, so I decided not to, as these valves would cost another €50,- each
Re: Intelligent Multi-Zone Heating Script
Posted: Thursday 09 February 2017 9:34
by Skippiemanz
bobkersten wrote:My first guess is that you didn't create a commandArray in your script. You can see this being done in the script_device_shared.lua script in my github repository, at the first line. This is necessary for the addCommand function to work properly. Can you verify that adding this line somewhere to the top of your script or include chain solves your problem?
Hero! This indeed works!
I've now copy and pasted everything into one script.
But would a better solution be?:
Code: Select all
commandArray = {}
package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
require "inc/functions"
require "inc/sqlite3"
require "inc/variables"
require "device_verwarming"
return commandArray
This would keeps thing more organized i assume?!
Re: Intelligent Multi-Zone Heating Script
Posted: Thursday 09 February 2017 9:37
by bobkersten
Whatever suits your needs, but I would say, yes