[Solved] Need some help with a script  [Solved]

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

Moderator: leecollings

Post Reply
darkdude
Posts: 7
Joined: Thursday 20 June 2019 7:41
Target OS: Linux
Domoticz version: Release
Location: Poland
Contact:

[Solved] Need some help with a script  [Solved]

Post by darkdude »

Hello,
I need some help in finding a mistake in this script:

Code: Select all

return 
{
    on = 
    {    
        devices = 
        {
            "Bufor - GÓRA",
        },
    },
    
    data = 
    { 
        count = 
        { 
            initial = 0, 
        },
        temp =
        {
            initial = 0,
        },
    },
     
     logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'nagrzewaniePiecem',
    },
 
   execute = function(domoticz)
       
                    
       if domoticz.data.count == 0 then
            domoticz.data.temp = domoticz.devices("Bufor - GÓRA").temperature
            domoticz.data.count = domoticz.data.count + 1
            domoticz.notify('0')
       
       elseif domoticz.data.count > 0 and domoticz.data.count < 2 then
           domoticz.data.count = domoticz.data.count + 1
           domoticz.notify('1')
       
       elseif domoticz.data.count == 2 then
           local ratio = domoticz.devices("Bufor - GÓRA").temperature - domoticz.data.temp
           domoticz.notify('2')
           if ratio > 0.3 and ratio < 5 then
               domoticz.variables("nagrzewanie_piecem").set(1)
               
           else
               domoticz.variables("nagrzewanie_piecem").set(0)
               
           end
           
           domoticz.data.count = 0 
       end
               
     end  
}
It's purpose is to determine if a gas heater is working, based on differences in temperature readings. A sensor is updated every 10 seconds and the script is called. On first run it should put a reading into temperature variable. On second run it should only increase run counter. On the third run it should cmpare past reading to present one, change a variable and reset run counter.

It runs OK, does not report any errors but for some reason noting printed to log apart from information about script being processed. And variable is not updated.

Regards,
Last edited by darkdude on Friday 30 October 2020 23:40, edited 1 time in total.
darkdude
Posts: 7
Joined: Thursday 20 June 2019 7:41
Target OS: Linux
Domoticz version: Release
Location: Poland
Contact:

Re: Need some help with a script

Post by darkdude »

I don't know what the initial problem was, but... at some point the counter passed 2 (which should never happen) and continued up to infinity :) Adding a line which reinitialized it after passing 2 solved the case.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest