Intelligent Multi-Zone Heating Script

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Intelligent Multi-Zone Heating Script

Post 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.
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
PatrickEekhout
Posts: 4
Joined: Tuesday 24 November 2015 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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.
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
PatrickEekhout
Posts: 4
Joined: Tuesday 24 November 2015 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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.
PatrickEekhout
Posts: 4
Joined: Tuesday 24 November 2015 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: NL
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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?
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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.
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
JvdBosch
Posts: 6
Joined: Tuesday 19 April 2016 11:06
Target OS: Windows
Domoticz version:
Location: Heeze
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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. ;)
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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 :)
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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.
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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?
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post by bobkersten »

Place it anywhere you can include it, or copy and paste it's content into the time_verwarming script.
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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!
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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 :)
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Intelligent Multi-Zone Heating Script

Post 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?!
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Intelligent Multi-Zone Heating Script

Post by bobkersten »

Whatever suits your needs, but I would say, yes :)
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest