back to basics

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

Moderator: leecollings

Post Reply
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

back to basics

Post 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
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: back to basics

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: back to basics

Post 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
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: back to basics

Post 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
}
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: back to basics

Post 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'
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: back to basics

Post 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
}
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest