Page 1 of 1

Problem writing value in custom sensor

Posted: Thursday 05 November 2020 14:26
by dutchronnie
I have an IBC filled with water, and want to see the following

filled in %
how many liters

I get the distance and percentage in domoticz, but i am not able to see the amount of liters.

i am using the following script

Code: Select all

return {
     on = {
                devices =   {
                                'Niveau Regenwater'
                            },
        },
   
   logging = {
                level = domoticz.LOG_INFO,
                marker = "Converter"
             },    
    
    execute = function(dz, item)
        local inverted              = false          -- if max value of sensor should be reflected in 0% and minValue in 100% 
        local dataFromSensor        = item.rawData[1]
        local maxValue              = 920
        local minValue              = 0
        local decimals              = 0
        local percentage            = ( dataFromSensor - minValue ) / ( maxValue - minValue ) * 1000
        local liters                = ( dataFromSensor * 0.92 )
     
          
        if inverted then 
               percentage = 100 - percentage 
        end
          
        local roundedPercentage     = dz.utils.round(percentage,decimals )
        local percentageDevice      = dz.devices('Percentage IBC gevuld')
        local roundedLiters         = dz.utils.round(liters,decimals )
        local litersDevice          = dz.devices('Liters')


        dz.log("Rounded percentage is " ..  roundedPercentage .. "%")
        percentageDevice.updatePercentage(roundedPercentage)
        
        dz.log("Rounded liters is " ..  roundedLiters .. "Ltr")
        litersDevice.update(roundedLiters)
        

     end
}
In the log i see that the ibc is filed for 23%
and that the amount of liters is: 19 Liter

but the value is not writen in the custom sensor

I hope somebody can help

Re: Problem writing value in custom sensor

Posted: Thursday 05 November 2020 15:38
by waaren
dutchronnie wrote: Thursday 05 November 2020 14:26

Code: Select all

        litersDevice.update(roundedLiters)
In the log i see that the ibc is filed for 23%
and that the amount of liters is: 19 Liter

but the value is not writen in the custom sensor

I hope somebody can help
Please search the wiki
The method to update a custom Sensor is.... updateCustomSensor(value)

Re: Problem writing value in custom sensor  [Solved]

Posted: Thursday 05 November 2020 21:08
by dutchronnie
Thanks, That was the solution.