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

Time based switching


Question

Posted

Hi,

 

I am not new to Fibaro, but unfortunately don't know too much about LUA programming.

I have to operate a switch based on a schedule like this:

switch on every day at 6:00, and at 16:00 on workdays

switch off at 8:00 on workdays and every day at 23:59

 

What would be the most effective way of doing this? Can it be done in a single scene?

I would appreciate if you could point me to a similar topic or help me with a code segment.

 

Thanks,
Levente

5 answers to this question

Recommended Posts

  • 0
Posted (edited)

@lcseh  assume you have HC2

 

Please login or register to see this link.

 

As Sankotronic said: It is the only scene necessary to loop endlessly because it is the source of most important events generated on our gateways and that are time based events!

 

For example to control a switch, first simply create a manual scene like a switch toggle.

 

if ( fibaro:getValue(SwitchId, 'value') == "0" ) then

fibaro:call(SwitchID, "turnOn") else

fibaro:call(SwitchID, "turnOff")

end

 

Just in case you didn't understand above code.  When above scene is run, firstly it checks the switch state (on or off?) then press its opposite state. If off then on, or vice versa, acting like a On/Off switch. You may also create a VD with On Off Buttons to operate the switch you said, it's up to you.

 

Then setup your desired schedule inside MTBE scene.  It will run for you automatically. Depends on what you want to run, MTBE clearly separated each section.  Read instruction carefully how it is setup.

 

 

Edited by Sirhideo
  • 0
Posted (edited)
On 5/29/2018 at 6:31 PM, lcseh said:

Hi,

 

I am not new to Fibaro, but unfortunately don't know too much about LUA programming.

I have to operate a switch based on a schedule like this:

switch on every day at 6:00, and at 16:00 on workdays

switch off at 8:00 on workdays and every day at 23:59

 

What would be the most effective way of doing this? Can it be done in a single scene?

I would appreciate if you could point me to a similar topic or help me with a code segment.

 

Thanks,
Levente

Please login or register to see this code.

 

Edited by jgab
  • 0
  • Inquirer
  • Posted

    Thanks guys, I will give it a try today when I get back home. Appreciate your help. :-)

    • 0
  • Inquirer
  • Posted
    On 5/30/2018 at 11:47 AM, jgab said:

    Please login or register to see this code.

     

     

     

    I went and created a scene by pasting this piece of code, and changing the device ID to the one matching the switch, yet nothing happened. I have even restarted the HC2 last night, but now when I was checking, the power consumption showed that is was on all day. 

    How can I start debugging it?

    • 0
    Posted (edited)
    49 minutes ago, lcseh said:

     

     

    I went and created a scene by pasting this piece of code, and changing the device ID to the one matching the switch, yet nothing happened. I have even restarted the HC2 last night, but now when I was checking, the power consumption showed that is was on all day. 

    How can I start debugging it?

    Things happening with hours between them are a bit boring to debug :-)

    Ok, add a fibaro:debug("Starting") before the first 'every...' and make sure you start the scene. Then you at least know that the scene has started.

    Then comment out every 'every' statement and replace it with one single

    Please login or register to see this code.

    where HH:MM is a time in the near future (check what the clock is on the HC2), and start the scene and wait see if you get a HUPP! at the specified time.

    If that works, the other rules should work too.

    I've added some debug statements to the original post/code.

    The scene should be continuously running because it's based on timers that are re-invoked. No problems as it takes no CPU resources (better than the notorious fibaro:sleep)

    Btw, depending on your language/locale the workday function may not work as it has a dependency that '%a' returns weekday in english.

    Edited by jgab

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