Errors with combined device and timer script

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

Moderator: leecollings

Post Reply
mhfrey
Posts: 11
Joined: Sunday 06 April 2014 2:26
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8160
Location: USA
Contact:

Errors with combined device and timer script

Post by mhfrey »

I am trying to control a thermostat to have 2 modes Home and Away with Domoticz v3.8795. When Away is On the temperature is set low and does not change. When Home is On (Away is Off) I want the temperature to change a few times during the day. I have listed my script below

When a time event triggers I get an error for the if statement for the device, line 16. When I manually trigger the Away on and off I get an error at the first if for the triggerInfo,trigger.

I know I am missing something, your help correcting my dumb mistakes would be greatly appreciated.

Code: Select all

local Away_temp = 50
local Home_temp_dayh = 68
local Home_temp_dayl = 63
local Home_temp_nght = 60

return {
	on = {
		devices = {'Away Switch'},
		timer = {   'at 05:30', -- raise temp
		            'at 08:00', -- lower temp up stairs
		            'at 19:00', -- raise temp up stairs
		            'at 23:00'  -- lower temp
		            }
	},
	execute = function(domoticz, device, triggerInfo)
        if (device.state == 'On') then
            domoticz.devices('Down Stairs Set').updateSetPoint(Away_temp)
            domoticz.devices('Up Stairs Set').updateSetPoint(Away_temp)
	    	domoticz.log('Away Set Point changed to: ' .. Away_temp,  domoticz.LOG_INFO)
        else
	    	--domoticz.log('Home Set Point ' .. triggerInfo.trigger,  domoticz.LOG_INFO)
            if (triggerInfo.trigger == 'at 05:30') then
                domoticz.devices('Down Stairs Set').updateSetPoint(Home_temp_dayh)
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayh)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_dayh,  domoticz.LOG_INFO)
            elseif (triggerInfo.trigger == 'at 08:00') then
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayl)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_dayl,  domoticz.LOG_INFO)
            elseif (triggerInfo.trigger == 'at 19:00') then
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayh)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_dayh,  domoticz.LOG_INFO)
            elseif (triggerInfo.trigger == 'at 23:00') then
                domoticz.devices('Down Stairs Set').updateSetPoint(Home_temp_nght)
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_nght)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_nght,  domoticz.LOG_INFO)
    	    else 
                domoticz.devices('Down Stairs Set').updateSetPoint(Home_temp_dayh)
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayh)
	    	    domoticz.log('Home Set Point changed to: ' .. Home_temp_dayh,  domoticz.LOG_INFO)
            end    
        end
	end
}
mhfrey
Posts: 11
Joined: Sunday 06 April 2014 2:26
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8160
Location: USA
Contact:

Re: Errors with combined device and timer script

Post by mhfrey »

Found what appears to be a simple fix , changed (device.state == 'On') to (domoticz.devices('Away Switch').state == 'On').

Current code:

Code: Select all

local Away_temp = 50
local Home_temp_dayh = 68
local Home_temp_dayl = 63
local Home_temp_nght = 60

return {
	on = {
		devices = {'Away Switch'},
		timer = {   'at 05:30', -- raise temp
		            'at 08:00', -- lower temp up stairs
		            'at 19:00', -- raise temp up stairs
		            'at 23:00'  -- lower temp
		            }
	},
	execute = function(domoticz, device, triggerInfo)
        if (domoticz.devices('Away Switch').state == 'On') then
            domoticz.devices('Down Stairs Set').updateSetPoint(Away_temp)
            domoticz.devices('Up Stairs Set').updateSetPoint(Away_temp)
	    	domoticz.log('Away Set Point changed to: ' .. Away_temp,  domoticz.LOG_INFO)
        else
	    	domoticz.log('Home Set Point ' .. tostring(triggerInfo.trigger),  domoticz.LOG_INFO)
            if (triggerInfo.trigger == 'at 05:30') then
                domoticz.devices('Down Stairs Set').updateSetPoint(Home_temp_dayh)
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayh)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_dayh,  domoticz.LOG_INFO)
            elseif (triggerInfo.trigger == 'at 08:00') then
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayl)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_dayl,  domoticz.LOG_INFO)
            elseif (triggerInfo.trigger == 'at 19:00') then
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayh)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_dayh,  domoticz.LOG_INFO)
            elseif (triggerInfo.trigger == 'at 23:00') then
                domoticz.devices('Down Stairs Set').updateSetPoint(Home_temp_nght)
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_nght)
	    	    domoticz.log('Home Set Point ' .. triggerInfo.trigger .. ' changed to: ' .. Home_temp_nght,  domoticz.LOG_INFO)
    	    else 
                domoticz.devices('Down Stairs Set').updateSetPoint(Home_temp_dayh)
                domoticz.devices('Up Stairs Set').updateSetPoint(Home_temp_dayh)
	    	    domoticz.log('Home Set Point changed to: ' .. Home_temp_dayh,  domoticz.LOG_INFO)
            end    
        end
        domoticz.log('End Set Point Script',  domoticz.LOG_INFO)
	end
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Errors with combined device and timer script

Post by dannybloe »

It's very simple: if your script is triggered by a timer rule then the second parameter of the execute function is nil (this will change in 2.4 btw). So you have to check for either triggerInfo.type == domoticz. EVENT_TYPE_DEVICE or for device ~= nil.
If the script is triggered due to the change of device 'Away Switch' then that switch is the device parameter of your execute function.
See the documentation.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest