Page 1 of 1

script produces error [Solved]

Posted: Friday 01 May 2020 12:13
by jkimmel
I switched from Raspi to Windows. The scripts were fine under Buster

Here is the script

Code: Select all

-- assumptions:
-- the setpoint is set by a selector dummy device where the values are numeric temperatures
-- but you can easily change it to a setpoint device

local BOILER_DEVICE = 'FB 23 Heizkreis Buero' -- switch device
local SETPOINT_DEVICE = 'Solltemperatur Buero' -- selector dummy device
local TEMPERATURE_SENSOR = 'Buero'
local MODUS_DEVICE = 'Modus Waermepumpe' -- selector dummy device
local LOGGING = false

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

    logging =   
    {
        level = LOGGING and domoticz.LOG_DEBUG or domoticz.LOG_ERROR or domoticz.LOG_INFO,
        marker = 'HZ Buero', 
    },
    active = true,
    execute = function(domoticz)

        local boiler = domoticz.devices(BOILER_DEVICE)

        local temperature = domoticz.devices(TEMPERATURE_SENSOR).temperature
        local setpoint = domoticz.devices(SETPOINT_DEVICE).levelName
        local modusState = domoticz.devices(MODUS_DEVICE).state

        local boilerState = boiler.state
        local setpointValue = tonumber(setpoint)

        domoticz.log('Current temperature: ' .. temperature, domoticz.LOG_DEBUG)
        domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_DEBUG)
        domoticz.log('Current boiler state: ' .. boilerState, domoticz.LOG_DEBUG)

        -- now determine what to do
       if setpoint == 'Off' or modusState ~= 'Heizen' then
             boiler.switchOff()
        elseif temperature > setpointValue and boilerState == 'On' then
            boiler.switchOff()
        elseif temperature <= setpointValue and boilerState == 'Off' and modusState == 'Heizen'  then
            boiler.switchOn()
        end
        
         if temperature > setpointValue then
            domoticz.log('Target temperature reached, boiler off', domoticz.LOG_INFO)
        else
            domoticz.log('Target temperature not reached, boiler on', domoticz.LOG_INFO)
        end
    end
}
producing the error:

Code: Select all

2020-05-01 12:09:00.400 Error: dzVents: Error: (3.0.2) HZ Buero: An error occurred when calling event handler Klima Buero
2020-05-01 12:09:00.400 Error: dzVents: Error: (3.0.2) HZ Buero: ...oticz\scripts\dzVents\generated_scripts/Klima Buero.lua:39: attempt to concatenate a nil value (local 'setpointValue')

Re: Two similar scripts one produces error the other not

Posted: Friday 01 May 2020 12:31
by waaren
jkimmel wrote: Friday 01 May 2020 12:13 -- the setpoint is set by a selector dummy device where the values are numeric temperatures
It seems that the setpoint (string) cannot be converted to a number.
can you change line 39 to

Code: Select all

        domoticz.log('Setpoint: ' .. tostring(setpoint), domoticz.LOG_DEBUG)
and show the result?

Re: script produces error

Posted: Friday 01 May 2020 13:04
by jkimmel
Now this:

Code: Select all

2020-05-01 13:03:00.383 Error: dzVents: Error: (3.0.2) HZ Buero: An error occurred when calling event handler Klima Buero
2020-05-01 13:03:00.383 Error: dzVents: Error: (3.0.2) HZ Buero: ...oticz\scripts\dzVents\generated_scripts/Klima Buero.lua:51: attempt to compare nil with number
It seems to me handling of setpointvalue is different running Windows, because under Buster no problems

Re: script produces error

Posted: Friday 01 May 2020 13:19
by waaren
jkimmel wrote: Friday 01 May 2020 13:04 Now this:

Code: Select all

2020-05-01 13:03:00.383 Error: dzVents: Error: (3.0.2) HZ Buero: An error occurred when calling event handler Klima Buero
2020-05-01 13:03:00.383 Error: dzVents: Error: (3.0.2) HZ Buero: ...oticz\scripts\dzVents\generated_scripts/Klima Buero.lua:51: attempt to compare nil with number
It seems to me handling of setpointvalue is different running Windows, because under Buster no problems
You need to set the level of logging to debug to see what is happening.

So change this part

Code: Select all

    logging =   
    {
        level = LOGGING and domoticz.LOG_DEBUG or domoticz.LOG_ERROR or domoticz.LOG_INFO,
        marker = 'HZ Buero', 
    },
to

Code: Select all

    logging =   
    {
       -- level = LOGGING and domoticz.LOG_DEBUG or domoticz.LOG_ERROR or domoticz.LOG_INFO,
        level = domoticz.LOG_DEBUG,
        marker = 'HZ Buero', 
    },

Re: script produces error

Posted: Friday 01 May 2020 14:13
by jkimmel
Status

Code: Select all

2020-05-01 14:06:00.222 Status: dzVents: Info: HZ Buero: ------ Start internal script: Klima Buero:, trigger: "every 3 minutes"
2020-05-01 14:06:00.232 Status: dzVents: Debug: HZ Buero: Processing device-adapter for FB 23 Heizkreis Buero: Switch device adapter
2020-05-01 14:06:00.232 Status: dzVents: Debug: HZ Buero: Processing device-adapter for Buero: Temperature+humidity device adapter
2020-05-01 14:06:00.232 Status: dzVents: Debug: HZ Buero: Processing device-adapter for Solltemperatur Buero: Switch device adapter
2020-05-01 14:06:00.232 Status: dzVents: Debug: HZ Buero: Processing device-adapter for Modus Waermepumpe: Switch device adapter
2020-05-01 14:06:00.232 Status: dzVents: Debug: HZ Buero: Current temperature: 23.39999961853
2020-05-01 14:06:00.240 Status: dzVents: Debug: HZ Buero: Setpoint: 25
2020-05-01 14:06:00.240 Status: dzVents: Debug: HZ Buero: Current boiler state: Off
2020-05-01 14:06:00.240 Status: dzVents: Debug: HZ Buero: Constructed timed-command: On
2020-05-01 14:06:00.240 Status: dzVents: Info: HZ Buero: Target temperature not reached, boiler on
2020-05-01 14:06:00.240 Status: dzVents: Info: HZ Buero: ------ Finished Klima Buero
2020-05-01 14:06:00.240 Status: dzVents: Debug: Commands sent to Domoticz:
2020-05-01 14:06:00.240 Status: dzVents: Debug: - FB 23 Heizkreis Buero = On
2020-05-01 14:06:00.240 Status: dzVents: Debug: 
Error:

Code: Select all

2020-05-01 14:03:00.211 Error: dzVents: Error: (3.0.2) HZ Buero: An error occurred when calling event handler Klima Buero
2020-05-01 14:03:00.211 Error: dzVents: Error: (3.0.2) HZ Buero: ...oticz\scripts\dzVents\generated_scripts/Klima Buero.lua:52: attempt to compare nil with number

Re: script produces error

Posted: Friday 01 May 2020 15:34
by waaren
jkimmel wrote: Friday 01 May 2020 14:13

Code: Select all

Error: (3.0.2) HZ Buero: ...oticz\scripts\dzVents\generated_scripts/Klima Buero.lua:52: attempt to compare nil with number
The script uses a mix of string and number without checking these. You need to add an additional check for that.

Can you try this?

Code: Select all

-- assumptions:
-- the setpoint is set by a selector dummy device where the values are numeric temperatures
-- but you can easily change it to a setpoint device

local BOILER_DEVICE = 'FB 23 Heizkreis Buero' -- switch device
local SETPOINT_DEVICE = 'Solltemperatur Buero' -- selector dummy device
local TEMPERATURE_SENSOR = 'Buero'
local MODUS_DEVICE = 'Modus Waermepumpe' -- selector dummy device
local LOGGING = false

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

    logging =   
    {
        -- level = LOGGING and domoticz.LOG_DEBUG or domoticz.LOG_ERROR or domoticz.LOG_INFO,
        level = domoticz.LOG_DEBUG,
        marker = 'HZ Buero', 
    },
    active = true,
    execute = function(domoticz)

        local boiler = domoticz.devices(BOILER_DEVICE)

        local temperature = domoticz.devices(TEMPERATURE_SENSOR).temperature
        local setpoint = domoticz.devices(SETPOINT_DEVICE).levelName
        local modusState = domoticz.devices(MODUS_DEVICE).state

        local boilerState = boiler.state
        local setpointValue = tonumber(setpoint) or -99  -- set it to -99 when setpoint is a string that cannot be converted to a number)  

        domoticz.log('Current temperature: ' .. temperature, domoticz.LOG_DEBUG)
        domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_DEBUG)
        domoticz.log('Current boiler state: ' .. boilerState, domoticz.LOG_DEBUG)

       -- now determine what to do
        if setpoint == 'Off' or modusState ~= 'Heizen' then
             boiler.switchOff()
             return
        end
        
        if setpointValue ~= -99 then
            if temperature > setpointValue and boilerState == 'On' then
                boiler.switchOff()
            elseif temperature <= setpointValue and boilerState == 'Off' and modusState == 'Heizen'  then
                boiler.switchOn()
            end
            
             if temperature > setpointValue then
                domoticz.log('Target temperature reached, boiler off', domoticz.LOG_INFO)
            else
                domoticz.log('Target temperature not reached, boiler on', domoticz.LOG_INFO)
            end
        end
    end
}

Re: script produces error

Posted: Friday 01 May 2020 19:24
by jkimmel
Answer as quick as ever.
Many thanks

Re: script produces error [Solved]

Posted: Saturday 02 May 2020 0:52
by HvdW
Hi,
I'm following this thread with interest.
Can you explain what is:

Code: Select all

local MODUS_DEVICE = 'Modus Waermepumpe' -- selector dummy device
Is it to know if the Boiler_device is on or off?
If so can you explain how to create a dummy device that shows the state?

Re: script produces error [Solved]

Posted: Saturday 02 May 2020 10:25
by jkimmel
stboiler
HvdW wrote: Saturday 02 May 2020 0:52 Hi,
I'm following this thread with interest.
Can you explain what is:

Code: Select all

local MODUS_DEVICE = 'Modus Waermepumpe' -- selector dummy device
Is it to know if the Boiler_device is on or off?
If so can you explain how to create a dummy device that shows the state?
In my case it is a selector which can be changed from "off" to heating or cooling. Nothing to do with the boiler.

Code: Select all

local boilerState = boiler.state
is what you're looking for