Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 3

SCENE. How to write to InfluxDb


10der
 Share

Question

Please login or register to see this code.

 

a special thanks @tinman ?

 

 

Please login or register to see this attachment.

 

Please login or register to see this attachment.

 

 

 

 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Recommended Posts

  • 0

i just dont know, how would the line be if the ID would be 220

 

line 77 and 78 ?

 

 local roomID = 220
    local room = api.get("/rooms?id="..roomID)

 

results in

 

[17.08.2021] [16:36:58] [ERROR] [SCENE73]: /opt/fibaro/lua_engine/lua/engine/fibaro_sdk.lua:236: Assertion failed: Expected number

Edited by ppeterr
Link to comment
Share on other sites

  • 0

Please login or register to see this code.

 

Something is happening in this part of the code. If I look at Swagger, maybe change to:

 

Please login or register to see this code.

 

If that doesn't help, maybe change (for testing purpose) this line to:

 

Please login or register to see this code.

(brute force :-) )

Link to comment
Share on other sites

  • 0

Uhmm almost, i now get a empty error :) joehoe

 

function saveByDeviceID(measurement, deviceID, property)
    property = property or "value"
    local roomID = 220
    local room = api.get("/rooms/"..roomID)
    local section = api.get("/sections/"..room.sectionID)
    local value = fibaro.getValue(deviceID, property)
    saveToInflux(measurement, value, deviceID, fibaro.getName(deviceID), "default", "default")
 
 
[17.08.2021] [16:58:46] [ERROR] [SCENE73]:  joehoe, nee die error stond hier niet :P
Link to comment
Share on other sites

  • 0

this is what i have now, forced to room id 220. And edited a few id's

 

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0

And it works?

 

 

1 hour ago, ppeterr said:

this is what i have now, forced to room id 220. And edited a few id's


@10der would turn around in its digital grave 😬 You better look out, he is like Drakula, sometime he is back 👻
 

 

 

Edited by SmartHomeEddy
Link to comment
Share on other sites

  • 0
38 minutes ago, SmartHomeEddy said:

And it works?

 

 


@10der would turn around in its digital grave 😬 You better look out, he is like Drakula, sometime he is back 👻
 

 

 

 

Well, bite me. It doesnt work :)

 

Or at least, if this is the output i need.....

[17.08.2021] [19:10:27] [ERROR]

Anyway, for this day...i'm done....time flies when doing stuff like this.

 

Link to comment
Share on other sites

  • 0
5 hours ago, SmartHomeEddy said:

Maybe put some debug messages in the code, to see what is happening 

 

Started fresh, again it failed to get the room ID. Removed the line 

local roomID = fibaro.getRoomID(deviceID) again. So it uses the room id 200.

 

Again it ends up with.

 

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0

when i add 

Please login or register to see this code.

 

after

 

Please login or register to see this code.

it results in

 

8086://192.168.1.134/write%3Fdb%3Dpi

 

Makes me a little confused 😐

 

So, i changed that to

 

local url = "http://" .. host .. ":".. port .. "/write" .. urlencode("?db=" .. dbName)

 

And it works....is this topic a test or somthing :P come on.....

Edited by ppeterr
Link to comment
Share on other sites

  • 0

@SmartHomeEddy

 

So, i have it running. Now i need to set the declaration for the scene. I was thinking to set some

timer, run every 15mins, and also a refresh in grafana for 15 mins. How do you do it, and how would 

the declaration look like. I tried to make one in a block scene, but it seems i cant make a timed declaration

with that. Or better. Only a timer.

 

How do you have this sorted ?

 

@10der

 

I'd like to thank you for this script. Thanks!

 

Could you explain to me why the local url syntax is formatted to start with the port ?

I changed it, now it works. But it seems not to work as it is in the openings post.

Edited by ppeterr
Link to comment
Share on other sites

  • 0
  • Inquirer
  • 30 minutes ago, ppeterr said:

    Could you explain to me why the local url syntax is formatted to start with the port ?

    I changed it, now it works. But it seems not to work as it is in the openings post.

    Fibaro playing with url format

    at first time this format for Fibaro was ok

    after some time Fibaro changed url format to normal

    so you right 

    Link to comment
    Share on other sites

    • 0
    3 minutes ago, 10der said:

    Fibaro playing with url format

    at first time this format for Fibaro was ok

    after some time Fibaro changed url format to normal

    so you right 

     

    Thanks for clearing that up.

    Link to comment
    Share on other sites

    • 0

    I am trying to use this code and I get this error:

    {"data":"404 page not found\n","status":404,"headers":{"Connection":"close","Date":"Tue, 07 Dec 2021 10:15:56 GMT","Content-Length":"19","X-Influxdb-Version":"1.8.10","X-Influxdb-Build":"OSS","X-Content-Type-Options":"nosniff","Content-Type":"text\/plain; charset=utf-8"}}

    Link to comment
    Share on other sites

    • 0

    Also working on the integration with Influx/Grafana.

     

    I tried the script of @10der and @hater and they both work. I found that 10der is using the current timestamp and hater uses the timestamp of the last change of the value (supplied by the device). I think hater his solution is a better one, it will save a lot of space in the database as far as I can see.

     

    But I run into 1 issue. Timestamp. Both scripts will give an incorrect timestamp, sometimes just a random number but most of the time value is is getting negative. Does not matter what kind of multiplication I add (script is doing *1000000000, also tried * 2 by example). So I am a little lost. If I remove the multiplication Unix Epoch Timestamp is written correctly to Influx DB in seconds.

     

    Grafana expect the value to be in milliseconds, I suppose that is the reason to multiply the value. But as it is not working..

     

    Anybody has a clue?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Ps: grafana != influx ;) 

    By default, InfluxDB returns the timestamp in nanosecond Unix time
    otherwise please RTFM 

    Please login or register to see this link.

    Link to comment
    Share on other sites

    • 0
    59 minutes ago, 10der said:

    Ps: grafana != influx ;) 

    By default, InfluxDB returns the timestamp in nanosecond Unix time
    otherwise please RTFM 

    Please login or register to see this link.


    But what is the reason to do a *1000000 in LUA which results in a negative value?

    Link to comment
    Share on other sites

    • 0
    13 hours ago, B_b_B said:

    I tried the script of @10der and @hater and they both work. ...

    I think hater his solution is a better one.

    You shouldn't say that - his schizophrenia will get worse ;-) 

    • Like 2
    Link to comment
    Share on other sites

    • 0
    4 minutes ago, jgab said:

    You shouldn't say that - his schizophrenia will get worse ;-) 

    At this moment I even want to hand over some beers to help me out ;)

    Link to comment
    Share on other sites

    • 0
    12 minutes ago, B_b_B said:

    At this moment I even want to hand over some beers to help me out ;)

    The solution seems to be in the url that @10der posted. Remove the 10^6 multiplication and add the precision field to the url in sendDataToInflux. - or better, make it a parameter.

    • Like 1
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

     Share

    ×
    ×
    • Create New...