Author Topic: LUA help on displaying retrieved values  (Read 796 times)

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
LUA help on displaying retrieved values
« on: December 30, 2017, 09:33:20 am »
I need some help displaying values which are retrived from my thermostat.
When I enter the below URL: IPaddress:10080/happ_thermstat?action=getThermostatInfo I get the following information:

{"result":"ok", "currentTemp":"1896", "currentSetpoint":"1950", "currentInternalBoilerSetpoint":"50", "programState":"1", "activeState":"1", "nextProgram":"1", "nextState":"0", "nextTime":"1514653200","nextSetpoint":"1950","randomConfigId":"1804289383","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"44"}

I would like to display in eg, the Multistring App (urn:schemas-upnp-org:device:VContainer:1) the currentTemp, currentSetpoint and activeState.

any help/suggestion how to achive this would be great
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: LUA help on displaying retrieved values
« Reply #1 on: December 30, 2017, 10:10:23 am »
I'm doing almost the exact same thing you are trying to do. My usage is to write variables from a Lua programmed Slow Dim Ramp function. Since I had additional requirements I could not use some of the already available scripts, so I expanded it to meet my needs. Here is the code I use to write some of the variables to MultiString. Please note that you will have to set your variables before you can write them to MultiString. (See the first line of code below). In my case MultiString is device #190.

Code: [Select]
varDimLevel2 = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",varDevice2)
varDimLevel2 = varDimLevel2 - varDimStep
luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget=varDimLevel2 },varDevice2)

varActionTime = os.date("%m/%d/%Y %H:%M:%S")
luup.variable_set("urn:upnp-org:serviceId:VContainer1","VariableName3","Last Action",190)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3",varActionTime,190)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","VariableName4","Delay:Step",190)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable4",varDelayPeriod/60 .. ":" .. varDimStep,190)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","VariableName5","Dim Level",190)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable5",varDimLevel2,190)


Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: LUA help on displaying retrieved values
« Reply #2 on: December 30, 2017, 10:24:26 am »
Thx for your response....I have a hard time now creating the variables (being a non programmer :))

   varTemp = luup.inet.wget( 'http://192.xxxx:10080/happ_thermstat?action=getThermostatInfo)
   varTemp = CurrentTemp

But that gives me an error in LUA
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10091
  • Karma: +763/-142
Re: LUA help on displaying retrieved values
« Reply #3 on: December 30, 2017, 12:53:12 pm »
I see two issues:
1) You do not have a matching double quote after getThermostatInfo
2) You get the value in vaTemp, then immediately write over it with some other value (CurrentTemp) before you even look at vaTemp.

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: LUA help on displaying retrieved values
« Reply #4 on: December 30, 2017, 01:54:56 pm »
Ok, it now writes something to the Multiswitch ;D

varTemp = luup.inet.wget( 'http://192.168.178.116:10080/happ_thermstat?action=getThermostatInfo')
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3",varTemp,82)

But how do I define to only write the current temperature form this information which is returned from the URL:

{"result":"ok", "currentTemp":"1896", "currentSetpoint":"1950", "currentInternalBoilerSetpoint":"50", "programState":"1", "activeState":"1", "nextProgram":"1", "nextState":"0", "nextTime":"1514653200","nextSetpoint":"1950","randomConfigId":"1804289383","errorFound":"255","connection":"0","burnerInfo":"0","otCommError":"0","currentModulationLevel":"44"}


Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: LUA help on displaying retrieved values
« Reply #5 on: December 30, 2017, 02:34:57 pm »
First thing I would do is simplify what variables you are looking for. The code you are using returns ALL the variables in a concatenated string. This is difficult to work with if you just need to see what a particular variables value is, but can be useful if you want a global picture of that device. So.. try something like this:

Code: [Select]
varDimLevel2 = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",varDevice2)

Keep in mind that you will need to substitute the service ID (urn:upnp-org:serviceId:Dimming1), parameter (LoadLevelStatus) and Node ID (varDevice2) to match those of your thermostat. This is how I get the current dim level of the light before I subtract the amount to dim in my code. These are basic set and get calls using Lua. There are lots of references on how this works. Also look at the setting for your thermostat by clicking the arrow, scrolling down to [Advanced] then selecting the Parameters and Variables tabs. These will contain all the necessary parts you will need to replace the items in my code with the info for your thermostat.

Lastly, to address what Richard said, EACH variable you want to work with will need is own definition, (varDimLevel2) or in your case (varCurrentTemp, varCurrentSetpoint and so on). Something like this:

Code: [Select]
varCurrentTemp = luup.variable_get("urn:upnp-org:serviceId:xxxxxxxxx","currentTemp",## or variable as NodeID)
varActiveState = luup.variable_get("urn:upnp-org:serviceId:xxxxxxxxx","activeState",## or variable as NodeID)

varCurrentTemp will equal 1896, varActiveState will equal 1 based on your return string in your original post. Once you get the parameters into a variable, then you simply set the values of MultiString with the variables you defines and filled.

Code: [Select]
luup.variable_set("urn:upnp-org:serviceId:VContainer1","VariableName3","Active State",82)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3",varActiveState,82)

Maybe search the Wiki for a better understanding. http://wiki.micasaverde.com/index.php/Special:AllPages and here http://wiki.micasaverde.com/index.php/Luup_Example.
This will also be helpful: http://wiki.micasaverde.com/index.php/Luup_Variables
« Last Edit: December 30, 2017, 02:44:46 pm by kartcon »

Offline ChrisTheC

  • Full Member
  • ***
  • Posts: 143
  • Karma: +4/-1
  • Baltimore, MD & Washington, DC
Re: LUA help on displaying retrieved values
« Reply #6 on: January 05, 2018, 06:30:07 am »
kartcon,
. . . hijack . . .
Good post & pointers for us luup beginners!
Thanks,
Chris
openLuup with ALTUI, ALTHUE, 8x iPhoneLocators, Harmony Hub, Honeywell Wifi T-stat, Foscam Fi8608w & 2x R2, bridged to . . .
Vera 3/UI5 with Schlage BE469NX, 3x EZMotion+, 3x Ecolink PIR, 3x Schlage door sensors, 2x Aeotec micro switches, 2x Aeotec appliance switches, Leviton RZM10 & DZMX1, Wemo

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: LUA help on displaying retrieved values
« Reply #7 on: January 05, 2018, 02:54:13 pm »
Thx Karton for your post!
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user