Page 1 of 1

back to basics

Posted: Thursday 18 July 2019 12:06
by markjgabb
hi everyone
its been forever since i picked up domoticz and had to blow away my config to get everything back up....

i think ive completely forgotten my dzvents, which is a shame as i was getting quite good at it...

can anyone help me jumpstart my memory so i can get back into it?

Code: Select all

local Heatpower = 11
local Heatswitch = 12

return {
	active = {
		true, 
	on = {
	
		devices = {
		
			12, -- Heater Switch
			11    -- Heater Power Monitor
		},

	},

	
	data = {
	},


	logging = {
        level = domoticz.LOG_DEBUG,
        marker = "Cool script"
    },

	execute = function(domoticz, triggeredItem, info)


		if Heatpower.WhActual > 0 then 
		 Heatswitch.Switchon    
		end
	end
}
}


As you can see i havent got far

so my situation is as follows

i have the following devices
Rflink power monitor hooked directly to my heat pump
1 rf push button (Heatpump on)
1 rf push buttpon Heatpump off)
1 dummy switch (heater control)


so what i would like to achieve is that when i turn the heater on using the dumy switch in domoticz that it checks if the power meter has a reading sets the switch to on and turns it on if needed....

i could just go for the classic turn it on and or off....
but im after something a little more elgant, this way it doesnt matter if someone grabs the remote and changes the setting or muchs around pressing buttons, the power monitor is aware of if the power is on or not and takes care of it


18 months ago i could of written this is my sleep, but the whole thing escapes me at the moment

Re: back to basics

Posted: Thursday 18 July 2019 12:36
by waaren
markjgabb wrote: Thursday 18 July 2019 12:06 so what i would like to achieve is that when i turn the heater on using the dummy switch in domoticz that it checks if the power meter has a reading sets the switch to on and turns it on if needed....
I seem to miss the point in your description. What would you not have if you switch the heater with a switchOn().checkFirst() command ?

Re: back to basics

Posted: Thursday 18 July 2019 12:47
by markjgabb
turning switch on triggers a push button RF button, turning off triggers a push button RF button..... they have no state only on.... so if someone has grabbed the remote from the wall and turned on the reverse cycle, domoticz only way of knowing is through power consumption on the power monitor

Re: back to basics

Posted: Thursday 18 July 2019 13:28
by markjgabb
ok i busted my memory more for what im trying to achieve and this is it i think?

Code: Select all

local Heatswitch = domoticz.devices(12)
local heatpower = domoticz.devices(11).WhActual

return {

	active = {

		true,  -- either true or false, or you can specify a function

	}

	on = {
		devices = {
			-- scripts is executed if the device that was updated matches with one of these triggers
			12, -- Heater Switch
			   -- Heater Power Monitor
			
		},

	},

	data = {
		myVar = { initial = 5 },
		myHistoryVar = { maxItems = 10 },
	},

	logging = {
        level = domoticz.LOG_DEBUG,
        marker = "Cool script"
    },

	execute = function(domoticz, triggeredItem, info)

if (device.state == 'On') then 
    domoticz.log(" Heater control switch turned on")
		if heatpower == 0 then
					domoticz.log(" reverse cycle is not on, turning it now")
					domoticz.devices('Lounge Heater On').switchOn()
				elseif heatpower > 0 then
				    domoticz.log(" reverse cycle is already on, only changing state")
			end
	elseif (device.state == 'Off') then 
    domoticz.log(" Heater control switch turned off")
		if heatpower == 0 then
					domoticz.log(" reverse cycle is not on, doing nothing at all")
					domoticz.devices('Lounge Heater On').switchOn()
				elseif heatpower > 0 then
				    domoticz.log(" reverse cycle is on, turning off now")
				    domoticz.devices('Lounge Heater Off').switchOn()
			end
	end
end
}

Re: back to basics

Posted: Thursday 18 July 2019 13:38
by markjgabb
however ive obviously screwed up my syntax somewhere im getting the following error

2019-07-18 21:38:00.371 ...icz/scripts/dzVents/generated_scripts/Heater Control.lua:12: '}' expected (to close '{' at line 4) near 'on'

Re: back to basics

Posted: Thursday 18 July 2019 14:48
by markjgabb
lol usually my way i work though things slowly


new set of code at bottom

so i now have control working perfectly
but the issue is detecting someone who has not used domoticz to control the heater

i can use the power monitor to tell if the heater is actually on or not, but im not sure how to use that in a say 5 minute looping script to change the state of the heater swtich to update its state without restarting the script loop again

i assume it would be something along the lines of if 11.whactual > 0 then
lounge heater on check first. and have it keep looping but not actually perform the other actions....

Code: Select all

return {
	on = {
		devices = {
			12
		}
	},
	execute = function(domoticz, device)
if (device.state == 'On') then 
    domoticz.log(" Heater control switch turned on")
		if domoticz.devices(11).WhActual == 0 then
					domoticz.log(" reverse cycle is not on, turning it now")
					domoticz.devices('Lounge Heater On').switchOn()
				elseif domoticz.devices(11).WhActual > 0 then
				    domoticz.log(" reverse cycle is already on, only changing state")
			end
	elseif (device.state == 'Off') then 
    domoticz.log(" Heater control switch turned off")
		if domoticz.devices(11).WhActual == 0 then
					domoticz.log(" reverse cycle is not on, doing nothing at all")
					domoticz.devices('Lounge Heater On').switchOn()
				elseif domoticz.devices(11).WhActual > 0 then
				    domoticz.log(" reverse cycle is on, turning off now")
				    domoticz.devices('Lounge Heater Off').switchOn()
			end
	end
end
}