Soom Luup coding needed

Hij there

I am looking a piece of luupcode to read out the value from the rainmeter and put it on a virtual rainmeter or other solution to read out the daily values.
My rainmeter only shows total rain it ever recorded. I would like to see today’s rain…
Can someone help me?

Attached the Rainmeter.json file which you could use.
I think the value showing my total rain is: luup.variable_get(“urn:upnp-org:serviceId:serviceId:RainSensor1”,“CurrentTRain”, 279)

Any help would be apriciated

You could create a virtual Rain Meter - using the same device_file as the real one. Then create a new scene with the following code in the LUUP tab. Schedule the scene to run at the time when you want the daily figure updated.

local dIDR = 279 -- Device ID of Rain Meter local dIDV = 123 -- Device ID of virtual Rain Meter local newTRain = luup.variable_get("urn:upnp-org:serviceId:RainSensor1","CurrentTRain", dIDR) or 0 local lastTRain = luup.variable_get("urn:upnp-org:serviceId:RainSensor1","LastTRain", dIDR) or 0 local dailyRain = tonumber(newTRain) - tonumber(lastTRain) luup.variable_set("urn:upnp-org:serviceId:RainSensor1","LastTRain",newTRain, dIDR) luup.variable_set("urn:upnp-org:serviceId:RainSensor1","CurrentTRain",dailyRain, dIDV)

Change the value of dIDV to the device number of your virtual Rain Meter.

Edit: 28/02/2015 08:53 Fixed typos.

Thank you!!!
One question. how can I create a virtual rainmeter or can I show this value in my current meter?

One question. how can I create a virtual rainmeter

Click Apps → Develop apps → Create device. Copy from your existing device’s Advanced tab the values for the fields Device type and Upnp Device Filename. Enter a suitable name in Description then click Create device. Reload Luup and refresh your browser page and you should see the device.

Thank you, very much apreciated.!

Hi TwannieM,

What rainmeter do you have ? I have a TFA 30.3148 meter and I have the same request as you have. I also want to see the daily values. Did you already succeed in the solution provided by RexBeckett ?

I am not sure, i bought it along with a homewizard.
I think it is a TFA

I will have a look and when I found a nice solution i will post it… i a bit new a this so give me some time ::slight_smile:

I also bought it at Homewizard, it’s the TFA 30.3148. I will also try to find a solution. My preference is to adapt the current device and not create an extra virtual rain sensor. I will also post my experiences.

Hello Rex

Can’t I create a new variable to be set in the current rainmeter?

[quote=“TwannieM, post:9, topic:186112”]Hello Rex

Can’t I create a new variable to be set in the current rainmeter?[/quote]

You can but, unless you change the device json file, it will only be displayed on the Advanced tab.

The json file would not be a problem… i will give it a try

Hello RexBeckett and TwannieM,

I managed to get it to work in the current rainmeter, without changing the json file. I saw in the json file that the variable that displays the value for Current rain in the UI of the device is “CurrentRain”. Then I adapted the code of RexBeckett as follows:

[code]local RegenmeterID = 230 – TFA regenmeter
local allow = true

local newTRain = luup.variable_get(“urn:upnp-org:serviceId:RainSensor1”,“CurrentTRain”, RegenmeterID) or 0
local lastTRain = luup.variable_get(“urn:upnp-org:serviceId:RainSensor1”,“LastTRain”,RegenmeterID) or 0

local dailyRain = tonumber(newTRain)-tonumber(lastTRain)

luup.variable_set(“urn:upnp-org:serviceId:RainSensor1”,“LastTRain”,newTRain,RegenmeterID)
luup.variable_set(“urn:upnp-org:serviceId:RainSensor1”,“CurrentRain”,dailyRain,RegenmeterID)
[/code]

I put this code in a scene with a daily schedule at Sunrise. This morning I saw the daily rain correctly displayed in the UI of the rainmeter device in Vera and also in the apps I use (Imperihome and Veramate).
And I also made a graph in the Datamine plugin of both daily rain and total rain.

PS 1: “Regenmeter” = rainmeter in Dutch
PS 2: There were some small mistakes in the code that RexBeckett posted: 2 times “serviceId:serviceID:” and one time “LastTRain” i.s.o. “lastTRain”

Nevertheless: thank you very very much RexBeckett you were of great help!!

excellent, thabks!

Thanks, I noticed the extra field to
One is CurrentTrain and the other currentrain… probably this is for other brand rainmeter.

did not work

it created 2 new variableles in my device
variabele 1 and variabele LastTrain

also when i think about this, how would the rain for today be added up?

[quote=“TwannieM, post:14, topic:186112”]did not work

it created 2 new variableles in my device
variabele 1 and variabele LastTrain

also when i think about this, how would the rain for today be added up?[/quote]

Check the serviceId and variable names in the code against those in the json. There were typos in my code. I don’t know about @Mai Pensato’s. I don’t have the device so I test it.

For me it works…now for second day the daily rain is calculated and displayed correctly. You have to indeed check your code very well, it’s case sensitive. I copy/pasted my code so it should be OK ?
You have to see the following three variables in the advanced tab of your rain meter:
And it’s important to have a schedule in your scene that triggers it once per day on a fixed time (I took Sunrise)

CurrentTRain : existing one showing the total rain in mm and updated every time new rain is registered
LastTRain : new one that every day (when scene runs) sets the value of CurrentTRain at that moment
CurrentRain : new one where every day the difference between CurrentTRain (actual value) and LastTRain (value of day before) is set

In this way you see every morning the rain of the day and night before.

Off course you can adapt it to know rain of last month or last hour…

After copy and past you code it created an extra field “1” in the variables list
(When I mouseover it states “RainToday”, see images) that was not there before

@TwannieM, copy and paste the code back from your scene LUUP tab. Something must be corrupted…

? am not shure as i had to restore a backup but i saved the code in a textfile

local RegenmeterID = 279
local allow = true

local newTRain = luup.variable_get(“urn:upnp-org:serviceId:RainSensor1”,“CurrentTRain”, RegenmeterID) or 0
local lastTRain = luup.variable_get(“urn:upnp-org:serviceId:RainSensor1”,“LastTRain”,RegenmeterID) or 0

local dailyRain = tonumber(newTRain)-tonumber(lastTRain)

luup.variable_set(“urn:upnp-org:serviceId:RainSensor1”,“LastTRain”,newTRain,RegenmeterID)
luup.variable_set(“urn:upnp-org:serviceId:RainSensor1”,“CurrentRain”,dailyRain,RegenmeterID)

I do’n understand something
This code resets todays rain but, how is the Current Rain filed updated when rain is falling?