Virtual Temperature Sensor

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
panser
Posts: 27
Joined: Thursday 03 April 2014 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sandnes / Norway
Contact:

Virtual Temperature Sensor

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

Image
Last edited by panser on Tuesday 08 April 2014 14:32, edited 1 time in total.
SweetPants

Re: Viritual Temperature Sensor

Post by SweetPants »

You can't
panser
Posts: 27
Joined: Thursday 03 April 2014 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sandnes / Norway
Contact:

Re: Viritual Temperature Sensor

Post 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.
pwhooftman
Posts: 75
Joined: Monday 11 November 2013 18:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Viritual Temperature Sensor

Post 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.
Domoticz v 1.16xx
1X RFXtrx433 USB 433.92MHz Transceiver Firmware version: 71
1X Synology Nas DS918+ DSM 7 (12Gb RAM mod)
SweetPants

Re: Viritual Temperature Sensor

Post 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.
panser
Posts: 27
Joined: Thursday 03 April 2014 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sandnes / Norway
Contact:

Re: Viritual Temperature Sensor

Post 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.
SweetPants

Re: Viritual Temperature Sensor

Post 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.
jfcjfc
Posts: 10
Joined: Monday 15 July 2013 14:37
Target OS: -
Domoticz version:
Location: France
Contact:

Re: Virtual Temperature Sensor

Post 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&param=udevice&idx=75&nvalue=0&svalue='.. Tsc -- Tmax = 45 - ['Tp_EXT_E1' / Virtual
commandArray['OpenURL']='192.168.0.3:8080/json.htm?type=command&param=udevice&idx=141&nvalue=0&svalue='.. Tdi -- 'T_TUYAU-E1_CHAUFF' - Tmax / Virtual

'ALL INCLUSIVE' except averaging ! ! !
panser
Posts: 27
Joined: Thursday 03 April 2014 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sandnes / Norway
Contact:

Re: Virtual Temperature Sensor

Post 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&param=udevice&idx=194&nvalue=0&svalue='..tempaverage..';'..humaverage..';'..humstat

end

return commandArray
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Virtual Temperature Sensor

Post 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
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
panser
Posts: 27
Joined: Thursday 03 April 2014 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sandnes / Norway
Contact:

Re: Virtual Temperature Sensor

Post 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]' ?
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Virtual Temperature Sensor

Post 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>')
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
panser
Posts: 27
Joined: Thursday 03 April 2014 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sandnes / Norway
Contact:

Re: Virtual Temperature Sensor

Post 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 :) ?
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Virtual Temperature Sensor

Post 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*)
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest