Concatenating an URL with values from sensors. Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
radiochild
Posts: 4
Joined: Tuesday 10 July 2018 8:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Concatenating an URL with values from sensors.

Post by radiochild »

Hi, I am running Domoticzs on a Synology NAS and I am trying to send a value to an ESPEasy LED display. I can send the dummy info, just as a straight number, e.g.

Code: Select all

commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
but I can't substitute a sensor value for the number, e.g.

Code: Select all

commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..sensortemp}

commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..['Sensor_Temperature']}
The errors usually relate to concatenation a global or things like that.
I don't understand the examples and other posts I have read. Can someone please explain if this can work or how to do it if it can't?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

radiochild wrote: Wednesday 11 July 2018 7:32 Hi, I am running Domoticzs on a Synology NAS and I am trying to send a value to an ESPEasy LED display. I can send the dummy info, just as a straight number, e.g.

Code: Select all

commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
but I can't substitute a sensor value for the number, e.g.

Code: Select all

commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..sensortemp}

commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..['Sensor_Temperature']}
The errors usually relate to concatenation a global or things like that.
I don't understand the examples and other posts I have read. Can someone please explain if this can work or how to do it if it can't?
Yes it can work. If you post the complete script it is easier to comment on what modifications are needed to get this to work.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
radiochild
Posts: 4
Joined: Tuesday 10 July 2018 8:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by radiochild »

Hi Waaren, thanks for having a look for me.

Code: Select all

-- Variables
baseurlESPEasy = "http://192.168.1.xx/control?cmd="
commandArray =  {}
if devicechanged['Undercot_Temperature'] then
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
end
This works.
I just can't figure out how to put a value from a sensor where the '333' is.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

radiochild wrote: Wednesday 11 July 2018 12:13

Code: Select all

-- Variables
baseurlESPEasy = "http://192.168.1.xx/control?cmd="
commandArray =  {}
if devicechanged['Undercot_Temperature'] then
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'..333 }
end
This works.
I just can't figure out how to put a value from a sensor where the '333' is.
This will send the same as in your example with the temperature from sensor Undercot_Temperature. (dzVents)

Code: Select all

-- Send Undercot Temp

return {
    on =        {       devices   =   { "Undercot_Temperature" }},                        
              
    logging =   {       level   =   domoticz.LOG_DEBUG,                                   
                        marker  =   "Send undercot" },                                           

    execute = function(domoticz, undercot )
   
        local baseurlESPEasy = "http://192.168.1.xx/control?cmd=" 
        domoticz.openURL({ 
                            url = baseurlESPEasy .. "7dt" .. undercot.temperature,
                            method = "GET" 
                        })
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
radiochild
Posts: 4
Joined: Tuesday 10 July 2018 8:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by radiochild »

Hi Waaren.
I tried your code and I get;

Error: EventSystem: in Portable LED Display: [string "-- Send Undercot Temp ..."]:6: attempt to index global 'domoticz' (a nil value)

I am using this in Events. I realise I didn't mention that before, does that make a difference?
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by jvdz »

So you have an LUA event script and you want to send the new received value for ... to ESPEASY....right?
Something like this should be close for a Device Lua event script:

Code: Select all

baseurlESPEasy = "http://192.168.1.xx/control?cmd="
commandArray =  {}
if devicechanged['Undercot_Temperature'] then
commandArray[1]={['OpenURL'] = baseurlESPEasy..'7dt,'.. devicechanged['Undercot_Temperature']}
end
.. but are you sure about that ESPEASY URL? Does that work directly from a browser?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
radiochild
Posts: 4
Joined: Tuesday 10 July 2018 8:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by radiochild »

Hi jvdz,
Thank you! That worked a charm. The url works in a browser for ESPEasy. It now works in Domoticz. It's just an update to a MAX7219 LED display. So simple but I just couldn't figureit out.

Thank you again, Waaren and jvdz for helping me out.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

radiochild wrote: Wednesday 11 July 2018 13:29 Hi Waaren.
I tried your code and I get;

Error: EventSystem: in Portable LED Display: [string "-- Send Undercot Temp ..."]:6: attempt to index global 'domoticz' (a nil value)

I am using this in Events. I realise I didn't mention that before, does that make a difference?
Hi radioChild, my script is dzVents. Choose dzVents in the event editor and copy paste the script ..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

Hello, please can someone advise me, I try the script written above, but my display shows nothing.
When I enter a command via URL, it will show up on the display.
Thanks for the help

Code: Select all

-- Send Undercot Temp

return {
    on =        {       devices   =   { "Outdoor_thermometer" }},                        
              
    logging =   {       level   =   domoticz.LOG_DEBUG,                                   
                        marker  =   "Send undercot" },                                           

    execute = function(domoticz, undercot )
   
        local baseurlESPEasy = "http://192.168.7.71/control?cmd=" 
        domoticz.openURL({ 
                            url = baseurlESPEasy .. "7dt" .. Outdoor_thermometer,
                            method = "GET" 
                        })
    end
}
Device:
48 Dummy 14080 1 Outdoor_thermometer Temp LaCrosse TX3 2.7 C

LOG:
2020-02-19 06:57:59.694 Status: dzVents: Error (2.4.19): Send undercot: An error occured when calling event handler Displej-1
2020-02-19 06:57:59.694 Status: dzVents: Error (2.4.19): Send undercot: ...Domoticz\scripts\dzVents\generated_scripts/Displej-1.lua:13: attempt to concatenate global 'Outdoor_thermometer' (a nil value)
2020-02-19 06:57:59.694 Status: dzVents: Info: Send undercot: ------ Finished Displej-1
2020-02-19 06:58:02.679 EventSystem: Event triggered: Termostat-Loznice_2
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

MarloCZ wrote: Wednesday 19 February 2020 6:56 Hello, please can someone advise me, I try the script written above, but my display shows nothing.
You copied and paste some unexpected values.

Can you try this

Code: Select all

-- Send temperature of a sensor to ESP Easy

return
{
    on =
    {
        devices   =
        {
            'Outdoor_thermometer',
        }
    }, 

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Temperature to ESPEasy'
    },

    execute = function(dz, item)

        local ESPEasyURL = 'http://192.168.7.71/control?cmd='
        dz.openURL(
            {
                url = ESPEasyURL .. '7dt,' .. item.temperature,
                method = 'GET',
            })
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

Thank you very much for the modified script.
I turned it on, but the screen still doesn't show me anything :(

The extract from the log is as follows:

2020-02-19 13:06:25.489 Status: dzVents: Info: Handling events for: "Outdoor_thermometer", value: "5.06"
2020-02-19 13:06:25.490 Status: dzVents: Info: Temperature to ESPEasy: ------ Start internal script: Display-1: Device: "Outdoor_thermometer (Dummy)", Index: 48
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: url = http://192.168.7.71/control?cmd=7dt5.0599999427795
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: method = GET
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: post data = nil
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: headers = nil
2020-02-19 13:06:25.490 Status: dzVents: Debug: Temperature to ESPEasy: OpenURL: callback = nil
2020-02-19 13:06:25.491 Status: dzVents: Info: Temperature to ESPEasy: ------ Finished Display-1
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

So I figured it out - it works :)
There was no comma in 7dt,

Code: Select all

url = ESPEasyURL .. '7dt,' .. item.temperature,
Can I have another request, could it be done on the display alternate between two different temperatures - from outside and from inside thermometer - alternately ?

Thank you in advance for your help.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

MarloCZ wrote: Wednesday 19 February 2020 13:22 Can I have another request, could it be done on the display alternate between two different temperatures - from outside and from inside thermometer - alternately ?
Could be something like

Code: Select all

-- Send temperature of two sensors alternately to ESP Easy

return
{
    on =
    {
        timer =
        {
            'every minute',
        }
    }, 

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Temperature to ESPEasy'
    },

    execute = function(dz, item)
        local display 

        if dz.time.minutes % 2 == 0 then 
            display = dz.utils.round(dz.devices('Outdoor_thermometer').temperature,1)
        else
            display = dz.utils.round(dz.devices('Indoor_thermometer').temperature,1)
        end
       
        local ESPEasyURL = 'http://192.168.7.71/control?cmd='
        dz.openURL(
            {
                url = ESPEasyURL .. '7dt,' .. display
                method = 'GET',
            })
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

Thanks for the new script, but it reports me an error :(

Code: Select all

2020-02-19 21:36:57.915 Status: dzVents: Error (2.4.19): error loading module 'Display-2' from file 'C:\Program Files (x86)\Domoticz\scripts\dzVents\generated_scripts/Display-2.lua':
2020-02-19 21:36:57.915 ...Domoticz\scripts\dzVents\generated_scripts/Display-2.lua:32: '}' expected (to close '{' at line 30) near 'method'
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

MarloCZ wrote: Wednesday 19 February 2020 21:43 Thanks for the new script, but it reports me an error :(
Sorry for that. I missed a comma after display.

can you try again ?

Code: Select all

-- Send temperature of two sensors alternately to ESP Easy

return
{
    on =
    {
        timer =
        {
            'every minute',
        }
    }, 

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Temperature to ESPEasy'
    },

    execute = function(dz, item)
        local display 

        if dz.time.minutes % 2 == 0 then 
            display = dz.utils.round(dz.devices('Outdoor_thermometer').temperature,1)
        else
            display = dz.utils.round(dz.devices('Indoor_thermometer').temperature,1)
        end
       
        local ESPEasyURL = 'http://192.168.7.71/control?cmd='
        dz.openURL(
            {
                url = ESPEasyURL .. '7dt,' .. display,
                method = 'GET',
            })
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

Thank you, it works very well. ;)

I have one more request, is somehow done to change temperatures not after one minute, but after 5 (10) seconds :?:
Thank you
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

MarloCZ wrote: Thursday 20 February 2020 7:07 is somehow done to change temperatures not after one minute, but after 5 (10) seconds
Thank you
That's possible with the attached script. Please note that the temperature shown can be 50 seconds behind measured temperature. It is possible to have a real-time temperature with a different approach but that would require dzVents >= 3.0.0

Code: Select all

-- Send temperature of two sensors alternately to ESP Easy every 10 seconds

local scriptVar = 'Temperature to ESPEasy'
return
{
    on =
    {
        timer =
        {
            'every minute',
        },
    }, 
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        local display = {}
            display[0] = dz.utils.round(dz.devices('Outdoor_thermometer').temperature,1)
            display[1] = dz.utils.round(dz.devices('Indoor_thermometer').temperature,1)

        local function sendTemp(selector)
            temperature = display[selector % 2]
            
            local ESPEasyURL = 'http://192.168.7.71/control?cmd='
                dz.openURL(
                {
                    url = ESPEasyURL .. '7dt,' .. temperature,
                    method = 'GET',
                }).afterSec(selector * 10)
        end

        -- main
        for i = 0, 5 do
            sendTemp(i)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

Thank you very much, it works great. ;)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren »

MarloCZ wrote: Thursday 20 February 2020 17:37 Thank you very much, it works great. ;)
Show us a picture please ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MarloCZ
Posts: 11
Joined: Tuesday 26 November 2019 21:53
Target OS: Windows
Domoticz version:
Contact:

Re: Concatenating an URL with values from sensors.

Post by MarloCZ »

Picture of what? A picture of the display?
I am currently testing two adults, 7 numbers and 4 numbers.
https://uloz.to/file/Up42O3LzfwyK/2020- ... -40-50-jpg
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest