round function does not seem to work

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

Moderator: leecollings

Post Reply
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

round function does not seem to work

Post 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
}
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: round function does not seem to work

Post 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))
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: round function does not seem to work

Post 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)
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: round function does not seem to work

Post 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
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: round function does not seem to work

Post 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.
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: round function does not seem to work

Post by Gravityz »

i understand. it seemed logical but i will change the code so it does everything at once.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest