We have moved at community.getvera.com

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

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #15 on: August 25, 2013, 04:20:42 pm »
Done !! :-)

It's working Perfectly, attached a screenshot of one of the camera's in my heating room.

When I logged in This morning , I saw the file was  created , so I think it was due to the very slow internet connection I had to the computer running Blue iris ( I am 2000 miles away from home for the moment and use a programm to logon to the computer , black and white screen and very slow).

I didn't use your "get" command , but copied all files ( 3 for the moment) to a local directory, it is working fine, is there a benefit to use the "get" command if I use the Blueiris folder only for these files I want to copy?
This is what I am using for the moment:
Code: [Select]
option batch continue
option confirm off
open vera3
lcd C:\blueiris\macro\files
synchronize local C:\blueiris\macro\files /www/blueiris
exit


Many thanks for your help guys! , much appreciated :-)

*************************************************
For people who are interested , here is the how to:

Create a scene , with a schedule which repeats itself every ?? minutes/hours.
LUUP code for 1 device (where 122 is the device ID and /www/blueiris/oatemp.txt is the file in a folder blueiris created with winscp)
Code: [Select]
local devID = 122
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/oatemp.txt", "w")
file:write(temperature .. "\176C\n")
file:close()

The code to create more txt files from the devices.
Code: [Select]
local devID = 122
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/oatemp.txt", "w")
file:write(temperature .. "\176C\n")
file:close()

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

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


create with winscp a directory www/blueiris in your vera.

On the computer which runs Blue iris follow this procedure:
http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/

The script ( where I copy the files from vera www/blue iris to my computer to :C:\blueiris\macro\files
Code: [Select]
option batch continue
option confirm off
open vera3
lcd C:\blueiris\macro\files
synchronize local C:\blueiris\macro\files /www/blueiris
exit

Open in blue iris the setup
Open Options>Macro Tab
Click on %1 Type in line
Click on Set to file...
This will open a Windows Explorer window that you will navigate to the network location
that the text file is located such as:.
C:\blueiris\macro\files\oatemp.txt
Click on this text file.

Open the camera properties >> video>> edit text and graphic overlay.
On the top field "enter some text %1"
click OK

That's it ( in a nutshell)

Cor

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Getting data from a sensor in a file
« Reply #16 on: August 25, 2013, 04:49:45 pm »
I'm happy to hear it is all working. It looks good on the still. 8)

Quote
I didn't use your "get" command , but copied all files ( 3 for the moment) to a local directory, it is working fine, is there a benefit to use the "get" command if I use the Blueiris folder only for these files I want to copy?

There would be no benefit in using get if you always want to synchronize all the files in the folder.

The line lcd C:\blueiris\macro\files in your WinSCP script is now redundant as you are specifying the local directory in the synchronize... command. It isn't hurting anything, though.

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #17 on: November 22, 2013, 07:13:50 am »
ohhh  :-\   This threads needs a follow up.

I just updated to the latest version and there is a small change in there which make this text overlay not work as good.
It is just a very small thing I noticed , but I don't know how to change it ( if it is possible).

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

The file is saved with the cursor on the next line, basically instead of a 1 line txt, there are now 2 lines/rows , where 1 is empty. Blue iris still reads this second line and for the background ( to read the text better), the background is now 2 rows, which is not so good.

Is there a way that the txt files is saved with the cursor on the first line and no "enter" on the second line?

thanks,
Cor

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Getting data from a sensor in a file
« Reply #18 on: November 22, 2013, 07:38:34 am »
Try changing:
Code: [Select]
file:write(temperature .. "\176C\n")
to:
Code: [Select]
file:write(temperature .. "\176C")
The string \n is a new-line character.

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #19 on: November 22, 2013, 08:15:25 am »
@RexBeckett: thanks , that did the trick :-)

Cor

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #20 on: April 18, 2015, 11:37:42 am »
Time to adjust something here :-)

Writing these temperatures in a file works very well.
Unfortunately, with the blue iris programm you can only have 9 macro's 9 in my case 9 different temperature overlays.

I use this code  now that every temperature sensor will have his own .txt file
Code: [Select]
local devID = 128
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/blueiris/oatemp.txt", "w")
file:write(temperature .. "\176C")
file:close()

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

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

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

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


Is it possible to write all these variables in 1 files, and in a specific order, (below each other) ,like:

19,9 ?C
21 ?C
60 ?C




etc.

many thanks,
Cor

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Getting data from a sensor in a file
« Reply #21 on: April 18, 2015, 12:56:58 pm »
Quote
Is it possible to write all these variables in 1 files, and in a specific order, (below each other) ,like:

19,9 ?C
21 ?C
60 ?C

Yes that is easy to do:

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

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

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

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

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

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #22 on: April 18, 2015, 02:58:59 pm »
NICE!!!!! ;D

To makr it near perfect , After every variable there is now this " "\176C" code to make it de Celcius character. Is it possible to have before a variable the name of the variable  than the variable , than the Celcius sign?

Like this:

Bathroom  xx.x ?C

Thanks,
Cor

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Getting data from a sensor in a file
« Reply #23 on: April 18, 2015, 05:15:18 pm »
No problem. Just adjust the text in the following:

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

devID = 43
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bath Main " .. temperature .. "\176C")

devID = 48
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bath Up " .. temperature .. "\176C")

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

devID = 186
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Heizung " .. temperature .. "\176C")
file:close()

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #24 on: April 19, 2015, 07:17:41 am »
Hi RexBecket,

I just changed the LUUP code , but there is somewhere something wrong , the variables are not written below each other on the next line , but next to each other.

Like this:
Code: [Select]
Ambient 20?CBuffer 43?CBoiler 40?CWater 34?CBathroom Upstairs 12?CBathroom Downstairs 14?C
This is the LUUP code:
Code: [Select]
local devID = 186
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")

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

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

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

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

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


Is it possible to have it written on seperate lines?

Like this?
Code: [Select]
Ambient 20?C
Buffer 43?C
Boiler 40?C
Water 34?C
Bathroom Upstairs 12?C
Bathroom Downstairs 14?C


Many thanks,
Cor

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Getting data from a sensor in a file
« Reply #25 on: April 19, 2015, 07:26:18 am »
Quote
Is it possible to have it written on seperate lines?

Sure. Just add a newline character (\n) at the end of each output string. So replace "\176C" with "\176C\n" in each file:write(...) statement.

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #26 on: April 19, 2015, 08:45:03 am »
Cool  ;D,

It's working perfect, many thanks!
Cor

Offline Cor

  • Hero Member
  • *****
  • Posts: 1249
  • Karma: +8/-4
Re: Getting data from a sensor in a file
« Reply #27 on: November 18, 2016, 04:45:14 pm »
A little update,

I would also like to add the humidity. I tried to add this in the LUUP code , but it didn't work.

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 = 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 = 87
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
file:write("Bathroom Upstairs: " .. temperature .. "\176C\n")

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

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

file:close()

It is the bottom one which I would like to include with device # 79

Anyone sees what I am doing wrong?

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Getting data from a sensor in a file
« Reply #28 on: November 18, 2016, 05:48:20 pm »
This is certainly wrong...

Code: [Select]
devID = 79
temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentHumidity",devID)
file:write("Bathroom Downstairs: " .. humidity .. "\176C")

You would need instead...

Code: [Select]
devID = 79
humidity = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1","CurrentLevel",devID)
file:write("Bathroom Downstairs: " .. humidity .. "\176C")

...or something along those lines.

I haven't checked the whole thing, there may be others.

You need to understand where the serviceIds and variable names come from.  This would be a start: http://wiki.micasaverde.com/index.php/Luup_UPnP_Variables_and_Actions
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 #29 on: November 18, 2016, 06:24:06 pm »
Super!

Thanks, It works now.

Understanding all the coding  :o .... but it makes more sense now.

Cor