http command

Moderator: leecollings

Post Reply
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

http command

Post by Sagitarius »

As you can add multipple devices to a scene, would be great to have also the option to add multipple http commands
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: http command

Post by Egregius »

Put them in a script and execute that script.
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzvents openURL command domoticz

Post by Sagitarius »

Hi All,
I'm trying to get PV information from Benning device via dzvents into domoticz.
The IE http command like "http://<IP PV>/getentry.cgi?&oid=10" works fine.
Result e.g.
[
{
"oid" : 10,
"label" : "UserConfig.Inverter.Info.SystemName", "type" : "S",
"val" : "PVINV110",
"uitext" : "System name", "savetype" : 1,
"factor" : 1.000000, "unit" : "", "portal" : 1,
"AutoZero" : 0,
"fb" : 1
},

but to be honest, I have no clue how the dzvents "openURL" command should look like :(

Anyone out there to help ?

Many thanks
Rgds
Sagitarius
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: http command

Post by erem »

Regards,

Rob
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: http command

Post by Sagitarius »

Hi Rob,
thanks, I had a view on this but the 2nd part, looks like, is a bit complex for me yet.
That's what I have so far

Code: Select all

return {
    on = {
    timer = {'every 1 minutes'},
    httpResponses = { 'oid' }
    },

    execute = function(dz, item)
        
    if (item.isTimer) then  
	    dz.openURL({
	    url =  'http://192.168.178.20/getentry.cgi?&oid=10',
	    method = 'GET',
	    callback = 'oid',
	    })
	end

    if (item.isHTTPResponse) then
        if (item.ok) then
            local pv_data = dz.utils.toJSON(item.data)
          	dz.log('PVSW30 ' .. pv_data, dz.LOG_ERROR)
        else
            dz.log('PVSW30 not OK', dz.LOG_ERROR)
        end
    end

    end
}
Log:

Code: Select all

2021-05-11 16:57:00.621 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-05-11 16:57:01.082 Status: dzVents: Info: Handling httpResponse-events for: "oid
2021-05-11 16:57:01.082 Status: dzVents: Info: ------ Start internal script: PVSW30 dz: HTTPResponse: "oid"
2021-05-11 16:57:01.086 Status: dzVents: Error (2.4.19): PVSW30 "-1"
2021-05-11 16:57:01.086 Status: dzVents: Info: ------ Finished PVSW30 dz 
Original :

Code: Select all

http://192.168.178.20/getentry.cgi?&oid=10
{ "oid" : 10, "label" : "UserConfig.Inverter.Info.SystemName", "type" : "S", "val" : "PVSW30", "uitext" : "System name", "savetype" : 1, "factor" : 1.000000, "unit" : "", "portal" : 1, "AutoZero" : 0, "fb" : 1 }
Any further detailed information is really appreciated

Many thanks

Rgds
Paul
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: http command

Post by waaren »

Sagitarius wrote: Tuesday 11 May 2021 17:08 thanks, I had a view on this but the 2nd part, looks like, is a bit complex for me yet.
Any further detailed information is really appreciated
Can you try this one? It is not complete but should point you in the right direction

Code: Select all

local scriptVar = 'oid'

return
{
    on =
    {
        timer =
        {
            'every 1 minutes'
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL(
            {
                url =  'http://192.168.178.20/getentry.cgi?&oid=10',
                method = 'GET',
                callback = scriptVar,
            })
        elseif item.isHTTPResponse and item.ok then
            dz.log('item.data: ' .. item.data, dz.LOG_FORCE)

            dz.utils.dumpTable(item) -- only during debug

            local pv_data = dz.utils.fromJSON(item.data) -- you want to convert a JSON to a Lua table
            dz.utils.dumpTable(pv_data) -- only during debug
        else
            dz.log('PVSW30 not OK', dz.LOG_ERROR)
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: http command

Post by Sagitarius »

Thanks Waaren, will spend some time over the weekend
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: http command

Post by Sagitarius »

Hi Waaren

that's what I get, but I'm not sure what kind of information would help.
The http command via IE works fine. It collects data from a XML database where I do not have the name from.
But anything I tried so far, the result via openURL would be -1, which means wrong oid no. and the JSON object
is not shown.

2021-05-14 11:38:01.038 Status: dzVents: Info: oid: ------ Start internal script: Script #2: HTTPResponse: "oid"
2021-05-14 11:38:01.038 Status: dzVents: !Info: oid: item.data: -1
2021-05-14 11:38:01.038 Status: dzVents: > isHTTPResponse: true
2021-05-14 11:38:01.038 Status: dzVents: > _contentType: text/html
2021-05-14 11:38:01.038 Status: dzVents: > isGroup: false
2021-05-14 11:38:01.038 Status: dzVents: > isJSON: false
2021-05-14 11:38:01.038 Status: dzVents: > ok: true
2021-05-14 11:38:01.038 Status: dzVents: > statusText: OK
2021-05-14 11:38:01.038 Status: dzVents: > trigger: oid
2021-05-14 11:38:01.038 Status: dzVents: > callback: oid
2021-05-14 11:38:01.038 Status: dzVents: > protocol: HTTP/1.1
2021-05-14 11:38:01.038 Status: dzVents: > isSecurity: false
2021-05-14 11:38:01.038 Status: dzVents: > isTimer: false
2021-05-14 11:38:01.038 Status: dzVents: > data: -1
2021-05-14 11:38:01.038 Status: dzVents: > headers:
2021-05-14 11:38:01.038 Status: dzVents: > Server: Benning Web Server
2021-05-14 11:38:01.038 Status: dzVents: > Content-Type: text/html
2021-05-14 11:38:01.038 Status: dzVents: > Connection: close
2021-05-14 11:38:01.038 Status: dzVents: > isVariable: false
2021-05-14 11:38:01.038 Status: dzVents: > statusCode: 200
2021-05-14 11:38:01.039 Status: dzVents: > isDevice: false
2021-05-14 11:38:01.039 Status: dzVents: > isScene: false
2021-05-14 11:38:01.039 Status: dzVents: > baseType: httpResponse
2021-05-14 11:38:01.042 Status: dzVents: Error (2.4.19): oid: An error occured when calling event handler Script #2
2021-05-14 11:38:01.043 Status: dzVents: Error (2.4.19): oid: /home/pi/domoticz/dzVents/runtime/Utils.lua:182: bad argument #1 to 'pairs' (table expected, got number)
2021-05-14 11:38:01.043 Status: dzVents: Info: oid: ------ Finished Script #2

I could not find a hint in regards to bad argument .......
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: http command

Post by waaren »

Sagitarius wrote: Friday 14 May 2021 11:58 that's what I get, but I'm not sure what kind of information would help.
The call only returns -1 so not much to work with. It should return the same information as what comes back if you enter this http in your browser. Can you try to do this from an incognito browser page and post the result?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: http command

Post by Sagitarius »

I tested Chrome and Firefox in private mode, Firefox has no problem but Chrome
has problem with oid's below 10000, they are not working but above some.
I did the same test with Domoticz and got the same result like with Chrome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest