Temperature sensor  [Solved]

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

Moderator: leecollings

Post Reply
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Temperature sensor

Post by acaonweb »

Hi, i've noticed for the first time (my fault :) ) that next to the temperature sensor panel, there is an arrow that indicate probably the temperature is rising up or down
Cattura.PNG
Cattura.PNG (10.12 KiB) Viewed 3687 times
there's a way with dzevents to get that information?

Thanx in advance

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

Re: Temperature sensor

Post by waaren »

acaonweb wrote: Tuesday 04 June 2019 13:57 I've noticed that next to the temperature sensor panel, there is an arrow that indicate probably the temperature is rising up or down
there's a way with dzVents to get that information?
Not directly but a relative simple method, using persistent data, to achieve this

Code: Select all

local sensors = {433, 530, 591, 842, 1639} -- lest of temperature sensors that you want to watch for trend
return
{
    on = { devices = sensors }, 
    logging = {level = domoticz.LOG_ERROR, marker = 'Temperature ' },
    data = { sensors = { initial = {}}},

    execute = function(dz,item)
        lastMeasuredTemperature = dz.data.sensors[item.id]
        newTemperature = dz.utils.round(item.temperature,2)

        local function message(trend)
            dz.log ('trend for ' .. item.name .. ' is ' .. (trend or 'stable'),dz.LOG_FORCE)
        end

        if not lastMeasuredTemperature then message()
        elseif lastMeasuredTemperature ==  newTemperature then message() 
        elseif lastMeasuredTemperature <  newTemperature then message('up') 
        else message('down') 
        end
        dz.data.sensors[item.id] = newTemperature
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temperature sensor

Post by acaonweb »

thanx, your script are so useful because they make me learn lua and dzevents so good.
i hoped to get this data directly, but the script is very simple... i'm just worried about use persistent data for the rpi3's perfomance :)
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temperature sensor

Post by acaonweb »

Another question:
it's possible to have functions available for every scripts? A sort of "libraries of common functions"?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temperature sensor

Post by waaren »

acaonweb wrote: Friday 07 June 2019 9:22 i'm just worried about use persistent data for the rpi3's perfomance :)
The Lua engine in domoticz is driving the IO with the persistent data and from what I see it's doing that quite efficient. I never noticed any delay in the dzVents scripts as a result of using persistent data. One thing to be be aware of is the wearing of the SD card over time.
Always ensure you have a recent clone of the card and also make frequent backups of your database and external scripts / data.
One of the reasons why I do my IO to my NAS using berryboot :)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temperature sensor

Post by waaren »

acaonweb wrote: Friday 07 June 2019 9:46 Another question:
it's possible to have functions available for every scripts? A sort of "libraries of common functions"?
Sure. Have a look at this topic of the dzVents wiki
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temperature sensor

Post by acaonweb »

waaren wrote: Friday 07 June 2019 9:55
acaonweb wrote: Friday 07 June 2019 9:22 i'm just worried about use persistent data for the rpi3's perfomance :)
The Lua engine in domoticz is driving the IO with the persistent data and from what I see it's doing that quite efficient. I never noticed any delay in the dzVents scripts as a result of using persistent data. One thing to be be aware of is the wearing of the SD card over time.
Always ensure you have a recent clone of the card and also make frequent backups of your database and external scripts / data.
One of the reasons why I do my IO to my NAS using berryboot :)
im really newbie.. how do that?
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temperature sensor

Post by acaonweb »

waaren wrote: Friday 07 June 2019 9:57
acaonweb wrote: Friday 07 June 2019 9:46 Another question:
it's possible to have functions available for every scripts? A sort of "libraries of common functions"?
Sure. Have a look at this topic of the dzVents wiki
Do if i write a script called global_data with the internal script editor, i can put functions in the same way ad a local function calling them with .helpers?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temperature sensor  [Solved]

Post by waaren »

acaonweb wrote: Friday 07 June 2019 10:09
waaren wrote: Friday 07 June 2019 9:55
acaonweb wrote: Friday 07 June 2019 9:22 i'm just worried about use persistent data for the rpi3's perfomance :)
One of the reasons why I do my IO to my NAS using berryboot :)
im really newbie.. how do that?
https://www.berryterminal.com/doku.php/ ... sing_iscsi
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Temperature sensor

Post by waaren »

acaonweb wrote: Friday 07 June 2019 10:15
waaren wrote: Friday 07 June 2019 9:57
acaonweb wrote: Friday 07 June 2019 9:46 Another question:
it's possible to have functions available for every scripts? A sort of "libraries of common functions"?
Sure. Have a look at this topic of the dzVents wiki
Do if i write a script called global_data with the internal script editor, i can put functions in the same way ad a local function calling them with .helpers?
Yes. if you have a function in the helpers section of global_data.lua you call it with dz.helpers.<name of function>
If the function needs anything from the domoticz object you will have to pass a pointer to the domoticz object to it.

example global_data.lua

Code: Select all

-- global_data.lua 
 
return 
{
    
    data =
    {
        hostname                                = { initial = "notset" },
    },

    helpers =
    {

        hostname = function(dz)
            if dz.globalData.hostname ~= "notset" then return dz.globalData.hostname end
            local fileHandle     = assert(io.popen("hostname", 'r'))
            local commandOutput  = assert(fileHandle:read('*a'))
            fileHandle:close()
            dz.globalData.hostname = commandOutput
            return commandOutput
        end,
        
        myYouless = function(dz)
            return dz.devices('Youless').powerYield
        end,

    },
}
example call to helper function hostname

Code: Select all

dz.log(dz.helpers.hostname(dz))
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