collect data from multiple temp sensors in one sensor

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

Moderator: leecollings

Post Reply
svdhaar
Posts: 36
Joined: Friday 10 April 2020 7:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

collect data from multiple temp sensors in one sensor

Post by svdhaar »

Hi,

is it possible to collect the temperature data from different temp sensors and store / show them in a custom sensor?
i have 3 temp sensors which shows temperature data from my Nas (CPU / HDD1 & HDD2).

my goal is to present this data in one sensor. Main reason is to save space on screen :-)

I'm not a programmer.. found a little script and was trying a bit. With no luck..

anyone with some tips? :-)

Code: Select all


return {
      on = { 
        timer = {
           'every 1 minutes'            
        },
    }, 
    execute = function(domoticz, device, timer)

        local tempnas      = domoticz.devices('NAS - Temp')
        local temphd1       = domoticz.devices('NAS - Temp hd1')
        local temphd2       = = domoticz.devices('NAS - Temp hd2')
        local Temptest      = domoticz.devices('NAS - TEMP test')

      
        
          Temptest.updateCustomSensor(tempnas, temphd1, temphd2)
          
          
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by waaren »

svdhaar wrote: Monday 22 February 2021 15:50 my goal is to present this data in one sensor. Main reason is to save space on screen :-)
On what screen? You add a device that will also be visible on a screen. So you go from 3 to 4 devices?
anyone with some tips? :-)
A custom sensor can only display one value so you could average the 3 temperatures but not display all 3.
You could use a text sensor to display multiple values
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
svdhaar
Posts: 36
Joined: Friday 10 April 2020 7:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by svdhaar »

waaren wrote: Monday 22 February 2021 16:05
svdhaar wrote: Monday 22 February 2021 15:50 my goal is to present this data in one sensor. Main reason is to save space on screen :-)
On what screen? You add a device that will also be visible on a screen. So you go from 3 to 4 devices?
anyone with some tips? :-)
A custom sensor can only display one value so you could average the 3 temperatures but not display all 3.
You could use a text sensor to display multiple values
Do you have an coding example?

i'm using aurora which makes the graphic a bit nicer. ultimate goal is to screw an ipad onto the wall.
as you can see i have NAS sensors shoing data. i would like to add some more.
6 items is the max. thats why i would like to combine the 3 temp values in one sensor.

Image
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by waaren »

svdhaar wrote: Monday 22 February 2021 17:51 Do you have an coding example?
Sure..

Code: Select all


return 
{
    on = 
    { 
        timer = 
        {
           'every minute',
        },
    }, 
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'combine values',
    },
    
    execute = function(dz)

        local tempnas = dz.devices('Combined NAS - Temp') -- create as text sensor
        
        local temphd1 = dz.devices('NAS - Temp hd1')
        local temphd2 = dz.devices('NAS - Temp hd1')
        local Temptest = dz.devices('NAS - TEMP test')

        local text = 
            temphd1.name .. ': ' .. dz.utils.round(temphd1.temperature,1) ..' °C\n' ..
            temphd2.name .. ': ' .. dz.utils.round(temphd2.temperature,1) ..' °C\n' ..
            Temptest.name .. ': ' .. dz.utils.round(Temptest.temperature,1) ..  ' °C'

        if tempnas.text ~= text then tempnas.updateText(text) end

    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
svdhaar
Posts: 36
Joined: Friday 10 April 2020 7:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by svdhaar »

waaren wrote: Monday 22 February 2021 19:33
svdhaar wrote: Monday 22 February 2021 17:51 Do you have an coding example?
Sure..

Code: Select all


return 
{
    on = 
    { 
        timer = 
        {
           'every minute',
        },
    }, 
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'combine values',
    },
    
    execute = function(dz)

        local tempnas = dz.devices('Combined NAS - Temp') -- create as text sensor
        
        local temphd1 = dz.devices('NAS - Temp hd1')
        local temphd2 = dz.devices('NAS - Temp hd1')
        local Temptest = dz.devices('NAS - TEMP test')

        local text = 
            temphd1.name .. ': ' .. dz.utils.round(temphd1.temperature,1) ..' °C\n' ..
            temphd2.name .. ': ' .. dz.utils.round(temphd2.temperature,1) ..' °C\n' ..
            Temptest.name .. ': ' .. dz.utils.round(Temptest.temperature,1) ..  ' °C'

        if tempnas.text ~= text then tempnas.updateText(text) end

    end
}

NICE!

thx! working like a charm :-).

would it be possible to cut of the name of the device? and show the values without the .0?

As you can see the with is maximized
output like this:
21°C 21°C 40°C


Image
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by waaren »

svdhaar wrote: Tuesday 23 February 2021 7:50 would it be possible to cut of the name of the device? and show the values without the .0?
Sure, change the local text part to

Code: Select all

        local text = 
            dz.utils.round(temphd1.temperature) ..'°C\n' ..
            dz.utils.round(temphd2.temperature) ..'°C\n' ..
            dz.utils.round(Temptest.temperature) ..  '°C'
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
svdhaar
Posts: 36
Joined: Friday 10 April 2020 7:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by svdhaar »

waaren wrote: Tuesday 23 February 2021 8:38
svdhaar wrote: Tuesday 23 February 2021 7:50 would it be possible to cut of the name of the device? and show the values without the .0?
Sure, change the local text part to

Code: Select all

        local text = 
            dz.utils.round(temphd1.temperature) ..'°C\n' ..
            dz.utils.round(temphd2.temperature) ..'°C\n' ..
            dz.utils.round(Temptest.temperature) ..  '°C'
Thank you!! :D :D
svdhaar
Posts: 36
Joined: Friday 10 April 2020 7:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by svdhaar »

svdhaar wrote: Tuesday 23 February 2021 8:48
waaren wrote: Tuesday 23 February 2021 8:38
svdhaar wrote: Tuesday 23 February 2021 7:50 would it be possible to cut of the name of the device? and show the values without the .0?
Sure, change the local text part to

Code: Select all

        local text = 
            dz.utils.round(temphd1.temperature) ..'°C\n' ..
            dz.utils.round(temphd2.temperature) ..'°C\n' ..
            dz.utils.round(Temptest.temperature) ..  '°C'
Thank you!! :D :D
I would like to perform this arithmic on my internet speed sensors. Those are custom sensors.
Where can i find the needed atributes? i've tried .values, with no luck :-) : attempt to perform arithmetic on a nil value (local 'x')

Code: Select all

return 
{
    on = 
    { 
        timer = 
        {
           'every 1 minutes',
        },
    }, 
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'combine values',
    },
    
    execute = function(dz)

        local speed = dz.devices('Speed') -- create as text sensor
        
        local download = dz.devices('Internet - Download')
        local upload = dz.devices('Internet - Upload')
        local ping = dz.devices('Internet - Ping')

        local text = 
            dz.utils.round(download.values) ..
            dz.utils.round(upload.values) ..
            dz.utils.round(ping.values) ..  ''

        if speed.text ~= text then speed.updateText(text) end

    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by waaren »

svdhaar wrote: Tuesday 23 February 2021 9:43 I would like to perform this arithmic on my internet speed sensors. Those are custom sensors.
Where can i find the needed atributes? i've tried .values, with no luck :-) : attempt to perform arithmetic on a nil value (local 'x')
Did you try to find it in the https://www.domoticz.com/wiki/DzVents:_ ... nts wiki ?
There you will see that the attributes name is "sensorValue" (version >= 3.0.11) if you are on an older build you can try sValue or rawData[1]
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
svdhaar
Posts: 36
Joined: Friday 10 April 2020 7:01
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by svdhaar »

waaren wrote: Tuesday 23 February 2021 10:14
svdhaar wrote: Tuesday 23 February 2021 9:43 I would like to perform this arithmic on my internet speed sensors. Those are custom sensors.
Where can i find the needed atributes? i've tried .values, with no luck :-) : attempt to perform arithmetic on a nil value (local 'x')
Did you try to find it in the https://www.domoticz.com/wiki/DzVents:_ ... nts wiki ?
There you will see that the attributes name is "sensorValue" (version >= 3.0.11) if you are on an older build you can try sValue or rawData[1]
thx, wil use this wiki site before posting questions :-)
i'm using domo 2020.1

i've added .sensorValue attribute. that returns an error

Code: Select all

return 
{
    on = 
    { 
        timer = 
        {
           'every 1 minutes',
        },
    }, 
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'combine values',
    },
    
    execute = function(dz)

        local speed = dz.devices('Speed') -- create as text sensor
        
        local download = dz.devices('Internet - Download')
        local upload = dz.devices('Internet - Upload')
        local ping = dz.devices('Internet - Ping')

        local text = 
            dz.utils.round(download.sensorValue) ..
            dz.utils.round(upload.sensorValue) ..
            dz.utils.round(ping.sensorValue)

        if speed.text ~= text then speed.updateText(text) end

    end
}
attempt to perform arithmetic on a nil value (local 'x')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: collect data from multiple temp sensors in one sensor

Post by waaren »

svdhaar wrote: Tuesday 23 February 2021 11:14 attempt to perform arithmetic on a nil value (local 'x')
Your version does not support this attribute
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest