Page 1 of 1

calculation

Posted: Friday 05 June 2020 12:44
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
}

Re: calculation

Posted: Friday 05 June 2020 13:40
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
}

Re: calculation

Posted: Friday 05 June 2020 17:39
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
}

Re: calculation  [Solved]

Posted: Sunday 07 June 2020 9:02
by elbennito
i ended up using the multipliers on my analog inputboard to do the calculation.