The Vera Community forums have moved!

General => Temperature Monitoring & HVAC Control => Topic started by: Cor on August 21, 2013, 03:08:27 pm

Title: Getting data from a sensor in a file
Post by: Cor on August 21, 2013, 03:08:27 pm
Hello all,

I would like to get data (temperature for example) in a file , which another programm can read and use.

With the programm Blue iris it is possible to use data pulled from( I believe) a text file and overlay this on a camera view.
http://www.cam-it.org/index.php?topic=1965.0 (http://www.cam-it.org/index.php?topic=1965.0)

Is it possible to get data from a temperature sensor and save it to a file on a computer?
Most important would be temperature readout from a fibaro universal sensor. But I have also some eversping temperature and humidity sensors.

What are the possibilities?

Thanks,
Cor

(someone allready used Blue iris macro's to display data from a device on a camera view?)

Title: Re: Getting data from a sensor in a file
Post by: RexBeckett on August 21, 2013, 05:49:42 pm
The following Lua in a scene should append each new reading to the file /var/temperatures.txt. You could schedule the scene by interval or trigger it by some appropriate means. <deviceID> is the ID of your temperature sensor. You would need some mechanism to clear the file whenever you have collected the data.

Code: [Select]
local devID = <deviceID>
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/var/temperatures.txt", "a+")
file:write(temperature .. "\n")
file:close()

You could also make the file name /www/temperatures.txt and then you could inspect it from a browser using: <veraipaddress>/temperatures.txt (http://<veraipaddress>/temperatures.txt)
Title: Re: Getting data from a sensor in a file
Post by: Cor on August 21, 2013, 11:57:15 pm
@ RecBeckett;    I think that is very close to what I need.   Is it also possible not to append the data , but simply overwrite the data (2 digits) everytime.

Many  Thanks,
Cor

Title: Re: Getting data from a sensor in a file
Post by: RexBeckett on August 22, 2013, 01:47:11 am
If you change the file mode in the io.open(...) statement from "a+" to "w" then the file will contain only the last reading.
Title: Re: Getting data from a sensor in a file
Post by: Cor on August 22, 2013, 10:40:00 am
WOW!!!! , Works great,I changed the code like you said:
Code: [Select]
local devID = 122
local temperature = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",devID)
local file = io.open("/www/temperatures.txt", "w")
file:write(temperature .. "\n")
file:close()

and when I click it it makes the temperature.txt file, which I can check via a browser ...GREAT!! :-)

Some more questions;

-When I made the scene it gave me in the middle top part in blue in the GUI an "error in LUUP file"    but it is working fine...... something to worry about?

- The plan is to have in totall 5 of those scenes running 24/7 every 10 minutes or so , will this affect the performance of vera3 and the activation of other scenes and devices ( This should be a low priority scene, If it is not refreshed I will be quite happy when it does in the next round).


I will conitnue to post the progress , maybe helpfull for other people who want to use this feature of Vera in Blue iris.

Cor
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett on August 22, 2013, 01:34:41 pm
Quote
-When I made the scene it gave me in the middle top part in blue in the GUI an "error in LUUP file"    but it is working fine...... something to worry about?
You should not get any errors when you save the scene. I pasted the Lua from your post into a new scene and I do not get any errors. It also works. Check you don't have any stray characters, spaces or blank lines in your Luup window.

Quote
- The plan is to have in totall 5 of those scenes running 24/7 every 10 minutes or so , will this affect the performance of vera3 and the activation of other scenes and devices ( This should be a low priority scene, If it is not refreshed I will be quite happy when it does in the next round).
This code will have very little impact on Vera performance.

Are you going to be logging to five separate files? I suppose you must otherwise you will step on your previous reading. Why do you need five different scenes? You could do it all in one scene.
Title: Re: Getting data from a sensor in a file
Post by: Cor on August 22, 2013, 02:22:36 pm
@RexBeckett:   I am getting very close.  ;D   So much fun !

Attached allready a screenshot, it is the data on the left , the number "19"

Some more questions ;D

It seems that blue iris macro-option can only read from a local HD and not read the file from the network. Can the file be written to a computer on the LAN?  The computer which runs blue iris has Ip adress 10.0.0.20 and the file should be saved on C:\Blueiris\macro\temperature.txt

In the attachement you see it nicely ads the digits from the file ( as a test I copied the temperatures.txt to the computer which runs blue iris.)  Is it possible to add text via the LUUP code as well?, Ideally it would be  nice if the digits would be fetched and next to it "degrees C" would be written. like this (In blue iris I can only add text in front of the variable:
Code: [Select]
20 degrees C.

Your suggestion to use just 1 scene , that would make it much easier , That would mean to copy paste this LUUP code 5 times in a row with the different Device ID and txt file?     But I guess I cannot simply copy paste this code 5 times in a row  :-\   What would be the correct code?

Again , many many thanks,
Cor



Title: Re: Getting data from a sensor in a file
Post by: RexBeckett on August 22, 2013, 04:03:24 pm
Quote
It seems that blue iris macro-option can only read from a local HD and not read the file from the network. Can the file be written to a computer on the LAN?
That is not so easy. It depends on what facilities your other system has. You may be better finding a way to get your remote machine to pull the file from Vera's web server.

Quote
Is it possible to add text via the LUUP code as well?, Ideally it would be  nice if the digits would be fetched and next to it "degrees C" would be written.
That bit is easy:
Code: [Select]
file:write(temperature .. " degrees C\n")
Quote
But I guess I cannot simply copy paste this code 5 times in a row
If you are reading different temperature variables and writing to different files then you would, basically, paste the code five times and edit the device ID and file name.
Title: Re: Getting data from a sensor in a file
Post by: Brientim on August 22, 2013, 04:24:10 pm
If you wanted to visualise the data recorded directly in vera, you could also write to a variable container.  The  VC app allows you to capture 5 variables which seems to also meet the requirements.
Title: Re: Getting data from a sensor in a file
Post by: Cor on August 23, 2013, 12:07:20 am
@ RexBeckett,  The machine which runs Blue iris is an Intel I5 on the same LAN (computer is 10.0.0.20 , vera3 is 10.0.0.10). I can install a programm there to pull the file from vera ..... But how? , are there programms for that,or can that be done with a (simple) batch file? For the moment I was only able to copy the txt-file to the computer via winscp.

Tonight when I am back behind the computer I will try the "degrees C"  ... many thanks.

@ Brientim: thanks for the suggestion , doing it via the LUUP code is almost complete, I think I will continue using this ....  but that VC APP,I cannot not find that in the app list , it is a vera plugin?

Cor
Title: Re: Getting data from a sensor in a file
Post by: Brientim on August 23, 2013, 12:35:23 am
You can find the app here:
http://apps.mios.com/plugin.php?id=1458

The forum is here:
http://forum.micasaverde.com/index.php?topic=9022.0

Using this you will still need to use luup to write to the variable container.
Title: Re: Getting data from a sensor in a file
Post by: SOlivas on August 23, 2013, 01:33:53 am
Cor,
If you are using winscp, check out this on scripting it:

http://winscp.net/eng/docs/scripting

And here is an example of how to automate it:

http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett on August 23, 2013, 03:57:12 am
I think WinSCP is going to be your easiest route as @SOlivas suggests. You already have a connection profile established so a simple script to change local and remote directories and get the remote file should take care of it.
 
BTW: You could make your display string more compact by replacing degrees with the symbol:

Code: [Select]
file:write(temperature .. " \176C\n")
Title: Re: Getting data from a sensor in a file
Post by: Cor on August 24, 2013, 06:24:15 pm
Slowly I am getting there.

@Brientim: cool plugin , I will not use it for this project , but I can use it for something else .... thanks for the tip.
@ SOlivas & RexBeckett ...... pffff it's difficult;

I am trying that script http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/ (http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/) , But I need to change it a bit;
This is the script from that website:
Code: [Select]
1 option batch continue
2 option confirm off
3 open lab-net-01
4 lcd C:\FTP
5 synchronize both -delete
6 synchronize both C:\FTP /
7 exit

As I understand it, it syncs both ways....not good ,I need to sync it from remote to local.

I changed here and there some bits,
These are some options of the scipts: http://winscp.net/eng/docs/scriptcommand_synchronize#syntax (http://winscp.net/eng/docs/scriptcommand_synchronize#syntax)
Code: [Select]
option batch continue
option confirm off
open vera3
lcd C:\blueiris\macro\files
synchronize local -delete
synchronize local C:\blueiris\macro\files /www\blueiris
exit

It is working  , but I am not sure if it is correct,can someone take a look at it (line 5 and 6)?
I want the files from vera to the local directory C:\blueiris\macro\files ( what does the line "synchronize local -delete" do? )

The other issue I have ,is the directory in vera. I created the directory blueiris in vera www\blueiris
( see attachment) , but when I run the LUUP code , the oatemp.txt is not created;
Luup 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()

Is there something wrong with the directory I created? or something else?
When I remove </blueiris>, it works and the txt file is created in the www directory, but I need it in a seperate directory since the script wants to copy otherwise all files.

Many thanks again ,
Cor
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett on August 24, 2013, 07:01:36 pm
To get a single file from Vera, try this:
Code: [Select]
option batch continue
option confirm off
open vera3
lcd C:\blueiris\macro\files
cd /www
get oatemp.txt
exit

How did you create your directory in /www? I just tried it out and it works just fine. I created the directory by clicking F7 - Create Directory and then changed the pathname in the Lua accordingly. Using a folder would allow you to synchronize multiple files with a single command but it wouldn't be any quicker than putting multiple get commands in the script. Personally, I would use individual get <filename> lines in the WinSCP script.

Edit: A new thought: Did you refresh WinSCP's display after running the Vera scene? A new file will not show-up in the list unless you click on the refresh icon or hit ctrl-R.

You don't need to delete the Vera files with the WinSCP script as they are overwritten whenever the Vera script runs. There is probably more overhead in deleting and recreating a file than in just rewriting its only record.
 
Title: Re: Getting data from a sensor in a file
Post by: Cor 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/ (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
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett 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.
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett 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.
Title: Re: Getting data from a sensor in a file
Post by: Cor on November 22, 2013, 08:15:25 am
@RexBeckett: thanks , that did the trick :-)

Cor
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett 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()
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett 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()
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: RexBeckett 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.
Title: Re: Getting data from a sensor in a file
Post by: Cor on April 19, 2015, 08:45:03 am
Cool  ;D,

It's working perfect, many thanks!
Cor
Title: Re: Getting data from a sensor in a file
Post by: Cor 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?
Title: Re: Getting data from a sensor in a file
Post by: akbooer 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
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: sre 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 ?
Title: Re: Getting data from a sensor in a file
Post by: akbooer 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.
Title: Re: Getting data from a sensor in a file
Post by: sre on November 20, 2016, 09:11:24 pm
Thanks @akbooer.  It was really valuable information
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: akbooer on January 16, 2017, 12:23:43 pm
...so what errors are shown in the log?
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: akbooer 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?
Title: Re: Getting data from a sensor in a file
Post by: Cor 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
Title: Re: Getting data from a sensor in a file
Post by: Cor 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()
Title: Re: Getting data from a sensor in a file
Post by: Cor 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.
Title: Re: Getting data from a sensor in a file
Post by: Don Phillips 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.