Page 1 of 1

Get temperature

Posted: Wednesday 31 January 2018 7:51
by welby
I currently have a working script that sends an email to my wife if the temp goes over a certain value and runs every hour. It works fine but i'd like to include the actual temp in the email if possible? This is my current code for testing it but it's not working, i'm sure someone will know where i've gone wrong.

Code: Select all

return {
	on = {
		timer = { 'every minute between 12:00 and 22:00'
		
		}
	},
	execute = function(domoticz, )
		if (domoticz.devices ('Temperature').temperature > 20) then
		    domoticz.email('Hi Prue you may turn the Aircon on because the temp is:' .. 'Temperature'.temperature '',  '*****@gmail.com')
		    end
	        
	 end
}

Re: Get temperature

Posted: Wednesday 31 January 2018 8:50
by SweetPants
Google is your friend, search for LUA string concatenation https://www.lua.org/pil/3.4.html

Re: Get temperature

Posted: Wednesday 31 January 2018 11:43
by waaren
welby wrote: Wednesday 31 January 2018 7:51 I currently have a working script that sends an email to my wife if the temp goes over a certain value and runs every hour. It works fine but i'd like to include the actual temp in the email if possible? This is my current code for testing it but it's not working, i'm sure someone will know where i've gone wrong.

Code: Select all

return {
	on = {
		timer = { 'every minute between 12:00 and 22:00'
		
		}
	},
	execute = function(domoticz, )
		if (domoticz.devices ('Temperature').temperature > 20) then
		    domoticz.email('Hi Prue you may turn the Aircon on because the temp is:' .. 'Temperature'.temperature '',  '*****@gmail.com')
		    end
	        
	 end
}
There are some other minor syntax errors in your example please find corrected below

Code: Select all

--[[

Email test
    

 ]]
 
return {
	on = {
		timer = { 'every minute between 12:00 and 22:00'
		
		}
	},
	execute = function(domoticz)
		local myTemp = domoticz.devices ('Kantoor').temperature
		if myTemp  < 20 then
			print ("Sending mail")
		    domoticz.email("Temperature alert for Prue", "Hi Prue you may turn the Aircon on because the temp is: " .. tostring(myTemp),  "[email protected]")
		end
	        
	 end
}


Re: Get temperature

Posted: Wednesday 31 January 2018 12:21
by welby
Awesome waaren it works great thanks alot ;) I've got alot to learn and this has helped me heaps.