Heating multiple Zone  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
alphawarrior
Posts: 15
Joined: Friday 09 January 2015 10:02
Target OS: NAS (Synology & others)
Domoticz version:
Location: Eindhoven
Contact:

Heating multiple Zone

Post by alphawarrior »

Hello everyone,

Cold is coming, and I'm a bit late in my heating system.... :o

To resume the situation
I have X number of eurotronic valve, I can control them with a script to open and close as below. This script is link to a dummy called "heat_demand_X" which this one is triggered by the plugin virtual Thermostat. This work perfectly. https://www.domoticz.com/wiki/Plugins/S ... ostat.html

Code: Select all

return {
   on = {
      devices = {
         'heat_demand_saloon'  extra comment this is not in the actual script (The idx is entered in the virtual thermostat)
      }
   },
   execute = function(domoticz, device)
      	if (device.active) then
	    domoticz.devices('Saloon valve mode').updateMode('Manufacturer Specific')
	    domoticz.devices('Heating Kitchen').switchOn()
	            domoticz.log('Valve open and Heater under kitchen ON!')
	else 
        domoticz.devices('Saloon valve mode').updateMode('Off') .afterMin(5)
        domoticz.devices('Heating Kitchen').switchOff() .afterMin(5)
                domoticz.log('Valve closed and Heater under kitchen OFF!!')
	end
end
}
My problem is to be able to have multiple zone ON and other OFF in same time. I tried blocky but not luck. So I try now the same thing in dzvents.
Hers is the script

Code: Select all

return {
  on = {
    devices = {
      'heat_demand_saloon',
      'heat_demand_study',
      'heat_demand_parent',
      'heat_demand_lilou',
      'heat_demand_djimo',
      'heat_demand_hall'
    }
  },
  execute = function(domoticz, switch)
    if
    domoticz.devices('heat_demand_saloon').switchOn().checkFirst()
    or
    domoticz.devices('heat_demand_study').switchOn().checkFirst()
    or
    domoticz.devices('heat_demand_parent').switchOn().checkFirst()
    or
    domoticz.devices('heat_demand_lilou').switchOn().checkFirst()
    or
    domoticz.devices('heat_demand_djimo').switchOn().checkFirst()
    or
    domoticz.devices('heat_demand_hall').switchOn().checkFirst()

    then
      domoticz.devices('Boiler').switchOn().checkFirst()
    else
      domoticz.devices('Boiler').switchOff().checkFirst()
    end
end
}
At this moment if I switch manually the dummy heat_demand_study for example, the boiler goes ON :D , but also the heat_demand_saloon :? .
Why? Because is first in the list...I might miss a separator or something.
I'm sure it is a stupid thing, but checked the forum which help me a lot alreday to get the script for the valve. But how to have a script with condition? So actually the boiler should be off only if all the zone are off. And if let say two zone are ON and one stop it should not send an off command to the boiler.
Please some help

Thanks
HP NL54 with Xpenology DSM 5.2-5592 Update 3
HarmonyHub
Rpi
alphawarrior
Posts: 15
Joined: Friday 09 January 2015 10:02
Target OS: NAS (Synology & others)
Domoticz version:
Location: Eindhoven
Contact:

Re: Heating multiple Zone

Post by alphawarrior »

Hello,

Nobody...

I had before zipato was happy with it but not like Dz. I used Dz and zipato in same time for different feature. In the meantime I also tried HCL,HC2 pro and Veraplus. It was always something wrong with one of them. Or the UI or the way to set timer....was not good as Dz.
I really want to achieve everything now with Dz which I know it's possible.

This was my blocky in zipato is there a way to do the same...
Image
With this any TRV will turn the boiler ON if needed but the boiler is only turned off if NO thermostat needs the heat.
HP NL54 with Xpenology DSM 5.2-5592 Update 3
HarmonyHub
Rpi
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Heating multiple Zone

Post by waaren »

