Page 1 of 1

Problem using Costum sensor

Posted: Wednesday 20 January 2021 10:30
by YOYO
Hi,

Im trying to get data from my wMbus to do some calculations.
In order to do this i'm pushing data using MQTT to a Costum device which i then want to use in a dzvents script.

Unfortunately i cant use any data not even with a simple print script.
I tried different sollutions including the stuff provided in the wiki but i cant get it to work.

Can somebody help me on my wayy?

Script to run:

Code: Select all

return {
	on = {
		timer = {
			'every minute',              -- causes the script to be called every minute
	   },
    },
	execute = function(domoticz, timer)

local TempInSensor = 'Stadsverwarming Aanvoer'
local TempOutSensor = domoticz.devices(248)
local Temp_IN = tonumber(TempInSensor.state)
local Temp_Retour = tonumber(TempOutSensor.state)
print('Temp In' .. TEMP_IN .. '°C' )

--local Delta_T = Temp_In -  Temp_Retour
--print('Delta T van Stadsverwarming =' .. Delta_T ..'°C' )

--local Water_M = 1000 * ((domoticz.devices(246).nValue) / 3600)
--print('Watermassa van Stadsverwarming =' .. Water_M .. 'kg')

--local Actueel_Vermogen = Water_M * 4180 * Delta_T
-- print('Actueel vermogen van Stadsverwarming =' .. Actueel_Vermogen .. 'kW')
	end
}
Error code:

Code: Select all

2021-01-20 10:23:00.141 Error: dzVents: Error: (3.0.2) /config/scripts/dzVents/generated_scripts/Script #3.lua:13: attempt to concatenate a nil value (global 'TEMP_IN')

Re: Problem using Costum sensor

Posted: Wednesday 20 January 2021 10:57
by waaren
YOYO wrote: Wednesday 20 January 2021 10:30 Can somebody help me on my wayy?

Error code:

Code: Select all

2021-01-20 10:23:00.141 Error: dzVents: Error: (3.0.2) /config/scripts/dzVents/generated_scripts/Script #3.lua:13: attempt to concatenate a nil value (global 'TEMP_IN')
Can you try this one?

btw what type of devices are these?
If they are temperature sensors you don't have to use the generic state but can use the temperature attribute.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'every minute',              -- causes the script to be called every minute
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Stadsverwarming',
    },

    execute = function(domoticz, timer)

        local TempInSensor = domoticz.devices('Stadsverwarming Aanvoer')
        local TempOutSensor = domoticz.devices(248)
        local Temp_IN = TempInSensor.state
        local Temp_Retour = tonumber(TempOutSensor.state)

        domoticz.log('Temp In ' .. TEMP_IN .. ' °C' , domoticz.LOG_FORCE )

        --local Delta_T = Temp_In -  Temp_Retour
        --print('Delta T van Stadsverwarming =' .. Delta_T ..'°C' )

        --local Water_M = 1000 * ((domoticz.devices(246).nValue) / 3600)
        --print('Watermassa van Stadsverwarming =' .. Water_M .. 'kg')

        --local Actueel_Vermogen = Water_M * 4180 * Delta_T
        -- print('Actueel vermogen van Stadsverwarming =' .. Actueel_Vermogen .. 'kW')
    end
}

Re: Problem using Costum sensor

Posted: Wednesday 20 January 2021 11:26
by YOYO
Hi Waaren,

Here is the result for youre code:

Code: Select all

 2021-01-20 11:19:00.267 Error: dzVents: Error: (3.0.2) /config/scripts/dzVents/generated_scripts/Script #3.lua:13: attempt to concatenate a nil value (global 'TEMP_IN')
2021-01-20 11:19:00.268 Error: dzVents: Error: (3.0.2) Stadsverwarming: An error occurred when calling event handler Script #4
2021-01-20 11:19:00.268 Error: dzVents: Error: (3.0.2) Stadsverwarming: /config/scripts/dzVents/generated_scripts/Script #4.lua:24: attempt to concatenate a nil value (global 'TEMP_IN') 
btw what type of devices are these?
If they are temperature sensors you don't have to use the generic state but can use the temperature attribute.
Its a costum sensor.
Here is the device info:

Code: Select all

idx		Hardware		ID		UNIT		Name		Type		Subtype		Data	
248		wmbus sensoren		00082248		1		Stadsverwarming Retour		General		Custom Sensor		22.32 °C

Re: Problem using Costum sensor

Posted: Wednesday 20 January 2021 12:08
by waaren
YOYO wrote: Wednesday 20 January 2021 11:26

Code: Select all

2021-01-20 11:19:00.268 Error: dzVents: Error: (3.0.2) Stadsverwarming: An error occurred when calling event handler Script #4
2021-01-20 11:19:00.268 Error: dzVents: Error: (3.0.2) Stadsverwarming: /config/scripts/dzVents/generated_scripts/Script #4.lua:24: attempt to concatenate a nil value (global 'TEMP_IN') 
Case matters !

Change

Code: Select all

        domoticz.log('Temp In ' .. TEMP_IN .. ' °C' , domoticz.LOG_FORCE )
to

Code: Select all

        domoticz.log('Temp In ' .. Temp_IN .. ' °C' , domoticz.LOG_FORCE )

Re: Problem using Costum sensor  [Solved]

Posted: Wednesday 20 January 2021 12:15
by YOYO
Yes thats giving something:

Code: Select all

 2021-01-20 12:12:00.293 Status: dzVents: Info: Stadsverwarming: ------ Start internal script: Script #4:, trigger: "every minute"
2021-01-20 12:12:00.293 Status: dzVents: !Info: Stadsverwarming: Temp In 69.38 °C
2021-01-20 12:12:00.293 Status: dzVents: Info: Stadsverwarming: ------ Finished Script #4 

Re: Problem using Costum sensor

Posted: Wednesday 20 January 2021 15:39
by YOYO
@waaren

You where right checked the whole script on typ errors and found some.
Many thanks! :D