Page 1 of 1

NooB question: how to send URl when switch is pressed?

Posted: Sunday 19 December 2021 13:06
by Sjonnie2017
Hi,

I have a probably simple question about sending a URL when a button is pressed. I have read the documentation but I am afraid programming is not my forte and I can't make heads or tails of it. But I do need this so I can fully use my Shelly 2.5 switches (roller shutter mode) with my Zigbee 2-gang switches.

So I hope you will be able to help me.

I have a dzVents script that triggers my roller shutter on the press of a button. This used to work flawlessly with my Zigbee roller shutter device. I have replaced the Zigbee roller shutter device with a Shelly 2.5. The plugin does not support the "stop" command but I have found out I can send a URL request that stops the roller shutter.

Now I am struggling to get the dzVents script to send the url.

The URL looks like this:

Code: Select all

http://192.168.xxx.yyy/roller/0?go=stop
The original dzVents script looks like his:

Code: Select all

--Control Zigbee roller shutter module QS-ZIGBEE-C01 with additional switch (Aqara WXKG07LM)

return
{

    on =
    {
        devices =
        {
            'Schakelaar Keuken 2',
        },
    },

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

    execute = function(dz, item)
        if item.state == '10' or item.state == 'B1' then
            dz.devices(396).open()
        elseif item.state == '20' or item.state == 'B2' then
            dz.devices(396).close()
        elseif item.state == '30' or item.state == 'B3'then
            dz.devices(396).stop()
--            domoticz.openURL('http://192.168.xxx.yyy/roller/0?go=stop')
        end
        dz.log(item.state, dz.LOG_DEBUG)
    end
}
I tried to send the URL as you can see in the comment line. But if I uncomment that line (and comment the line above it) it does not work.

What do I need to change?

Thanks in advance!

Re: NooB question: how to send URl when switch is pressed?

Posted: Sunday 19 December 2021 22:43
by keros
The line doesn't work but you should have some info in the DomoticZ logs.

In your case, you have definied execute = function(dz, item) and use it dz.devices(396).open() or dz.log(item.state, dz.LOG_DEBUG). That is why domoticz.openURL('http://192.168.xxx.yyy/roller/0?go=stop') is not recognized.

Re: NooB question: how to send URl when switch is pressed?

Posted: Monday 20 December 2021 18:25
by Sjonnie2017
Hi,

Thanks for your reply.

I found this in the log after I pressed the button(s) on the switch:

Code: Select all

2021-12-20 18:39:44.013 ConBee2: (ConBee2) ### Update device (Schakelaar Keuken 2) : {'nValue': 30, 'sValue': '30'}
2021-12-20 18:39:44.099 Status: dzVents: Info: Handling events for: "Schakelaar Keuken 2", value: "B3"
2021-12-20 18:39:44.099 Status: dzVents: Info: roomSwitcher: ------ Start internal script: DzV - Schakelaar Luik Keuken: Device: "Schakelaar Keuken 2 (ConBee2)", Index: 394
2021-12-20 18:39:44.099 Status: dzVents: Info: roomSwitcher: ------ Finished DzV - Schakelaar Luik Keuken
2021-12-20 18:39:44.099 Error: dzVents: Error: (3.1.7) roomSwitcher: An error occurred when calling event handler DzV - Schakelaar Luik Keuken
2021-12-20 18:39:44.099 Error: dzVents: Error: (3.1.7) roomSwitcher: ...Vents/generated_scripts/DzV - Schakelaar Luik Keuken.lua:27: attempt to index a nil value (global 'domoticz')
2021-12-20 18:39:46.531 ConBee2: (ConBee2) onMessage called
Not sure what that means though :oops:

Help much appreciated!

Re: NooB question: how to send URl when switch is pressed?

Posted: Monday 20 December 2021 20:11
by waltervl
Replace domoticz.openURL by dz.openURL

Re: NooB question: how to send URl when switch is pressed?

Posted: Monday 20 December 2021 20:14
by keros

Code: Select all

Keuken.lua:27: attempt to index a nil value (global 'domoticz')
Means that on line 27 there is a variable domoticz that does not exist. The good variable to use in your code is dz, which you defined previously (see my post above).

Re: NooB question: how to send URl when switch is pressed?

Posted: Monday 20 December 2021 20:17
by Sjonnie2017
Thank you both for your support. I will test and report back.

Re: NooB question: how to send URl when switch is pressed?

Posted: Tuesday 21 December 2021 18:00
by Sjonnie2017
Gentlemen,

I adjusted the code as per your instructions and I can confirm the stop function is now working.

Thank you both for your support! Truly appreciated!!