Author Topic: Virtual Tempurature Sensor Problems  (Read 2778 times)

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Virtual Tempurature Sensor Problems
« on: April 07, 2014, 03:55:48 pm »
I've been trying to add a virtual temp sensor and have done this many times successfully in the past. This time however no matter what I do i cannot get the "CurrentTemperature" variable to show up. I've restarted and rebooted multiple times with no success. Any ideas?

M

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3891
  • Karma: +482/-12
Re: Virtual Tempurature Sensor Problems
« Reply #1 on: April 07, 2014, 04:03:33 pm »
How did you create your virtual temperature device? What is supposed to update the CurrentTemperature variable?

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: Virtual Tempurature Sensor Problems
« Reply #2 on: April 07, 2014, 04:22:10 pm »
I created it by following these instructions in Apps>Create Device:

Device type:  urn:schemas-micasaverde-com:device:TemperatureSensor:1
Upnp Device Filename: D_TemperatureSensor1.xml



I will update the variable from a scene that calculates the value.

(When I run that scene I get this in the log:

01   04/07/14 16:23:00.931   GetLuaInterface can't find device type: -1/0xcc3d80 str: (null) <0x32e7e680>
01   04/07/14 16:23:00.933   luup_variable_set interface 0xcd4b78 args 3

M
« Last Edit: April 07, 2014, 04:24:21 pm by resq93 »

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3891
  • Karma: +482/-12
Re: Virtual Tempurature Sensor Problems
« Reply #3 on: April 07, 2014, 05:13:25 pm »
When you create the device, don't enter anything in the Device Type field. Just enter Description: <an appropriate name> and Upnp Device Filename: D_TemperatureSensor1.xml (as you already did).

 

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: Virtual Tempurature Sensor Problems
« Reply #4 on: April 07, 2014, 05:26:23 pm »
Same thing... Please see screenshot

« Last Edit: April 07, 2014, 05:30:38 pm by resq93 »

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3891
  • Karma: +482/-12
Re: Virtual Tempurature Sensor Problems
« Reply #5 on: April 07, 2014, 05:35:12 pm »
The CurrentTemperature variable will not be automatically created with the device. It will be created when something writes to it. With a plugin, this happens during startup initialization. In your case, you would write it from your scene Lua code.

You could also create it by entering this in Test Luup code (Lua):
Code: [Select]
luup.variable_set("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature","",dID)
Replace dID with the device number.
« Last Edit: April 07, 2014, 05:39:09 pm by RexBeckett »

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: Virtual Tempurature Sensor Problems
« Reply #6 on: April 07, 2014, 06:05:15 pm »
That did work but now I am still having trouble with my lua code (attempting to calibrate a physical temp sensor)

Code: [Select]
local dIDT = 235     -- Device ID of actual temperature device
local dIDD = 237    -- Device ID of dummy temperature device
local adjust = 3    -- Amount to adjust temperature
local curTemp = tonumber((luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",dIDT)))
local newTemp = curTemp + adjust
luup.variable_set("urn:upnp-org:serviceId:TemperatureSensor1",{CurrentTemperature=newTemp},dIDD)

Whenever this runs I get this error

Quote
01   04/07/14 18:04:27.102   GetLuaInterface can't find device type: -1/0xec9238 str: (null) <0x2b7cb680>
01   04/07/14 18:04:27.102   luup_variable_set interface 0xed15d8 args 3

Any ideas?

M

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Virtual Tempurature Sensor Problems
« Reply #7 on: April 07, 2014, 06:12:43 pm »
Code: [Select]
local curTemp = tonumber((luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",dIDT)))
typically needs to be split into two lines:
Code: [Select]
local curTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",dIDT)
curTemp = tonumber(curTemp)

as luup.variable_get returns 2 values, not one, and it will freak out tonumber()

The second issue is that luup.variable_set. 

It should be more like:
Code: [Select]
luup.variable_set("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", newTemp, dIDD)

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3891
  • Karma: +482/-12
Re: Virtual Tempurature Sensor Problems
« Reply #8 on: April 07, 2014, 06:33:37 pm »
Quote
as luup.variable_get returns 2 values, not one, and it will freak out tonumber()

The extra set of parentheses in:
Code: [Select]
local curTemp = tonumber((luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",dIDT)))
eliminates the second value.

I agree that the issue is with the luup.variable_set(...) call.

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Virtual Tempurature Sensor Problems
« Reply #9 on: April 07, 2014, 06:44:28 pm »
oops, missed the second set of parens.  Still wouldn't do it though as it's too easy to leave them out and be scratching my head ;)

Offline resq93

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +0/-2
Re: Virtual Tempurature Sensor Problems
« Reply #10 on: April 07, 2014, 08:58:43 pm »
I agree that the issue is with the luup.variable_set(...) call.

This worked! Thanks to the both of you for your help.

M

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 582
  • Karma: +9/-12
Re: Virtual Tempurature Sensor Problems
« Reply #11 on: August 13, 2016, 12:18:16 pm »
Could this value be updated by HTTP from another device (Raspberry Pi)???