Page 1 of 1

Blocky to DzVents Thermo valve

Posted: Thursday 30 April 2020 8:08
by wouterlet
Hi Guys,

I'm turning my Blocky events to DzVents since these seem more reliable. I attached my Blocky, I translated it to this DzVents:

Code: Select all

return {
	on = {
		devices = {'Thermo Level*'}
	    },
	execute = function(dz, item)
	    if item.state ~= 'Off' then
	    dz.devices('CV Switch 2').switchOn()
		dz.log('CV klep boven open')
	elseif item.state == 'Off'.forEach("Thermo Level*") then
        dz.devices('CV Switch 2').switchOff()
    end
end
}
Now the log says:


2020-04-30 08:06:33.563 ...s/dzVents/generated_scripts/Thermostaat Klep DzVents.lua:9: 'then' expected near '.'

So I should delete my forEach Should I then write all devices out? Or could I do this on another way?
And maybe have a look if the rest of my script looks fine?

Best regards,

Wouter Lettinga

Re: Blocky to DzVents Thermo valve

Posted: Thursday 30 April 2020 9:32
by boum
You've got the first part right. If any device triggers the script and the state is not Off, you activate your switch.
If one device triggers and is Off, you'll have to iterate over all devices to check the status. There are several methods to do that in dzVents.

I propose (not tested, sorry):

Code: Select all

return {
    on = {
        devices = {'Thermo Level*'}
    },
    execute = function(dz, item)
        if item.state ~= 'Off' then
            dz.devices('CV Switch 2').switchOn()
            dz.log('CV klep boven open')
        else
            local foundDeviceOn = dz.devices().find(function(device)
              -- look for a device with a name starting with "Thermo Level" and state not Off
              return (device.name:find("^Thermo Level") == 1) and (device.state ~= 'Off') 
            end)
            if not foundDeviceOn then
              -- all Thermo Level devices are Off
              dz.devices('CV Switch 2').switchOff()
            end
        end
    end
}
Look at https://www.domoticz.com/wiki/DzVents:_ ... _iterators for documentation

Re: Blocky to DzVents Thermo valve  [Solved]

Posted: Thursday 30 April 2020 19:47
by wouterlet
Thanks it works great now. I have to look in to it to see how it really works. But it's always nice to learn!