Issues with DzVents since update  [SOLVED]

Moderator: leecollings

Post Reply
MarkEs
Posts: 2
Joined: Wednesday 05 May 2021 7:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Issues with DzVents since update

Post by MarkEs »

Version: 2021.1
Platform: Pi
Plugin/Hardware: DzVents
Description:
After the update to 2021.1 yesterday, my custom events (from DzVents) are no longer working. Looks like the raw customEvent data does not come through.

Triggers:

Code: Select all

http://###.###.###.###:####/json.htm?type=command&param=customevent&event=Heating%20on&data=[{"trigger":"JSON","delay":"0"}] -- JSON-url
domoticz.emitEvent('Heating on', {{trigger = item.trigger, delay = 0}, {''}}) --Script
The script that handles the custom event:

Code: Select all

local strTriggerData = item.trigger .. ', ' .. item.data[1].trigger .. ', ' .. item.data[1].delay
Error in log:
2021-05-05 07:44:00.479 Error: dzVents: Error: (3.1.7) An error occurred when calling event handler Shutter V2
2021-05-05 07:44:00.479 Error: dzVents: Error: (3.1.7) ...omoticz/scripts/dzVents/generated_scripts/Shutter V2.lua:9: attempt to index a nil value (field '?')
The custom event is recognized in the follow-up script, but the additional data is not.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Issues with DzVents since update  [SOLVED]

Post by waaren »

MarkEs wrote: Wednesday 05 May 2021 13:48 The custom event is recognized in the follow-up script, but the additional data is not.
item.data is a string but you try to access it as a table.

You can test with.

Code: Select all

return
{
    on =
    {
        customEvents =
        {
            'Heating on' -- event triggered by emitEvent
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },

    execute = function(dz, item)

        local strTriggerData = item.trigger .. ', ' .. item.json[1].trigger .. ', ' .. item.json[1].delay
        dz.log('\n', dz.LOG_DEBUG)
        dz.log('trigger, source, delay ==>> ' .. strTriggerData,dz.LOG_DEBUG)

        dz.log('Type item.data         ==>> ' .. type(item.data), dz.LOG_DEBUG )
        dz.log('Type item.json         ==>> ' .. type(item.json), dz.LOG_DEBUG )
        dz.log('\n', dz.LOG_DEBUG)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarkEs
Posts: 2
Joined: Wednesday 05 May 2021 7:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Issues with DzVents since update

Post by MarkEs »

Hi waaren, thank you for your reply and solution. That does work, I just came across the ' domoticz.utils.fromJSON' function, but your solution is much more elegant.

But what about a custom event comming from DzVents itself (using ' domoticz.emitEvent')?

My handler scripts receive custom events from either JSON or other scripts. Should I distinguish between the two and use something like 'item.lines[1].trigger' for custom events triggered by DzVents?

I guess I was lucky, having it working before the update..

So I came to this solution and it works:

Code: Select all

            local eventData = {}
            if item.isJSON == true then
               eventData = item.json[1]
            elseif item.hasLines == true then
                eventData = item.lines
            end
            local strTriggerData = item.trigger .. ', ' .. eventData.trigger .. ', ' .. eventData.delay
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Issues with DzVents since update

Post by waaren »

MarkEs wrote: Wednesday 05 May 2021 17:12 But what about a custom event from DzVents itself (using ' domoticz.emitEvent')?
There is no difference between the internal handling of item.data based on where it originated from. If it is recognized as a valid JSON, a Lua table with the converted JSON is put in item.json
The item.data will not change.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest