Problem writing value in custom sensor  [Solved]

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

Moderator: leecollings

Post Reply
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Problem writing value in custom sensor

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem writing value in custom sensor

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Problem writing value in custom sensor  [Solved]

Post by dutchronnie »

Thanks, That was the solution.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest