Problem using Costum sensor  [Solved]

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

Moderator: leecollings

Post Reply
YOYO
Posts: 27
Joined: Tuesday 09 June 2015 21:22
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.23393
Location: The Netherlands
Contact:

Problem using Costum sensor

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

Re: Problem using Costum sensor

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
YOYO
Posts: 27
Joined: Tuesday 09 June 2015 21:22
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.23393
Location: The Netherlands
Contact:

Re: Problem using Costum sensor

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

Re: Problem using Costum sensor

Post 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 )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
YOYO
Posts: 27
Joined: Tuesday 09 June 2015 21:22
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.23393
Location: The Netherlands
Contact:

Re: Problem using Costum sensor  [Solved]

Post 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 
YOYO
Posts: 27
Joined: Tuesday 09 June 2015 21:22
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.23393
Location: The Netherlands
Contact:

Re: Problem using Costum sensor

Post by YOYO »

@waaren

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

Who is online

Users browsing this forum: No registered users and 1 guest