Change temperature format

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

Moderator: leecollings

Post Reply
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Change temperature format

Post 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 :)
SweetPants

Re: Change temperature format

Post by SweetPants »

Please upgrade, there was an issue with float format (lengths) which should be solved
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Change temperature format

Post 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]
Last edited by rkarolek on Tuesday 16 October 2018 20:45, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Change temperature format

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Change temperature format

Post 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)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Change temperature format

Post 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))	
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Change temperature format

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest