Page 1 of 1

round function does not seem to work

Posted: Thursday 29 September 2022 18:34
by Gravityz
i have a simple program which checks certain temperature devices
somehow the round function does not work
instead of rounding the numbers they seem to be floating (13 digits)

so instead of 10,25 i get 10,2500012334467

Code: Select all

return {
	on = {
		devices = {'CV Status','CV Aanvoer', 'test'},
		timer = {},
		variables = {},
		scenes = {},
		groups = {},
		security = {},
		httpResponses = {},
		shellCommandResponses = {},
		customEvents = {},
		system = {},
	},
	data = {},
	logging = {},
	execute = function(domoticz, device)
	 --local text = domoticz.devices('CV Status').text
	 local starttemp = domoticz.devices('Thermostaat-Temperatuur').temperature
	 local doeltemp = domoticz.devices('Thermostaat-Setpoint').temperature
	 local CVdelta = domoticz.devices('CV Delta').temperature
	 domoticz.utils.round(starttemp,2)
	 domoticz.utils.round(doeltemp,2)
     domoticz.utils.round(CVdelta,2)

	 
if (device.name == 'CV Status' and device.text == 'OpenTherm') then
    domoticz.notify("Domoticz", "CV Aan".."\r\n".."Start Temperatuur:"..(starttemp).."˚C".."\r\n".."Doel Temperatuur :"..(doeltemp).."˚C", "telegram")
end

--if (device.name == 'CV Aanvoer' and device.temperature >= 45) then
if (device.name == 'test') then
    domoticz.notify("Domoticz", "CV Delta:"..(CVdelta).."˚C", "telegram")
end


	end
}

Re: round function does not seem to work

Posted: Thursday 29 September 2022 19:33
by Gravityz
i changed it to

strange that domoticz.utils.round does not work
i am on build 14311 but i would guess that this function exists for a long time
otherwise i would have gotten an error

Code: Select all

starttemp = tonumber(string.format("%.1f", starttemp))

Re: round function does not seem to work

Posted: Thursday 29 September 2022 23:07
by roblom
First of all, I'm no DzEvents expert but can you try:

local starttemp =domoticz.utils.round(domoticz.devices('Thermostaat-Temperatuur').temperature,2)

Re: round function does not seem to work

Posted: Friday 30 September 2022 8:51
by Gravityz
tried it and that works.

the weird thing is that with the original code it initially worked with starttemp,doeltemp but not with CVdelta which uses exactly the same code
after a lot of trial/error the first 2 also stopped and i got floating numbers with all 3

maybe it was a memorything which screwed up the round function in domoticz

the code you provied is the same instuction as i used only for readability i spliited it into 2 commands.
thanks and i will keep an eye on it

Re: round function does not seem to work

Posted: Friday 30 September 2022 10:32
by roblom
The spilt caused the "round function" does nothing. You first put a value in the local parameter and then on the second line you round the value but it isn't put in the local parameter so the parameter isn't changed.

Re: round function does not seem to work

Posted: Friday 30 September 2022 12:27
by Gravityz
i understand. it seemed logical but i will change the code so it does everything at once.