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

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

Moderator: leecollings

Post Reply
User avatar
Sjonnie2017
Posts: 375
Joined: Wednesday 02 August 2017 19:43
Target OS: Linux
Domoticz version: Latest ß
Location: The Netherlands
Contact:

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

Post 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!
ConBee II - TRÅDFRI lights + switches, loads of ChingLing dimmers and switches, Heiman and Xiaomi sensors
SolarEdge SE4000H (with active modbus_tcp)
YouLess Energy meter
Shelly 2.5 in roller shutter mode
keros
Posts: 77
Joined: Saturday 27 July 2019 0:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Moderator on Easydomoticz.com, the French DomoticZ forum.
French writer for ZigBeeForDomoticZ Plugin Wiki
User avatar
Sjonnie2017
Posts: 375
Joined: Wednesday 02 August 2017 19:43
Target OS: Linux
Domoticz version: Latest ß
Location: The Netherlands
Contact:

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

Post 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!
ConBee II - TRÅDFRI lights + switches, loads of ChingLing dimmers and switches, Heiman and Xiaomi sensors
SolarEdge SE4000H (with active modbus_tcp)
YouLess Energy meter
Shelly 2.5 in roller shutter mode
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

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

Post by waltervl »

Replace domoticz.openURL by dz.openURL
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
keros
Posts: 77
Joined: Saturday 27 July 2019 0:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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).
Last edited by keros on Monday 20 December 2021 21:24, edited 1 time in total.
Moderator on Easydomoticz.com, the French DomoticZ forum.
French writer for ZigBeeForDomoticZ Plugin Wiki
User avatar
Sjonnie2017
Posts: 375
Joined: Wednesday 02 August 2017 19:43
Target OS: Linux
Domoticz version: Latest ß
Location: The Netherlands
Contact:

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

Post by Sjonnie2017 »

Thank you both for your support. I will test and report back.
ConBee II - TRÅDFRI lights + switches, loads of ChingLing dimmers and switches, Heiman and Xiaomi sensors
SolarEdge SE4000H (with active modbus_tcp)
YouLess Energy meter
Shelly 2.5 in roller shutter mode
User avatar
Sjonnie2017
Posts: 375
Joined: Wednesday 02 August 2017 19:43
Target OS: Linux
Domoticz version: Latest ß
Location: The Netherlands
Contact:

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

Post 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!!
ConBee II - TRÅDFRI lights + switches, loads of ChingLing dimmers and switches, Heiman and Xiaomi sensors
SolarEdge SE4000H (with active modbus_tcp)
YouLess Energy meter
Shelly 2.5 in roller shutter mode
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest