Page 1 of 1

[SOLVED] updateSetPoint function in DzVents

Posted: Tuesday 27 November 2018 9:42
by Sapp1123
Hey everyone,
im very new to LUA and DzVents.
I have a bit of trouble to undersand why the following Script is not working:

Code: Select all

return {
	on = {
		devices = {
			'Test Heizung'                            -- a dummy switch
		},
		variables = {
		TH = 'Test Heizung'
		    },
	},

	execute = function(domoticz, TH)
	    local Setpoint = domoticz.devices('Setpoint') -- a Setpoint
	    
	    if(TH == 'On') then
	        Setpoint.updateSetPoint(16)                -- Setpoint should be 16°C when switch = on
	        end
	    
		domoticz.log(Setpoint.setPoint)                 -- Log the new setPoint
	end
}
I want to change the thermostat Setpoint to 16°C when toggleing the switch to on.

Log output is:

Code: Select all

 2018-11-27 08:03:48.903 Status: User: admin initiated a switch command (48/Test Heizung/On)
2018-11-27 08:03:49.044 Status: dzVents: Info: Handling events for: "Test Heizung", value: "On"
2018-11-27 08:03:49.045 Status: dzVents: Info: ------ Start internal script: Heizungscript: Device: "Test Heizung (Switches)", Index: 48
2018-11-27 08:03:49.045 Status: dzVents: Info: 19
2018-11-27 08:03:49.045 Status: dzVents: Info: ------ Finished Heizungscript 
would appreciate any help.

Thanks :)

Re: updateSetPoint function in DzVents

Posted: Tuesday 27 November 2018 10:11
by waaren
Sapp1123 wrote: Tuesday 27 November 2018 9:42 I have a bit of trouble to understand why the following Script is not working:
I want to change the thermostat Setpoint to 16°C when toggling the switch to on.
would appreciate any help.
See comments in script below.

Code: Select all

return {
            on =    {   devices     =   { 'Test Heizung'    },                 -- a dummy switch
                        variables   =   { 'Test Heizung'    },                 -- Not sure what you want with this trigger variable ?
                    },                                                         -- As it is not used in the script   
 
    execute = function(domoticz, item )                                        -- item can be the device or the variable
                                                                               -- they are both collections (tables)
        local Setpoint = domoticz.devices('Setpoint') -- a Setpoint
        
        if item.state == 'On' then
            Setpoint.updateSetPoint(16)                -- Setpoint should be 16°C when switch = on
        end
        
        -- the log statement below does show the the setpoint as it was before execution of the script. The new setpoint is
        -- only visible to dzVents in a next execution of a script. This is because everyrhing is passed to the script in the function call
        -- as first parameter ====>> function (domoticz,item)
        domoticz.log(Setpoint.setPoint)                 -- Log the new setPoint
    end
}

Re: updateSetPoint function in DzVents

Posted: Tuesday 27 November 2018 13:23
by Sapp1123
At first, thanks for the help, i got the script running. The mistake was "if(TH == 'On') instead of if(TH.state == 'On')

Code: Select all

return {
	on = {
		devices = {
			'Test Heizung'
		},
		variables = {
		TH = 'Test Heizung'					-- To use TH instead of "Test Heizung" beause the compiler seems 
	 },								--to have trouble with the spacing in device names
	},
	execute = function(domoticz, TH)			-- TH used here
	    local Setpoint = domoticz.devices('Setpoint')
	    
	    if(TH.state == 'On') then
	    Setpoint.updateSetPoint(16)
	    end
end		
}
One more Question, how can i display the new Setpoint in the log?

Re: updateSetPoint function in DzVents

Posted: Tuesday 27 November 2018 14:00
by waaren
Sapp1123 wrote: Tuesday 27 November 2018 13:23 One more Question, how can i display the new Setpoint in the log?
in your script the TH in execute = function(domoticz, TH) is not a Lua var with the string "Test Heizung" but in fact the device that triggered the script with all attributes and functions
See wiki on variables =
I never encountered a problem with spacing in device names, nor with Lua nor with dzVents.
You can see the result of the updateSetPoint in the log , in the Gui or when you trigger the script again. See below

Code: Select all

return {
    on = {
        devices = { 
        'Test Heizung', 'Setpoint'
        },
        variables = {
        TH = 'Test Heizung'                    -- To use TH instead of "Test Heizung" beause the compiler seems 
     },                                --to have trouble with the spacing in device names
    },
    execute = function(domoticz, TH, info)            -- TH used here
        local Setpoint = domoticz.devices('Setpoint')

        domoticz.log('Script ' .. info.scriptName .." is triggered by " .. TH.name  )
        
        if TH.name == 'SetPoint' then
            domoticz.log('setpoint of device ' .. TH.name .." is now" .. TH.setpoint  )
        elseif TH.state == 'On' then
            domoticz.log(TH.name .." is now On; setting Setpoint")  
            Setpoint.updateSetPoint(16)
        elseif TH.state == 'Off' then
            domoticz.log(TH.name .." is now Off; no further action " )
        end
end        
}

Re: updateSetPoint function in DzVents

Posted: Tuesday 27 November 2018 19:07
by Sapp1123
Thanks a lot.