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


  • 0

Need help PLEASE - Calculating Temperature


benjamins

Question

Hi all,

 

I need help for a (tricky) thing:

I added 2 underwater temperature sensors on my Fibaro smart implant.

 

Now i need to calculate the middle value of both sensors over a.e. two days.

Example:

-Sensor 1:  8 degree on day 1 and day 2

-Sensor 2: 10 degree on day 1 and day 2

- middle value: 9 degree

 

This value should trigger a global variable like "summer" - for middle value >8 degree and "winter" for middle value <8 degree.

I need this to know when i have to feed winter pellets for my kois and to trigger a scene that switches my pond pumps.

 

I´m not really good into lua. I thought about to adapt other scripts that calculate time or to build a table that stores the values and triggers a global variable or maybe to use a virtual device but... What should I say? - I´m a noob :D

Also searched different keywords in this forum and searched with google but i didn´t found a scipt that does this.

 

It would be so nice if anyone can help me with this. I feel really sad that I don´t get it.

 

Benjamin

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
19 hours ago, benjamins said:

It would be so nice if anyone can help me with this. I feel really sad that I don´t get it.

 

Benjamin

 Could look something like this - not exactly sure how you want to calculate the value and how often you want to sample the sensors - the value for a day, is it mean, max or min values? Daytime or whole day? In the example below it’s just the average over the last 48 hours.

Please login or register to see this code.

You need to create fibaro global "season" and "samples" (or other names you make up)

And set SENSOR1/SENSOR2 to the deviceIDs of the sensors

Edited by jgab
  • Like 1
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Wow! Thank you so much!

    I understand what your script likes to to (only until calculate average ? but I´m shure I never get it by myself ?)

    You´re right - I only need average over 48 hours.

     

    I copied script and changed sensor ID´s but debug shows error:

    [DEBUG] 18:30:26: 2019-10-02 18:30:26.445453 [ fatal] Unknown exception: /opt/fibaro/scenes/87.lua:31: 'do' expected near 'then'

    Of course, I can´t figure out why this error appears...

     

    I added global variable "season" with "summer" and "winter"

    Did I understand you right that i only have to add simple variable without predefinied value "sample"?

     

    Thanks again for your quick help with this.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
    30 minutes ago, benjamins said:

    Wow! Thank you so much!

    I understand what your script likes to to (only until calculate average ? but I´m shure I never get it by myself ?)

    You´re right - I only need average over 48 hours.

     

    I copied script and changed sensor ID´s but debug shows error:

    [DEBUG] 18:30:26: 2019-10-02 18:30:26.445453 [ fatal] Unknown exception: /opt/fibaro/scenes/87.lua:31: 'do' expected near 'then'

    Of course, I can´t figure out why this error appears...

     

    I added global variable "season" with "summer" and "winter"

    Did I understand you right that i only have to add simple variable without predefinied value "sample"?

     

    Thanks again for your quick help with this.

     

     

    Sorry, I changed a for loop to a while loop and missed the 'do' keyword in

    Please login or register to see this code.

    I changed the original post.

    and spelled 'samples' wrong -fixed.

     

    Yes, you don't need predefined values.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • You don´t have to be sorry for your help :D

     

    Ok i changed code and also changed

    Please login or register to see this code.

    there is a "p" missing in third samples. Only for everyone else that uses your code...

     

    Do I have to fill new variable "samples" with a value or why does debug say that samples is nil?

    Quote

    [DEBUG] 19:07:45: Sensor1: 14, Sensor2: 13
    [DEBUG] 19:07:45: 2019-10-02 19:07:45.730758 [ fatal] Unknown exception: /opt/fibaro/scenes/87.lua:27: attempt to get length of local 'samples' (a nil value)

     

    Sorry to bother you but without your help...

     

    Quote

    [DEBUG] 19:16:16: Sensor1: 14, Sensor2: 13
    [DEBUG] 19:16:16: 2019-10-02 19:16:16.926241 [ fatal] Unknown exception: /opt/fibaro/scenes/87.lua:27: attempt to get length of local 'samples' (a number value)

     

    Link to comment
    Share on other sites

    • 0
    14 minutes ago, benjamins said:

    You don´t have to be sorry for your help :D

     

    Ok i changed code and also changed

    Please login or register to see this code.

    there is a "p" missing in third samples. Only for everyone else that uses your code...

     

    Do I have to fill new variable "samples" with a value or why does debug say that samples is nil?

     

    Sorry to bother you but without your help...

     

     

    That's strange. Can you post the whole scene as it looks now for you?

     

    To be real safe that samples doesn't contain some old value, you could add the third line in function sample()

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Please login or register to see this code.

    This works!

    I added debug into "set global" for summer and winter.

    Quote

    Please login or register to see this code.

     

     

    Thanks alot for this nice piece of coding. I was trying to fin a solution along 4 month ?

    • 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.

    ×
    ×
    • Create New...