Dewpoint

Moderator: leecollings

Post Reply
ErikM
Posts: 8
Joined: Monday 23 March 2020 10:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Dewpoint

Post by ErikM »

Is there anyone who can explain to me how to use the dewpoint device in a Blockly script? The wiki doesn't offer any explanation on it and I'm still very new to using Blockly (or any form of scripting, for that matter).

What I am trying to achieve is to use the dewpoint in a room to trigger an action that closes the valves on the underfloor cooling in that room when the temperature above the floor is at a safe level (say 2 degrees) above the dewpoint to avoid condensation on the floor. I was planning on measuring both temperature and dewpoint with an Aeotec Multisensor 6 (but if there are better sensor options, I'm open to suggestions. ;) )
knielen
Posts: 46
Joined: Sunday 10 September 2017 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dewpoint

Post by knielen »

As far as I know that's not possible with Blockly. You can compare the value of the dewpoint with the actual temperature. Or you can compare the dewpoint with a fixed number. But it's not possible to compare with the actual temperature and an offset.
Try to master dzvents, pretty steep learning curve, but eventually you need it anyway :-)
ErikM
Posts: 8
Joined: Monday 23 March 2020 10:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dewpoint

Post by ErikM »

Darn... I already found Blockly to be a steep learning curve and when I look at a dzvents or lua script I break out in a sweat... :shock: All the indentation makes it look extremely complicated and while Dewpoint is a device in Blockly, it is not in the normal device list. This is looking to be a lot more complicated than I had expected it to be...
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Dewpoint

Post by jake »

ErikM wrote:Darn... I already found Blockly to be a steep learning curve and when I look at a dzvents or lua script I break out in a sweat... :shock: All the indentation makes it look extremely complicated and while Dewpoint is a device in Blockly, it is not in the normal device list. This is looking to be a lot more complicated than I had expected it to be...
That was my first thought about lua (before dzvents was around) too. I didn't look forward to the learning curve. But when you want to do something more complicated than just a single if then else, it becomes a nightmare in blockly. So at some point I was fed up with it and decided to go for it. In the dzvents wiki is plenty of material to learn and 'steal' from. Over time I collected my scripts from using parts from other scripts and reuse of my own scripts. For instance I always start with a copy of an existing script, so the base is correct.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Dewpoint

Post by rrozema »

dzVents isn't hard. I've written you below example in 15 minutes. I hope the comments in the code will help you understand what this code does and opens up the opportunity to learn dzVents fast.

Code: Select all

-- Change the names below to match your device names.
-- When changing the names take care to use the exact same
-- case as used in your device names.
-- For example: "TempHum" is not the same as "Temphum".
local TEMPERATURE_DEVICE_NAME = 'Keuken: TempHum'
local SWITCH_DEVICE_NAME = 'Keuken: Cooling'

-- I like to use variables for device names to avoid mistyping a 
-- name when it is referenced multiple times in a script. I make 
-- these variable names in all caps, but that is nu requirement.
-- I do this to easily identify where the variable is used.
--
-- Please also not the use of "local" in front of every declaration 
-- of a variable. If you don't put that "local" in front of your 
-- variables the script will run without problems. If however you 
-- use in another script a variable with the same name, the variables
-- wil get mixed-up. So always specify the word "local" in front of
-- every variable declaration.

-- Indentation (spaces or tabs in front of lines) is not a requirement,
-- but it does help keep the code readable. So do yourself a favor, 
-- always use proper indentation.


return {
	on = {
	    -- The "devices" section defines for which devices the execute-section 
	    -- below will be executed. It can contain a list of device names
	    -- separated by a , . In this example only 1 device is listed
	    -- so no comma needed.
		devices = {
			TEMPERATURE_DEVICE_NAME
		}
	},
	-- This execute section is the code that will get executed when the device
	-- in the devices section changes value.
	execute = function(domoticz, device)
	    
		-- The way to show output in your log file (if the log level is high enough).
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
		
		-- Ask domoticz for a device object with the name of SWITCH_DEVICE_NAME.
		local switch = domoticz.devices(SWITCH_DEVICE_NAME)

		-- If you misspelled the name a nil-value will be returned.
		-- "==" is equals, "~=" is not equals.
	    
		-- Every "if <condition>" must be followed by a "then", which must be
		-- closed by an "end". Optionally an "else" can be used in between the 
		-- "then" and the "end".
        	if nil == switch then
			-- This is another message i want shown in the log, here I specify
			-- LOG_ERROR to make the text show up in bold and red in the log.
			domoticz.log("Switch device " .. SWITCH_DEVICE_NAME .. " not found.", domoticz.LOG_ERROR)
		else
			-- what properties a device exposes depends on the type of the 
			-- device. Documentation is available in the wiki: 
			-- https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting

			-- In this case I tried to implement what I think you asked for:
			-- if the temperature is at least 2 degrees above the dewPoint
			-- the switch must be switched off, if it falls below that it must
			-- be switched on again.
			if device.temperature >= device.dewPoint + 2 then

				-- .switchOff() changes the devices' state to "Off". I don't
				-- like to send to many commands, so I specify .checkFirst()
				-- to make sure that no "Off" command is sent if the device
				-- is already "Off".
				switch.switchOff().checkFirst()
			else
				switch.switchOn().checkFirst()
			end
		end
	end	-- This is the "end" for the execute section.
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest