calculation  [Solved]

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

Moderator: leecollings

Post Reply
elbennito
Posts: 21
Joined: Tuesday 27 February 2018 18:19
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

calculation

Post by elbennito »

help:
I Have a chlorine sensor connected to domoticz. (this is a analog sensor)
name in domoticz: chloor.
I want to make a calculation with the value (devide by 1.4)
That value should then update a dummy sensor named: chloorcal
this is what I have now. But it doesnt work. Any idea anybody?

Code: Select all

return {
      on = { 
        timer = {
           'every 1 minutes'            
        },
    }, 
    execute = function(domoticz, device, timer)
        local chloorcal  = domoticz.devices('chloorcal')
        local chloor  = domoticz.devices('chloor')
        local factor = 1.4
        local chloorcal = tonumber(domoticz.utils.round (chloor / factor) )   
          chloorcal.updateCustomSensor(chloorcal)
    end
}
elbennito
Posts: 21
Joined: Tuesday 27 February 2018 18:19
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: calculation

Post by elbennito »

update, but still not working

Code: Select all

CODE: SELECT ALL

return {
      on = { 
        timer = {
           'every 1 minutes'            
        },
    }, 
    execute = function(domoticz, device, timer)
        local chloorcal  = domoticz.devices('chloorcal')
        local chloor  = domoticz.devices('chloor').value
        local factor = 1.4
        local chloorcal = tonumber(domoticz.utils.round (chloor / factor) )   
          chloorcal.updateCustomSensor(chloorcal)
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: calculation

Post by waaren »

elbennito wrote: Friday 05 June 2020 13:40 update, but still not working
value is not one of the attributes of a device. So in your script it will always be nil.

What type / subtype is your chloor device (as seen on the devices tab)?
What is your domoticz / dzVents version?

When debugging a script it helps to add some logging.

Below script might show some useful information in the log

Code: Select all

return
{
    on =
    {
        timer =
        {
           'every 1 minutes',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Chloor',
    },

    execute = function(domoticz)
        local chloorcal  = domoticz.devices('chloorcal')
        local chloor  = domoticz.devices('chloor')

        domoticz.log('deviceType chloor: ' .. chloor.deviceType,domoticz.LOG_DEBUG)
        domoticz.log('deviceSubType chloor: ' .. chloor.deviceSubType,domoticz.LOG_DEBUG)
        domoticz.log('nValue chloor: ' .. chloor.nValue,domoticz.LOG_DEBUG)
        domoticz.log('sValue chloor: ' .. chloor.sValue,domoticz.LOG_DEBUG)

        local factor = 1.4
        --local chloorcal = tonumber(domoticz.utils.round (chloor / factor) )
        --chloorcal.updateCustomSensor(chloorcal)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
elbennito
Posts: 21
Joined: Tuesday 27 February 2018 18:19
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: calculation  [Solved]

Post by elbennito »

i ended up using the multipliers on my analog inputboard to do the calculation.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest