Author Topic: reading Current Temperature from Virtual Outdoor Temp device  (Read 535 times)

Offline jchin

  • Sr. Newbie
  • *
  • Posts: 43
  • Karma: +0/-0
reading Current Temperature from Virtual Outdoor Temp device
« on: April 14, 2018, 04:37:10 pm »
How can I read the current outdoor temperature from the Virtual Outdoor Temperature (VOTD) device?

Using the luup code:
local OutdoorTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 23) -- where 23 is the device ID
does not seem to work.

Offline jchin

  • Sr. Newbie
  • *
  • Posts: 43
  • Karma: +0/-0
Re: reading Current Temperature from Virtual Outdoor Temp device
« Reply #1 on: April 14, 2018, 06:26:11 pm »
Finally I got a WORKING SOLUTION !!!

I use this LUUP code in a scene that is triggered by a motion detector.
Used to control the heat in my basement.
Basically, if it is warm outside, do not turn up the heat in the basement and someone goes in.


Code: [Select]
local THERMOSTAT = 16 -- deviceID for Thermostat
local TEMP = 72 -- temperature to set
local HEATOFF = 65 -- temperature to set when outside is warm
local VOTD = 23 -- deviceID of Virtual Outdoor Temp
local TEMPwarm = 55 -- temperature outside considered warm

local OutdoorTemp = tonumber((luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", VOTD)))
-- note the number of parentheses

if (OutdoorTemp < TEMPwarm) then
luup.call_action("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat", "SetCurrentSetpoint", {NewCurrentSetpoint = TEMP}, THERMOSTAT)
else
luup.call_action("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat", "SetCurrentSetpoint", {NewCurrentSetpoint = HEATOFF}, THERMOSTAT)
end

Offline jswim788

  • Hero Member
  • *****
  • Posts: 788
  • Karma: +57/-2
Re: reading Current Temperature from Virtual Outdoor Temp device
« Reply #2 on: April 14, 2018, 11:14:50 pm »
local OutdoorTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 23) -- where 23 is the device ID
does not seem to work.

I'll guess that you tried to use OutdoorTemp as a number?  Remember that luup.variable_get always returns a string (actually 2 return values, but typically you only want the first), and you need to convert the string to a number as in your second post if you want to compare it to other numbers.

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 567
  • Karma: +9/-12
Re: reading Current Temperature from Virtual Outdoor Temp device
« Reply #3 on: July 20, 2018, 06:54:02 pm »
I'm trying to create a virtual temp sensor (already done) that I can set via http call. I have the following:

http://192.168.0.10:3480/data_request?id=lu_action&output_format=json&DeviceNum=242&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&action=SetCurrentTemperature&newCurrentTemperature=84.01

It's not doing the trick or I wouldn't be asking for help. Anyone have the answer for this one???

Offline jswim788

  • Hero Member
  • *****
  • Posts: 788
  • Karma: +57/-2
Re: reading Current Temperature from Virtual Outdoor Temp device
« Reply #4 on: July 21, 2018, 10:36:00 am »
Does the virtual temp sensor support a SetCurrentTemperature action?  On UI5 I don't think it does but maybe it's there in UI7.  Maybe you could just set the variable directly?

...data_request?id=variableset&DeviceNum=242&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value=25

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 567
  • Karma: +9/-12
Re: reading Current Temperature from Virtual Outdoor Temp device
« Reply #5 on: July 22, 2018, 04:47:00 pm »
I figured it out after I posted this and forgot to answer myself. Thank you though, it might make it easier for the next poor soul to find. :-)