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

Heating scene with timeofday variable - SIMPLE LUA


Question

Posted

Thanks to petergebruers for the involment on this.

I put it here as its working, and maybe someone might want to use.

For me, i use it to set when the heater should go on/off, depending on time of day and a temperature device. Instead of using a built in thermostat. I will add some more stuff to it later on.

Change value 72 for your own temperature meassurment device id.

Change value 79 for your heating device

In this example i set the heater to start when temperature is under 20 degrees and turn off when over 21 degrees. This to avoid it from going on/off like crazy. And also to be off during night. Later i will probably add some presence in house etc. Once i feel its a usefull thing.

This one will need a

Please login or register to see this link.

of time_of_day.

Please login or register to see this code.

10 answers to this question

Recommended Posts

  • 0
Posted

Two misplaced ")". Fixed in this version:

Please login or register to see this code.

  • 0
  • Inquirer
  • Posted

    Thank you very much.

    I see where you fixed them.

    Is there a reason for you to move the code this far to the right? Is there some spesific to this or is it mostly just to seperate them for view? Like can i just space it as much or little as i want?

    Only thing i see is that you have "capsule" some of the code.

    • 0
    Posted

    The layout is for readability only. I put the 'or' on separate lines for readability too. To be honest, the indentation didn't cost me very much effort

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" /> Just select all then press SHIFT-TAB in editor. It'll help find those unbalanced brackets...

    • 0
  • Inquirer
  • Posted
    The layout is for readability only. I put the 'or' on separate lines for readability too. To be honest, the indentation didn't cost me very much effort

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" /> Just press SHIFT-TAB in editor. It'll help find those unbalanced brackets...

    Ok, thank you anyway

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" /> Its strange, but once iv change some over from box to LUA, they are less buggy for some reason, dont ask me why. And i try to learn from the box setting and transfer it over to LUA, learning that way. Also hope the scene display will become less messy having less but bigger LUA codes instead.

    I will keep all you wrote in mind

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    [ Added: 2015-01-05, 13:20 ]

    Hmm. It seems this is not working the temperature is now 19.5 degrees here and it should start. but it just doesn't any reason for this? Is the code wrong?

    • 0
    Posted

    The comparison <= 20 degrees seems correct to me. And the script runs when the value of device ID 5 changes. And it also runs when the global variable is changed by som other code. Triggering with global variables only works from code, not when you change the variable in the variable panel. So... If temperature hasn't changed since you last saved this scene, and the global variable hasn't changed, nothing wil happen. But when device 5 reports a higher or lower temperature, your script will run.

    If I were you, I'd remove this:

    Please login or register to see this code.

    Because it wil turn on ID 35, executing none of your other logic, when you press "start". Without this, you can press "start" to simulate that either ID 5 or the global variable changed, following your logic

    If that doesn't help, it's time to sprinkle some

    Please login or register to see this code.

    throughout your code and watch what's happening.

    • 0
  • Inquirer
  • Posted

    OK. Cause this code was alway there from the box setting. thought it needed to be there for some unknown reason.

    Please login or register to see this code.

    So can i remove this line from all other codes too?

    Your last debug code there, what does that do? and where do i put it?

    • 0
    Posted

    I have my own style of coding, feel free to adopt it or not

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Like Krikroff said in another post, it can be wise to put this right after the header

    Please login or register to see this code.

    But because this script executes very fast, changes of triggering twice are low.

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Thank you very much i really like your coding. it looks so readable for me.

    Though i have to experiment a little of the debug stuff to understand how it work for me to later use on my own.

    The debug in the end is there in case it goes wrong right?

    and if i add

    Please login or register to see this code.

    Then i will also get a debug when that variable was triggered right or?

    • 0
    Posted

    The "else fibaro:debug ("I don't etc..." is there in case you have forgotten about this code... maybe after a year or so

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" /> Then you'll add a new value to the variable and debug will tell you about it. Of course, this makes more sense for longer scripts with deeper nested if/then/else. The extra typing aside, there is no downside in doing it this way.

    Yes, you will get debugging from the code you wrote ("Sunny_Cloudy = etc..."). Beware that this logging is there in the web interface, when you look at the scene. As far as I know, it is not (yet) possible to write things to a more permanent log or to the event panel.

    • 0
  • Inquirer
  • Posted
    The "else fibaro:debug ("I don't etc..." is there in case you have forgotten about this code... maybe after a year or so

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" /> Then you'll add a new value to the variable and debug will tell you about it. Of course, this makes more sense for longer scripts with deeper nested if/then/else. The extra typing aside, there is no downside in doing it this way.

    Yes, you will get debugging from the code you wrote ("Sunny_Cloudy = etc..."). Beware that this logging is there in the web interface, when you look at the scene. As far as I know, it is not (yet) possible to write things to a more permanent log or to the event panel.

    Aha!

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" /> Thank you very much. I already did some changes added some more stuff etc.

    Its strange, you don't always know what you need. I know i need the XBMC integration in some way. Cause i want a different scene when i watch movies etc.

    And also how will i do that cause when i was watching a movie now, in the middle of the movie "Night" came active and turned on some lights i had turned off during the movie...

    [ Added: 2015-01-06, 10:14 ]

    For some reason the heating scene did not start this morning. Is there something wrong?

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" />

    I added some debug to it and it says its "morning" and "autostart". but it just wont start... maybe having both on and of in same code is bad? or i seperate it wrong.

    Please login or register to see this code.

    [ Added: 2015-01-06, 10:34 ]

    I think i got it working. I think it was something to do with seperation of code or something. But the heater suddenly started again

    Please login or register to see this image.

    /emoticons/default_icon_razz.gif" alt=":-P" /> Lets just hope it will work further on...

    Please login or register to see this code.

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