alphawarrior wrote: Sunday 03 November 2019 20:04 Cold is coming, and I'm a bit late in my heating system.... :o
So actually the boiler should be off only if all the zone are off. And if let say two zone are ON and one stop it should not send an off command to the boiler.
Please some help
Can you try this one ?

Code: Select all

local commonPart = 'heat_demand_'
return 
{
    on = { devices = { commonPart .. '*' }},
	
	logging = {level = domoticz.LOG_DEBUG },
		
	execute = function(dz)
         _G.logMarker =  _G.moduleLabel
         
        local atLeastOneZoneActive = false
        local boiler = dz.devices('Boiler')
    	
    	dz.devices().forEach(function(dv) -- loop over all devices
            if dv.active  and (dv.name):find(commonPart) then -- active and name match with wildcard ?
                atLeastOneZoneActive = true 
            end
        end)
    	
    	if atLeastOneZoneActive then 
    	    boiler.switchOn().checkFirst()
        else
            boiler.switchOff().checkFirst()
        end
    end    
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alphawarrior
Posts: 15
Joined: Friday 09 January 2015 10:02
Target OS: NAS (Synology & others)
Domoticz version:
Location: Eindhoven
Contact:

Re: Heating multiple Zone  [Solved]

Post by alphawarrior »

Waaren you are the best, it works :D

I undertsand what you did what the scrip did.
If I know a bit more of code I will find out but I really lack in this part.
What will be yuor best suggestion for learn? I know the wiki but obviously it does not really explain such of script
For example this _G.logMarker = _G.moduleLabel what is that.

Do you think this will be possible in blocky...Just wonder.

Thanks again. I see you are in Netherland like me. Are you close from Eindhoven? If yes I will pay you a beer with pleasure.
HP NL54 with Xpenology DSM 5.2-5592 Update 3
HarmonyHub
Rpi
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Heating multiple Zone

Post by waaren »

alphawarrior wrote: Tuesday 05 November 2019 21:05 If I know a bit more of code I will find out but I really lack in this part.
What will be your best suggestion for learn? I know the wiki but obviously it does not really explain such of script.
dzVents is for the biggest part Lua. Behind the scenes there is some C++ code to efficiently communicate from and to the domoticz data but most of the Lua code that makes it easier to script in Lua and work with domoticz data is in the <domoticz dir>/dzVents/runtime/ directories
What I did to better understand how stuff is working is looking at the code in these directory's. What also worked for me is to search the internet for all kinds of information on Lua. If you already know a bit about other programming languages, Lua is not extremely difficult and once you get a better understanding on how Lua tables work you are more then halfway :D Luckily you can find tons of information on that and a good starting point is https://www.lua.org/pil/2.5.html

What confuses most people at first is the difference between {} and [] and that tableName.keyName is the same as tableName["keyName"]

In general terms:
everything between {} is a table
everything between [] is a key in a table. And a key can be any Lua datatype (yes also a table :D ) except nil

if a table has no explicit keys than the keys are consecutive integers starting from 1

For example this _G.logMarker = _G.moduleLabel what is that.
_G.logMarker contains the string printed to the domoticz logfile to identify the script sending it. _G.moduleLable is the file name of your script without the extention.

_G is the a global accessible table coming from domoticz to dzVents and Lua with all device- and variable information. dzVents adds a lot of useful information to it and makes this available to dzVents scripts.
Do you think this will be possible in blocky...Just wonder.
I guess it would be possible if you use for every switch a separate Blockly and a lot of if xx and yy and zz type of statements. I have no intention to try :)
I see you are in Netherland like me. Are you close from Eindhoven? If yes I will pay you a beer with pleasure.
In our small country everything is close to Eindhoven....
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alphawarrior
Posts: 15
Joined: Friday 09 January 2015 10:02
Target OS: NAS (Synology & others)
Domoticz version:
Location: Eindhoven
Contact:

Re: Heating multiple Zone

Post by alphawarrior »

Thank you Waaren for these details explanation.
Hoe to meet you one day.
HP NL54 with Xpenology DSM 5.2-5592 Update 3
HarmonyHub
Rpi
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest