Page 1 of 1
Virtual Temperature Sensor
Posted: Tuesday 08 April 2014 12:40
by panser
Hi.
I would like to create a virtual temp-sensor. This sensor should get data from existing sensors that's been selected. The outcome from this sensor should be the average from the selected sensors.
Example:

Re: Viritual Temperature Sensor
Posted: Tuesday 08 April 2014 13:15
by SweetPants
You can't
Re: Viritual Temperature Sensor
Posted: Tuesday 08 April 2014 13:24
by panser
SweetPants wrote:You can't
That's why I want to suggest this as a new feature, so it might get implemented in next version.
Re: Viritual Temperature Sensor
Posted: Tuesday 08 April 2014 13:25
by pwhooftman
SweetPants wrote:You can't
You can, if you are prepared to make a lua script which reads the various values from different sensors, calculates the average, and write that back to the virtual temp-sensor. You'll have to alter the lua script to select which readings to involve in the calculation of the average.
Re: Viritual Temperature Sensor
Posted: Tuesday 08 April 2014 13:49
by SweetPants
pwhooftman wrote:SweetPants wrote:You can't
You can, if you are prepared to make a lua script which reads the various values from different sensors, calculates the average, and write that back to the virtual temp-sensor. You'll have to alter the lua script to select which readings to involve in the calculation of the average.
I meant with "You can't", you can't get the 'dropdown' menu's in the sensor as panser pointed out. The only way now is to create multiple sensors to display your readings.
Re: Viritual Temperature Sensor
Posted: Tuesday 08 April 2014 14:31
by panser
pwhooftman wrote:SweetPants wrote:You can't
You can, if you are prepared to make a lua script which reads the various values from different sensors, calculates the average, and write that back to the virtual temp-sensor. You'll have to alter the lua script to select which readings to involve in the calculation of the average.
Interesting. Unfortunately I don't know LUA....yet =) I will start to learn.Is it possible to create a virtual temp-sensor? (How?)
Anyway, I still think the way I suggest (the screen-shot) would be a very easy and good way to do it.
As I have 6-7 temp sensor's outside, it would be grate to have one virtual sensor that gives me the average of all those 6-7 sensors to get a more accurate reading.
Re: Viritual Temperature Sensor
Posted: Tuesday 08 April 2014 14:58
by SweetPants
panser wrote:As I have 6-7 temp sensor's outside, it would be grate to have one virtual sensor that gives me the average of all those 6-7 sensors to get a more accurate reading.
There are two solutions:
1) You wait until the developers take up your request.
2) Create your own script(s)
a) GoTo Settings + Hardware and create a 'Dummy' hardware device
b) Create Virtual Sensors as per your requirement using the drop down list
c) Update the virtual sensor using Perl/Python and JSON API (
http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s) this requires some expericence with programming)
I think in your case that would be a cron job reading the current values from every sensor using JSON API, calculate the average and update the virtual sensor using JSON API.
Re: Virtual Temperature Sensor
Posted: Tuesday 08 April 2014 18:51
by jfcjfc
or only LUA, see
lua script "heating control".
http://www.domoticz.com/forum/viewtopic ... =66#p11155
ALL ARE INSIDE :
five virtual and real temperatures
Tms = otherdevices_svalues['Tp-MS-Salon'] -- 131 => 156 / Real
Tb = otherdevices_svalues['Tp-Basse'] -- 73 / Virtual
Tv = otherdevices_svalues['Tp-Vacances'] -- 74 / Virtual
Th = otherdevices_svalues['Tp-Haute'] -- 72 / Virtual
Tex = otherdevices_svalues['Tp_EXT_E1'] -- 34 / Real
calculation
and two new virtual devices
commandArray['OpenURL']='192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=75&nvalue=0&svalue='.. Tsc -- Tmax = 45 - ['Tp_EXT_E1' / Virtual
commandArray['OpenURL']='192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=141&nvalue=0&svalue='.. Tdi -- 'T_TUYAU-E1_CHAUFF' - Tmax / Virtual
'ALL INCLUSIVE' except averaging ! ! !
Re: Virtual Temperature Sensor
Posted: Thursday 03 March 2016 3:17
by panser
Hi,
I have now started to learn lua and got this working. It calculate average temp of my 5 temp sensors, and average hum of my 3 hum sensors and writes the hum stat from my sensor #1 to a virtual device. This happens once every one minute.
Please excuse any "bad programming" as im a n00b.
However it works
Code: Select all
tmp1, hum1, humstat1 = string.match(otherdevices_svalues['Device1'], "(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*)")
tmp2, hum2 = string.match(otherdevices_svalues['Device2'], "(%d+%.*%d*);(%d+%.*%d*)")
tmp3 = otherdevices_svalues['Device3']
tmp4 = otherdevices_svalues['Device4']
tmp5, hum3 = string.match(otherdevices_svalues['Device5'], "(%d+%.*%d*);(%d+%.*%d*)")
commandArray = {}
time = os.date("*t")
if((time.min % 1)==0)then
local tempaverage = ((tmp1 + tmp2 + tmp3 + tmp4 + tmp5) / 5)
local humaverage = ((hum1 + hum2 + hum3) / 3)
local humstat = humstat1
commandArray['OpenURL'] = 'http://192.168.1.186:8080/json.htm?type=command¶m=udevice&idx=194&nvalue=0&svalue='..tempaverage..';'..humaverage..';'..humstat
end
return commandArray
Re: Virtual Temperature Sensor
Posted: Thursday 03 March 2016 11:23
by Westcott
Panser,
Just a suggestion, but if it is a 'time' script, it will run every minute, so you don't need the 'if((time.min % 1)==0)then' check.
Also, have you tried updating device 194 directly, rather than with json?
E.g. commandArray['UpdateDevice'] = '194|0|'..tempaverage..';'..humaverage..';'..humstat
Re: Virtual Temperature Sensor
Posted: Friday 04 March 2016 2:33
by panser
Westcott wrote:Panser,
Just a suggestion, but if it is a 'time' script, it will run every minute, so you don't need the 'if((time.min % 1)==0)then' check.
Also, have you tried updating device 194 directly, rather than with json?
E.g. commandArray['UpdateDevice'] = '194|0|'..tempaverage..';'..humaverage..';'..humstat
Westscott,
Thanks mate
I have changed the commandArray to use update directley istead of jason. Thanks.
Regarding timer, I actually use every 5min now: 'if((time.min % 5)==0)then'
Btw, do you know how I can use device idx 194 in other scripts?
like 'otherdevices_svalues[name of idx194]' ?
Re: Virtual Temperature Sensor
Posted: Friday 04 March 2016 12:30
by Westcott
There's a built-in function to get the device's index using its name -
idx = otherdevices_idx[device]
I wrote a small function to handle multiple updates in one Lua script -
Code: Select all
-- Index for CommandArray update
i = 1
-- The Update function
function UpdateDevice(device, data)
-- Get the device index from its name
idx = otherdevices_idx[device]
commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
i = i+1
end
-- Call it like this from your code
UpdateDevice('<deviceName>', '<yourData>')
Re: Virtual Temperature Sensor
Posted: Saturday 05 March 2016 13:25
by panser
Westcott, thanks a lot
I found one issue with my pgrogram:
Code: Select all
tmp1, hum1, humstat1 = string.match(otherdevices_svalues['Device1'], "(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*)")
tmp1 (%d+%.*%d*) will return -1.0 as 1.0 - How can i make it to include the "-" as it is freezing outside

?
Re: Virtual Temperature Sensor
Posted: Saturday 05 March 2016 14:34
by Westcott
Have a look at this -
http://www.lua.org/pil/20.2.html
I think it will be -
(%-?%d+%.*%d*)
or
([+-]?%d+%.*%d*)