switch switchOn().afterMin(3) not working

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

Moderator: leecollings

Post Reply
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

switch switchOn().afterMin(3) not working

Post by tuxmartin »

Hi, Im trying to write script for control heating.
What I need:
  • When heating is allowed (switch "heating") and temperature is lower than thermostat temperature - > turn on heating.
  • When heating is allowed (switch "heating") and temperature is higher than thermostat temperature - > turn off heating.
  • Turn on heating: turn on radiators, wait 3 minutes and after that turn on boiler.
  • Turn off heating: turn off boiler, wait 3 minutes and after that turn off radiators.
  • When heating switch is off: turn off boiler, wait 3 minutes and after that turn off radiators.

Code: Select all

function turnOffHeating(domoticz)
    local boiler = domoticz.devices('boiler')
    local left_radiator = domoticz.devices('left_radiator')
    local right_radiator = domoticz.devices('right_radiator')
	
    boiler.switchOff()
    left_radiator.switchOff().afterMin(3)
    right_radiator.switchOff().afterMin(3)
end

function turnOnHeating(domoticz)
    local boiler = domoticz.devices('boiler')
    local left_radiator = domoticz.devices('left_radiator')
    local right_radiator = domoticz.devices('right_radiator')
	
    left_radiator.switchOn()
    right_radiator.switchOn()
    boiler.switchOn().afterMin(3)
end

return {
	active = true,

	on = {
		devices = {
			'temp_hum',
			'heating', -- alow heating
			'thermostat'
		},

		timer = {
			'every 1 minutes'
		}
	},

	execute = function(domoticz)				
		local heating = domoticz.devices('heating')
		local boiler = domoticz.devices('boiler')
		local left_radiator = domoticz.devices('left_radiator')
		local right_radiator = domoticz.devices('right_radiator')
		local thermostat = domoticz.devices('thermostat')
		local temp_hum = domoticz.devices('temp_hum')

		if (heating.state == 'On' and temp_hum.temperature < thermostat.setPoint ) then
		    domoticz.log('turn on heating')		    
		    turnOnHeating(domoticz)
		elseif (temp_hum.temperature > thermostat.setPoint) then
		    domoticz.log("turn off heating")
		    turnOffHeating(domoticz)
		elseif (heating == 'Off') then
		    domoticz.log("heating prohibited")
		    turnOffHeating(domoticz)
		else
		    domoticz.log("undefined state")		    
		    turnOffHeating(domoticz)
		end
		    
	end
}
turnOnHeating enable both radiators, but not enable boiler.
What I do bad?
Is problem in timer 'every 1 minutes'? I mean that command boiler.switchOn().afterMin(3) run every 1 minute, so boiler cannot wait 3 minutes to enable. Is is true?

How can I fix it?
SweetPants

Re: switch switchOn().afterMin(3) not working

Post by SweetPants »

You have to determine what triggered your script, device or timer and act accordingly

execute = function(domoticz, device, triggerInfo)

-- Timer triggered use
if (triggerInfo.type == domoticz.EVENT_TYPE_TIMER) then


-- Device triggered use
elseif (triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

Re: switch switchOn().afterMin(3) not working

Post by tuxmartin »

I modified my script:

Code: Select all

function turnOffHeating(domoticz)
    local boiler = domoticz.devices('boiler')
    local left_radiator = domoticz.devices('left_radiator')
    local right_radiator = domoticz.devices('right_radiator')
	
    boiler.switchOff()
    left_radiator.switchOff().afterMin(3)
    right_radiator.switchOff().afterMin(3)
end

function turnOnHeating(domoticz)
    local boiler = domoticz.devices('boiler')
    local left_radiator = domoticz.devices('left_radiator')
    local right_radiator = domoticz.devices('right_radiator')
	
    left_radiator.switchOn()
    right_radiator.switchOn()
    boiler.switchOn().afterMin(3)
end

return {
	active = true,

    logging = {
        level = domoticz.LOG_DEBUG,
        marker = "HEATING_"
    },	

	on = {
		devices = {
			'temp_hum',
			'heating', -- alow heating
			'thermostat'
		},

		timer = {
			'every 1 minutes'
		}
	},

	execute = function(domoticz)	
				
	    -- Timer triggered use
        if (triggerInfo.type == domoticz.EVENT_TYPE_TIMER) then
            domoticz.log("event: EVENT_TYPE_TIMER")
        -- Device triggered use
        elseif(triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then
            domoticz.log("event: EVENT_TYPE_DEVICE  aaa")
            domoticz.log(device.name)
            domoticz.log("event: EVENT_TYPE_DEVICE  bbb")
        end
        				
		local heating = domoticz.devices('heating')
		local boiler = domoticz.devices('boiler')
		local left_radiator = domoticz.devices('left_radiator')
		local right_radiator = domoticz.devices('right_radiator')
		local thermostat = domoticz.devices('thermostat')
		local temp_hum = domoticz.devices('temp_hum')
		
        domoticz.log("aaa")
        domoticz.log(tostring(thermostat.setPoint))
        domoticz.log("bbb") 
        domoticz.log(tostring(temp_hum.temperature))
        domoticz.log("ccc") 		

		if (heating.state == 'On' and temp_hum.temperature < thermostat.setPoint ) then
		    domoticz.log('turn on heating')		    
		    turnOnHeating(domoticz)
		elseif (temp_hum.temperature > thermostat.setPoint) then
		    domoticz.log("turn off heating")
		    turnOffHeating(domoticz)
		elseif (heating == 'Off') then
		    domoticz.log("heating prohibited")
		    turnOffHeating(domoticz)
		else
		    domoticz.log("undefined state")		    
		    turnOffHeating(domoticz)
		end
		    
	end
}
All switchs are off and in log I see:

Code: Select all

2017-12-28 11:59:00.477 dzVents: Info: HEATING_: ------ Start internal script: HEATING_dzVents:, trigger: every 1 minutes
2017-12-28 11:59:00.477 dzVents: Info: HEATING_: event: EVENT_TYPE_TIMER
2017-12-28 11:59:00.544 dzVents: Debug: HEATING_: Device-adapter found for heating: Switch device adapter
2017-12-28 11:59:00.572 dzVents: Debug: HEATING_: Processing device-adapter for heating: Switch device adapter
2017-12-28 11:59:00.576 dzVents: Debug: HEATING_: Device-adapter found for boiler: Switch device adapter
2017-12-28 11:59:00.577 dzVents: Debug: HEATING_: Processing device-adapter for boiler: Switch device adapter
2017-12-28 11:59:00.580 dzVents: Debug: HEATING_: Device-adapter found for left_radiator: Switch device adapter
2017-12-28 11:59:00.581 dzVents: Debug: HEATING_: Processing device-adapter for left_radiator: Switch device adapter
2017-12-28 11:59:00.584 dzVents: Debug: HEATING_: Device-adapter found for right_radiator: Switch device adapter
2017-12-28 11:59:00.585 dzVents: Debug: HEATING_: Processing device-adapter for right_radiator: Switch device adapter
2017-12-28 11:59:00.588 dzVents: Debug: HEATING_: Device-adapter found for thermostat: Thermostat setpoint device adapter
2017-12-28 11:59:00.589 dzVents: Debug: HEATING_: Processing device-adapter for thermostat: Thermostat setpoint device adapter
2017-12-28 11:59:00.593 dzVents: Debug: HEATING_: Device-adapter found for temp_hum: Temperature+humidity device adapter
2017-12-28 11:59:00.594 dzVents: Debug: HEATING_: Processing device-adapter for temp_hum: Temperature+humidity device adapter
2017-12-28 11:59:00.594 dzVents: Info: HEATING_: aaa
2017-12-28 11:59:00.594 dzVents: Info: HEATING_: 13.5
2017-12-28 11:59:00.594 dzVents: Info: HEATING_: bbb
2017-12-28 11:59:00.595 dzVents: Info: HEATING_: 12.699999809265
2017-12-28 11:59:00.595 dzVents: Info: HEATING_: ccc
2017-12-28 11:59:00.595 dzVents: Info: HEATING_: undefined state
2017-12-28 11:59:00.595 dzVents: Debug: HEATING_: Constructed timed-command: Off
2017-12-28 11:59:00.596 dzVents: Debug: HEATING_: Constructed timed-command: Off
2017-12-28 11:59:00.596 dzVents: Debug: HEATING_: Constructed timed-command: Off AFTER 180
2017-12-28 11:59:00.596 dzVents: Debug: HEATING_: Constructed timed-command: Off
2017-12-28 11:59:00.597 dzVents: Debug: HEATING_: Constructed timed-command: Off AFTER 180
2017-12-28 11:59:00.597 dzVents: Info: HEATING_: ------ Finished HEATING_dzVents
Why "undefined state"? It might be "elseif (heating == 'Off') then" - heating switch is off.

After I enable switch "heating", in log:

Code: Select all

2017-12-28 11:59:00.477 dzVents: Info: HEATING_: ------ Start internal script: HEATING_dzVents:, trigger: every 1 minutes
2017-12-28 11:59:00.477 dzVents: Info: HEATING_: event: EVENT_TYPE_TIMER
2017-12-28 11:59:00.544 dzVents: Debug: HEATING_: Device-adapter found for heating: Switch device adapter
2017-12-28 11:59:00.572 dzVents: Debug: HEATING_: Processing device-adapter for heating: Switch device adapter
2017-12-28 11:59:00.576 dzVents: Debug: HEATING_: Device-adapter found for boiler: Switch device adapter
2017-12-28 11:59:00.577 dzVents: Debug: HEATING_: Processing device-adapter for boiler: Switch device adapter
2017-12-28 11:59:00.580 dzVents: Debug: HEATING_: Device-adapter found for left_radiator: Switch device adapter
2017-12-28 11:59:00.581 dzVents: Debug: HEATING_: Processing device-adapter for left_radiator: Switch device adapter
2017-12-28 11:59:00.584 dzVents: Debug: HEATING_: Device-adapter found for right_radiator: Switch device adapter
2017-12-28 11:59:00.585 dzVents: Debug: HEATING_: Processing device-adapter for right_radiator: Switch device adapter
2017-12-28 11:59:00.588 dzVents: Debug: HEATING_: Device-adapter found for thermostat: Thermostat setpoint device adapter
2017-12-28 11:59:00.589 dzVents: Debug: HEATING_: Processing device-adapter for thermostat: Thermostat setpoint device adapter
2017-12-28 11:59:00.593 dzVents: Debug: HEATING_: Device-adapter found for temp_hum: Temperature+humidity device adapter
2017-12-28 11:59:00.594 dzVents: Debug: HEATING_: Processing device-adapter for temp_hum: Temperature+humidity device adapter
2017-12-28 11:59:00.594 dzVents: Info: HEATING_: aaa
2017-12-28 11:59:00.594 dzVents: Info: HEATING_: 13.5
2017-12-28 11:59:00.594 dzVents: Info: HEATING_: bbb
2017-12-28 11:59:00.595 dzVents: Info: HEATING_: 12.699999809265
2017-12-28 11:59:00.595 dzVents: Info: HEATING_: ccc
2017-12-28 11:59:00.595 dzVents: Info: HEATING_: undefined state
2017-12-28 11:59:00.595 dzVents: Debug: HEATING_: Constructed timed-command: Off
2017-12-28 11:59:00.596 dzVents: Debug: HEATING_: Constructed timed-command: Off
2017-12-28 11:59:00.596 dzVents: Debug: HEATING_: Constructed timed-command: Off AFTER 180
2017-12-28 11:59:00.596 dzVents: Debug: HEATING_: Constructed timed-command: Off
2017-12-28 11:59:00.597 dzVents: Debug: HEATING_: Constructed timed-command: Off AFTER 180
2017-12-28 11:59:00.597 dzVents: Info: HEATING_: ------ Finished HEATING_dzVents

2017-12-28 11:59:59.671 dzVents: Info: HEATING_: ------ Start internal script: HEATING_dzVents: Device: "temp_hum (1st_floor)", Index: 10
2017-12-28 11:59:59.671 dzVents: Info: HEATING_: event: EVENT_TYPE_DEVICE aaa
2017-12-28 11:59:59.671 dzVents: Info: HEATING_: temp_hum
2017-12-28 11:59:59.671 dzVents: Info: HEATING_: event: EVENT_TYPE_DEVICE bbb
2017-12-28 11:59:59.672 dzVents: Debug: HEATING_: Device-adapter found for heating: Switch device adapter
2017-12-28 11:59:59.672 dzVents: Debug: HEATING_: Processing device-adapter for heating: Switch device adapter
2017-12-28 11:59:59.673 dzVents: Debug: HEATING_: Device-adapter found for boiler: Switch device adapter
2017-12-28 11:59:59.673 dzVents: Debug: HEATING_: Processing device-adapter for boiler: Switch device adapter
2017-12-28 11:59:59.674 dzVents: Debug: HEATING_: Device-adapter found for left_radiator: Switch device adapter
2017-12-28 11:59:59.674 dzVents: Debug: HEATING_: Processing device-adapter for left_radiator: Switch device adapter
2017-12-28 11:59:59.675 dzVents: Debug: HEATING_: Device-adapter found for right_radiator: Switch device adapter
2017-12-28 11:59:59.675 dzVents: Debug: HEATING_: Processing device-adapter for right_radiator: Switch device adapter
2017-12-28 11:59:59.676 dzVents: Debug: HEATING_: Device-adapter found for thermostat: Thermostat setpoint device adapter
2017-12-28 11:59:59.676 dzVents: Debug: HEATING_: Processing device-adapter for thermostat: Thermostat setpoint device adapter
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: aaa
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: 13.5
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: bbb
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: 12.699999809265
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: ccc
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: turn on heating
2017-12-28 11:59:59.676 dzVents: Debug: HEATING_: Constructed timed-command: On
2017-12-28 11:59:59.676 dzVents: Debug: HEATING_: Constructed timed-command: On
2017-12-28 11:59:59.676 dzVents: Debug: HEATING_: Constructed timed-command: On
2017-12-28 11:59:59.676 dzVents: Debug: HEATING_: Constructed timed-command: On AFTER 180
2017-12-28 11:59:59.676 dzVents: Info: HEATING_: ------ Finished HEATING_dzVents
Trigger was timer and "temp_hum" device. It is ok.
But after 3 minutes boiler must sitch on - not works. I wait about 10 minutes and boiler is still off.

My function "function turnOnHeating(domoticz)" run every 1 minute and turn on both radiators. But not boiler after 3 minutes.

How can I fix it?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests