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.
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 » 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?

User avatar
waaren
Posts: 690
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren » Wednesday 11 July 2018 9:33

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

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 » Wednesday 11 July 2018 12:13

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: 690
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren » Wednesday 11 July 2018 12:56

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

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 » 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?

User avatar
jvdz
Posts: 1338
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by jvdz » Wednesday 11 July 2018 13:37

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

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 » Wednesday 11 July 2018 13:46

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: 690
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Concatenating an URL with values from sensors.

Post by waaren » Wednesday 11 July 2018 17:19

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 ..
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests