Blocky to DzVents Thermo valve  [Solved]

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

Moderator: leecollings

Post Reply
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Blocky to DzVents Thermo valve

Post 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
Attachments
Thermo valve.png
Thermo valve.png (34.37 KiB) Viewed 847 times
User avatar
boum
Posts: 136
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Blocky to DzVents Thermo valve

Post 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
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blocky to DzVents Thermo valve  [Solved]

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest