We have moved at community.getvera.com

Author Topic: Getting data from a sensor in a file  (Read 12771 times)

Offline sre

  • Full Member
  • ***
  • Posts: 110
  • Karma: +0/-1
Re: Getting data from a sensor in a file
« Reply #30 on: November 20, 2016, 02:36:51 am »
Thanks  @RexBeckett.  I was looking for this info for some time.  Can you also tell me how to fetch the time stamp along with the temperature info please ?

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Getting data from a sensor in a file
« Reply #31 on: November 20, 2016, 03:06:37 am »
Can you also tell me how to fetch the time stamp along with the temperature info please ?

The documentation here:

http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_variable_get

Would tell you that all you need is:

Code: [Select]
devID = 79
humidity, tstamp = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)

However, this may not be reliable if the system has reloaded in the meantime.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline sre

  • Full Member
  • ***
  • Posts: 110
  • Karma: +0/-1
Re: Getting data from a sensor in a file
« Reply #32 on: November 20, 2016, 09:11:24 pm »
Thanks @akbooer.  It was really valuable information

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #33 on: January 16, 2017, 12:11:37 pm »
Hello again ,

All was working very well ...... untill I updated the firmware this morning ..... :-\
I got it partially working again , but wierdly enough 2 files are not working.

This is the complete Luup code which was working with the previous firmware:
Code: [Select]
local devID = 37
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/Living_room.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 40
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/corridor.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 117
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/garage.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID =212
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/OAT.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 212
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/heating2.txt", "w")
file:write("Outside: " .. temperature .. "\176C\n")

devID = 40
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Corridor: " .. temperature .. "\176C\n")

devID = 37
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Living: " .. temperature .. "\176C\n")

devID = 117
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Garage: " .. temperature .. "\176C\n")

devID = 228
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Hobby: " .. temperature .. "\176C\n")

devID = 230
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Hobby: " .. humidity .. "\%")
file:close()


local devID = 91
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/heating.txt", "w")
file:write("Ambient: " .. temperature .. "\176C\n")

devID = 92
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Buffer: " .. temperature .. "\176C\n")

devID = 93
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Boiler: " .. temperature .. "\176C\n")

devID = 94
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Radiator: " .. temperature .. "\176C\n")

devID = 87
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Upstairs: " .. temperature .. "\176C\n")

devID = 88
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Upstairs: " .. humidity .. "\%\n")

devID = 78
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Downstairs: " .. temperature .. "\176C\n")

devID = 79
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Downstairs: " .. humidity .. "\%")
file:close()

local devID = 228
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/Hobby.txt", "w")
file:write("Hobby: " .. temperature .. "\176C\n")

devID = 230
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Humid: " .. humidity .. "\%")
file:close()

Now , 2 files will not create , this part which is at the bottom:
Code: [Select]
local devID = 228
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/Hobby.txt", "w")
file:write("Hobby: " .. temperature .. "\176C\n")

devID = 230
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Humid: " .. humidity .. "\%")
file:close()

And this part in the middle, here the file is created , but the file remains empty:
Code: [Select]
local devID = 91
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/heating.txt", "w")
file:write("Ambient: " .. temperature .. "\176C\n")

devID = 92
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Buffer: " .. temperature .. "\176C\n")

devID = 93
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Boiler: " .. temperature .. "\176C\n")

devID = 94
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Radiator: " .. temperature .. "\176C\n")

devID = 87
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Upstairs: " .. temperature .. "\176C\n")

devID = 88
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Upstairs: " .. humidity .. "\%\n")

devID = 78
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Downstairs: " .. temperature .. "\176C\n")

devID = 79
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Downstairs: " .. humidity .. "\%")
file:close()

The device ID are still correct ..
anyone has an idea why it does not want to write , the rest of the LUUP code , writing it's files works fine.

Thanks,
Cor
« Last Edit: January 16, 2017, 12:21:28 pm by Cor »

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Getting data from a sensor in a file
« Reply #34 on: January 16, 2017, 12:23:43 pm »
...so what errors are shown in the log?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #35 on: January 16, 2017, 12:54:55 pm »
I downloaded the LUAupnp.log file ( That is the one you are referring to?)

I might have found the problem , But I have no idea what to do with this info:
Code: [Select]
08      01/16/17 18:45:48.624   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x6f96
c520>
08      01/16/17 18:45:48.624   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x6f96c520>
08      01/16/17 18:45:48.625   JobHandler_LuaUPnP::HandleActionRequest argument action=RunScene <0x6f96c520>
08      01/16/17 18:45:48.625   JobHandler_LuaUPnP::HandleActionRequest argument SceneNum=12 <0x6f96c520>
08      01/16/17 18:45:48.625   JobHandler_LuaUPnP::HandleActionRequest argument rand=0.11006943929211022 <0x6f96c520>
08      01/16/17 18:45:48.625   Scene::RunScene running 12 Script write temperatures file <0x6f96c520>
01      01/16/17 18:45:48.641   GetLuaInterface can't find device type: 3/0x1d33860 str: 91 <0x6f96c520>
01      01/16/17 18:45:48.642   luup_variable_get interface 0x1d30bc0 args 3 <0x6f96c520>
01      01/16/17 18:45:48.642   LuaInterface::CallFunction_Scene Scene  12 failed [string "function event_4()..."]:62: attempt to concatenate local 'temperature' (a nil
 value) <0x6f96c520>

It says It can not find a device type.......    Very wierd since before the firmware update this morning it was working fine.

Thanks,
Cor

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Getting data from a sensor in a file
« Reply #36 on: January 16, 2017, 01:06:11 pm »
I'd hazard a guess that it's having a problem with device #91... are you sure it's there?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #37 on: January 16, 2017, 01:17:01 pm »
I think you found my problem  ;D  !!

The device is indeed gone!  :o   , It is a universal sensor with 5 temperature sensors, the names are gone , the id changed ......crap!!!! 


Anyway , I now know what to do tonight! >:(   


Many thanks,
Cor

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #38 on: January 23, 2018, 03:54:20 am »
Since a couple of days , it doesn't work anymore.

I updated to the latest firmware , since than the folder www\blueiris was removed.
I created in winscp the folder again , and it seemed to be working. but it is not. it did work once or twice , but now nothing anymore , when I start the scene manualy , nothing is written to the files.

Anyone has an idea , maybe something wrong with the rights of the folder?

Attached a screenshot of winscp , below the Lua code from the scene . ( Lua code was not changed).

Code: [Select]
local devID = 37
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/Living_room.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 40
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/corridor.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 321
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/garage.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 268
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/OAT.txt", "w")
file:write(temperature .. "\176C")
file:close()

local devID = 268
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/heating2.txt", "w")
file:write("Outside: " .. temperature .. "\176C\n")

devID = 40
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Corridor: " .. temperature .. "\176C\n")

devID = 37
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Living: " .. temperature .. "\176C\n")

devID = 321
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Garage: " .. temperature .. "\176C\n")

devID = 212
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Gate electrics: " .. temperature .. "\176C\n")

devID = 228
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Hobby: " .. temperature .. "\176C\n")

devID = 230
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Hobby: " .. humidity .. "\%")

file:close()


local devID = 91
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/heating.txt", "w")
file:write("Ambient: " .. temperature .. "\176C\n")

devID = 92
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Buffer: " .. temperature .. "\176C\n")

devID = 93
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Boiler: " .. temperature .. "\176C\n")

devID = 94
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Radiator: " .. temperature .. "\176C\n")

devID = 87
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Upstairs: " .. temperature .. "\176C\n")

devID = 88
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Upstairs: " .. humidity .. "\%\n")

devID = 78
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Downstairs: " .. temperature .. "\176C\n")

devID = 79
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Downstairs: " .. humidity .. "\%")

file:close()

local devID = 228
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/Hobby.txt", "w")
file:write("Hobby: " .. temperature .. "\176C\n")

devID = 230
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Humid: " .. humidity .. "\%")

file:close()

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #39 on: January 23, 2018, 04:32:20 am »
I think I found it .......

Due to the firmware update a device was gone , after getting it back , it had a new device ID . After changing the Lua script with the correct device ID , it seems to be working again.

Cor

note to myself: Only do a firmware update on the first day of vacation to iron out all the errors in the following days.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: Getting data from a sensor in a file
« Reply #40 on: January 23, 2018, 09:41:00 am »
note to myself: Only do a firmware update on the first day of vacation to iron out all the errors in the following days.

I did my update Sunday morning to give myself time to "fix" things. Last summer I did it like on a Wednesday evening and was up late "fixing" things.
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1