Page 1 of 1

Change temperature format

Posted: Tuesday 16 October 2018 20:13
by rkarolek
Hi
I have two temperature sensors (DS18B20) both sending temperature to domoticz and both are visible as xx.x C.
I made script which read temperature value from both sensor, counting average and change other domoticz device value and.... i have problem :(
average temperature is visible as xx.xxxxxxxxxxxx C (yes, it has 12 digits after dot), is it possible to change?

its part of code

Code: Select all

	
	local Temp_100_1 = domoticz.devices('Temperatura_1').temperature 				this device have format xx.x C
	local Temp_100_2 = domoticz.devices('Temperatura_2').temperature 				this device have format xx.x C
	local Temp_100 = (Temp_100_1+Temp_100_2)/2
	domoticz.devices('Temperatura').updateTemperature(Temp_100)					but this device have format xx.xxxxxxxxxxxx C
	
sorry for my english :)

Re: Change temperature format

Posted: Tuesday 16 October 2018 20:28
by SweetPants
Please upgrade, there was an issue with float format (lengths) which should be solved

Re: Change temperature format

Posted: Tuesday 16 October 2018 20:43
by rkarolek
hmmmm i think i have newest version, how can i checkit?
btw, you mean dzvents or domoticz version?
nvm i got it, its version's of my system

Code: Select all

Version: 4.9700
Build Hash: a3a45906
Compile Date: 2018-06-23 16:24:51
dzVents Version: 2.4.6
Python Version: 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124]

Re: Change temperature format

Posted: Tuesday 16 October 2018 20:43
by waaren
rkarolek wrote: Tuesday 16 October 2018 20:13 Hi
I have two temperature sensors (DS18B20) both sending temperature to domoticz and both are visible as xx.x C.
I made script which read temperature value from both sensor, counting average and change other domoticz device value and.... i have problem :(
average temperature is visible as xx.xxxxxxxxxxxx C (yes, it has 12 digits after dot), is it possible to change?

its part of code

Code: Select all

	
	local Temp_100_1 = domoticz.devices('Temperatura_1').temperature 				this device have format xx.x C
	local Temp_100_2 = domoticz.devices('Temperatura_2').temperature 				this device have format xx.x C
	local Temp_100 = (Temp_100_1+Temp_100_2)/2
	domoticz.devices('Temperatura').updateTemperature(Temp_100)					but this device have format xx.xxxxxxxxxxxx C
	
sorry for my english :)
change line

Code: Select all

domoticz.devices('Temperatura').updateTemperature(Temp_100)					but this device have format xx.xxxxxxxxxxxx C
to

Code: Select all

local decimals = 2
domoticz.utils.round(domoticz.devices('Temperatura').updateTemperature(Temp_100),decimals)					this device have format xx.xx C

Re: Change temperature format

Posted: Tuesday 16 October 2018 21:11
by rkarolek
unfortunatelly it not work :(
its error log

Code: Select all

2018-10-16 21:05:00.486 Status: dzVents: Error (2.4.6): A100_temp: /home/pi/domoticz/dzVents/runtime/Domoticz.lua:159: attempt to perform arithmetic on local 'x' (a table value)
i try change for

Code: Select all

local Temp=round(Temp_100,2)
domoticz.devices('Temperatura').updateTemperature(Temp)
but i got other error

Code: Select all

2018-10-16 21:00:00.444 Status: dzVents: Error (2.4.6): A100_temp: ...domoticz/scripts/dzVents/generated_scripts/A100_temp.lua:26: attempt to call global 'round' (a nil value)

Re: Change temperature format

Posted: Tuesday 16 October 2018 21:17
by waaren
rkarolek wrote: Tuesday 16 October 2018 21:11 unfortunatelly it not work :(
its error log

Code: Select all

2018-10-16 21:05:00.486 Status: dzVents: Error (2.4.6): A100_temp: /home/pi/domoticz/dzVents/runtime/Domoticz.lua:159: attempt to perform arithmetic on local 'x' (a table value)
Sorry was to quick and advised incorrect. Try this

Code: Select all

local decimals = 2
domoticz.devices('Temperatura').updateTemperature(domoticz.utils.round(Temp_100,decimals))	

Re: Change temperature format

Posted: Tuesday 16 October 2018 21:36
by rkarolek
didnt work too, but... i change it for

Code: Select all

	
	local Temp_100 = domoticz.utils.round(((Temp_100_1+Temp_100_2)/2),decimals)
       domoticz.devices('Temperatura').updateTemperature(Temp_100)
and its work fine, idk why it doesnt work in one line, anyway tyvm for help